/* ============================================
   AgriPricePH - Global Styles
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=DM+Sans:wght@300;400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

:root {
  --color-primary:        #1A3A2A;
  --color-primary-dark:   #122A1E;
  --color-primary-mid:    #2D5A3E;
  --color-accent:         #4CAF6E;
  --color-accent-hover:   #3D9E5F;
  --color-accent-light:   rgba(76, 175, 110, 0.12);
  --color-live:           #F59E0B;
  --color-live-bg:        rgba(245, 158, 11, 0.15);
  --color-danger:         #EF4444;
  --color-danger-bg:      rgba(239, 68, 68, 0.12);
  --color-warning:        #F59E0B;
  --color-info:           #3B82F6;
  --color-info-bg:        rgba(59, 130, 246, 0.12);
  --bg-body:              #F4F6F3;
  --bg-sidebar:           #1A3A2A;
  --bg-card:              #FFFFFF;
  --bg-input:             #F4F6F3;
  --text-primary:         #1C2B1E;
  --text-secondary:       #5A7060;
  --text-muted:           #647B6B;
  --text-sidebar:         #C5D9CA;
  --border-color:         #E2EAE4;
  --border-radius-sm:     6px;
  --border-radius:        10px;
  --border-radius-lg:     14px;
  --border-radius-xl:     20px;
  --shadow-sm:            0 1px 3px rgba(26,58,42,0.06), 0 1px 2px rgba(26,58,42,0.04);
  --shadow-md:            0 4px 12px rgba(26,58,42,0.08), 0 2px 6px rgba(26,58,42,0.05);
  --shadow-lg:            0 8px 24px rgba(26,58,42,0.10), 0 4px 12px rgba(26,58,42,0.06);
  --color-success:        #2D8A50;
  --color-success-bg:     rgba(45,138,80,0.12);
  --sidebar-width:        258px;
  --topbar-height:        64px;
  --content-padding:      28px;
  --font-sans:            'Plus Jakarta Sans', system-ui, sans-serif;
  --font-mono:            'DM Mono', monospace;
  --transition-fast:      150ms ease;
  --transition:           250ms ease;
  /* Spacing scale (4px base) */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px;
  /* Type scale */
  --fs-caption: 11px; --fs-small: 12px; --fs-body: 13px;
  --fs-h3: 16px; --fs-h2: 20px; --fs-h1: 24px;
  /* Pill radius */
  --radius-pill: 999px;
  /* Tooltip chip — deliberately dark in BOTH themes for legibility */
  --tooltip-bg: #1C2B1E;
  --tooltip-fg: #FFFFFF;
  /* Status TEXT (inline "Saved." / error messages): a darker shade than --color-danger/--color-success
     reads better on white; html.theme-dark swaps in lighter ones. */
  --color-danger-text:    #B91C1C;
  --color-success-text:   #2D8A50;
}

html.theme-dark {
  --bg-body:              #0f1a14;
  --bg-sidebar:           #0d1812;
  --bg-card:              #152820;
  --bg-input:             #1a3226;
  --text-primary:         #e8f0eb;
  --text-secondary:       #9bb0a4;
  --text-muted:           #849c8e;
  --text-sidebar:         #b8cfc4;
  --border-color:         #243d30;
  --color-accent-light:   rgba(76, 175, 110, 0.18);
  --color-danger-text:    #f87171;
  --color-success-text:   #6fd59a;
  --shadow-sm:            0 1px 3px rgba(0,0,0,0.25);
  --shadow-md:            0 4px 12px rgba(0,0,0,0.35);
}

html.theme-dark .log-viewer { background: #0a1410; }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 { font-weight: 600; line-height: 1.3; color: var(--text-primary); }
p { color: var(--text-secondary); }
a { text-decoration: none; color: inherit; }

/* ── Layout Shell ── */
#app { display: flex; width: 100%; min-height: 100vh; }

/* ── Sidebar ── the admin sidebar is styled in admin/css/sidebar.css (only the admin uses it). */

/* ── Main Content ── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  /* A flex item's default min-width is `auto` (its content's min-content size), not 0 — so a
     single wide descendant anywhere on the page (e.g. a table cell set to `white-space: nowrap`)
     was quietly forcing this whole column, and every card in it, past the viewport width instead
     of wrapping/shrinking. That's what made cards look "not responsive" even when their own CSS
     had the right breakpoints: the breakpoints were correct, but the container never actually
     shrank down to the width that should have triggered them. */
  min-width: 0;
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 var(--content-padding);
  gap: 16px;
  position: sticky; top: 0; z-index: 50;
}

.topbar-title { font-size: 18px; font-weight: 700; color: var(--text-primary); flex-shrink: 0; }

.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 8px 14px;
  margin-left: auto;
  min-width: 260px;
  position: relative;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-bar:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-light);
}

.search-bar input {
  border: none; background: none; outline: none;
  font-family: var(--font-sans);
  font-size: 13px; color: var(--text-primary);
  width: 100%;
}

.search-bar input::placeholder { color: var(--text-muted); }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.topbar-clock {
  text-align: right;
  padding-right: 12px;
  margin-right: 4px;
  border-right: 1px solid var(--border-color);
  line-height: 1.3;
}
.topbar-clock-date { font-size: 12px; font-weight: 600; color: var(--text-primary); }
.topbar-clock-time { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); margin-top: 1px; }

.topbar-user {
  display: flex; align-items: center; gap: 8px; cursor: pointer; margin-left: 4px;
  background: none; border: none; padding: 4px 6px; margin-right: -6px;
  font: inherit; color: inherit; text-align: left; border-radius: var(--border-radius-sm);
  transition: background var(--transition-fast);
}
.topbar-user:hover { background: var(--bg-input); }

.topbar-avatar {
  width: 36px; height: 36px;
  background: var(--color-primary-mid);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
  flex-shrink: 0; letter-spacing: 0.5px;
  overflow: hidden;
}

.topbar-avatar img { width: 100%; height: 100%; object-fit: cover; }

.topbar-user-info h4 { font-size: 13px; font-weight: 600; color: var(--text-primary); line-height: 1.3; }
.topbar-user-info span { font-size: 11px; color: var(--text-muted); font-weight: 400; }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  position: relative;
}

.icon-btn:hover { background: var(--bg-input); color: var(--text-primary); }

.notif-dot {
  width: 7px; height: 7px;
  background: var(--color-danger);
  border-radius: 50%;
  position: absolute; top: 6px; right: 6px;
  border: 1.5px solid white;
}

.notif-dot[hidden] { display: none; }
.notif-dot.has-count {
  width: auto; height: auto; min-width: 16px;
  top: 2px; right: 1px;
  padding: 1px 4px;
  border-radius: 999px;
  font-size: 9.5px; font-weight: 700; line-height: 12px;
  color: #fff; text-align: center;
}
.topbar-alert-row.is-unread .topbar-alert-title { font-weight: 700; }
.topbar-alert-row.is-unread { background: var(--bg-input); }

/* ── Global search suggestions ── */
.search-suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  z-index: 300;
  max-height: 320px;
  overflow-y: auto;
  padding: 6px 0;
}

.search-suggest-group {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 8px 12px 4px;
}

.search-suggest-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-family: var(--font-sans);
  transition: background var(--transition-fast);
}

.search-suggest-item:hover,
.search-suggest-item.active {
  background: var(--color-accent-light);
}

.search-suggest-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.search-suggest-route {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: capitalize;
  flex-shrink: 0;
}

/* ── Topbar alerts dropdown panel ── */
#topbar-alerts-anchor { position: relative; }

.topbar-alerts-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(380px, calc(100vw - 48px));
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  z-index: 400;
  display: flex;
  flex-direction: column;
  max-height: min(420px, 70vh);
}

.topbar-alerts-panel[hidden] { display: none !important; }

.topbar-alerts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.topbar-alerts-body {
  overflow-y: auto;
  flex: 1;
  padding: 4px 0;
}

.topbar-alerts-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.topbar-alert-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
}

.topbar-alert-row:last-child { border-bottom: none; }

.topbar-alert-text { flex: 1; min-width: 0; }

.topbar-alert-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
}

.topbar-alert-desc {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
  line-height: 1.4;
}

.topbar-alert-time {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.topbar-alerts-empty {
  padding: 20px 16px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-alerts-empty p { margin-bottom: 12px; }

/* ── Page Content ── */
.page-content {
  padding: var(--content-padding);
  flex: 1;
  display: none;
  overflow: hidden;
  min-height: calc(100vh - var(--topbar-height));
}

.page-content.active { display: block; }

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-color);
}

.card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.card-body { padding: 20px; }

/* ── Stat Cards ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 10px;
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
  cursor: default;
}

.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.stat-icon {
  width: 40px; height: 40px;
  border-radius: var(--border-radius-sm);
  display: flex; align-items: center; justify-content: center;
}

.stat-value { font-size: 24px; font-weight: 700; color: var(--text-primary); font-family: var(--font-mono); letter-spacing: -0.5px; }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.stat-change { font-size: 11px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.stat-change.up   { color: var(--color-accent); }
.stat-change.down { color: var(--color-danger); }
/* Cost indicators (currency, diesel): rising is the unwelcome direction, the opposite of the
   ML "lower is better" cards above — same red-up/green-down convention the rice price ticker
   already uses. */
.stat-change.cost-up   { color: var(--color-danger); }
.stat-change.cost-down { color: var(--color-accent); }

/* ── Grids ── */
.content-grid { display: grid; gap: 20px; }
.grid-2   { grid-template-columns: 1fr 1fr; }
.grid-3   { grid-template-columns: 1fr 1fr 1fr; }
.grid-2-1 { grid-template-columns: 2fr 1fr; }

/* ── Table ── */
.data-table { width: 100%; border-collapse: collapse; }

.data-table th {
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.6px;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  background: #FAFCFB;
}

.data-table td {
  padding: 11px 14px;
  font-size: 13px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-body); }
/* Dark-mode header (the hardcoded #FAFCFB had no dark override -> white strip on dark cards). */
html.theme-dark .data-table th { background: var(--bg-input); color: var(--text-muted); }

/* ── Pills ── */
.pill {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px; font-weight: 600;
  line-height: 1.4;
}

.pill-green  { background: rgba(76,175,110,0.12);  color: #2D8A50; }
.pill-orange { background: rgba(245,158,11,0.12);  color: #B45309; }
.pill-blue   { background: rgba(59,130,246,0.12);  color: #1D4ED8; }
.pill-red    { background: rgba(239,68,68,0.12);   color: #B91C1C; }
.pill-gray   { background: rgba(100,116,139,0.10); color: #475569; }

/* Semantic status pills (token-based) — one consistent badge system.
   Height/padding/radius/typography all inherit from .pill. No emojis. */
.pill-success { background: var(--color-success-bg); color: var(--color-success); font-weight: 700; }
.pill-neutral { background: rgba(100,116,139,0.12);  color: #64748B; font-weight: 700; }
.pill-warning { background: rgba(245,158,11,0.14);   color: #B45309; font-weight: 700; }
.pill-danger  { background: var(--color-danger-bg);  color: #B91C1C; font-weight: 700; }
.pill-info    { background: var(--color-info-bg);    color: #1D4ED8; font-weight: 700; }
.pill-admin   { background: rgba(59,130,246,0.14);   color: #2f6fd8; font-weight: 700; }
html.theme-dark .pill-neutral { color: #9fb0bd; }
/* Dark mode: the pills' text colours above are dark shades on a see-through tint, so on a dark card
   they were dark-on-dark (#1D4ED8 / #B91C1C on #152820 is about 2:1). */
html.theme-dark .pill-blue,
html.theme-dark .pill-info,
html.theme-dark .pill-admin   { color: #93c5fd; }
html.theme-dark .pill-red,
html.theme-dark .pill-danger  { color: #fca5a5; }
html.theme-dark .pill-gray    { color: #b6c2cf; }
html.theme-dark .pill-warning { color: #fbbf24; }
html.theme-dark .pill-success { color: #6fd59a; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--border-radius-sm);
  font-family: var(--font-sans);
  font-size: 13px; font-weight: 600;
  cursor: pointer; border: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-primary { background: var(--color-accent); color: #fff; }
.btn-primary:hover { background: var(--color-accent-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-secondary); }
.btn-outline:hover { background: var(--bg-input); color: var(--text-primary); }
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 6px 10px; }
.btn-ghost:hover { background: var(--bg-input); color: var(--text-primary); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #DC2626; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 14px; }

/* ── Form Elements ── */
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  font-family: var(--font-sans);
  font-size: 13px; color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-light);
  /* Theme-aware focus surface — was hardcoded #fff, which made near-white text
     unreadable on a white background in dark theme while typing. */
  background: var(--bg-card);
}

/* Browser autofill (saved logins/addresses) paints its own background straight
   into the input — regular `background` can't touch it — clashing with the
   site's --bg-input tone (shows as a mismatched pale blue/yellow fill). The
   inset box-shadow trick is the only way to override it; the long transition
   delay stops the browser's own fade-in flash from sneaking through first. */
.form-input:-webkit-autofill,
.form-input:-webkit-autofill:hover,
.form-input:-webkit-autofill:focus,
.form-input:-webkit-autofill:active {
  -webkit-text-fill-color: var(--text-primary);
  -webkit-box-shadow: 0 0 0 1000px var(--bg-input) inset;
  box-shadow: 0 0 0 1000px var(--bg-input) inset;
  transition: background-color 5000s ease-in-out 0s, color 5000s ease-in-out 0s;
}

.form-textarea { resize: vertical; min-height: 80px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-group { margin-bottom: 16px; }

/* ── Progress Bar ── */
.progress-bar { height: 6px; background: var(--border-color); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 99px; transition: width 0.5s ease; }

/* ── Toggle Switch ── */
.toggle-switch { position: relative; width: 36px; height: 20px; display: inline-block; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute; cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border-color);
  border-radius: 99px;
  transition: var(--transition-fast);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  background: #fff; border-radius: 50%;
  left: 3px; top: 3px;
  transition: var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.toggle-switch input:checked + .toggle-slider { background: var(--color-accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Section Header ── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-title { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.section-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Utilities ── */
.text-xs   { font-size: 11px; }
.text-sm   { font-size: 12px; }
.font-mono { font-family: var(--font-mono); }
.text-muted   { color: var(--text-muted); }
.text-success { color: var(--color-accent); }
.text-danger  { color: var(--color-danger); }

/* ── Tooltip ── */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%);
  background: var(--tooltip-bg); color: var(--tooltip-fg);
  /* Reset explicitly: a trigger that's itself an icon-font glyph (e.g. Tabler's
     .ti class) sets font-family on the element, and ::after inherits it — without
     this the tooltip text renders as icon glyphs instead of readable words. */
  font-family: var(--font-sans); font-weight: 400; font-style: normal;
  font-size: 11px; white-space: nowrap;
  padding: 4px 8px; border-radius: 4px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition-fast);
  z-index: 200;
}
[data-tooltip]:hover::after, [data-tooltip]:focus-visible::after { opacity: 1; }

/* The topbar sits flush against the top of the viewport, so the default upward-opening tooltip
   has nowhere to render — it ends up clipped above the page, invisible on hover. Open downward
   there instead. */
.topbar-actions [data-tooltip]::after {
  bottom: auto;
  top: calc(100% + 6px);
}

/* Wide variant: multi-line explanatory tooltips (e.g. stat-card info icons).
   Opens BELOW the trigger, not above — these icons sit near the top of short
   cards, and an upward popover tall enough for a full sentence would cover the
   card's own headline value instead of just overlaying empty page space.
   `pre-line` is what makes these readable: the data-tooltip string can use real
   line breaks to separate "what it means" / "what the arrow means" / "where the
   number came from" into short paragraphs instead of one dense wall of text. */
[data-tooltip].tooltip-wide::after {
  bottom: auto; top: calc(100% + 6px);
  white-space: pre-line;
  width: max-content;
  max-width: min(260px, 72vw);
  text-align: left;
  line-height: 1.55;
  padding: 10px 12px;
  font-size: 11.5px;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
}
/* Bias the popover so it doesn't clip past the edge of the first/last card in a row */
[data-tooltip].tooltip-left::after  { left: 0; transform: translateX(0); }
[data-tooltip].tooltip-right::after { left: auto; right: 0; transform: translateX(0); }

/* Small "i" info affordance next to shortened stat-card labels */
.stat-info-icon {
  display: inline-block;
  font-size: 13px;
  color: var(--text-muted);
  cursor: help;
  vertical-align: -2px;
  margin-left: 3px;
  transition: color var(--transition-fast);
}
.stat-info-icon:hover, .stat-info-icon:focus-visible { color: var(--color-accent); }

/* Inside a stat card the popover is anchored to the CARD, not to the tiny icon:
   `position: static` on the trigger makes its ::after resolve against the card
   (which is `position: relative`), so the popover spans the card's own width and
   drops straight below it. A popover centred on the icon instead runs off-screen
   on the last card of the row and gets clipped mid-sentence. */
.stat-card { position: relative; }
.stat-card:hover, .stat-card:focus-within { z-index: 3; }
.stat-card .stat-info-icon { position: static; }
.stat-card .stat-info-icon[data-tooltip]::after {
  top: calc(100% + 8px); bottom: auto;
  left: 0; right: 0;
  transform: none;
  width: auto; max-width: none;
}

/* ── Divider ── */
.divider { height: 1px; background: var(--border-color); margin: 16px 0; }

/* ── Empty State ── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px;
  padding: 48px; color: var(--text-muted); text-align: center;
}
.empty-state h3 { font-size: 14px; color: var(--text-secondary); font-weight: 600; }
.empty-state p  { font-size: 12px; color: var(--text-muted); max-width: 240px; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .grid-2   { grid-template-columns: 1fr; }
  .grid-2-1 { grid-template-columns: 1fr; }
  .grid-3   { grid-template-columns: 1fr 1fr; }
}

/* Admin nav burger — hidden on desktop, shown when the sidebar collapses (mobile). */
.admin-burger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  margin-right: 10px;
  border: 1px solid var(--border-color, #2e5941);
  border-radius: 9px;
  background: transparent;
  color: var(--text-primary, #e6f0ea);
  cursor: pointer;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .main-content { margin-left: 0; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .admin-burger { display: inline-flex; }
}

/* ── Admin topbar: laptop → phone ──
   The title never shrank, the search had a fixed 260px minimum, and the clock + user name were
   always shown, so below ~900px the bar pushed the whole page sideways (every admin page scrolled
   horizontally on tablets/phones). Each step below gives space back in order of importance. */
.topbar-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 1; }
.search-bar { flex: 0 1 300px; }

@media (max-width: 1200px) {
  .search-bar { min-width: 180px; }
}
@media (max-width: 1024px) {
  .topbar-clock { display: none; }
  .topbar { gap: 12px; }
}
@media (max-width: 768px) {
  :root { --content-padding: 16px; }
  .topbar { padding: 0 16px; gap: 10px; }
  .topbar-title { font-size: 16px; }
  .topbar-user-info { display: none; }
  .topbar-user { margin-left: 0; margin-right: 0; padding: 2px; }
  .search-bar { min-width: 0; flex: 1 1 160px; max-width: 280px; padding: 7px 12px; }
  .admin-burger { margin-right: 0; }
  .section-header { flex-wrap: wrap; gap: 10px; }
}
/* Cards/grid cells must be allowed to shrink below their content's natural width — a flex/grid
   item defaults to min-width:auto, so one long card header was widening its whole column past
   the screen on phones. */
.card, .stat-card, .content-grid > *, .grid-2 > *, .grid-3 > *, .grid-2-1 > * { min-width: 0; }
/* Same for the page body itself: .page-content is a flex item of .main-content (admin and the
   public shell), so a wide table inside it (e.g. the Rice Catalog's 720px table, which is meant
   to scroll inside its own wrapper) was stretching the whole page past the phone screen. */
.page-content { min-width: 0; }

@media (max-width: 768px) {
  /* Card headers (title + pills + buttons) wrap instead of forcing the card wider. */
  .card-header { flex-wrap: wrap; gap: 8px 10px; padding: 14px 16px; }
  .card-body { padding: 16px; }
  .card-title { min-width: 0; overflow-wrap: anywhere; }
}

@media (max-width: 560px) {
  /* Phones: search drops to its own full-width row under the title. */
  .topbar { flex-wrap: wrap; height: auto; min-height: var(--topbar-height); padding: 10px 14px; row-gap: 10px; }
  .topbar-actions { margin-left: auto; }
  .search-bar { order: 3; flex: 1 1 100%; max-width: none; margin-left: 0; }
  .topbar-alerts-panel { position: fixed; top: 64px; left: 12px; right: 12px; width: auto; }
  .page-content { min-height: 0; }

  /* Compact stat cards: two per row on a phone left ~150px each, so the desktop padding/type
     made each card ~200px tall and badges like "Typical Miss" wrapped into the icon. */
  .stat-grid { gap: 10px; margin-bottom: 16px; }
  .stat-card { padding: 14px; gap: 8px; }
  .stat-card:hover { transform: none; }
  .stat-icon { width: 34px; height: 34px; }
  .stat-icon svg { width: 17px; height: 17px; }
  .stat-value { font-size: 19px; }
  .stat-label { font-size: 11.5px; }
  .stat-card .pill { font-size: 10px; padding: 2px 8px; white-space: nowrap; }
  .section-title { font-size: 15px; }
}

/* Suppress the browser's native password-reveal / clear controls so our own SVG eye toggle is the
   only visibility control. (Fixes the login eye that dropped after an error and the duplicate eye on
   signup — both were the native Edge/IE control appearing alongside our button.) */
input::-ms-reveal,
input::-ms-clear { display: none; }
input::-webkit-credentials-auto-fill-button,
input::-webkit-strong-password-auto-fill-button { visibility: hidden; display: none !important; }
/* Bell panel: a notification opens its summary in place */
.topbar-alert-row { cursor: pointer; }
.topbar-alert-row:focus-visible { outline: 2px solid var(--color-accent, #4CAF6E); outline-offset: -2px; }
.topbar-alert-detail { display: none; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border-color); font-size: 11.5px; }
.topbar-alert-row.is-open .topbar-alert-detail { display: grid; gap: 4px; }
.topbar-alert-row.is-open .topbar-alert-desc { white-space: normal; overflow: visible; -webkit-line-clamp: unset; display: block; }
.topbar-alert-detail > div { display: flex; justify-content: space-between; gap: 10px; }
.topbar-alert-detail span { color: var(--text-muted); }
.topbar-alert-detail b { color: var(--text-primary); font-weight: 600; text-align: right; }
.topbar-alert-detail .btn { margin-top: 6px; justify-self: start; }
