/* Savia Cloud operator panel -- design tokens, page shell and navigation chrome.
   The brand palette (green accent on an off-white field) is unchanged; everything
   else here is scale: radii, elevation, motion and type. */

:root {
  /* --- brand palette (unchanged) ------------------------------------------ */
  --bg: #f6f7f5;
  --surface: #ffffff;
  --ink: #1c2420;
  --muted: #68746e;
  --line: #e3e7e2;
  --accent: #2e7d4f;
  --accent-ink: #ffffff;
  --error: #b3372f;
  --ok-bg: #e8f3ec;
  --err-bg: #fbeae8;

  /* --- derived surfaces and ink ------------------------------------------- */
  --ink-2: #47534d;                 /* secondary text, still >= 4.5:1 on surface */
  --sunken: #fafbfa;                /* table stripes, inert wells */
  --line-soft: #eef1ee;
  --line-strong: #d4dbd6;
  --accent-deep: #24623d;
  --accent-wash: color-mix(in srgb, var(--accent) 8%, transparent);
  --warn: #9a6b1f;
  --warn-bg: #faf1e4;
  --info: #2f6d8c;
  --info-bg: #e9f2f7;
  --idle: #5b6570;
  --idle-bg: #eef0f2;

  /* --- series hues: validated categorical slots 1-3 ------------------------
     CVD worst adjacent pair deltaE 9.2 (deutan) on white; HS30 sits below 3:1
     against the surface, so it always ships a direct label and the table. */
  --viz-hs10: #2a78d6;
  --viz-hs30: #1baf7a;
  --viz-ta:   #eb6834;

  /* --- shape -------------------------------------------------------------- */
  --r-xs: 6px;
  --r-sm: 9px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  /* --- elevation: soft, ink-tinted, never grey ---------------------------- */
  --sh-1: 0 1px 2px rgba(28, 36, 32, 0.04), 0 1px 1px rgba(28, 36, 32, 0.03);
  --sh-2: 0 2px 4px rgba(28, 36, 32, 0.04), 0 10px 24px -8px rgba(28, 36, 32, 0.10);
  --sh-3: 0 12px 44px -14px rgba(28, 36, 32, 0.26);

  /* --- motion ------------------------------------------------------------- */
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-1: 110ms;
  --dur-2: 200ms;
  --dur-3: 340ms;

  /* --- layout ------------------------------------------------------------- */
  --appbar-h: 56px;
  --sidenav-w: 236px;
  --page-max: 1320px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* The hidden attribute must win over any display set by a class. */
[hidden] { display: none !important; }

::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* --- type ------------------------------------------------------------------ */

h1 {
  font-size: clamp(1.4rem, 1.15rem + 0.85vw, 1.85rem);
  font-weight: 640;
  letter-spacing: -0.021em;
  margin: 0;
  line-height: 1.2;
}
h2 {
  font-size: 1rem;
  font-weight: 620;
  letter-spacing: -0.008em;
  margin: 0 0 0.85rem;
}
h3 { font-size: 0.9rem; font-weight: 600; margin: 0 0 0.5rem; }

.mono {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  letter-spacing: -0.01em;
}
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.num { font-variant-numeric: tabular-nums; }
.eyebrow {
  font-size: 0.71rem;
  font-weight: 650;
  letter-spacing: 0.085em;
  text-transform: uppercase;
  color: var(--muted);
}

a { color: var(--accent); }

/* Focus: one ring everywhere, drawn outside so it never shifts layout. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* --- app bar --------------------------------------------------------------- */

.appbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--appbar-h);
  padding: 0 1.1rem;
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  -webkit-backdrop-filter: saturate(1.5) blur(14px);
  backdrop-filter: saturate(1.5) blur(14px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 0.12em;
  font-weight: 700;
  letter-spacing: 0.13em;
  font-size: 0.95rem;
  color: var(--ink);
  text-decoration: none;
}
.brand span { color: var(--accent); font-weight: 500; letter-spacing: 0.05em; }
.brand.big { font-size: 1.55rem; }
.appbar-spacer { flex: 1; }
.appbar-end { display: flex; align-items: center; gap: 0.5rem; }

/* Drawer toggle: only a handle on narrow screens. */
.nav-toggle {
  display: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.nav-toggle:hover { border-color: var(--line-strong); color: var(--ink); }

/* --- shell + side navigation ---------------------------------------------- */

.shell { display: grid; grid-template-columns: var(--sidenav-w) minmax(0, 1fr); }

.sidenav {
  border-right: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: var(--appbar-h);
  align-self: start;
  height: calc(100vh - var(--appbar-h));
  padding: 1.1rem 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 35;
}
.sidenav nav { display: flex; flex-direction: column; gap: 0.15rem; }
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  text-decoration: none;
  font-size: 0.92rem;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.nav-item .ico { color: var(--muted); transition: color var(--dur-1) var(--ease); }
.nav-item:hover { background: var(--bg); color: var(--ink); }
.nav-item:hover .ico { color: var(--ink-2); }
.nav-item.is-active { background: var(--ok-bg); color: var(--accent-deep); font-weight: 600; }
.nav-item.is-active .ico { color: var(--accent); }
/* Active marker grows out of the rail instead of appearing. */
.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: -0.75rem;
  top: 50%;
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  transform: translateY(-50%) scaleY(0);
  transform-origin: center;
  animation: rail-in var(--dur-3) var(--ease-out) forwards;
}
@keyframes rail-in { to { transform: translateY(-50%) scaleY(1); } }

.sidenav-foot {
  margin-top: auto;
  padding: 0.6rem 0.7rem 0;
  border-top: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.76rem;
  color: var(--muted);
}
.sidenav-foot .row-between { display: flex; justify-content: space-between; gap: 0.5rem; }

/* Sits outside .shell so the grid never has a say in how big it is. */
.nav-scrim {
  display: none;
  position: fixed;
  top: var(--appbar-h);
  left: 0;
  width: 100%;
  height: calc(100vh - var(--appbar-h));
  height: calc(100dvh - var(--appbar-h));
  background: rgba(28, 36, 32, 0.34);
  z-index: 34;
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease);
}

/* --- main ------------------------------------------------------------------ */

main {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 1.5rem 1.4rem 4rem;
  width: 100%;
  min-width: 0;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem 1.2rem;
  flex-wrap: wrap;
  margin-bottom: 1.3rem;
}
.page-head .titles { min-width: 0; }
.page-head .sub {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.actions { display: flex; gap: 0.55rem; flex-wrap: wrap; }

/* --- tabs ------------------------------------------------------------------ */

.tabs {
  display: flex;
  gap: 0.15rem;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.3rem;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  padding: 0.6rem 0.9rem;
  white-space: nowrap;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.93rem;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  transition: color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.tab:hover { color: var(--ink); background: var(--accent-wash); }
.tab.is-active { color: var(--accent-deep); font-weight: 600; }
/* The rule under the active tab draws itself in, left to right. */
.tab.is-active::after {
  content: "";
  position: absolute;
  left: 0.55rem;
  right: 0.55rem;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
  transform: scaleX(0);
  animation: tab-in var(--dur-3) var(--ease-out) forwards;
}
@keyframes tab-in { to { transform: scaleX(1); } }

/* --- toasts: bottom right, out of the way of the page actions -------------- */

.toasts {
  position: fixed;
  bottom: 1.1rem;
  right: 1.1rem;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: min(440px, calc(100vw - 2rem));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.75rem 0.6rem 0.75rem 0.9rem;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--sh-3);
  font-size: 0.9rem;
  animation: toast-in var(--dur-3) var(--ease-out) backwards;
}
.toast span { flex: 1; min-width: 0; }
.toast .ico { flex: none; margin-top: 1px; }
.toast-ok { background: var(--ok-bg); border-color: transparent; color: var(--accent-deep); }
.toast-error { background: var(--err-bg); border-color: transparent; color: var(--error); }
.toast-x {
  flex: none;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.3rem;
  opacity: 0.55;
  border-radius: var(--r-xs);
}
.toast-x:hover { opacity: 1; }
.toast.is-going { animation: toast-out var(--dur-2) var(--ease) forwards; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(16px); }
}

/* --- entrance: content settles in, staggered, once per load ---------------- */

.reveal { animation: reveal var(--dur-3) var(--ease-out) backwards; }
.reveal:nth-child(2) { animation-delay: 40ms; }
.reveal:nth-child(3) { animation-delay: 80ms; }
.reveal:nth-child(4) { animation-delay: 120ms; }
.reveal:nth-child(5) { animation-delay: 160ms; }
@keyframes reveal {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* --- responsive ------------------------------------------------------------ */

@media (max-width: 960px) {
  :root { --appbar-h: 52px; }
  .nav-toggle { display: inline-flex; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  /* The drawer keeps an explicit height: as a positioned child of the grid it
     would otherwise align to its content instead of stretching to the viewport. */
  .sidenav {
    position: fixed;
    top: var(--appbar-h);
    left: 0;
    width: min(280px, 82vw);
    height: calc(100vh - var(--appbar-h));
    height: calc(100dvh - var(--appbar-h));
    transform: translateX(-102%);
    transition: transform var(--dur-3) var(--ease-out);
    box-shadow: var(--sh-3);
  }
  body.nav-open .sidenav { transform: none; }
  body.nav-open .nav-scrim { display: block; opacity: 1; }
  main { padding: 1.1rem 1rem 3.5rem; }
  .toasts { left: 1rem; right: 1rem; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
