:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --nav: #0b1320;
  --nav-active: #334155;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --blue: #2f80ed;
  --green: #06c167;
  --amber: #f6bb2f;
  --red: #ff414d;
  --purple: #8179d6;
  --teal: #10bfa4;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 8px;
  --sidebar: 260px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

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

.app-shell.auth-mode {
  display: block;
  background:
    radial-gradient(circle at 18% 18%, rgba(249, 115, 22, 0.18), transparent 26%),
    linear-gradient(135deg, #071024 0%, #0f172a 48%, #123336 100%);
}

.app-shell.auth-mode .sidebar,
.app-shell.auth-mode .topbar {
  display: none;
}

.app-shell.auth-mode .main {
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: var(--nav);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 22px;
  overflow: auto;
}

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

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

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

.brand strong {
  font-size: 20px;
  line-height: 1.1;
}

.brand span {
  margin-top: 3px;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 700;
}

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

.nav-item {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 14px;
  background: transparent;
  color: #e5e7eb;
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  font-weight: 800;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.nav-item.active {
  background: var(--nav-active);
  color: #fff;
}

.sync-card {
  margin-top: auto;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.sync-card strong,
.sync-card span {
  display: block;
}

.sync-card strong {
  font-size: 13px;
}

.sync-card span {
  color: #94a3b8;
  font-size: 12px;
  margin-top: 2px;
}

.sync-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f59e0b;
}

.sync-dot.live { background: #22c55e; }
.sync-dot.error { background: #ef4444; }

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 78px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
  font-weight: 900;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  display: grid;
  place-items: center;
}

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mobile-menu {
  display: none;
}

.mobile-menu span {
  width: 18px;
  height: 2px;
  background: currentColor;
  display: block;
}

.primary-button,
.ghost-button,
.danger-button,
.success-button,
.warning-button {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 16px;
  font-weight: 900;
}

.primary-button { background: #071024; color: #fff; }
.ghost-button { background: #fff; color: #0f172a; border: 1px solid var(--border); }
.danger-button { background: #fee2e2; color: #b91c1c; }
.success-button { background: var(--green); color: #fff; }
.warning-button { background: var(--amber); color: #111827; }

.content-grid {
  padding: 22px;
  display: grid;
  gap: 18px;
}

.login-panel {
  min-height: 100vh;
  padding: 24px;
  display: grid;
  place-items: center;
}

.login-card {
  width: min(460px, 100%);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  padding: 28px;
  display: grid;
  gap: 16px;
}

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

.login-mark {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: #f97316;
  color: #fff;
  font-size: 24px;
  font-weight: 900;
}

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

.login-brand span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.login-brand strong {
  margin-top: 2px;
  font-size: 24px;
  line-height: 1.1;
}

.login-copy {
  display: grid;
  gap: 8px;
}

.login-card h2 {
  margin: 0;
  font-size: 26px;
}

.login-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.login-foot {
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

label {
  display: grid;
  gap: 7px;
  color: #334155;
  font-size: 13px;
  font-weight: 900;
}

input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

.error-text {
  min-height: 18px;
  color: #b91c1c;
  font-weight: 800;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.filters input,
.filters select {
  width: 220px;
}

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

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

.metric-card {
  min-height: 128px;
  border-radius: var(--radius);
  padding: 20px;
  color: #fff;
  display: grid;
  place-items: center;
  text-align: center;
  box-shadow: var(--shadow);
}

.metric-card strong {
  display: block;
  font-size: 28px;
  line-height: 1.1;
  margin-top: 8px;
}

.metric-card span {
  font-size: 16px;
  font-weight: 800;
}

.metric-card small {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.82);
}

.blue { background: var(--blue); }
.green { background: var(--green); }
.amber { background: var(--amber); }
.red { background: var(--red); }
.purple { background: var(--purple); }
.teal { background: var(--teal); }
.soft-blue { background: #b8d8fb; color: #071024; }
.soft-green { background: #aef1cf; color: #071024; }
.soft-yellow { background: #fff197; color: #071024; }
.soft-red { background: #ffc6c6; color: #071024; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

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

.panel h2,
.panel h3 {
  margin: 0;
  line-height: 1.2;
}

.panel h2 { font-size: 22px; }
.panel h3 { font-size: 18px; }

.panel p {
  color: var(--muted);
  margin: 6px 0 0;
  line-height: 1.45;
}

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

.chart {
  width: 100%;
  height: 260px;
  display: block;
}

.chart text {
  fill: #667085;
  font-size: 12px;
  font-weight: 700;
}

.chart .axis {
  stroke: #9ca3af;
  stroke-width: 1.4;
}

.chart .grid-line {
  stroke: #e5e7eb;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

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

th, td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #e5e7eb;
  color: #071024;
  font-weight: 900;
}

tr:last-child td {
  border-bottom: 0;
}

.table-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 900;
}

.status-pill.green { background: #dcfce7; color: #15803d; }
.status-pill.gray { background: #f1f5f9; color: #64748b; }
.status-pill.red { background: #fee2e2; color: #b91c1c; }

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

.form-grid .wide {
  grid-column: 1 / -1;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.tab-button {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  padding: 0 14px;
  font-weight: 900;
  color: #475569;
}

.tab-button.active {
  background: #071024;
  color: #fff;
  border-color: #071024;
}

.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.next-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.next-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.next-card strong {
  display: block;
  font-size: 16px;
}

.next-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin-top: 6px;
  line-height: 1.45;
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal {
  width: min(820px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  padding: 22px;
}

.modal.small { width: min(560px, 100%); }

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

.modal h2 {
  margin: 0;
  color: #1d4ed8;
}

.modal-close {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 900;
}

.health-meter {
  display: grid;
  place-items: center;
  min-height: 190px;
}

.gauge {
  width: 260px;
  height: 145px;
}

.gauge text {
  font-size: 24px;
  font-weight: 900;
  fill: #111827;
}

.kpi-stack {
  display: grid;
  gap: 12px;
}

.kpi-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}

.kpi-row strong {
  color: #334155;
}

.visually-muted {
  color: var(--muted);
}

@media (max-width: 1100px) {
  .metric-grid,
  .metric-grid.three,
  .two-col,
  .next-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .sidebar {
    position: fixed;
    z-index: 40;
    width: min(320px, 88vw);
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu {
    display: grid;
  }

  .topbar {
    align-items: flex-start;
    padding: 14px;
  }

  .topbar-actions {
    margin-left: auto;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .content-grid {
    padding: 14px;
  }

  .metric-grid,
  .metric-grid.three,
  .two-col,
  .next-list,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .filters input,
  .filters select {
    width: 100%;
  }

  .toolbar,
  .panel-header {
    align-items: stretch;
  }
}
