/* ---------------------------------------------------------------------------
   Green Mycelia farm admin.

   Same materials as the storefront — warm paper, ink, hairline rules, one
   green accent, a display serif for headings and figures — but tuned for a
   dense tool rather than a landing page: 14px base, tight rows, and serif
   kept to the places where a number or a title carries the eye.

   The chart palette below is deliberately left alone. It is validated for
   contrast against the card surface and follows the data-viz roles, so it
   does not follow the brand.
   --------------------------------------------------------------------------- */

:root {
  --green-900: #0f3d1d;
  --green-800: #144d24;
  --green-700: #175c2b;
  --green-600: #1e7a38;
  --green-500: #2f9a4b;
  --green-100: #e4eee2;
  --green-50: #eef4ec;

  --accent: var(--green-600);
  --accent-strong: var(--green-700);
  --accent-soft: var(--green-50);

  --ink: #1b211c;
  --body: #4f5a51;
  --muted: #8b9389;

  --paper: #f3f2ed;
  --paper-raised: #fbfaf6;
  --frame: #23281f;

  --page: var(--paper);
  --surface: var(--paper-raised);
  --line: #e3e1d8;
  --line-strong: #cfccc0;

  --danger: #a33325;
  --danger-bg: #f8ebe8;
  --warn: #7a5c14;
  --warn-bg: #f6efdc;

  /* Chart roles — see references/palette.md. Validated against the card. */
  --chart-surface: #fbfaf6;
  --grid: #e3e1d8;
  --axis: #cfccc0;
  --chart-ink: #1b211c;
  --chart-muted: #8b9389;

  --series: #1e7a38; /* single-series marks: trend line, magnitude bars */

  --stage-1: #6fbb87; /* ordinal ramp, workflow stages, light -> dark */
  --stage-2: #35a457;
  --stage-3: #1e7a38;
  --stage-4: #175c2b;
  --stage-5: #0f3d1d;
  --stage-cancelled: #d03b3b; /* reserved status colour, never a stage */

  --cat-1: #2a78d6; /* categorical, fixed order, never cycled */
  --cat-2: #eb6834;
  --cat-3: #1baf7a;
  --cat-4: #eda100;
  --cat-5: #e87ba4;

  --radius: 10px;
  --radius-lg: 18px;
  --shadow: 0 1px 2px rgba(27, 33, 28, .04);
  --sidebar-w: 236px;

  --font: 'DM Sans', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  /* Georgia is deliberately absent: its figures are oldstyle, so a fallback
     would set every tile number at x-height with ascenders and descenders. */
  --font-display: 'Instrument Serif', 'Playfair Display', 'Times New Roman', Times, serif;
}

* { box-sizing: border-box }
html, body { margin: 0; padding: 0 }

/* The UA rule for [hidden] is display:none, which ANY author `display` beats.
   .gate and .layout both set display:grid, so without this the sign-in screen
   and the app render on top of each other. Keep this above every layout rule. */
[hidden] { display: none !important }

body {
  font-family: var(--font);
  background: var(--page);
  color: var(--body);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 2rem;
  line-height: 1.05;
  letter-spacing: -.005em;
  color: var(--ink);
  margin: 0 0 .35rem;
}

h2, h3 {
  color: var(--ink);
  margin: 0 0 .35rem;
  letter-spacing: -.01em;
  line-height: 1.25;
}
h2 { font-size: 1rem; font-weight: 500 }
h3 { font-size: .9rem; font-weight: 500 }

p { margin: 0 0 .8rem }
a { color: var(--accent-strong); text-decoration: none }
a:hover { color: var(--ink); text-decoration: underline }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px }

/* ------------------------------------------------------------------ layout */

.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh }

.sidebar {
  background: var(--frame);
  color: #b3bdaf;
  display: flex;
  flex-direction: column;
  padding: 1rem .75rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: .6rem; padding: .3rem .5rem 1.2rem }
.brand-mark { width: 34px; height: 34px; flex: none }
.brand b { display: block; color: var(--paper); font-size: .92rem; font-weight: 500; letter-spacing: .01em; line-height: 1.2 }
.brand span { display: block; font-size: .68rem; color: #8b9a86 }

.side-label {
  font-size: .62rem; text-transform: uppercase; letter-spacing: .16em;
  color: #7c8a77; padding: 1rem .6rem .35rem;
}

.side-link {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .6rem; border-radius: 999px;
  color: #c3ccbe; font-weight: 400; font-size: .88rem; cursor: pointer;
  border: none; background: none; width: 100%; text-align: left; font-family: inherit;
}
.side-link:hover { background: rgba(255, 255, 255, .06); color: var(--paper); text-decoration: none }
.side-link.on { background: var(--accent); color: #fff; font-weight: 500 }
.side-link svg { flex: none; opacity: .9 }
.side-link .tally {
  margin-left: auto; background: rgba(255, 255, 255, .14); color: #fff;
  border-radius: 999px; padding: 0 .4rem; font-size: .7rem; font-weight: 500;
  min-width: 20px; text-align: center; font-variant-numeric: tabular-nums;
}
.side-link.on .tally { background: rgba(0, 0, 0, .25) }

.side-foot { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .1); padding-top: .7rem }
.side-foot .who { font-size: .76rem; color: #8b9a86; padding: 0 .6rem .5rem }

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

.main { min-width: 0; display: flex; flex-direction: column }

.topbar {
  background: var(--page); border-bottom: 1px solid var(--line);
  padding: .9rem 1.75rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
}
.topbar .grow { margin-left: auto }
.crumb { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .14em }

.view { padding: 1.75rem; max-width: 1500px; width: 100% }

/* ------------------------------------------------------------------ pieces */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow) }
.card-head { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; padding: .95rem 1.2rem; border-bottom: 1px solid var(--line) }
.card-head h2 { margin: 0 }
.card-head .grow { margin-left: auto }
.card-body { padding: 1.2rem }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); gap: 1rem; margin-bottom: 1.25rem }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.1rem 1.2rem; box-shadow: var(--shadow) }
.tile .k { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .12em }
.tile .v {
  font-family: var(--font-display); font-weight: 400; font-size: 2.4rem;
  color: var(--ink); letter-spacing: -.01em; line-height: 1; margin: .35rem 0 .15rem;
  font-variant-numeric: tabular-nums lining-nums; font-feature-settings: 'tnum' 1, 'lnum' 1;
}
.tile .s { font-size: .78rem; color: var(--muted) }
.tile.act .v { color: var(--warn) }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 1rem }
.chart-grid .wide { grid-column: 1 / -1 }

/* -------------------------------------------------------------------- viz */

.viz-root { color-scheme: light }
.viz { display: block; width: 100%; overflow: visible }
.viz text { font-family: var(--font); fill: var(--chart-muted); font-size: 11px }
.viz .grid-line { stroke: var(--grid); stroke-width: 1 }
.viz .axis-line { stroke: var(--axis); stroke-width: 1 }
.viz .val { fill: var(--chart-ink); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums }
.viz .cat { fill: var(--chart-ink); font-size: 11.5px }
.viz .dot { stroke: var(--chart-surface); stroke-width: 2 }
.viz-empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); font-size: .86rem }

.legend { display: flex; flex-wrap: wrap; gap: .35rem .9rem; margin-top: .7rem; font-size: .78rem; color: var(--body) }
.legend span { display: inline-flex; align-items: center; gap: .35rem }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none }

.viz-tip {
  position: fixed; z-index: 60; pointer-events: none; background: var(--ink); color: #fff;
  border-radius: 8px; padding: .4rem .6rem; font-size: .78rem; line-height: 1.35;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .22); opacity: 0; transition: opacity .1s; white-space: nowrap;
}
.viz-tip.on { opacity: 1 }
.viz-tip b { color: #fff; font-variant-numeric: tabular-nums }

/* ------------------------------------------------------------------ tables */

.scroll { overflow-x: auto }
table { width: 100%; border-collapse: collapse; font-size: .86rem }
th {
  text-align: left; font-size: .66rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted); padding: .65rem 1.2rem; border-bottom: 1px solid var(--line);
  white-space: nowrap; font-weight: 500;
}
td { padding: .75rem 1.2rem; border-bottom: 1px solid var(--line); vertical-align: top }
tr:last-child td { border-bottom: none }
tbody tr:hover { background: var(--accent-soft) }
.mono { font-family: ui-monospace, Consolas, monospace; font-weight: 600; color: var(--ink) }
.strong { color: var(--ink); font-weight: 500 }
.sub { color: var(--muted); font-size: .78rem }
.num { text-align: right; white-space: nowrap; color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums }

.badge { display: inline-flex; align-items: center; gap: .3rem; border-radius: 999px; padding: .18rem .6rem; font-size: .72rem; font-weight: 500; white-space: nowrap; background: var(--accent-soft); color: var(--accent-strong) }
.badge.warn { background: var(--warn-bg); color: var(--warn) }
.badge.bad { background: var(--danger-bg); color: var(--danger) }
.badge.dead { background: #eceae2; color: #6f776c }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none }

/* ------------------------------------------------------------------ controls */

select, input, textarea, button { font: inherit }
select, input[type=text], input[type=number], input[type=password], input[type=search], textarea {
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: .5rem .7rem;
  color: var(--ink); background: var(--paper); width: 100%;
}
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(27, 33, 28, .07) }
.inline { width: auto; min-width: 140px }

.btn { border: 1px solid transparent; border-radius: 999px; padding: .5rem 1.1rem; font-weight: 500; cursor: pointer; background: var(--accent); color: #fff; white-space: nowrap }
.btn:hover { background: var(--accent-strong) }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong) }
.btn.ghost:hover { background: var(--surface); border-color: var(--ink); color: var(--ink) }
.btn.sm { padding: .3rem .8rem; font-size: .78rem }
.btn:disabled { opacity: .5; cursor: not-allowed }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; background: var(--surface) }
.seg button { border: none; background: none; padding: .38rem .85rem; font-size: .8rem; font-weight: 400; color: var(--body); cursor: pointer }
.seg button:hover { color: var(--ink) }
.seg button.on { background: var(--ink); color: var(--paper); font-weight: 500 }

.field { display: block; margin-bottom: .9rem }
.field > span { display: block; font-size: .78rem; font-weight: 500; color: var(--ink); margin-bottom: .3rem }
.field .hint { font-weight: 400; color: var(--muted) }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr)); gap: 0 1rem }

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted) }

.ok-note {
  background: var(--accent-soft); color: var(--accent-strong); border: 1px solid var(--green-100);
  border-radius: 9px; padding: .5rem .75rem; font-size: .83rem; font-weight: 500; margin-bottom: .8rem;
}

/* ------------------------------------------------------------ bell & inbox */

.bell { position: relative; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; color: var(--body) }
.bell:hover { background: var(--accent-soft); color: var(--accent-strong); text-decoration: none }
.bell-count {
  position: absolute; top: 1px; right: 0; min-width: 17px; height: 17px; padding: 0 .25rem;
  border-radius: 999px; background: var(--accent); color: #fff; font-size: .66rem; font-weight: 600;
  display: grid; place-items: center; border: 2px solid var(--page);
}

.notice { display: flex; gap: .8rem; align-items: flex-start; padding: .85rem 1.2rem; border-bottom: 1px solid var(--line); color: inherit }
.notice:last-child { border-bottom: none }
.notice:hover { background: var(--accent-soft); text-decoration: none }
.notice.unread { background: var(--accent-soft) }
.notice.unread b::after {
  content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); margin-left: .4rem; vertical-align: middle;
}
.notice-icon { font-size: 1.05rem; line-height: 1.4; flex: none }
.notice-text { display: flex; flex-direction: column; gap: .1rem; min-width: 0; flex: 1 }
.notice-text b { color: var(--ink); font-weight: 500 }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 1.2rem; z-index: 80; background: var(--ink); color: var(--paper); border-radius: 999px; padding: .6rem 1.3rem; font-weight: 500; box-shadow: 0 18px 40px rgba(27, 33, 28, .25); opacity: 0; pointer-events: none; transition: opacity .18s }
.toast.show { opacity: 1 }
.toast.bad { background: var(--danger); color: #fff }

/* --------------------------------------------------------------------- gate */

.gate { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: var(--frame) }
.gate form { background: var(--paper); border-radius: 26px; padding: 2.25rem; width: min(400px, 100%); box-shadow: 0 30px 70px rgba(0, 0, 0, .35) }
.gate h1 { margin-bottom: .35rem }
.gate p { font-size: .85rem; color: var(--muted) }
.gate input { margin-bottom: .75rem }
.gate .btn { width: 100%; justify-content: center }
.err { background: var(--danger-bg); color: var(--danger); border: 1px solid #eccbc4; border-radius: var(--radius); padding: .55rem .8rem; font-size: .83rem; font-weight: 500; margin-bottom: .8rem }

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

.menu-btn { display: none; border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius); padding: .35rem .55rem; cursor: pointer }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .18s }
  .sidebar.open { transform: none }
  .menu-btn { display: block }
  .view { padding: 1rem }
  .topbar { padding: .8rem 1rem }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 30 }
}

/* Phones. The farm reads this on a handset in the packing room as often as on a
   laptop, so the dense parts have to survive a narrow screen rather than just
   scroll off it. */
@media (max-width: 560px) {
  .view { padding: 1rem .9rem }
  .topbar { padding: .75rem 1rem }
  .card-body { padding: 1rem }
  .card-head { padding: .8rem 1rem }
  th, td { padding: .6rem .8rem }

  /* Tiles two-up rather than one long column of headings. */
  .tiles { grid-template-columns: 1fr 1fr; gap: .7rem }
  .tile { padding: .85rem .9rem }
  .tile .v { font-size: 1.7rem }

  .form-grid { grid-template-columns: 1fr }

  /* The clock is the first thing worth losing when the bar gets tight. */
  #clock { display: none }

  h1 { font-size: 1.6rem }
}

/* Fingers, not cursors. */
@media (pointer: coarse) {
  .btn, .chip, .seg button, .side-link, .bell { min-height: 44px }
  .btn.sm { min-height: 38px }
  select, input, textarea { min-height: 42px }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important } }
