/* Web UI kit — AgriProfile (staff) */

*, *::before, *::after { box-sizing: border-box; }
/* The whole UI renders at 90%, like 90% browser zoom, on desktop widths.
   Zoom shrinks vh/vw too, so viewport-sized rules use var(--vh)/var(--vw), and
   JS places fixed popups with pageRect()/pageViewport() from base.js. */
:root { --ui-zoom: 1; --vh: calc(1vh / var(--ui-zoom)); --vw: calc(1vw / var(--ui-zoom)); }
@media (min-width: 1024px) { :root { --ui-zoom: .9; } }
html { zoom: var(--ui-zoom); }
html, body { margin: 0; padding: 0; min-height: calc(100 * var(--vh)); background: var(--bg); }
/* The page scrolls without showing the browser's scrollbar (wheel, touch and
   keys still work). With no scrollbar there is no width to lose, so the layout
   doesn't shift sideways when an open modal stops the page scrolling. */
html { scrollbar-width: none; }
html::-webkit-scrollbar { display: none; }
html:has(dialog:modal), html:has(.modal-backdrop:not([hidden])) { overflow: hidden; }
body { font-family: var(--font-sans); color: var(--fg-1); }
a { color: inherit; text-decoration: none; }

.app { display: flex; min-height: calc(100 * var(--vh)); }
.main { flex: 1; min-width: 0; }

/* ---- Sidebar ---- */
.sidebar { width: 240px; flex: 0 0 240px; background: var(--bg-alt); border-right: 1px solid var(--border); padding: 16px 12px; position: sticky; top: 0; height: calc(100 * var(--vh)); overflow: visible; display: flex; flex-direction: column; transition: width 220ms var(--ease-out), flex-basis 220ms var(--ease-out), padding 220ms var(--ease-out); }
.sidebar .logo { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.sidebar .logo-name { font-weight: 700; font-size: 15px; }
.sidebar .section { font-size: 11px; font-weight: 600; color: var(--fg-3); letter-spacing: .06em; text-transform: uppercase; padding: 14px 8px 6px; }
.sidebar-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding-bottom: 12px; scrollbar-width: none; }
.sidebar-body::-webkit-scrollbar { display: none; }
.sidebar-footer { display: flex; justify-content: flex-end; padding: 8px; border-top: 1px solid rgba(0,0,0,.06); }
.sidebar-footer .sidebar-toggle { width: 34px; height: 34px; border-radius: 10px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--fg-2); font-size: 13px; cursor: pointer; font-weight: 500; min-width: 0; transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.nav-item:hover { background: rgba(31, 122, 76, .06); color: var(--fg-1); }
.nav-item.active { background: #ECF6EF; color: #114C32; font-weight: 600; }
.nav-item svg { width: 18px; height: 18px; }
.nav-label { display: inline-block; white-space: nowrap; overflow: hidden; max-width: 220px; opacity: 1; transform: translateX(0); transition: max-width 220ms var(--ease-out), opacity 180ms var(--ease-out), transform 220ms var(--ease-out); }

.app.sidebar-collapsed .sidebar { width: 72px; flex-basis: 72px; padding-left: 12px; padding-right: 12px; }
.app.sidebar-collapsed .sidebar .logo { justify-content: flex-start; }
.app.sidebar-collapsed .sidebar .logo-name { display: none; }
.app.sidebar-collapsed .sidebar .section { visibility: hidden; }
.app.sidebar-collapsed .nav-item { justify-content: flex-start; }
.app.sidebar-collapsed .nav-label { max-width: 0; opacity: 0; transform: translateX(-6px); pointer-events: none; }

/* Tooltip "portal" (JS) — avoids overflow clipping */
.sidebar-tip {
  position: fixed;
  transform: translateY(-50%);
  padding: 7px 10px;
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--fg-1);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .01em;
  white-space: nowrap;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-2);
  z-index: 2000;
  pointer-events: none;
}

/* Backdrop + mobile drawer */
.sidebar-backdrop { display: none; }

/* ---- Top bar ---- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 56px; border-bottom: 1px solid var(--border); background: var(--bg-elevated); display: flex; align-items: center; padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 5; }
.searchbox { flex: 1; max-width: 440px; display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--ink-50); border: 1px solid var(--border); border-radius: 10px; color: var(--fg-3); font-size: 13px; }
.searchbox input { flex: 1; background: transparent; border: 0; outline: 0; font-family: inherit; font-size: 13px; color: var(--fg-1); }
.topbar .actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.icon-action {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--fg-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
}
.icon-action:hover { background: transparent; color: var(--fg-2); }
.icon-action:active { transform: translateY(0); }
.icon-action:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.notif-bell { position: relative; }
.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--status-danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  box-sizing: border-box;
  pointer-events: none;
}
.notif-badge[hidden] { display: none; }

/* ---- Notifications pane (topbar bell dropdown) ---- */
.notif-pane-wrap { position: relative; }
.notif-bell { border: 0; cursor: pointer; font: inherit; }
.notif-bell[aria-expanded="true"] { background: var(--ink-50); color: var(--fg-1); }
/* Disabled on the Notifications page itself: no pane, no hover feedback. */
.notif-bell:disabled { cursor: default; opacity: .55; background: transparent; transform: none; }
.notif-pane { width: 380px; max-width: calc(100 * var(--vw) - 32px); padding: 0; display: flex; flex-direction: column; max-height: min(560px, calc(100 * var(--vh) - 90px)); }
.notif-pane[hidden] { display: none; }
.notif-pane-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 6px 16px; }
.notif-pane-title { font-weight: 750; font-size: 17px; color: var(--fg-1); letter-spacing: -.01em; }
.notif-pane-more { position: relative; }
.notif-pane-more-btn { width: 32px; height: 32px; border-radius: 999px; border: 0; background: transparent; color: var(--fg-2); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.notif-pane-more-btn:hover, .notif-pane-more-btn[aria-expanded="true"] { background: var(--ink-50); color: var(--fg-1); }
.notif-pane-more-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
/* Two selectors so these beat the shared .dropdown rules defined further down. */
.notif-pane .notif-pane-menu { top: calc(100% + 4px); min-width: 0; width: max-content; padding: 4px; }
.notif-pane-menu .dropdown-item { padding: 7px 10px; gap: 8px; }
.notif-pane-menu button.dropdown-item { width: 100%; text-align: left; background: none; border: 0; font: inherit; font-size: 13px; font-weight: 600; color: var(--fg-1); }
.notif-pane-tabs { display: flex; gap: 6px; padding: 4px 16px 10px; border-bottom: 1px solid var(--border-subtle); }
.notif-pane-tab { border: 0; border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 13px; font-weight: 600; color: var(--fg-2); background: transparent; cursor: pointer; }
.notif-pane-tab:hover { background: var(--ink-50); }
.notif-pane-tab.active { background: var(--green-50); color: var(--green-600); }
.notif-pane-tab:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.notif-pane-list { overflow-y: auto; padding: 6px; flex: 1 1 auto; }
.notif-pane-item { display: grid; grid-template-columns: 36px 1fr 10px; gap: 10px; align-items: start; padding: 10px; border-radius: 10px; color: inherit; text-decoration: none; }
.notif-pane-item:hover { background: var(--ink-25); }
.notif-pane-item:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.notif-pane-icon { width: 36px; height: 36px; border-radius: 999px; background: var(--green-50); color: var(--green-600); display: flex; align-items: center; justify-content: center; }
.notif-pane-icon svg { width: 17px; height: 17px; }
.notif-pane-text { min-width: 0; }
.notif-pane-item-title { display: block; font-size: 13.5px; font-weight: 500; color: var(--fg-1); line-height: 1.3; }
.notif-pane-item.unread .notif-pane-item-title { font-weight: 700; }
.notif-pane-item-body { margin-top: 2px; font-size: 12.5px; color: var(--fg-3); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.notif-pane-item-ago { display: block; margin-top: 4px; font-size: 11.5px; color: var(--fg-4); }
.notif-pane-item.unread .notif-pane-item-ago { color: var(--green-600); font-weight: 600; }
.notif-pane-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--green-500); margin-top: 13px; }
.notif-pane-empty { padding: 36px 16px; text-align: center; font-size: 13px; color: var(--fg-3); }
.sidebar-open-btn { display: none; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: #fff; color: var(--fg-2); align-items: center; justify-content: center; cursor: pointer; }
.sidebar-open-btn:hover { background: var(--ink-50); color: var(--fg-1); }
.sidebar-open-btn svg { width: 18px; height: 18px; }
.avatar { width: 32px; height: 32px; border-radius: 999px; background: #1F7A4C; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }

/* ---- User menu (avatar dropdown) ---- */
.user-menu { position: relative; }
.avatar-btn {
  border: 0;
  cursor: pointer;
  box-shadow: 0 0 0 0 rgba(0,0,0,0);
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out), filter var(--dur-fast) var(--ease-out);
}
.avatar-btn:hover { filter: brightness(1.03); }
.avatar-btn:active { transform: translateY(1px); }
.avatar-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }

.dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 240px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-2);
  padding: 8px;
  z-index: 60;
  opacity: 0;
  transform: translateY(-6px) scale(.98);
  pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
}
.dropdown.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.dropdown-head { padding: 8px 10px 10px; }
.dropdown-title { font-weight: 750; font-size: 13.5px; color: var(--fg-1); line-height: 1.15; }
.dropdown-sub { margin-top: 2px; font-size: 12px; color: var(--fg-3); }
.dropdown-sep { height: 1px; background: var(--border-subtle); margin: 6px 0; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-1);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.dropdown-item svg { width: 16px; height: 16px; color: var(--fg-2); flex: 0 0 auto; }
.dropdown-item span { min-width: 0; white-space: nowrap; }
.dropdown-item:hover { background: var(--ink-25); }
.dropdown-item:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.dropdown-item.danger { color: var(--status-danger); }
.dropdown-item.danger svg { color: var(--status-danger); }

.sidebar-toggle { width: 36px; height: 36px; border-radius: 0; border: 0; background: transparent; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--fg-2); transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.sidebar-toggle:hover { background: var(--ink-50); color: var(--fg-1); }
.sidebar-toggle svg { transition: transform var(--dur-fast) var(--ease-out); }
.app.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }

/* ---- Page shell ---- */
.page { padding: 24px 32px; width: 100%; max-width: none; }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 28px; font-weight: 700; letter-spacing: -.015em; }
.page-header .sub { font-size: 13px; color: var(--fg-3); margin-top: 4px; }
.breadcrumb { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--fg-3); margin-bottom: 12px; cursor: pointer; }
.breadcrumb svg { width: 14px; height: 14px; }

/* ---- Buttons ---- */
.btn { font-family: var(--font-sans); font-size: 14px; font-weight: 600; border-radius: 10px; padding: 9px 14px; border: 1px solid transparent; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out); text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-primary:active { background: var(--brand-press); transform: translateY(1px); }
.btn-secondary { background: #fff; color: var(--fg-1); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--border-strong); background: var(--ink-50); }
.btn-ghost { background: transparent; color: var(--brand); }
.btn-ghost:hover { background: var(--brand-subtle); }

/* ---- Stat cards ---- */
.grid-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 18px; box-shadow: var(--shadow-1); }
.stat-card .label { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--fg-3); }
.stat-card .value { font-family: var(--font-serif); font-size: 36px; font-weight: 600; line-height: 1.05; margin-top: 6px; letter-spacing: -.01em; }
.stat-card .delta { margin-top: 10px; font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat-card .delta.up { color: var(--status-success); }
.stat-card .delta.down { color: var(--status-danger); }

/* ---- Card ---- */
.card { background: #fff; border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-1); }
.card-h { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.card-h h3 { font-size: 15px; font-weight: 700; }
.card-b { padding: 18px; }

/* ---- Chips ---- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.chip.profiled { background: #E5F3EB; color: #114C32; border-color: #A7D5B8; }
.chip.review { background: #FBF1E9; color: #5C2F17; border-color: #E8BD9C; }
.chip.pending { background: #EAF3FB; color: #15466F; border-color: #8DC1E7; }
.chip.profile.pending { background: #FBF1E9; color: #7A3E14; border-color: #E8BD9C; }
.chip.overdue { background: #F9E4E0; color: #7E2A22; border-color: #EBB8B2; }
.chip.harvest { background: #FFF4D6; color: #6B5410; border-color: #E8D07A; }
.chip.crops, .chip.livestock { background:#FFF6D9; color:#7a6210; border-color:#E8D480;}
.chip.tag { background:#EEEBFB; color:#3B2C7A; border-color:#C4B8ED; }
/* Calamity chips; class suffix is the slugified value. Page-specific category colours are in calamity.css. */
.cal-chip { display: inline-block; font-family: var(--font-mono); font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 4px; background: var(--ink-50); border: 1px solid var(--border); white-space: nowrap; }
.cal-sev-low { background: #E5F3EB; color: #114C32; border-color: #A7D5B8; }
.cal-sev-moderate { background: #FFF4D6; color: #6B5410; border-color: #E8D07A; }
.cal-sev-severe { background: #F9E4E0; color: #7E2A22; border-color: #EBB8B2; }

/* ---- Charts ---- */
/* Chart.js canvases, marked by zoomAwareChartHover in base.js. A small 13px
   crosshair (the system one can't be resized), hotspot at its centre. */
.chart-canvas { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 13 13'%3E%3Cpath d='M6.5 0v13M0 6.5h13' stroke='%231F1C17' stroke-width='1'/%3E%3C/svg%3E") 6 6, crosshair; }

/* ---- Table ---- */
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 11px; color: var(--fg-3); letter-spacing: .04em; text-transform: uppercase; font-weight: 600; padding: 10px 18px; border-bottom: 1px solid var(--border); background: var(--ink-25); }
table.data td { padding: 14px 18px; border-bottom: 1px solid var(--border-subtle); }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover td { background: var(--ink-25); }
table.data .cell-name { font-weight: 600; }
table.data .cell-mono { font-family: var(--font-mono); font-size: 12.5px; color: var(--fg-2); }

/* Table density (Appearance › Density) — applied via <html data-density="…">.
   `comfortable` is the default set on the base rules above. */
:root[data-density="compact"] table.data th { padding-top: 7px; padding-bottom: 7px; }
:root[data-density="compact"] table.data td { padding-top: 8px; padding-bottom: 8px; }
:root[data-density="spacious"] table.data th { padding-top: 14px; padding-bottom: 14px; }
:root[data-density="spacious"] table.data td { padding-top: 20px; padding-bottom: 20px; }

/* ---- Inputs + filter bar ---- */
.inp { font-family: var(--font-sans); font-size: 14px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--fg-1); outline: none; width: 100%; }
.inp:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus-ring); }

.filter-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; background: var(--ink-50); padding: 3px; border-radius: 10px; border: 1px solid var(--border); }
.tab { padding: 6px 12px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--fg-2); cursor: pointer; user-select: none; }
.tab.active { background: #fff; color: var(--fg-1); box-shadow: var(--shadow-1); }

/* Filter-style dropdown: a pill button + .dropdown menu (farmers list, bulk edit). */
.filter-dropdown-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; line-height: 1.45;
  color: var(--fg-2); background: var(--ink-50); border: 1px solid var(--border);
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.filter-dropdown-btn:hover { background: var(--ink-100,#ece9e3); border-color: var(--border-strong,#b8b0a4); }
.fdd-active { background: var(--ink-25,#f8f6f2); font-weight: 700; }
.dropdown-item { cursor: pointer; }
.fdd { position: relative; }
.fdd-menu { left: 0; right: auto; max-height: 288px; overflow-y: auto; }

/* Custom select for form fields (.em-csel): a trigger styled as .inp and a
   listbox. Pages add their own variants (multi, check, group headers). */
.em-csel { position: relative; width: 100%; }
.em-csel-trigger { display: flex; justify-content: space-between; align-items: center; cursor: pointer; text-align: left; }
.em-csel-trigger[aria-expanded="true"] i, .em-csel-trigger[aria-expanded="true"] svg { transform: rotate(180deg); }
.em-csel-trigger.is-missing { border-color: var(--status-danger); }
.em-csel-drop { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 10px; max-height: 160px; overflow-y: auto; z-index: 300; box-shadow: var(--shadow-3); padding: 4px; margin: 0; list-style: none; opacity: 0; transform: translateY(-6px) scale(.98); pointer-events: none; transition: opacity .15s ease, transform .15s ease; }
.em-csel-drop.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.em-csel-opt { padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; color: var(--fg-1); }
.em-csel-opt:hover { background: var(--ink-50); }
.em-csel-opt[aria-selected="true"] { background: var(--brand-subtle); color: var(--green-700); font-weight: 600; }

/* ---- Pagination ---- */
.pg-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 10px;
  border-radius: 8px; border: none;
  background: transparent; color: var(--fg-2);
  font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background .12s;
}
.pg-btn:hover { background: var(--ink-50,#f3f1ed); }
.pg-btn.pg-label, .pg-btn.pg-label:hover { background: transparent; cursor: default; pointer-events: none; }
.pg-btn.active { background: transparent; color: #114C32; cursor: default; }
.pg-btn[disabled] { opacity: .4; cursor: default; pointer-events: none; }

/* ---- Chart ---- */
.chart { height: 220px; width: 100%; }
.chart-line { fill: none; stroke-width: 2; }

/* ---- Activity feed ---- */
.activity { display: flex; flex-direction: column; }
.activity-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border-subtle); }
.activity-item:last-child { border-bottom: 0; }
.act-icon { width: 32px; height: 32px; border-radius: 999px; background: var(--brand-subtle); color: var(--brand); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.act-icon svg { width: 16px; height: 16px; }
.act-body { flex: 1; min-width: 0; }
.act-body .t { font-size: 13.5px; }
.act-body .d { font-size: 11.5px; color: var(--fg-3); margin-top: 2px; }
.act-body .t b { font-weight: 600; }

/* ---- Placeholder page ---- */
.placeholder-body { padding: 48px; text-align: center; color: var(--fg-3); }
.placeholder-pill { display: inline-flex; padding: 16px; background: var(--brand-subtle); border-radius: 999px; margin-bottom: 12px; }
.placeholder-pill svg { width: 24px; height: 24px; color: var(--brand); }
.placeholder-title { font-weight: 600; color: var(--fg-1); }
.placeholder-desc { margin-top: 4px; }

@media (max-width: 1100px) {
  .grid-stats { grid-template-columns: repeat(2, 1fr); }
  .page { padding: 20px 24px; }
  .topbar { padding: 0 18px; }
}

@media (max-width: 720px) {
  .page { padding: 18px 16px; }
  .topbar { padding: 0 14px; }
  .searchbox { max-width: none; }
  .grid-stats { grid-template-columns: 1fr; }
  .card-h { flex-wrap: wrap; gap: 10px; align-items: flex-start; }
  .tabs { width: 100%; justify-content: flex-start; overflow-x: auto; }
}

@media (max-width: 860px) {
  .app { position: relative; }
  .sidebar-open-btn { display: inline-flex; }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms var(--ease-out);
    z-index: 40;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: calc(100 * var(--vh));
    width: 280px;
    flex-basis: 280px;
    transform: translateX(-102%);
    transition: transform 220ms var(--ease-out);
    z-index: 50;
    box-shadow: 0 16px 40px rgba(0,0,0,.20);
  }

  .app.sidebar-open .sidebar { transform: translateX(0); }
  .app.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
}

/* ---- Toast notifications ---- */
#toast-region{position:fixed;top:68px;left:50%;transform:translateX(-50%);display:flex;flex-direction:column;align-items:center;gap:10px;z-index:9999;pointer-events:none}
.toast{display:flex;align-items:center;gap:10px;padding:12px 16px;border-radius:10px;font-size:13.5px;font-weight:500;box-shadow:0 4px 20px rgba(0,0,0,.13);pointer-events:auto;max-width:360px;line-height:1.4;animation:_tin .2s ease}
.toast.success{background:var(--green-50);border:1px solid var(--green-200);color:var(--green-700)}
.toast.error{background:#F9E4E0;border:1px solid #EBB8B2;color:#7E2A22}
@keyframes _tin{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}
@keyframes _tout{to{opacity:0;transform:translateY(6px)}}


/* ---- Date picker (datepicker.js) ----
   The real <input type="date"> stays under the button, invisible, so forms and
   the browser's own validation keep working on it. */
.ap-date { position: relative; display: block; width: 100%; }
.ap-date-native { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; opacity: 0; pointer-events: none; }
.ap-date-trigger { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left; cursor: pointer; }
.ap-date-trigger svg { flex-shrink: 0; color: var(--fg-3); }
.ap-date-trigger.is-empty .ap-date-text { color: var(--fg-3); }
.ap-date-native:focus + .ap-date-trigger, .ap-date-trigger[aria-expanded="true"] { border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus-ring); }

.ap-cal { position: fixed; inset: auto; width: 288px; margin: 0; padding: 12px; background: var(--bg); color: var(--fg-1); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .16); }
.ap-cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.ap-cal-nav, .ap-cal-title, .ap-cal-link, .ap-cal-day, .ap-cal-pick { border: none; background: none; font: inherit; color: var(--fg-1); cursor: pointer; }
.ap-cal-nav { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; border-radius: 8px; color: var(--fg-2); }
.ap-cal-title { padding: 5px 10px; border-radius: 8px; font-size: 14px; font-weight: 600; }
.ap-cal-title:disabled { cursor: default; }
.ap-cal-nav:hover:not(:disabled), .ap-cal-title:hover:not(:disabled), .ap-cal-pick:hover:not(:disabled), .ap-cal-day:hover:not(:disabled) { background: var(--brand-subtle); color: var(--brand); }
.ap-cal-nav:disabled { opacity: .3; cursor: default; }
.ap-cal-week, .ap-cal-days { display: grid; grid-template-columns: repeat(7, 1fr); }
.ap-cal-week[hidden] { display: none; }
.ap-cal-week span { padding: 4px 0; text-align: center; font-size: 11px; font-weight: 600; color: var(--fg-3); }
/* Tall enough for six weeks, so the calendar keeps its size between months. */
.ap-cal-body { min-height: 226px; }
.ap-cal-days { row-gap: 2px; align-content: start; }
.ap-cal-picks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; align-content: center; }
.ap-cal-day { height: 36px; padding: 0; border-radius: 9px; font-size: 13px; }
.ap-cal-pick { height: 44px; padding: 0; border-radius: 9px; font-size: 13px; }
.ap-cal-day:disabled, .ap-cal-pick:disabled { color: var(--fg-3); opacity: .45; cursor: default; }
.ap-cal button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.ap-cal-day.is-today { font-weight: 700; color: var(--brand); }
.ap-cal-day.is-range { border-radius: 0; background: var(--brand-subtle); }
.ap-cal-day.is-picked, .ap-cal-day.is-picked:hover, .ap-cal-pick.is-picked, .ap-cal-pick.is-picked:hover { background: var(--brand); color: var(--fg-inverse); font-weight: 600; }
.ap-cal-foot { display: flex; align-items: center; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border-subtle); }
.ap-cal-link { padding: 4px 6px; border-radius: 6px; font-size: 12.5px; font-weight: 600; color: var(--brand); }
.ap-cal-link[hidden] { display: none; }
.ap-cal-link[data-action="today"] { margin-left: auto; }
.ap-cal-link:hover:not(:disabled) { text-decoration: underline; }
.ap-cal-link:disabled { opacity: .4; cursor: default; }
