:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f8fbff;
  --surface-3: #fbfdff;
  --surface-strong: #eff4fb;
  --line: #d6deeb;
  --text: #132033;
  --muted: #617086;
  --primary: #1f5fbf;
  --primary-soft: #eaf1fb;
  --success: #027a48;
  --danger: #b42318;
  --sidebar-bg: #f8fbff;
  --table-sticky: #ffffff;
  --table-head: #eff4fb;
  --table-foot: #f8fbff;
  --track: #e8eef7;
  --overlay: rgba(12, 20, 32, 0.32);
  --shadow-soft: 0 12px 34px rgba(15, 23, 42, 0.06);
  --shadow-panel: 0 18px 44px rgba(15, 23, 42, 0.08);
  --shadow-modal: 0 24px 60px rgba(15, 23, 42, 0.18);
  --radius: 8px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1726;
  --surface: #122033;
  --surface-2: #17273d;
  --surface-3: #1a2d45;
  --surface-strong: #21354f;
  --line: #2c405d;
  --text: #ebf3ff;
  --muted: #98abc5;
  --primary: #4e8ef7;
  --primary-soft: #203657;
  --success: #35c67b;
  --danger: #ff7a6c;
  --sidebar-bg: #111d2e;
  --table-sticky: #122033;
  --table-head: #1a2b42;
  --table-foot: #17273d;
  --track: #2a3c57;
  --overlay: rgba(4, 10, 18, 0.72);
  --shadow-soft: 0 14px 36px rgba(2, 6, 12, 0.28);
  --shadow-panel: 0 20px 48px rgba(2, 6, 12, 0.32);
  --shadow-modal: 0 30px 72px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 0;
}

.brand-context {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.15;
}

.brand span,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 14px;
}

.topbar-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
}

.topbar-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
}

.theme-button {
  border: 0;
  border-radius: 999px;
  width: 38px;
  height: 38px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.theme-button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.theme-button svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login-logo {
  width: min(228px, 100%);
  height: auto;
  display: block;
  margin: 0 auto 18px;
}

.login-title {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}

.password-field {
  position: relative;
}

.password-input {
  padding-right: 48px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.password-toggle svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.main {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--sidebar-bg);
  padding: 18px;
  overflow: auto;
}

.selector-stack {
  display: grid;
  gap: 14px;
}

.selector-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 12px;
  box-shadow: var(--shadow-soft);
}

.selector-card.open {
  background: var(--surface-2);
}

.selector-label {
  margin-bottom: 8px;
}

.selector-trigger {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  text-align: left;
  font-weight: 700;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.selector-trigger:hover {
  box-shadow: var(--shadow-soft);
}

.selector-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selector-chevron {
  flex: 0 0 auto;
  color: var(--muted);
}

.selector-card.open .selector-chevron {
  transform: rotate(180deg);
}

.selector-chevron svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.selector-search {
  margin-top: 10px;
}

.selector-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  max-height: 320px;
  overflow: auto;
}

.selector-option {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.selector-option:hover {
  box-shadow: var(--shadow-soft);
}

.selector-option.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  font-weight: 700;
}

.selector-empty {
  padding: 8px 4px 2px;
  font-size: 12px;
}

.nav-button,
.workspace-button,
.action-button,
.ghost-button,
.primary-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
  font-weight: 600;
}

.nav-button.active,
.workspace-button.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.nav-button:hover,
.workspace-button:hover,
.action-button:hover,
.ghost-button:hover,
.primary-button:hover {
  box-shadow: var(--shadow-soft);
}

.content {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 18px;
  padding: 18px 22px 28px;
  overflow: auto;
}

.view-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.view-button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.view-button.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

.summary-strip,
.annual-strip,
.pending-strip,
.login-panel,
.table-band {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.summary-strip,
.annual-strip,
.pending-strip {
  padding: 16px;
}

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

.admin-create-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.admin-create-actions {
  display: flex;
  align-items: end;
  height: 100%;
  grid-column: 1 / -1;
}

.admin-create-actions .primary-button {
  width: 100%;
  text-align: center;
}

.admin-user-result {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.admin-user-result-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}

.admin-user-result-line {
  font-size: 13px;
  color: var(--text);
  margin-top: 4px;
}

.manage-user-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.manage-user-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
  padding: 12px;
}

.manage-user-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.manage-user-name {
  font-size: 14px;
  font-weight: 700;
}

.manage-user-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.manage-user-actions,
.manage-user-password-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.manage-user-password-row {
  grid-template-columns: minmax(0, 1.2fr) repeat(2, minmax(0, 1fr));
}

.manage-user-badge {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.danger-button {
  border: 1px solid #efc0ba;
  border-radius: var(--radius);
  padding: 10px 12px;
  background: #fff5f3;
  color: var(--danger);
  cursor: pointer;
  text-align: center;
}

.status-badge-active {
  background: #eaf7ef;
  color: #136c3a;
}

.status-badge-blocked {
  background: #fff4e5;
  color: #9a6700;
}

.status-badge-archived {
  background: #eef2f6;
  color: #516072;
}

.archive-confirm {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #f1d0ca;
  border-radius: var(--radius);
  background: #fff9f7;
}

.archive-confirm-text {
  font-size: 12px;
  color: var(--muted);
}

.archive-confirm-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.metric-tile {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 88px;
  background: var(--surface-3);
  box-shadow: var(--shadow-soft);
}

.metric-tile h3,
.section-head h2 {
  margin: 0 0 6px;
  font-size: 13px;
}

.metric-value {
  font-size: 24px;
  font-weight: 700;
}

.delta {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 700;
}

.delta-up {
  color: var(--success);
}

.delta-down {
  color: var(--danger);
}

.delta-neutral {
  color: var(--muted);
}

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

.table-wrap {
  overflow: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 980px;
}

th,
td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  font-size: 13px;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--table-sticky);
  z-index: 1;
}

thead th {
  background: var(--table-head);
}

tfoot td {
  font-weight: 700;
  background: var(--table-foot);
}

.closure-cell {
  font-weight: 700;
}

.pending-grid {
  display: grid;
  gap: 10px;
}

.analytics-band {
  padding-bottom: 16px;
}

.analytics-grid,
.trend-grid,
.alert-grid {
  display: grid;
  gap: 14px;
  padding: 16px;
}

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

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

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

.chart-card,
.alert-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
  padding: 14px;
  box-shadow: var(--shadow-soft);
}

.compact-head {
  margin-bottom: 10px;
}

.compact-head h2 {
  margin: 0;
}

.range-pill {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  color: #000;
}

.progress-track,
.spark-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}

.progress-bar,
.spark-bar {
  height: 100%;
  border-radius: 999px;
}

.chart-meta,
.chart-submeta,
.alert-detail {
  font-size: 12px;
  color: var(--muted);
}

.chart-meta {
  margin-top: 10px;
}

.chart-submeta {
  margin-top: 6px;
}

.alert-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
}

.alert-behind {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--danger) 24%, var(--line));
}

.alert-ahead {
  background: color-mix(in srgb, var(--success) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--success) 26%, var(--line));
}

.alert-watch {
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--primary) 18%, var(--line));
}

.trend-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.trend-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
}

.trend-current {
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  margin-top: 6px;
}

.trend-submeta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

.trend-badge {
  min-width: 120px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
}

.trend-badge-value {
  font-size: 16px;
  font-weight: 700;
  margin-top: 4px;
}

.trend-months {
  display: grid;
  gap: 10px;
}

.trend-month-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface-3);
}

.trend-month-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.trend-month-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.trend-month-name,
.trend-month-value {
  font-size: 12px;
}

.trend-month-card.active .trend-month-name,
.trend-month-card.active .trend-month-value {
  font-weight: 700;
}

.trend-track {
  width: 100%;
  height: 16px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}

.trend-bar {
  height: 100%;
  border-radius: 999px;
}

.pending-row {
  display: grid;
  grid-template-columns: 1.4fr 120px 1fr 40px;
  gap: 8px;
}

.pending-row input {
  width: 100%;
}

.input,
.select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
}

.primary-button {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  text-align: center;
}

.ghost-button {
  background: transparent;
}

.action-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.status {
  font-size: 13px;
  color: var(--muted);
}

.status.ok {
  color: var(--success);
}

.status.error {
  color: var(--danger);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 18px;
}

.login-panel {
  width: min(396px, 100%);
  padding: 28px 26px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-panel);
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 0;
}

.field-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 2000;
}

.modal {
  width: min(720px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  z-index: 2001;
  box-shadow: var(--shadow-modal);
}

.modal-narrow {
  width: min(520px, 100%);
}

.account-password-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.register-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 10px;
  align-items: end;
}

.register-grid-metrics {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 10px;
}

.register-head {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 10px;
  margin-top: 14px;
}

.register-note {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.register-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 10px;
  background: var(--surface-3);
}

.register-key {
  font-size: 13px;
  font-weight: 700;
}

.register-subkey {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.assignment-grid {
  display: grid;
  gap: 10px;
}

.assignment-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  align-items: center;
}

@media (max-width: 1100px) {
  .main {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    margin-left: 0;
  }

  .topbar-controls {
    width: 100%;
    justify-content: flex-start;
  }

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

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

  .manage-user-actions,
  .manage-user-password-row {
    grid-template-columns: 1fr;
  }

  .analytics-grid,
  .trend-grid,
  .alert-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .content {
    padding: 14px;
  }

  .topbar {
    padding: 14px;
  }

  .brand {
    align-items: flex-start;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .admin-create-grid {
    grid-template-columns: 1fr;
  }

  .pending-row,
  .register-head,
  .register-grid,
  .assignment-row {
    grid-template-columns: 1fr;
  }

  .manage-user-head {
    flex-direction: column;
  }

  .archive-confirm-actions {
    flex-direction: column;
  }

  .view-switch {
    width: 100%;
  }

  .trend-hero {
    flex-direction: column;
  }
}
