:root {
  --ink: #10231c;
  --ink-soft: #3d564c;
  --paper: #f6f3ec;
  --paper-2: #ebe6da;
  --panel: rgba(255, 252, 246, 0.86);
  --line: rgba(16, 35, 28, 0.12);
  --brand: #0b3d2e;
  --brand-2: #1f6b52;
  --accent: #c45c26;
  --accent-soft: #f0d2c0;
  --good: #1b7a4a;
  --warn: #b7791f;
  --bad: #b42318;
  --shadow: 0 18px 50px rgba(16, 35, 28, 0.08);
  --radius: 18px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "DM Sans", "Segoe UI", sans-serif;
  --surface: rgba(255, 252, 246, 0.9);
  --surface-2: #fffaf2;
  --chip: #fffaf2;
  --on-brand: #f7f2e8;
  --bg-glow-a: rgba(31, 107, 82, 0.18);
  --bg-glow-b: rgba(196, 92, 38, 0.14);
  --bg-top: #f8f5ee;
  --table-surface: rgba(255, 252, 246, 0.55);
  --hover-row: rgba(31, 107, 82, 0.04);
}

html[data-theme="dark"] {
  --ink: #e7efe9;
  --ink-soft: #9fb4a9;
  --paper: #0e1713;
  --paper-2: #15201a;
  --panel: rgba(20, 32, 27, 0.92);
  --line: rgba(231, 239, 233, 0.12);
  --brand: #1f6b52;
  --brand-2: #4f9d7d;
  --accent: #e07a45;
  --accent-soft: #4a2e22;
  --good: #3ecf8e;
  --warn: #e0b45a;
  --bad: #f07167;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --surface: rgba(18, 28, 24, 0.95);
  --surface-2: #1a2922;
  --chip: #1a2922;
  --on-brand: #f4efe4;
  --bg-glow-a: rgba(31, 107, 82, 0.22);
  --bg-glow-b: rgba(196, 92, 38, 0.12);
  --bg-top: #0c1410;
  --table-surface: rgba(16, 26, 22, 0.7);
  --hover-row: rgba(79, 157, 125, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--bg-glow-a), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, var(--bg-glow-b), transparent 50%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--paper) 45%, var(--paper-2) 100%);
  transition: background 220ms ease, color 180ms ease;
}

body {
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  margin: 0 0 0.4rem;
}

p {
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  /* minmax(0, 1fr) prevents the main column from forcing page-wide overflow */
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
}

.sidebar {
  padding: 1.5rem 1.1rem;
  background: linear-gradient(180deg, #0b3d2e 0%, #134d3a 55%, #173f33 100%);
  color: #f4efe4;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  min-width: 0;
}

.brand {
  display: block;
  margin: 0 0 1.5rem;
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: auto;
  height: auto;
  object-fit: contain;
}

.brand-logo--dark {
  width: min(100%, 188px);
  margin: 0 auto 0 0;
}

.brand-logo--auth {
  width: min(100%, 210px);
  margin: 0 0 1.25rem;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav a {
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  color: rgba(244, 239, 228, 0.86);
  transition: background 160ms ease, transform 160ms ease;
}

.nav a:hover,
.nav a.active {
  background: rgba(255, 255, 255, 0.12);
  transform: translateX(2px);
}

.main {
  padding: 1.5rem 1.75rem 2.5rem;
  min-width: 0;
  max-width: 100%;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.4rem;
  min-width: 0;
}

.topbar > div:first-child {
  min-width: 0;
  flex: 1 1 16rem;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--brand-2);
  margin-bottom: 0.35rem;
}

.lede {
  color: var(--ink-soft);
  max-width: 56ch;
}

.controls {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}

select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"] {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  min-width: 140px;
  color: var(--ink);
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 0.7rem 1rem;
  cursor: pointer;
  font-weight: 600;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--brand);
  color: var(--on-brand);
  box-shadow: 0 10px 24px rgba(11, 61, 46, 0.22);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--brand);
  border: 1px solid var(--line);
}

.btn-accent {
  background: var(--accent);
  color: #fff8f2;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.2rem;
  min-width: 0;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.05rem;
  box-shadow: var(--shadow);
  animation: rise 420ms ease both;
  min-width: 0;
}

.kpi:nth-child(2) { animation-delay: 40ms; }
.kpi:nth-child(3) { animation-delay: 80ms; }
.kpi:nth-child(4) { animation-delay: 120ms; }
.kpi:nth-child(5) { animation-delay: 160ms; }
.kpi:nth-child(6) { animation-delay: 200ms; }

.kpi span {
  display: block;
  color: var(--ink-soft);
  font-size: 0.82rem;
  margin-bottom: 0.45rem;
}

.kpi strong {
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 1.6vw, 1.55rem);
  font-weight: 700;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.kpi .delta {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--good);
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
  min-width: 0;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  min-width: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  animation: rise 500ms ease both;
  min-width: 0;
}

.panel h2 {
  font-size: 1.15rem;
  margin-bottom: 0.85rem;
}

.chart-wrap {
  position: relative;
  height: 280px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.chart-wrap.tall {
  height: 340px;
}

.chart-wrap canvas {
  max-width: 100% !important;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.7rem 0.45rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}

th {
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

tr:hover td {
  background: var(--hover-row);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.badge-warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge-bad { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.badge-neutral { background: color-mix(in srgb, var(--ink-soft) 16%, transparent); color: var(--ink-soft); }

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

.table-wrap table {
  margin: 0;
}

.table-wrap th,
.table-wrap td {
  padding: 0.75rem 0.9rem;
  white-space: nowrap;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.table-actions button,
.link-btn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--brand);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.table-actions .danger,
.link-btn.danger,
.btn.danger {
  color: var(--bad);
}

.table-actions .good {
  color: var(--good);
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-width: 36rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-field label,
.field-label {
  font-size: 0.88rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.form-field input,
.form-field select,
.form-field textarea,
.input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  font: inherit;
  color: var(--ink);
}

.form-field textarea {
  min-height: 5rem;
  resize: vertical;
}

.form-hint {
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.form-check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.92rem;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.info-panel {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.9rem 1rem;
  border-radius: 12px;
  background: rgba(11, 61, 46, 0.05);
  border: 1px solid var(--line);
  font-size: 0.92rem;
}

.info-panel-label {
  color: var(--ink-soft);
  font-weight: 600;
  margin-right: 0.35rem;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(17, 28, 24, 0.48);
  backdrop-filter: blur(2px);
  animation: rise 180ms ease both;
}

.modal-content {
  width: min(100%, 440px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: 0 24px 60px rgba(17, 28, 24, 0.28);
  padding: 1.25rem 1.35rem;
}

.modal-content h3 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  margin-bottom: 0.25rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

.toast-stack {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(360px, calc(100vw - 2rem));
}

.toast {
  padding: 0.75rem 0.95rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  animation: rise 220ms ease both;
}

.toast-success { border-color: rgba(31, 107, 82, 0.35); }
.toast-error { border-color: rgba(176, 58, 46, 0.4); color: var(--bad); }
.toast-info { border-color: rgba(196, 92, 38, 0.35); }

.alert {
  padding: 0.75rem 0.95rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 0.9rem;
  margin-bottom: 0.85rem;
}

.alert-success {
  background: color-mix(in srgb, var(--good) 18%, transparent);
  border-color: color-mix(in srgb, var(--good) 30%, transparent);
}

.alert-warning {
  background: color-mix(in srgb, var(--warn) 18%, transparent);
  border-color: color-mix(in srgb, var(--warn) 30%, transparent);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  width: 100%;
  margin-bottom: 0.65rem;
  padding: 0.6rem 0.85rem;
  border-radius: 12px;
  border: 1px solid rgba(244, 239, 228, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: #f4efe4;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 160ms ease, transform 140ms ease;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.14);
  transform: translateY(-1px);
}

.theme-toggle-float {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: auto;
  margin: 0;
  z-index: 5;
  color: var(--ink);
  border-color: var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

html[data-theme="dark"] .theme-toggle-float {
  color: var(--ink);
}

html[data-theme="dark"] .sidebar .btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #f4efe4;
  border-color: rgba(244, 239, 228, 0.22);
}

html[data-theme="dark"] .auth-form input {
  background: var(--surface);
  color: var(--ink);
}

.settings-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 44rem;
}

.section-gap {
  margin-top: 1.25rem;
}

.list-plain {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.list-plain li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--line);
}

.muted {
  color: var(--ink-soft);
}

.form-error {
  color: var(--bad);
  margin-top: 0.75rem;
}

.empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--ink-soft);
}

.compare-select {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.chip {
  border: 1px solid var(--line);
  background: var(--chip);
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  color: var(--ink);
}

.chip.active {
  background: var(--brand);
  color: var(--on-brand);
  border-color: var(--brand);
}

.anomaly {
  border-left: 3px solid var(--accent);
  padding: 0.7rem 0.9rem;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: 0 12px 12px 0;
  margin-bottom: 0.6rem;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  position: relative;
}

.auth-shell {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  min-height: 620px;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(16, 35, 28, 0.16);
  border: 1px solid var(--line);
  background: var(--panel);
  animation: rise 500ms ease both;
}

.auth-panel {
  padding: 2.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-panel .lede {
  margin-bottom: 0.2rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 1.5rem;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.auth-docs {
  margin-top: 1rem;
}

.auth-docs a {
  color: var(--brand-2);
  font-weight: 600;
  text-decoration: none;
}

.auth-docs a:hover {
  text-decoration: underline;
}

.demo-login-badge {
  display: inline-flex;
  align-items: center;
  margin: 0 0 0.85rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: rgba(196, 92, 38, 0.14);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.demo-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: 0.55rem 1rem;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: #3a2418;
  background: linear-gradient(90deg, #f0d2c0, #f6e2c8 50%, #f0d2c0);
  border-bottom: 1px solid rgba(196, 92, 38, 0.25);
  box-shadow: 0 6px 18px rgba(16, 35, 28, 0.08);
}

body.has-demo-banner {
  --demo-banner-h: 2.55rem;
  padding-top: var(--demo-banner-h);
}

body.has-demo-banner .sidebar {
  top: var(--demo-banner-h);
  height: calc(100vh - var(--demo-banner-h));
}

.app-shell--demo {
  min-height: calc(100vh - var(--demo-banner-h, 2.55rem));
}

.auth-note {
  margin-top: 1rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.sso-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.1rem 0 0.35rem;
  color: var(--ink-soft);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sso-divider::before,
.sso-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.sso-providers {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.sso-providers .sso-btn {
  display: block;
  text-align: center;
  text-decoration: none;
  padding: 0.7rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: color-mix(in srgb, var(--panel) 88%, var(--ink) 4%);
  font: inherit;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.sso-providers .sso-btn:hover {
  background: color-mix(in srgb, var(--brand) 10%, transparent);
  border-color: color-mix(in srgb, var(--brand) 35%, var(--line));
}

.auth-visual {
  position: relative;
  background:
    linear-gradient(160deg, rgba(11, 61, 46, 0.92), rgba(23, 63, 51, 0.88)),
    url("data:image/svg+xml,%3Csvg width='160' height='160' viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23f4efe4' stroke-opacity='0.08'%3E%3Cpath d='M0 40h160M0 80h160M0 120h160M40 0v160M80 0v160M120 0v160'/%3E%3C/g%3E%3C/svg%3E");
  overflow: hidden;
}

.auth-metric-card {
  position: absolute;
  left: 12%;
  top: 28%;
  background: rgba(255, 252, 246, 0.12);
  border: 1px solid rgba(255, 252, 246, 0.2);
  color: #f7f2e8;
  border-radius: 18px;
  padding: 1.1rem 1.3rem;
  backdrop-filter: blur(6px);
  animation: float 4.5s ease-in-out infinite;
  z-index: 1;
}

.auth-metric-card.delay {
  left: auto;
  right: 12%;
  top: 54%;
  animation-delay: 0.8s;
}

.auth-metric-card span {
  display: block;
  opacity: 0.78;
  font-size: 0.85rem;
}

.auth-metric-card strong {
  font-family: var(--font-display);
  font-size: 2rem;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* Collapse earlier: 6 KPIs + 240px sidebar overflows common laptop widths at 100% zoom */
@media (max-width: 1400px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1100px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .grid-2,
  .grid-3 {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: relative;
    height: auto;
  }
  body.has-demo-banner .sidebar {
    top: auto;
    height: auto;
  }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .auth-shell {
    grid-template-columns: 1fr;
  }
  .auth-visual {
    min-height: 220px;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
