/* ==========================================================================
   Smart Odour — design system

   Built on the mockups' vocabulary (blue navigation, green commit actions,
   white cards on a cool field) with the flat greys replaced by a proper tonal
   scale, tinted status surfaces, and a dark mode that is a real theme rather
   than an inversion.

   Rules that hold throughout:
     · Saturated colour is reserved for sensor state. Nothing decorative is
       red, amber or green, so those three always mean something.
     · Every number is monospaced and tabular, so digits stay in column as they
       tick rather than jittering the layout.
     · Depth comes from layered low-opacity shadows, not heavier borders.
   ========================================================================== */

:root {
  --bg:        #eef2f8;
  --bg-accent: #e3ebf6;
  --card:      #ffffff;
  --card-alt:  #f7f9fc;
  --line:      #e2e8f2;
  --line-soft: #eef2f7;

  --ink:       #0f172a;
  --ink-2:     #334155;
  --muted:     #64748b;
  --faint:     #94a3b8;

  --blue:      #1d6ff2;
  --blue-dark: #1552c4;
  --blue-soft: #e7f0fe;
  --indigo:    #4f46e5;

  /* state — never used decoratively */
  --green:      #0e9f6e;
  --green-soft: #e3f6ee;
  --amber:      #e8940c;
  --amber-soft: #fdf3e0;
  --red:        #dc3545;
  --red-soft:   #fdeaec;

  --r:    12px;
  --r-sm: 8px;
  --shadow-1: 0 1px 2px rgba(15,23,42,.04), 0 1px 3px rgba(15,23,42,.06);
  --shadow-2: 0 2px 4px rgba(15,23,42,.04), 0 8px 20px rgba(15,23,42,.07);
  --shadow-3: 0 12px 36px rgba(15,23,42,.13);

  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
}

[data-theme="dark"] {
  --bg:        #0b1220;
  --bg-accent: #0f1a2e;
  --card:      #121c2f;
  --card-alt:  #16223a;
  --line:      #24334d;
  --line-soft: #1c2942;

  --ink:       #e8eef8;
  --ink-2:     #c3cfe2;
  --muted:     #8b9bb5;
  --faint:     #64748b;

  --blue:      #4d92ff;
  --blue-dark: #6ba5ff;
  --blue-soft: #17294a;

  --green:      #34d399;
  --green-soft: #10281f;
  --amber:      #fbbf24;
  --amber-soft: #2a2010;
  --red:        #f87171;
  --red-soft:   #2c1416;

  --shadow-1: 0 1px 2px rgba(0,0,0,.3);
  --shadow-2: 0 2px 6px rgba(0,0,0,.35), 0 10px 24px rgba(0,0,0,.28);
  --shadow-3: 0 16px 44px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(1100px 480px at 8% -8%, var(--bg-accent), transparent 60%),
    radial-gradient(900px 420px at 100% 0%, var(--blue-soft), transparent 55%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s, color .25s;
}

h1, h2, h3, h4 { margin: 0; letter-spacing: -.012em; }
button { font-family: inherit; }

/* ---------------------------------------------------------------- login -- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background:
    radial-gradient(900px 500px at 20% 10%, var(--blue-soft), transparent 60%),
    radial-gradient(700px 400px at 85% 85%, var(--bg-accent), transparent 60%),
    var(--bg);
}
.gate.hidden { display: none; }
.gate__card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: var(--shadow-3);
  width: 100%; max-width: 410px; padding: 36px 32px;
}
.gate__brand { text-align: center; margin-bottom: 24px; }
.gate__brand h1 { font-size: 23px; font-weight: 700; }
.gate__brand p {
  margin: 6px 0 0; font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .16em;
}
.gate__mark {
  width: 46px; height: 46px; margin: 0 auto 14px; border-radius: 14px;
  background: linear-gradient(140deg, var(--blue), var(--indigo));
  display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(29,111,242,.32);
}
.gate__mark svg { width: 24px; height: 24px; stroke: #fff; fill: none;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.field { margin-bottom: 15px; }
.field label {
  display: block; font-size: 12.5px; font-weight: 600;
  margin-bottom: 6px; color: var(--ink-2);
}
.field input, .field select, .inline-select {
  width: 100%; padding: 11px 13px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  font-family: inherit; font-size: 14px;
  background: var(--card); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .inline-select:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3.5px rgba(29,111,242,.16);
}
.field input:disabled { background: var(--card-alt); color: var(--muted); }

.msg { font-size: 13px; margin: 12px 0 0; min-height: 1.2em; }
.msg--err { color: var(--red); }
.msg--ok  { color: var(--green); }
.gate__switch { margin-top: 18px; text-align: center; font-size: 13px; color: var(--muted); }
.gate__switch a { color: var(--blue); cursor: pointer; text-decoration: none; font-weight: 600; }
.gate__switch a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ app -- */
.app { display: none; min-height: 100vh; }
.app.ready { display: flex; }

.side {
  width: 252px; flex: none;
  background: var(--card); border-right: 1px solid var(--line);
  padding: 22px 14px; position: sticky; top: 0; height: 100vh;
  overflow-y: auto; display: flex; flex-direction: column;
}
.side__brand {
  display: flex; align-items: center; gap: 11px;
  padding: 0 8px 20px; margin-bottom: 14px;
  border-bottom: 1px solid var(--line-soft);
}
.side__mark {
  width: 38px; height: 38px; flex: none; border-radius: 11px;
  background: linear-gradient(140deg, var(--blue), var(--indigo));
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(29,111,242,.3);
}
.side__mark svg { width: 20px; height: 20px; stroke: #fff; fill: none;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.side__brand h2 { font-size: 14.5px; font-weight: 700; line-height: 1.15; }
.side__brand p {
  margin: 2px 0 0; font-size: 9.5px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .13em;
}

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav button {
  display: flex; align-items: center; gap: 12px; width: 100%;
  text-align: left; padding: 11px 13px; border: 0;
  border-radius: 10px; background: transparent;
  font-size: 14px; font-weight: 500; color: var(--ink-2); cursor: pointer;
  transition: background .15s, color .15s;
}
.nav button:hover { background: var(--card-alt); color: var(--ink); }
.nav button.on {
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  color: #fff; box-shadow: 0 4px 14px rgba(29,111,242,.34);
}
.nav button.on .nav__ico { opacity: 1; }
.nav__ico { width: 18px; height: 18px; flex: none; opacity: .72; display: block; }
.nav__ico svg { width: 100%; height: 100%; stroke: currentColor; fill: none;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.side__foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.nav__link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 13px; border-radius: 10px;
  font-size: 13.5px; font-weight: 500; color: var(--muted);
  text-decoration: none; transition: background .15s, color .15s;
}
.nav__link:hover { background: var(--card-alt); color: var(--blue); }

.main { flex: 1; min-width: 0; padding: 20px 26px 44px; }

.top {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-1);
  padding: 15px 20px; display: flex; align-items: center;
  justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px;
}
.top h1 { font-size: 18px; font-weight: 650; }
.top p { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }
.who { display: flex; align-items: center; gap: 11px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(140deg, var(--blue), var(--indigo));
  color: #fff; display: grid; place-items: center;
  font-weight: 650; font-size: 13px;
  box-shadow: 0 3px 10px rgba(29,111,242,.3);
}
.who__name { font-size: 13.5px; font-weight: 600; line-height: 1.25; }
.who__role { font-size: 11px; color: var(--muted); text-transform: capitalize; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--card);
  display: grid; place-items: center; cursor: pointer; color: var(--ink-2);
  transition: background .15s, border-color .15s, color .15s;
}
.icon-btn:hover { background: var(--card-alt); border-color: var(--blue); color: var(--blue); }
.icon-btn svg { width: 17px; height: 17px; stroke: currentColor; fill: none;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ----------------------------------------------------------------- cards -- */
.cards {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(218px, 1fr));
  margin-bottom: 18px;
}
.card {
  position: relative; overflow: hidden;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-1);
  padding: 16px 18px;
  transition: transform .16s, box-shadow .16s;
}
.card:hover { transform: translateY(-1px); box-shadow: var(--shadow-2); }

/* A 3px top rule carries the state colour, so status is readable without
   parsing the number underneath it. */
.card::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--faint); opacity: .45;
}
.card--normal::before    { background: var(--green); opacity: 1; }
.card--warning::before   { background: var(--amber); opacity: 1; }
.card--hazardous::before { background: var(--red);   opacity: 1; }

.card__label {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .09em;
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.card__value {
  font-family: var(--mono); font-size: 29px; font-weight: 500;
  margin-top: 10px; font-variant-numeric: tabular-nums; letter-spacing: -.025em;
  line-height: 1.1;
}
.card__foot { font-size: 12px; color: var(--muted); margin-top: 6px; }
.v-normal { color: var(--green); }
.v-warning { color: var(--amber); }
.v-hazardous { color: var(--red); }
.v-idle { color: var(--ink); }

.card--action { display: flex; flex-direction: column; }

/* ----------------------------------------------------------------- panel -- */
.panel {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-1);
  padding: 18px 20px; margin-bottom: 18px;
}
.panel__head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; flex-wrap: wrap; margin-bottom: 15px;
  padding-bottom: 13px; border-bottom: 1px solid var(--line-soft);
}
.panel__head h3 { font-size: 15.5px; font-weight: 650; }
.panel__head p { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); max-width: 74ch; }

/* ---------------------------------------------------------------- tables -- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .07em;
  padding: 10px 11px; background: var(--card-alt);
  border-bottom: 1px solid var(--line);
}
td { padding: 11px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--card-alt); }
tr:last-child td { border-bottom: 0; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- pills -- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .05em;
}
.pill::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex: none;
}
.pill--green { background: var(--green-soft); color: var(--green); }
.pill--amber { background: var(--amber-soft); color: var(--amber); }
.pill--red   { background: var(--red-soft);   color: var(--red); }
.pill--grey  { background: var(--card-alt);   color: var(--muted); }
.pill--blue  { background: var(--blue-soft);  color: var(--blue); }
.pill--live::before { animation: pulse 2.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }

/* --------------------------------------------------------------- buttons -- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 0; border-radius: var(--r-sm);
  padding: 10px 17px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; background: var(--blue); color: #fff;
  box-shadow: 0 2px 8px rgba(29,111,242,.26);
  transition: background .15s, transform .1s, box-shadow .15s;
}
.btn:hover { background: var(--blue-dark); box-shadow: 0 4px 14px rgba(29,111,242,.34); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn--green { background: var(--green); box-shadow: 0 2px 8px rgba(14,159,110,.26); }
.btn--green:hover { background: #0b8a5e; }
.btn--amber { background: var(--amber); color: #3d2600; box-shadow: 0 2px 8px rgba(232,148,12,.28); }
.btn--amber:hover { background: #d2850a; }
.btn--ghost {
  background: var(--card); color: var(--ink-2);
  border: 1px solid var(--line); box-shadow: none;
}
.btn--ghost:hover { background: var(--card-alt); border-color: var(--blue); color: var(--blue); }
.btn--wide { width: 100%; padding: 12px; }
.btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.segmented {
  display: inline-flex; border: 1px solid var(--line);
  border-radius: var(--r-sm); overflow: hidden; background: var(--card);
}
.segmented button {
  border: 0; background: transparent; cursor: pointer;
  padding: 6px 13px; font-family: var(--mono); font-size: 12px; color: var(--muted);
  border-right: 1px solid var(--line);
}
.segmented button:last-child { border-right: 0; }
.segmented button.is-active { background: var(--blue); color: #fff; }

/* ---------------------------------------------------------------- layout -- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.grid2--top { align-items: start; }
.section { display: none; animation: rise .22s ease; }
.section.on { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(5px) } to { opacity: 1; transform: none } }

.empty { padding: 30px; text-align: center; color: var(--muted); font-size: 13px; }
.check { font-size: 12.5px; color: var(--muted); display: inline-flex; gap: 7px; align-items: center; }

/* ----------------------------------------------------------------- charts -- */
#stream, #hist, #ai-chart, #map { width: 100%; height: auto; display: block; }
.line { fill: none; stroke: var(--blue); stroke-width: 2.2; stroke-linejoin: round; }
.band { stroke: var(--line); stroke-width: 1; stroke-dasharray: 4 4; }
.axis { font-family: var(--mono); font-size: 10px; fill: var(--muted); }
.gridline { stroke: var(--line-soft); stroke-width: 1; }
.zone-label { font-family: var(--sans); font-size: 11px; font-weight: 650; fill: var(--ink); }
.zone-sub { font-family: var(--mono); font-size: 9.5px; fill: var(--muted); }

/* Leaflet, themed to match. Tiles are inverted in dark mode so markers stay
   legible against them. */
#leaflet-map {
  width: 100%; height: 420px; border-radius: var(--r-sm);
  border: 1px solid var(--line); z-index: 1;
}
[data-theme="dark"] #leaflet-map .leaflet-tile {
  filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9);
}
.leaflet-popup-content-wrapper { border-radius: var(--r-sm) !important; }
.map-legend {
  display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px;
  font-size: 12px; color: var(--muted);
}
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.map-legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ------------------------------------------------------------ incidents -- */
.incident-row {
  display: grid; grid-template-columns: auto 1fr auto;
  gap: 12px; align-items: center; padding: 12px 0;
  border-bottom: 1px solid var(--line-soft); font-size: 13.5px;
}
.incident-row:last-child { border-bottom: 0; }

/* --------------------------------------------------------------- toggles -- */
.toggle {
  display: flex; align-items: center; gap: 11px; padding: 11px 0;
  border-bottom: 1px solid var(--line-soft); font-size: 13.5px; cursor: pointer;
}
.toggle:last-of-type { border-bottom: 0; }
.toggle input { width: 18px; height: 18px; accent-color: var(--blue); cursor: pointer; }

.sub {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .09em; margin: 16px 0 8px;
}
.spec { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.spec li { padding: 7px 0; border-bottom: 1px solid var(--line-soft); color: var(--muted); }
.spec li:last-child { border-bottom: 0; }
.spec b { color: var(--ink); font-weight: 600; margin-right: 6px; }

.thr { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 6px; }
.thr__title {
  grid-column: 1 / -1; font-size: 13px; font-weight: 650;
  color: var(--blue); margin-top: 10px;
}

/* ---------------------------------------------------------------- modal -- */
.modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15,23,42,.5); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal.on { display: flex; }
.modal__card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 26px; width: 100%; max-width: 430px;
  box-shadow: var(--shadow-3);
}
.modal__card h3 { font-size: 17px; font-weight: 650; }

/* ---------------------------------------------------------------- report -- */
.report__blurb { margin: 0 0 14px; font-size: 13.5px; color: var(--muted); max-width: 64ch; }
.report__list { list-style: none; margin: 12px 0 0; padding: 0; }
.report__controls { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }

/* --------------------------------------------------------------- mobile -- */
@media (max-width: 980px) {
  .app.ready { flex-direction: column; }
  .side {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 20;
    border-right: 0; border-bottom: 1px solid var(--line);
    padding: 12px; flex-direction: row; align-items: center; gap: 12px;
  }
  .side__brand { border-bottom: 0; padding: 0; margin: 0; flex: none; }
  .nav { flex-direction: row; overflow-x: auto; gap: 6px; flex: 1; }
  .nav button { white-space: nowrap; padding: 9px 12px; font-size: 13px; }
  .side__foot { display: none; }
  .grid2, .thr { grid-template-columns: 1fr; }
  .main { padding: 14px; }
  .card__value { font-size: 25px; }
}
@media (max-width: 560px) {
  .side__brand h2, .side__brand p { display: none; }
  .nav button span:not(.nav__ico) { display: none; }
  .nav button { padding: 10px; }
  .top { padding: 12px 14px; }
  .who__name, .who__role { display: none; }
  #leaflet-map { height: 320px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
