/* ══════════════════════════════════════════════════════════════════════════
   DAIRY SUITE THEME — matches the Next.js farm app
   ══════════════════════════════════════════════════════════════════════════

   Loaded AFTER styles.css and overrides it. Nothing in styles.css or in the
   prototype markup is edited, so the build's byte-identity check on the
   inherited source still holds, and this whole layer can be removed by
   deleting one <link>.

   Palette taken from the farm app's globals.css, which defines everything in
   OKLCH around hue 155 (the green spine). Converted to hex here because this
   stylesheet has to work on older Android browsers in the field, where oklch()
   is not reliably supported.

     background   oklch(0.957 0.006 95)   #F2F1EC   warm paper, not grey
     primary      oklch(0.52 0.115 155)   #1F7C4B   pasture green
     sidebar      oklch(0.28 0.05 155)    #12301E   deep forest
     brand        oklch(0.66 0.16 155)    #10AE65   the vivid mark

   Layout: a green sidebar and a white top bar (src/app/40-shell.js) around a
   light grey page of white cards. The prototype's own header stays in
   index.html untouched and is hidden. The dashboard is src/app/45-dashboard.js.
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  /* ── surfaces ── */
  --bg: #F5F6F4;
  --surface: #FFFFFF;
  --surface2: #F3F3ED;
  --border: #E1E0DA;
  --border2: #D6D5CE;

  /* ── text ── */
  --text: #132018;
  --text2: #4A5750;
  --text3: #696E65;

  /* ── green spine ── */
  --accent: #1F7C4B;
  --accent-lt: #DCF2E3;
  --green: #1F7C4B;
  --green-lt: #DCF2E3;

  /* ── semantic accents: green up, salmon down, amber pending, blue rest ── */
  --red: #D05444;
  --red-lt: #FBEAE7;
  --amber: #DDA552;
  --amber-lt: #FAF2E4;
  --teal: #5E95C3;
  --teal-lt: #E9F0F7;
  --violet: #854ECE;
  --violet-lt: #F1EAFA;

  --radius: 10px;              /* farm app --radius: 0.625rem */
  --shadow: 0 1px 3px rgba(19, 32, 24, .07);

  /* ── sidebar ── */
  --sidebar: #12301E;
  --sidebar-fg: #D7E1D7;
  --sidebar-primary: #245337;
  --sidebar-accent: #1E402B;
  --sidebar-border: #294433;
  --brand: #10AE65;
  --sidebar-w: 252px;
}

html[data-theme="dark"] {
  --bg: #0D1610;
  --surface: #16211A;
  --surface2: #212F26;
  --border: #26372C;
  --border2: #2F4436;
  --text: #EAF1EA;
  --text2: #C4D0C5;
  --text3: #9DA89D;
  --accent: #3FB171;
  --accent-lt: #22392A;
  --green: #3FB171;
  --green-lt: #22392A;
  --red: #E76250;
  --red-lt: #35211D;
  --sidebar: #061009;
  --sidebar-primary: #1D472E;
  --sidebar-accent: #132A1B;
  --sidebar-border: #1E3325;
}

/* ══ SHELL ════════════════════════════════════════════════════════════════
   Built by src/app/40-shell.js: a green sidebar and a white top bar. The
   prototype's own header stays in the markup (byte-identical) but is hidden;
   its bell, dark-mode toggle and account menu are moved into the top bar.   */

:root {
  --sb-w: 268px;
  --sb-bg: #1D5337;
  --sb-text: #E9F2EC;
  --sb-muted: #A3C2AF;
  --sb-line: rgba(255, 255, 255, .13);
  --sb-hover: rgba(255, 255, 255, .07);
  --sb-active: rgba(255, 255, 255, .13);
}
html[data-theme="dark"] { --sb-bg: #0F2A1B; }

body { background: var(--bg); }
.header,
.nav-drawer,
.nav-drawer-overlay { display: none !important; }

/* ── sidebar ── */
#ds-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 300;
  width: var(--sb-w);
  display: flex;
  flex-direction: column;
  padding: 22px 16px 14px;
  overflow-y: auto;
  background: var(--sb-bg);
  color: var(--sb-text);
  font-family: 'DM Sans', system-ui, sans-serif;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .2) transparent;
}
.sb-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 8px 22px;
  font-size: 26px; font-weight: 700; letter-spacing: -.02em; color: #fff;
}
.sb-farm {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 24px; padding: 12px 14px;
  border: 1px solid var(--sb-line); border-radius: 10px;
}
.sb-farm b { display: block; font-size: 14.5px; font-weight: 600; color: #fff; }
.sb-farm small { display: block; font-size: 12.5px; color: var(--sb-muted); margin-top: 1px; }
.sb-label {
  padding: 0 10px; margin: 2px 0 8px;
  font-size: 12.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--sb-muted);
}
.sb-list { display: flex; flex-direction: column; gap: 2px; }
.sb-item {
  position: relative;
  display: flex; align-items: center; gap: 16px;
  width: 100%; padding: 11px 14px;
  border: 0; border-radius: 8px; background: none;
  font: 500 15.5px/1.2 'DM Sans', system-ui, sans-serif; color: var(--sb-text);
  text-align: left; cursor: pointer;
  transition: background .15s;
}
.sb-item:hover { background: var(--sb-hover); }
.sb-item.is-active { background: var(--sb-active); color: #fff; font-weight: 600; }
.sb-item.is-active::before {
  content: ''; position: absolute; left: -16px; top: 6px; bottom: 6px;
  width: 4px; border-radius: 0 4px 4px 0; background: #fff;
}
.sb-item:focus-visible, .sb-account:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.sb-sep { height: 1px; margin: 16px 6px; background: var(--sb-line); }
.sb-bottom { margin-top: auto; padding-top: 10px; }
.sb-account {
  display: flex; align-items: center; gap: 14px;
  width: 100%; padding: 6px 8px;
  border: 0; border-radius: 10px; background: none;
  color: var(--sb-text); font-family: inherit; text-align: left; cursor: pointer;
}
.sb-account:hover { background: var(--sb-hover); }
.sb-avatar {
  width: 46px; height: 46px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: rgba(255, 255, 255, .16);
  font-size: 16px; font-weight: 700; color: #fff;
}
.sb-who { flex: 1; min-width: 0; }
.sb-name { display: block; font-size: 15.5px; font-weight: 600; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-role { display: block; font-size: 12.5px; color: var(--sb-muted); }
.sb-role:empty { display: none; }

/* ── top bar ── */
#ds-topbar {
  position: sticky; top: 0; z-index: 150;
  display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-family: 'DM Sans', system-ui, sans-serif;
}
.tb-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.tb-crumbs { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--text3); white-space: nowrap; }
.tb-crumbs b { font-weight: 500; color: var(--text); }
.tb-spacer { flex: 0 0 auto; }
.tb-sep { width: 1px; height: 28px; background: var(--border); margin: 0 4px; }
.ds-burger { display: none !important; }

.ds-preview {
  display: none; padding: 3px 10px; border-radius: 999px;
  background: #E7EEF8; color: #3B5B8C; font-size: 12.5px; font-weight: 500; white-space: nowrap;
}
.ds-preview.is-on { display: inline-block; }
html[data-theme="dark"] .ds-preview { background: #1B2A38; color: #9FC3E6; }

.ds-wx { position: relative; }
.ds-wx-btn {
  display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 6px;
  border: 0; background: none; font: 15px 'DM Sans', system-ui, sans-serif; color: var(--text); cursor: pointer;
}
.ds-wx-temp { font-variant-numeric: tabular-nums; }
.ds-wx-loc { color: var(--text); }
.ds-wx-pop {
  display: none; position: absolute; top: calc(100% + 10px); right: 0; z-index: 400;
  padding: 10px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .10);
}
.ds-wx.is-open .ds-wx-pop { display: flex; gap: 4px; }
.ds-wx-day { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 44px; padding: 6px 4px; border-radius: 8px; font-size: 11px; color: var(--text3); }
.ds-wx-day.is-today { background: var(--accent-lt); color: var(--accent); }
.ds-wx-day b { color: var(--text); font-weight: 600; }
.ds-wx-day small { font-size: 10px; }

.ds-icon-btn,
#ds-topbar .dm-toggle,
#ds-topbar button[onclick="toggleNotifPanel()"] {
  width: 38px !important; height: 38px !important;
  display: flex !important; align-items: center; justify-content: center;
  border: 0 !important; border-radius: 10px !important; background: none !important;
  color: var(--text2); font-size: 18px !important; cursor: pointer;
}
.ds-icon-btn:hover,
#ds-topbar .dm-toggle:hover,
#ds-topbar button[onclick="toggleNotifPanel()"]:hover { background: var(--surface2) !important; }
#ds-topbar .dm-toggle span,
#ds-topbar button[onclick="toggleNotifPanel()"] { filter: grayscale(1); }
.ds-icon-btn.is-busy svg { animation: dsSpin .8s linear infinite; }
@keyframes dsSpin { to { transform: rotate(360deg); } }

#notif-badge:empty { display: none !important; }
#notif-badge {
  top: 5px !important; right: 5px !important;
  width: auto !important; min-width: 8px; height: 15px !important; padding: 0 3px;
  border-radius: 999px !important; font-size: 9.5px !important;
  border: 2px solid var(--surface); box-sizing: content-box; filter: none;
}
#notif-panel { top: calc(100% + 10px) !important; }

/* account: dark-green initials and a chevron, as in the design */
.tb-account button {
  border: 0 !important; background: none !important; padding: 2px !important; gap: 8px !important;
}
.tb-account button > div:first-child {
  width: 40px !important; height: 40px !important;
  background: var(--sb-bg) !important; color: #fff !important;
  font-size: 14px !important; font-weight: 600 !important;
}
.tb-account button > div:nth-child(2) { display: none !important; }
.tb-account button > span { font-size: 14px !important; }
#admin-drop { top: calc(100% + 10px) !important; right: 0 !important; z-index: 400; }

/* ── page area ── */
@media (min-width: 1024px) {
  body { padding-left: var(--sb-w); }
}
.main { padding: 22px 28px 48px; max-width: 1680px; }

/* ── phones and tablets: the sidebar slides in ── */
#ds-drawer-shade {
  display: none; position: fixed; inset: 0; z-index: 290;
  background: rgba(0, 0, 0, .4);
}
@media (max-width: 1023px) {
  #ds-sidebar { transform: translateX(-100%); transition: transform .22s ease; box-shadow: none; }
  body.ds-drawer-open #ds-sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  body.ds-drawer-open #ds-drawer-shade { display: block; }
  .ds-burger { display: flex !important; margin-left: -8px; }
  #ds-topbar { padding: 0 14px; gap: 6px; }
  .tb-crumbs span { display: none; }
  .tb-crumbs b { font-weight: 600; }
}
/* Dark mode lives in the menu on phones (the top bar needs the room). */
.sb-item[data-key="theme"] { display: none !important; }
@media (max-width: 640px) {
  .sb-item[data-key="theme"] { display: flex !important; }
  #ds-topbar .dm-toggle, .tb-account button > span { display: none !important; }
  /* the demo banner above says the same as "Preview data" on a phone */
  .ds-wx-loc, #ds-refresh, #ds-topbar .tb-sep, .ds-preview.is-on { display: none; }
  .ds-wx-pop { right: -90px; }
  .main { padding: 16px 12px 88px !important; }
}

/* ══ CARDS ════════════════════════════════════════════════════════════════ */
.card, .stat-card, .panel {
  background: var(--surface);
  border-color: var(--border);
  border-radius: var(--radius);
}

/* ══ DASHBOARD ════════════════════════════════════════════════════════════
   Markup from src/app/45-dashboard.js: white cards on a light grey page. The
   layout follows its own width (container queries), since that depends on
   whether the sidebar is showing.                                          */

.db { font-family: 'DM Sans', system-ui, sans-serif; color: var(--text); container-type: inline-size; }
.db h1, .db h2, .db h3 { font-family: 'DM Sans', system-ui, sans-serif; }
.db button, .db select { font-family: inherit; }
.db-click { cursor: pointer; }

.db-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.db-title { margin: 0; font-size: 34px; line-height: 1.15; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.db-date { margin: 4px 0 0; font-size: 17px; color: var(--text2); }
.db-head-actions { display: flex; gap: 12px; align-items: center; padding-top: 4px; }

.ds-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 46px; padding: 0 20px;
  border: 1px solid var(--border2); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: 500 15px/1 'DM Sans', system-ui, sans-serif; white-space: nowrap; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.ds-btn:hover { background: var(--surface2); }
.ds-btn-primary { border-color: #1A5C3A; background: #1A5C3A; color: #fff; }
.ds-btn-primary:hover { background: #144A2E; border-color: #144A2E; }
html[data-theme="dark"] .ds-btn-primary { background: #3FB171; border-color: #3FB171; color: #06140B; }

.db-card {
  min-width: 0;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.db-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.db-card-title { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -.01em; color: var(--text); display: flex; align-items: center; gap: 10px; }
.db-card-sub { margin: 4px 0 0; font-size: 14px; color: var(--text2); }
.db-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; height: 28px; padding: 0 6px; border-radius: 999px;
  background: var(--surface2); font-size: 14px; font-weight: 600; color: var(--text);
}
.db-link { border: 0; background: none; padding: 0; color: #2F6FB0; font-size: 15px; cursor: pointer; white-space: nowrap; }
.db-link:hover { text-decoration: underline; }
html[data-theme="dark"] .db-link { color: #8DB8E6; }

/* ── KPIs ── */
.db-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 22px 0; margin-bottom: 16px; }
.db-kpi { padding: 2px 30px; border-left: 1px solid var(--border); cursor: pointer; }
.db-kpi:first-child { border-left: 0; }
.db-kpi-label { font-size: 15.5px; color: var(--text2); }
.db-kpi-val { margin: 8px 0 8px; font-size: 34px; line-height: 1; font-weight: 700; letter-spacing: -.02em; color: var(--text); white-space: nowrap; font-variant-numeric: tabular-nums; }
.db-kpi-val .db-delta { margin-left: 8px; font-size: 13px; font-weight: 600; letter-spacing: 0; vertical-align: middle; }
.db-kpi-sub { font-size: 15.5px; color: var(--text2); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.db-up { color: #1E7A4A; }
.db-down { color: var(--red); }
.db-mon { display: inline-flex; align-items: center; gap: 2px; }
.db-mon button {
  width: 22px; height: 22px; padding: 0; border: 0; border-radius: 6px; background: none;
  color: var(--text3); font-size: 15px; line-height: 1; cursor: pointer;
}
.db-mon button:hover { background: var(--surface2); color: var(--text); }

/* ── rows of cards ── */
.db-row { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; align-items: stretch; }

/* ── chart ── */
.db-seg { display: inline-flex; padding: 3px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.db-seg button {
  border: 0; background: none; padding: 6px 16px; border-radius: 6px;
  font-size: 14px; color: var(--text2); cursor: pointer;
}
.db-seg button.is-on { background: #DCEFE2; color: #17583A; font-weight: 600; }
html[data-theme="dark"] .db-seg button.is-on { background: #22392A; color: #9AD8B1; }
.db-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.db-chart .grid line { stroke: var(--border); }
.db-chart .axis text { fill: var(--text2); font-size: 13px; }
.db-chart .last { fill: var(--text); font-size: 14px; font-weight: 700; paint-order: stroke; stroke: var(--surface); stroke-width: 5px; stroke-linejoin: round; }
.db-chart .line { fill: none; stroke: #1A5C3A; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
html[data-theme="dark"] .db-chart .line { stroke: #3FB171; }
.db-chart .pt { fill: #1A5C3A; stroke: var(--surface); stroke-width: 2; cursor: pointer; }
html[data-theme="dark"] .db-chart .pt { fill: #3FB171; }
.db-legend { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 14px; color: var(--text2); }
.db-legend i { width: 10px; height: 10px; border-radius: 50%; background: #1A5C3A; }
.db-empty { padding: 36px 16px; text-align: center; color: var(--text3); font-size: 14.5px; }
.db-empty .ds-btn { margin-top: 12px; height: 40px; }
#db-chart-tip {
  display: none; position: fixed; z-index: 9999; pointer-events: none;
  padding: 6px 10px; border-radius: 8px; background: #111827; color: #fff;
  font: 600 12px/1.35 'DM Sans', system-ui, sans-serif;
}

/* ── needs attention ── */
.db-att { list-style: none; margin: 0; padding: 0; }
.db-att li {
  display: flex; align-items: center; gap: 16px;
  padding: 15px 4px; border-top: 1px solid var(--border); cursor: pointer;
}
.db-att li:hover { background: var(--surface2); }
.db-dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
.db-dot.high { background: #D9483B; }
.db-dot.med { background: #E9A23B; }
.db-dot.low { background: #6C94BC; }
.db-dot.ok { background: #2E8B57; }
.db-att-main { flex: 1; min-width: 0; }
.db-att-title { font-size: 16px; font-weight: 500; color: var(--text); }
.db-att-sub { font-size: 14.5px; color: var(--text2); margin-top: 2px; }
.db-chev { color: var(--text3); flex-shrink: 0; display: flex; }

/* ── tables ── */
.db-table-wrap { overflow-x: auto; margin: 0 -2px; }
.db-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.db-table th {
  padding: 9px 10px; text-align: left; white-space: nowrap;
  font-size: 12.5px; font-weight: 500; letter-spacing: .05em; text-transform: uppercase; color: var(--text2);
  background: var(--surface2); border-bottom: 1px solid var(--border);
}
.db-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); color: var(--text); white-space: nowrap; font-variant-numeric: tabular-nums; }
.db-table tbody tr { cursor: pointer; }
.db-table tbody tr:hover td { background: var(--surface2); }
.db-table .num { text-align: center; }
.db-status { display: inline-flex; align-items: center; gap: 10px; }
.db-status::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.db-status span { color: var(--text); }
.db-st-ok { color: #1E7A4A; }
.db-st-warn { color: #E9A23B; }
.db-st-low { color: #D9483B; }
.db-st-rest { color: #8B9490; }
.db-cov-low { color: #D9483B; }
.db-cov-warn { color: #B26A14; }
.db-cov-ok { color: #1E7A4A; }
.db-foot { margin-top: 10px; font-size: 14px; color: var(--text2); }
.db-select {
  width: auto; flex: 0 0 auto;     /* styles.css makes every select full width */
  height: 38px; padding: 0 34px 0 14px;
  border: 1px solid var(--border2); border-radius: 8px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23596159' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--text); font-size: 14px; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}

/* ── herd overview ── */
.db-bar { display: flex; gap: 3px; height: 22px; margin: 4px 0 18px; }
.db-bar span { border-radius: 3px; min-width: 6px; }
.db-herd-row { display: grid; grid-template-columns: 22px 1fr 60px 64px; align-items: center; padding: 6px 0; font-size: 15.5px; }
.db-herd-row b { text-align: right; font-weight: 700; color: var(--text); }
.db-herd-row em { text-align: right; font-style: normal; color: var(--text2); font-size: 14.5px; }
.db-herd-row i { width: 13px; height: 13px; border-radius: 50%; }
.db-preg {
  display: grid; grid-template-columns: 1fr 60px 64px; align-items: center;
  margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--border);
  font-size: 15.5px; cursor: pointer;
}
.db-preg small { color: var(--text2); font-size: 14px; }
.db-preg b { text-align: right; }
.db-preg .db-chev { justify-self: end; }

/* ── quick actions ── */
.db-quick { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: center; }
.db-qlist { list-style: none; margin: 0; padding: 0; }
.db-qlist li {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 4px; border-top: 1px solid var(--border);
  font-size: 15.5px; color: var(--text); cursor: pointer;
}
.db-qlist li:hover { background: var(--surface2); }
.db-qlist li > span:not(.db-chev) { flex: 1; white-space: nowrap; }
.db-qlist svg { color: var(--text2); }
.db-buddy-wrap { padding-left: 14px; border-left: 1px solid var(--border); align-self: stretch; display: flex; align-items: center; }
.db-buddy {
  display: flex; align-items: center; gap: 8px;
  padding: 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font-size: 14.5px; font-weight: 500; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .05);
}
.db-buddy:hover { border-color: #1A5C3A; }

/* ── kept from the earlier dashboard ── */
.db-list { list-style: none; margin: 0; padding: 0; }
.db-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.db-rank { width: 22px; text-align: center; font-weight: 700; color: var(--text3); font-size: 13px; }
.db-li-main { flex: 1; min-width: 0; }
.db-li-title { font-size: 15px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-li-sub { font-size: 13px; color: var(--text3); }
.db-li-val { font-weight: 700; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.db-li-ico { color: var(--text2); display: flex; }

/* ── narrower content ── */
@container (max-width: 1100px) {
  .db-kpi { padding: 2px 20px; }
  .db-kpi-val { font-size: 30px; }
}
@container (max-width: 940px) {
  .db-row { grid-template-columns: minmax(0, 1fr); }
  .db-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 22px; }
  .db-kpi:nth-child(3) { border-left: 0; }
}
@container (max-width: 520px) {
  .db-title { font-size: 26px !important; }
  .db-date { font-size: 15px; }
  .db-head-actions { width: 100%; }
  .db-head-actions .ds-btn { flex: 1; height: 42px; padding: 0 12px; }
  .db-kpis { padding: 16px 0; }
  .db-kpi { padding: 2px 14px; }
  .db-kpi-val { font-size: 25px; }
  .db-kpi-label, .db-kpi-sub { font-size: 13.5px; }
  .db-card { padding: 16px 14px; }
  .db-card-title { font-size: 19px; }
  .db-card-head { flex-wrap: wrap; }
  .db-quick { grid-template-columns: minmax(0, 1fr); }
  .db-buddy-wrap { padding-left: 0; border-left: 0; }
  .db-buddy { width: 100%; }
}

/* ══ PHONES ═══════════════════════════════════════════════════════════════
   With src/app/48-mobile.js (which fits each page's grids, toolbars and
   tables after it renders), the fixes here are the structural ones.        */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: rgba(31, 107, 69, .12); }

/* every table scrolls sideways inside its own box, never the page */
.ds-tscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

@media (max-width: 768px) {
  /* Grid and flex children may shrink below their content, so a long word
     or a wide child cannot push the page sideways. */
  .main [style*="display:grid"] > *,
  .main [style*="display: grid"] > * { min-width: 0; }

  /* Animal card: profile above the details instead of a 290px side column. */
  .ac-layout { grid-template-columns: minmax(0, 1fr) !important; }
  .right-panel, .profile-card, .sec { min-width: 0; }

  .page-top { flex-wrap: wrap; }

  /* FarmBuddy sits above the bottom bar, and its chat fits the screen.
     (styles.css aimed these rules at #fb-btn, which does not exist.) */
  #fb-root-btn {
    width: 52px !important; height: 52px !important;
    right: 14px !important; bottom: calc(82px + env(safe-area-inset-bottom, 0px)) !important;
  }
  #fb-chat {
    left: 8px !important; right: 8px !important; width: auto !important; max-width: none !important;
    bottom: calc(144px + env(safe-area-inset-bottom, 0px)) !important;
    max-height: calc(100vh - 230px) !important;
    max-height: calc(100dvh - 230px) !important;
  }

  /* Menus from the top bar open as panels across the screen. */
  /* Below the top bar wherever it is (a banner above it moves it down);
     --ds-top is kept up to date by 48-mobile.js. */
  #notif-panel {
    position: fixed !important; top: calc(var(--ds-top, 56px) + 6px) !important; left: 8px !important; right: 8px !important;
    width: auto !important; max-height: 70vh; overflow-y: auto;
  }
  #admin-drop { position: fixed !important; top: calc(var(--ds-top, 56px) + 6px) !important; right: 8px !important; left: auto !important; }

  /* The slide-in menu covers the bottom bar while it is open. */
  #ds-sidebar { z-index: 700; padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
  #ds-drawer-shade { z-index: 690; }

  /* A pop-up has the screen to itself (48-mobile.js sets the class). */
  body.ds-modal-open #fb-root-btn,
  body.ds-modal-open #fb-chat,
  body.ds-modal-open .mobile-bottom-nav { display: none !important; }

  /* Prototype modals: never taller than the screen. */
  /* dvh, not vh: on iOS Safari 100vh ignores the address bar, which then hides
     the bottom of a pop-up (its Save buttons). vh stays as the fallback. */
  .modal-content { max-height: 92vh !important; max-height: 92dvh !important; }
  [id$="-modal"] > div, #generic-modal-overlay > div {
    max-width: calc(100vw - 16px) !important;
    max-height: 92vh !important; max-height: 92dvh !important; overflow-y: auto;
  }
}

/* ── fixes for every screen size, found while fitting phones ── */

/* The page fade-in left `transform: translateY(0)` on .main (fill-mode
   `both`). A transform makes the page the containing block for
   position:fixed children, so pop-ups drawn inside a page — Record milk's
   entry form among them — were centred on the whole page, often thousands
   of pixels below the screen. Opacity-only keeps the fade and fixes that. */
@keyframes pageIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes dsFade { from { opacity: 0; } to { opacity: 1; } }
/* …and an opacity animation held after it ends (`both`) still makes the
   page its own stacking layer, so those pop-ups (medicine inventory, pen
   moves) sat UNDER the top bar, their headers covered on phones.
   `backwards` keeps the fade-in and lets go when it finishes. */
#page-content, #tab-content, .main { animation-fill-mode: backwards; }

/* Form rows: let columns shrink below a date picker's natural width, so
   three fields share the row evenly instead of one squeezing the others. */
.field-row > * { min-width: 0; }
.field-row input, .field-row select, .field-row textarea { max-width: 100%; }

/* The toast parked itself 130% of its own width off-screen; an empty toast
   is ~37px wide, so ~9px of it stayed visible at the right edge. */
.notif:not(.show) { transform: translateX(calc(100% + 60px)); visibility: hidden; transition: transform .34s, visibility 0s .34s; }
.notif.show { visibility: visible; transition: transform .34s cubic-bezier(.34, 1.4, .45, 1); }

/* Long page names truncate instead of running under the weather. */
.tb-left { flex: 1 1 auto; min-width: 0; }
.tb-crumbs { min-width: 0; overflow: hidden; }
.tb-crumbs b { overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 768px) {
  /* ── tables as cards (48-mobile.js marks them .ds-cards) ── */
  .ds-tscroll.ds-tcards { overflow: visible; }
  table.ds-cards, table.ds-cards > tbody, table.ds-cards > tfoot { display: block; width: 100% !important; min-width: 0 !important; }
  table.ds-cards > thead { display: none; }
  /* One layout per table (48-mobile.js decides per COLUMN, so every card of
     a list puts each field in the same place). 6 tracks: short values
     (numbers, dates, amounts) three to a row, longer values two to a row,
     input fields three to a row, the title and wide cells across the card. */
  table.ds-cards tr {
    display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); column-gap: 12px; row-gap: 0;
    margin: 0 0 10px; padding: 10px 12px 8px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  }
  table.ds-cards td, table.ds-cards th {
    grid-column: span 3;
    display: block; padding: 3px 0 !important; border: 0 !important; background: none !important;
    text-align: left !important; font-size: 14px !important; line-height: 1.35;
    white-space: normal !important; overflow-wrap: anywhere;
    min-width: 0; max-width: none !important; width: auto !important; height: auto !important;
  }
  table.ds-cards td::before, table.ds-cards th::before {
    content: attr(data-label); display: block;
    font: 600 11px/1.3 'DM Sans', system-ui, sans-serif; letter-spacing: .02em; color: var(--text3);
    text-transform: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  table.ds-cards td[data-label=""]::before, table.ds-cards th[data-label=""]::before { display: none; }
  table.ds-cards td.ds-short { grid-column: span 2; }
  table.ds-cards td.ds-none { display: none; }
  table.ds-cards td.ds-full { grid-column: 1 / -1; }

  /* title across the top; tick box to its left; actions to its right */
  table.ds-cards td.ds-title { grid-column: 1 / -1; grid-row: 1; font-size: 15.5px !important; font-weight: 600; padding-bottom: 5px !important; }
  table.ds-cards td.ds-title::before { display: none; }
  table.ds-cards td.ds-check { grid-column: 1 / 2; grid-row: 1; display: flex; align-items: center; }
  table.ds-cards td.ds-check input { width: 22px; height: 22px; min-height: 0 !important; }
  table.ds-cards tr.ds-has-check td.ds-title { grid-column: 2 / -1; }
  table.ds-cards tr.ds-has-act td.ds-title { grid-column: 1 / 5; }
  table.ds-cards tr.ds-has-act.ds-has-check td.ds-title { grid-column: 2 / 5; }
  table.ds-cards td.ds-act { grid-column: 5 / -1; grid-row: 1; display: flex; justify-content: flex-end; align-items: flex-start; flex-wrap: wrap; gap: 6px; padding-top: 0 !important; }
  table.ds-cards td.ds-act::before { display: none; }

  /* buttons inside cards: finger-sized, and never past the card edge */
  table.ds-cards td button, table.ds-cards td .btn {
    min-height: 38px !important; max-width: 100%; padding: 6px 12px !important; white-space: normal;
  }

  /* input cells: three to a row, label above the field */
  table.ds-cards td.ds-in { grid-column: span 2; }
  table.ds-cards td.ds-in input, table.ds-cards td.ds-in select, table.ds-cards td.ds-in textarea {
    width: 100% !important; min-width: 0 !important; padding: 8px !important; min-height: 42px !important;
  }
  /* text fields and pickers need room for words: two to a row; the leading
     name field runs across the top of the card */
  table.ds-cards td.ds-inwide { grid-column: span 3; }
  table.ds-cards td.ds-lead { grid-column: 1 / -1; grid-row: 1; }
  table.ds-cards tr.ds-has-act td.ds-lead { grid-column: 1 / 5; }
  table.ds-cards td.ds-lead input { font-weight: 600; font-size: 15px !important; }

  /* buttons with words: their own row along the bottom of the card */
  table.ds-cards td.ds-actrow { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; padding-top: 8px !important; }
  table.ds-cards td.ds-actrow::before { display: none; }
  table.ds-cards td.ds-actrow > div { display: flex; flex-direction: row !important; flex-wrap: wrap; gap: 6px; }
  table.ds-cards td.ds-check { font-size: 18px !important; }
  table.ds-cards td button, table.ds-cards td .btn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Fields line up from card to card and row to row: short values first,
     three to a row, then longer ones two to a row, then wide ones. (Title,
     tick box and icon buttons are placed on row 1 explicitly; order does
     not move them.) */
  table.ds-cards td { order: 2; }
  table.ds-cards td.ds-short, table.ds-cards td.ds-in:not(.ds-inwide) { order: 1; }
  table.ds-cards td.ds-full { order: 3; }
  table.ds-cards td.ds-actrow { order: 4; }

  /* pills and chips stay inside the card: one line, cut with "…" */
  table.ds-cards td .pill, table.ds-cards td .chip, table.ds-cards td .badge,
  table.ds-cards td span[style*="border-radius"][style*="padding"] {
    display: inline-block; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle;
  }

  /* totals, group headings, "no records": a plain line, no labels */
  table.ds-cards tr.ds-sum { background: var(--surface2); }
  table.ds-cards tr.ds-sum td { font-weight: 600; }
  table.ds-cards tr.ds-sum td:empty { display: none; }
  table.ds-cards tr.ds-sum td.ds-full { order: 0; }
  table.ds-cards tr:hover td { background: none !important; }

  /* ── tables that keep scrolling (matrices, calendars): first column stays ── */
  .ds-tscroll > table:not(.ds-cards) tr > :first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
  .ds-tscroll > table:not(.ds-cards) thead tr > :first-child { background: var(--surface2); }
  .ds-tscroll > table:not(.ds-cards) th { white-space: nowrap; }
  .ds-tscroll td input { min-width: 72px; padding: 8px !important; min-height: 40px !important; }

  /* ── tab strips: fade the edge that has more tabs beyond it ── */
  .sub-tab-bar.ds-fade-r, #fin-sub-tabs.ds-fade-r { -webkit-mask-image: linear-gradient(90deg, #000 80%, transparent); mask-image: linear-gradient(90deg, #000 80%, transparent); }
  .sub-tab-bar.ds-fade-l, #fin-sub-tabs.ds-fade-l { -webkit-mask-image: linear-gradient(270deg, #000 80%, transparent); mask-image: linear-gradient(270deg, #000 80%, transparent); }
  .sub-tab-bar.ds-fade-l.ds-fade-r, #fin-sub-tabs.ds-fade-l.ds-fade-r { -webkit-mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent); mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent); }

  /* ── small things the reviews flagged ── */
  /* pills and badges never break across lines */
  .main span[style*="border-radius"][style*="padding"], .pill, .badge { white-space: nowrap; }
  /* inputs with a leading search icon keep room for it (styles.css forced padding:12px) */
  .main input[style*="padding-left:2"], .main input[style*="padding-left:3"],
  .main input[style*="padding-left: 2"], .main input[style*="padding-left: 3"] { padding-left: 36px !important; }
  /* narrow fixed-width inputs show their whole value */
  .main input[style^="width:"]:not([type="checkbox"]):not([type="radio"]):not([style*="width:100%"]), .main input[style*=";width:"]:not([type="checkbox"]):not([type="radio"]):not([style*="width:100%"]), .main input[style*="; width:"]:not([type="checkbox"]):not([type="radio"]):not([style*="width:100%"]) { padding-left: 8px !important; padding-right: 8px !important; min-width: 84px; }
  /* charts that scroll sideways */
  .ds-chart-scroll { padding-bottom: 4px; }
  /* tap targets on the dashboard's month switch */
  .db-mon button { width: 36px; height: 36px; font-size: 18px; }
  .db-qlist li .db-chev { margin-left: auto; }
  .db-mon { white-space: nowrap; }
  /* score chips and similar never split a word */
  .main [class*="chip"], .main [class*="pill"], .main [class*="badge"] { white-space: nowrap; }
  /* finger-sized buttons across the pages (Prev/Today/Next were 26px) */
  .main button:not(.stab):not([role="tab"]), .main .btn { min-height: 38px; }
  .ds-chart-scroll.ds-fade-l { -webkit-mask-image: linear-gradient(270deg, #000 85%, transparent); mask-image: linear-gradient(270deg, #000 85%, transparent); }
  .ds-chart-scroll.ds-fade-r { -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); }
}

/* Dark mode: off-white panels the prototype paints inline that styles.css's
   list of light backgrounds missed (the P&L "Milk revenue by buyer" block,
   breakdown boxes). Tinted badges and alerts keep their tint on purpose —
   their dark text needs it. */
html[data-theme="dark"] [style*="background:#f8faf8"],
html[data-theme="dark"] [style*="background:#fafafa"],
html[data-theme="dark"] [style*="background:#f7f8fa"],
html[data-theme="dark"] [style*="background:#fafff8"],
html[data-theme="dark"] [style*="background:#fef9f5"],
html[data-theme="dark"] [style*="background:#FEFAF5"],
html[data-theme="dark"] [style*="background:#fff8f8"],
html[data-theme="dark"] [style*="background:#fff5f5"] { background: var(--surface2) !important; }

@media (max-width: 768px) {
  /* fixed-size score boxes (mastitis quarters: "Trace" in a 38px box broke
     as "Trac/e") grow to fit their word */
  table.ds-cards td [style*="display:inline-flex"][style*="width:"] { width: auto !important; min-width: 38px; padding: 0 6px; white-space: nowrap; }
}

@media (max-width: 768px) {
  /* tables that stay tables and scroll sideways */
  table.ds-wide td, table.ds-wide th { white-space: nowrap; }
  .ds-tscroll.ds-fade-r, .ds-tscroll-x.ds-fade-r { -webkit-mask-image: linear-gradient(90deg, #000 86%, transparent); mask-image: linear-gradient(90deg, #000 86%, transparent); }
  /* month plans and calendars: the name column may wrap, so the months show */
  .ds-tscroll > table.ds-matrix tr > :first-child { min-width: 84px; max-width: 120px; white-space: normal !important; }
}

/* styles.css styles text/number/date fields only; fields with no type, or
   email/phone/password/search/time, fell back to the browser's own look
   (black inset border, Arial) — in Add employee, Add user, the vaccination
   form. Same look as the rest; width left as each form sets it. */
input:not([type]), input[type="email"], input[type="tel"], input[type="password"],
input[type="search"], input[type="time"], input[type="month"], input[type="url"], input[type="datetime-local"] {
  background: var(--surface); border: 1px solid var(--border2); color: var(--text);
  padding: 8px 11px; border-radius: 8px; font-size: 13px; font-weight: 450;
  font-family: 'DM Sans', sans-serif; outline: none; transition: border .15s, box-shadow .15s;
}

@media (max-width: 768px) {
  /* step editors: each box labelled (48-mobile.js copies the column heading) */
  .ds-steprow > [data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 3px;
    font: 700 10.5px/1.2 'DM Sans', system-ui, sans-serif; letter-spacing: .03em; color: var(--text3); text-transform: uppercase;
  }
  .ds-steprow { row-gap: 8px !important; }
  .ds-steprow input, .ds-steprow select { min-width: 0 !important; }
  .ds-steprow .remove-btn { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; }
}

@media (max-width: 768px) {
  /* date filters show the whole date, not "mm/dd/yyy" under the icon */
  .main input[type="date"] { min-width: 150px; padding-right: 6px !important; }
}

@media (max-width: 768px) {
  /* the Users page adds its own 24px padding inside the page's padding */
  #page-users div[style^="padding:24px;max-width:1400px"] { padding: 0 !important; }
}

/* ── until the farm's data has loaded (config.js / 10-data-layer.js) ──
   Pages stay hidden so the prototype's built-in sample numbers are never
   shown; sidebar, top bar and sign-in stay usable. */
html.ds-loading .main { visibility: hidden !important; }
html.ds-loading body::after {
  content: 'Loading farm data…';
  position: fixed; left: 50%; top: 45%; transform: translate(-50%, -50%); z-index: 50;
  padding: 14px 22px; border-radius: 12px; background: var(--surface); color: var(--text2, #555);
  border: 1px solid var(--border); box-shadow: 0 6px 24px rgba(0, 0, 0, .08);
  font: 600 14px/1.4 'DM Sans', system-ui, sans-serif; white-space: nowrap; pointer-events: none;
}
@media (min-width: 769px) { html.ds-loading body::after { left: calc(50% + var(--sidebar-w, 252px) / 2); } }
html.ds-loading.ds-load-failed body::after { content: 'Can’t reach the farm database — retrying…'; color: #b45309; }
