:root {
  color-scheme: light;
  --ink: #172326;
  --muted: #607175;
  --line: #d9e1df;
  --paper: #f7faf8;
  --panel: #ffffff;
  --teal: #1d6f73;
  --teal-dark: #183c3f;
  --coral: #c65f46;
  --gold: #c59a39;
  --green: #3f7f54;
  --blue: #395f9d;
  --shadow: 0 18px 45px rgba(27, 45, 44, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #eef5f0 0%, #f8faf7 44%, #f5f0e9 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  background: #102f32;
  color: #eef8f4;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f2c56f;
  color: #153335;
  font-weight: 900;
}

.brand strong, .brand span {
  display: block;
}

.brand span, .storage-panel span {
  color: #bad1cc;
  font-size: 0.86rem;
}

.nav-list {
  display: grid;
  gap: 7px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  padding: 12px;
  background: transparent;
  color: #e9f4f0;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 11px;
}

.nav-item.active, .nav-item:hover {
  background: rgba(255, 255, 255, 0.12);
}

.nav-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
}

.storage-panel {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  display: grid;
  gap: 10px;
}

.storage-panel strong {
  font-size: 0.95rem;
}

.storage-actions {
  display: flex;
  gap: 8px;
}

.import-label input {
  display: none;
}

.main-content {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.topbar h1, h2, p {
  margin: 0;
}

.topbar h1 {
  font-size: clamp(1.7rem, 3vw, 2.6rem);
  letter-spacing: 0;
}

.eyebrow {
  color: var(--coral);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.top-actions, .form-actions, .toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.primary, .ghost, .danger {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}

.primary {
  background: var(--teal);
  color: #fff;
}

.ghost {
  background: #fff;
  color: var(--teal-dark);
  border-color: var(--line);
}

.danger {
  color: #9d3528;
}

.small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.88rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric, .panel {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(169, 187, 183, 0.7);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  min-height: 104px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}

.metric span {
  color: var(--muted);
  font-weight: 700;
}

.metric strong {
  font-size: 2rem;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 16px;
}

.panel {
  padding: 18px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-heading h2 {
  font-size: 1.14rem;
}

.group-board, .compact-list, .people-list, .group-list {
  display: grid;
  gap: 10px;
}

.group-card, .person-row, .compact-person, .group-config, .schedule-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.group-card {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.group-color {
  width: 10px;
  height: 100%;
  min-height: 48px;
  border-radius: 4px;
}

.group-card p, .person-row p, .compact-person p {
  color: var(--muted);
  font-size: 0.9rem;
}

.toolbar {
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

input, select, textarea {
  width: 100%;
  border: 1px solid #cdd9d6;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  outline: 0;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(29, 111, 115, 0.12);
}

.org-stage {
  overflow: auto;
  min-height: 640px;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(24, 60, 63, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, rgba(24, 60, 63, 0.06) 1px, transparent 1px);
  background-size: 34px 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.org-chart {
  min-width: 880px;
  display: grid;
  justify-items: center;
  gap: 28px;
}

.org-level {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 42px 18px;
  width: 100%;
}

.org-level:not(:first-child)::before {
  content: "";
  position: absolute;
  top: -22px;
  left: 10%;
  right: 10%;
  height: 1px;
  background: #9bb2ae;
}

.person-card {
  position: relative;
  width: 205px;
  min-height: 126px;
  border: 1px solid #cbd8d4;
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  text-align: left;
  box-shadow: 0 10px 25px rgba(29, 47, 44, 0.1);
}

.person-card::before {
  content: "";
  position: absolute;
  top: -23px;
  left: 50%;
  height: 22px;
  width: 1px;
  background: #9bb2ae;
}

.org-level:first-child .person-card::before {
  display: none;
}

.avatar-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.avatar, #photoPreview {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  background: linear-gradient(135deg, #dfecd9, #f2c56f);
  flex: 0 0 auto;
}

.avatar.initials {
  display: grid;
  place-items: center;
  color: #153335;
  font-weight: 900;
}

.person-card strong, .person-row strong, .compact-person strong {
  display: block;
  overflow-wrap: anywhere;
}

.person-card span {
  color: var(--muted);
  font-size: 0.85rem;
}

.person-card .badge {
  margin-top: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: #edf3f0;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 900;
}

.people-list {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.person-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.person-actions, .dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 10px;
  color: var(--teal-dark);
  text-decoration: none;
  font-weight: 800;
  background: #fff;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(310px, 0.8fr);
  gap: 16px;
}

.form-panel {
  display: grid;
  gap: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.photo-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.file-control {
  width: fit-content;
  border: 1px dashed #a8b9b5;
  border-radius: 8px;
  padding: 10px 14px;
  background: #f7fbf9;
}

.file-control input {
  display: none;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}

.check-row label {
  display: flex;
  align-items: center;
}

.check-row input {
  width: auto;
}

.form-actions {
  justify-content: space-between;
}

.mini-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 14px;
}

.group-config {
  display: grid;
  gap: 8px;
}

.config-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.schedule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.schedule-card {
  display: grid;
  gap: 10px;
}

.schedule-card textarea {
  min-height: 120px;
}

.chat-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 16px;
}

.chat-groups {
  display: grid;
  align-content: start;
  gap: 8px;
}

.chat-room {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  padding: 0 12px;
  font-weight: 800;
}

.chat-room.active {
  border-color: var(--teal);
  background: #edf7f4;
}

.chat-panel {
  min-height: 640px;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.chat-messages {
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.message {
  max-width: 720px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 10px;
}

.message header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.chat-form {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 12px;
}

.person-dialog {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 30px 80px rgba(11, 22, 22, 0.28);
}

.person-dialog::backdrop {
  background: rgba(15, 32, 33, 0.55);
}

.dialog-close {
  position: absolute;
  right: 12px;
  top: 12px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: #eff5f2;
  font-size: 1.4rem;
}

.detail-wrap {
  padding: 24px;
  display: grid;
  gap: 18px;
}

.detail-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.detail-head .avatar {
  width: 76px;
  height: 76px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.detail-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.detail-item span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.detail-item p {
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.empty-state {
  border: 1px dashed #b6c4c0;
  border-radius: 8px;
  padding: 22px;
  text-align: center;
  color: var(--muted);
  display: grid;
  gap: 6px;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

  .nav-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .storage-panel {
    display: none;
  }

  .main-content {
    padding: 16px;
  }

  .metrics, .split-layout, .admin-grid, .chat-layout {
    grid-template-columns: 1fr;
  }

  .org-stage {
    min-height: 520px;
  }
}

@media (max-width: 620px) {
  .topbar, .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions, .toolbar, .chat-form, .mini-form, .form-grid, .detail-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-item {
    font-size: 0.9rem;
  }

  .people-list, .schedule-grid {
    grid-template-columns: 1fr;
  }
}
