/* Surabhi: warm cream + marigold theme. Chart series colours come from a CVD-validated palette, one fixed
   colour per measurement (activity is always orange, rumination always aqua, …). */
:root {
  color-scheme: light;
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --surface-2: #f3ede2;
  --border: #e7dfd1;
  --grid: #eee7da;
  --text: #1f1a14;
  --text-2: #5b5246;
  --muted: #8a8072;
  --brand: #c2600f;          /* marigold */
  --brand-ink: #ffffff;
  --brand-soft: #fbe9d6;
  --accent: #b4540a;
  --header-1: #3b2a17;       /* deep earth */
  --header-2: #6b3f12;
  --good: #0ca30c;
  --warning: #b37d00;
  --critical: #d03b3b;
  /* measurement colours (light) */
  --c-activity: #eb6834;
  --c-rumination: #1baf7a;
  --c-eating: #008300;
  --c-bouts: #d55181;
  --c-temp: #e34948;
  --c-batt: #6250d6;
  --c-signal: #2a78d6;
  --shadow: 0 1px 2px rgb(60 40 10 / .06), 0 4px 14px rgb(60 40 10 / .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #15120e; --surface: #1e1a15; --surface-2: #27221b; --border: #3a3329; --grid: #2e2820;
    --text: #f3ede4; --text-2: #cbc1b2; --muted: #968c7d;
    --brand: #e08a3c; --brand-soft: #3a2a18; --accent: #f0a35c;
    --header-1: #1e1a15; --header-2: #2c2016;
    --warning: #fab219;
    --c-activity: #d95926; --c-rumination: #199e70; --c-eating: #2f9e2f; --c-bouts: #d55181;
    --c-temp: #e66767; --c-batt: #9085e9; --c-signal: #3987e5;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15120e; --surface: #1e1a15; --surface-2: #27221b; --border: #3a3329; --grid: #2e2820;
  --text: #f3ede4; --text-2: #cbc1b2; --muted: #968c7d;
  --brand: #e08a3c; --brand-soft: #3a2a18; --accent: #f0a35c;
  --header-1: #1e1a15; --header-2: #2c2016; --warning: #fab219;
  --c-activity: #d95926; --c-rumination: #199e70; --c-eating: #2f9e2f; --c-bouts: #d55181;
  --c-temp: #e66767; --c-batt: #9085e9; --c-signal: #3987e5; --shadow: none;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 26px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 20px 48px; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px;
  background: linear-gradient(100deg, var(--header-1), var(--header-2)); color: #fff; position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: baseline; gap: 8px; color: #fff; font-weight: 700; font-size: 20px; letter-spacing: .01em; }
.brand:hover { text-decoration: none; }
.brand .logo { font-size: 22px; }
.brand .tagline { font-weight: 400; font-size: 13px; color: #f3d9b8; }
.top .pill { background: rgb(255 255 255 / .1); border-color: rgb(255 255 255 / .25); color: #fff; }
@media (max-width: 520px) { .brand .tagline { display: none; } }

/* ---------- cards & layout ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; box-shadow: var(--shadow); }
.section { margin-top: 18px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin: 6px 0 18px; }
.page-head .meta { margin-top: 6px; color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.back { display: inline-block; margin-bottom: 10px; font-size: 14px; }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.collar { cursor: pointer; position: relative; overflow: hidden; transition: transform .12s, box-shadow .12s, border-color .12s; padding-left: 24px; }
.collar::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 6px; background: var(--muted); }
.collar.good::before { background: var(--good); }
.collar.warning::before { background: var(--warning); }
.collar.critical::before { background: var(--critical); }
.collar:hover, .collar:focus-visible { transform: translateY(-2px); border-color: var(--brand); outline: none; }
.collar .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.collar .name { font-size: 18px; font-weight: 700; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.kv b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.kv span { font-size: 12px; color: var(--muted); }

/* ---------- pills & badges ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 3px 11px; border-radius: 99px;
  border: 1px solid var(--border); color: var(--text-2); background: var(--surface); white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.good .dot { background: var(--good); box-shadow: 0 0 0 3px rgb(12 163 12 / .18); }
.pill.warning .dot { background: var(--warning); }
.pill.critical .dot { background: var(--critical); }
.badge { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px; border-radius: 6px;
  background: var(--brand-soft); color: var(--accent); }

/* ---------- stat tiles ---------- */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow);
  border-top: 4px solid var(--c, var(--brand)); }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat .value { font-size: 28px; font-weight: 700; line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 14px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.stat .note { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- toolbar / segmented ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 22px 0 12px; }
.toolbar h2 { margin: 0 8px 0 0; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--text-2); padding: 6px 14px; font: inherit; font-size: 14px; border-radius: 7px; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); box-shadow: 0 1px 3px rgb(0 0 0 / .15); }

/* ---------- charts ---------- */
.charts { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }
.chart { padding: 14px 16px 10px; }
.chart .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chart h3 { font-size: 15px; margin: 0; display: flex; align-items: center; gap: 8px; }
.chart h3::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.chart .total { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.chart .sub { font-size: 12px; color: var(--muted); margin: 2px 0 6px; }
.chart svg { width: 100%; height: 160px; display: block; overflow: visible; }
.chart svg text { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart .empty { height: 160px; display: grid; place-items: center; color: var(--muted); font-size: 13px;
  background: repeating-linear-gradient(135deg, transparent 0 8px, var(--grid) 8px 9px); border-radius: 8px; }

.tip { position: fixed; pointer-events: none; z-index: 20; background: var(--text); color: var(--bg);
  border-radius: 8px; padding: 6px 10px; font-size: 12px; box-shadow: 0 4px 14px rgb(0 0 0 / .2); white-space: nowrap; }

/* ---------- settings ---------- */
.settings-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.mode-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 16px;
  background: var(--brand-soft); border-radius: 10px; }
.mode-row strong { font-size: 14px; }
.mode-row .seg { background: var(--surface); }
form.settings { display: grid; gap: 14px 18px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); align-items: start; }
form.settings label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--text-2); align-content: start; }
form.settings .hint { font-size: 12px; font-weight: 400; color: var(--muted); }
input, select { font: inherit; font-size: 14px; font-weight: 400; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-width: 0; height: 38px; }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
.btn { font: inherit; font-size: 14px; padding: 8px 16px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; transition: background .12s, border-color .12s; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger:hover { border-color: var(--critical); color: var(--critical); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; align-items: center; }
.actions .spacer { flex: 1; }
.msg { margin-top: 10px; font-size: 13px; color: var(--text-2); min-height: 1em; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; margin-top: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--surface-2); }
details summary { cursor: pointer; font-weight: 600; color: var(--text-2); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .big { font-size: 40px; }

@media (max-width: 640px) {
  .wrap { padding: 14px 16px 40px; }
  .charts { grid-template-columns: 1fr; }
  h1 { font-size: 22px; }
}

/* ---------- side navigation (collar list) ---------- */
.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 52px); }
.side { position: sticky; top: 52px; align-self: start; height: calc(100vh - 52px); overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px; display: flex; flex-direction: column; gap: 8px; }
.side-home { display: block; padding: 8px 10px; border-radius: 8px; font-weight: 600; color: var(--text); }
.side-home:hover { background: var(--surface-2); text-decoration: none; }
.side-home.active { background: var(--brand-soft); color: var(--accent); }
.side input[type="search"] { width: 100%; height: 34px; font-size: 13px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side .group { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 10px 10px 4px; }
.side-item { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 8px; color: var(--text); }
.side-item:hover { background: var(--surface-2); text-decoration: none; }
.side-item.active { background: var(--brand-soft); }
.side-item.active .nm { color: var(--accent); font-weight: 700; }
.side-item .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.side-item.good .dot { background: var(--good); }
.side-item.warning .dot { background: var(--warning); }
.side-item.critical .dot { background: var(--critical); }
.side-item .nm { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .when { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.side .none { font-size: 13px; color: var(--muted); padding: 8px 10px; }
.mobile-nav { display: none; padding: 12px 16px 0; }
.mobile-nav select { width: 100%; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { display: none; }
  .mobile-nav { display: block; }
}

.base-link { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; color: var(--text); }
.base-link:hover { border-color: var(--brand); text-decoration: none; }

/* cloud edition: signed-in person + goshala in the header */
.who { display: flex; align-items: center; gap: 10px; margin-left: 12px; flex-wrap: wrap; }
.who select { font: inherit; padding: 4px 6px; }
@media (max-width: 700px) { .who .small { display: none; } }
.top .who { color: #fff; }
.top .who .muted { color: rgb(255 255 255 / .7); }

/* install hint (pwa.js): how to put Surabhi on the home screen */
.install-hint { display: flex; align-items: center; gap: 10px; margin: 12px 16px 0; padding: 10px 12px;
  background: var(--brand-soft); border: 1px solid var(--border); border-radius: 10px; font-size: 14px; color: var(--text); }
.install-hint[hidden] { display: none; }
.install-hint .ih-text { flex: 1; }
.install-hint .ih-install { margin-left: 8px; }
.install-hint .ih-share { display: inline-flex; vertical-align: -3px; color: var(--accent); }
.install-hint .ih-close { background: none; border: 0; font-size: 16px; color: var(--muted); cursor: pointer; padding: 4px; }

/* heat (estrus) badge: brand colour, not a status colour */
.heat-badge { display: inline-block; margin-top: 8px; padding: 3px 8px; border-radius: 8px; font-size: 13px; font-weight: 600;
  background: var(--brand-soft); color: var(--accent); }
.heat-badge.possible { font-weight: 500; }
td .heat-badge { margin-top: 0; }
#heat-chart { margin: 10px 0; }

/* health index: status colours with an icon and words, never colour alone */
.health-badge { display: inline-block; margin-top: 6px; padding: 3px 8px; border-radius: 8px; font-size: 13px; font-weight: 600;
  border: 1px solid currentColor; }
.health-badge.watch { color: var(--warning); }
.health-badge.check { color: var(--critical); }
.health-score { display: inline-block; min-width: 2.2em; padding: 1px 8px; border-radius: 8px; font-size: 18px; text-align: center;
  border: 1px solid currentColor; }
.health-score.ok { color: var(--good); } .health-score.watch { color: var(--warning); }
.health-score.check { color: var(--critical); } .health-score.heat { color: var(--accent); }
#health-chart { margin-top: 10px; }
/* two-series chart legend */
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.legend i.ln { height: 3px; width: 14px; border-radius: 2px; }
