/* =============================================================
   FarmAssist v2 — Component styles
   ============================================================= */

/* ---------- Button ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg-default);
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
  user-select: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .lucide { width: 14px; height: 14px; }

.btn--sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn--lg { height: 38px; padding: 0 16px; font-size: 14px; }
.btn--icon { width: 32px; padding: 0; }
.btn--icon.btn--sm { width: 28px; }
.btn--icon.btn--lg { width: 38px; }

.btn--primary {
  background: var(--accent);
  color: var(--fg-on-accent);
  border-color: var(--accent);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.10), 0 1px 1px rgba(15,23,42,0.10);
}
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--primary:active { background: var(--blue-800); border-color: var(--blue-800); }

.btn--secondary {
  background: var(--bg-surface);
  color: var(--fg-default);
  border-color: var(--border-default);
  box-shadow: var(--shadow-xs);
}
.btn--secondary:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn--secondary:active { background: var(--bg-pressed); }

.btn--ghost { color: var(--fg-muted); }
.btn--ghost:hover { background: var(--bg-hover); color: var(--fg-default); }

.btn--danger {
  background: var(--bg-surface);
  color: var(--red-700);
  border-color: var(--border-default);
}
.btn--danger:hover { background: var(--red-50); border-color: var(--red-200); color: var(--red-700); }

[data-theme="dark"] .btn--danger { color: #fca5a5; }
[data-theme="dark"] .btn--danger:hover { background: rgba(239,68,68,0.10); }

.btn--accent-soft {
  background: var(--accent-soft);
  color: var(--fg-accent);
  border-color: transparent;
}
.btn--accent-soft:hover { background: var(--accent-soft-2); }

/* ---------- Card ---------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
}
.card__body { padding: var(--density-card-pad); }
.card__footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-sunken);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ---------- Badge / Lozenge ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.01em;
  background: var(--status-nu-bg);
  color: var(--status-nu-fg);
  border: 1px solid var(--status-nu-bd);
  white-space: nowrap;
}
.badge--ok    { background: var(--status-ok-bg); color: var(--status-ok-fg); border-color: var(--status-ok-bd); }
.badge--warn  { background: var(--status-wn-bg); color: var(--status-wn-fg); border-color: var(--status-wn-bd); }
.badge--err   { background: var(--status-er-bg); color: var(--status-er-fg); border-color: var(--status-er-bd); }
.badge--info  { background: var(--status-in-bg); color: var(--status-in-fg); border-color: var(--status-in-bd); }
.badge--solid-accent { background: var(--accent); color: var(--fg-on-accent); border-color: var(--accent); }

.dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--status-nu-dot);
  flex-shrink: 0;
}
.dot--ok   { background: var(--status-ok-dot); }
.dot--warn { background: var(--status-wn-dot); }
.dot--err  { background: var(--status-er-dot); }
.dot--info { background: var(--status-in-dot); }

.dot--pulse { position: relative; }
.dot--pulse::after {
  content: ""; position: absolute; inset: -4px;
  border-radius: 50%; background: currentColor; opacity: 0.3;
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(0.6); opacity: 0.6; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* ---------- Input / Select ---------- */
.input, .select, .textarea {
  display: flex;
  align-items: center;
  width: 100%;
  height: 32px;
  padding: 0 10px;
  font-family: inherit;
  font-size: 13px;
  color: var(--fg-default);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  transition: border-color 120ms, box-shadow 120ms;
}
.textarea { height: auto; padding: 8px 10px; line-height: 1.5; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--fg-subtle); }

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}
.input-group .lucide {
  position: absolute;
  left: 10px;
  width: 14px; height: 14px;
  color: var(--fg-subtle);
  pointer-events: none;
}
.input-group .input { padding-left: 30px; }
.input-group--sm .input { height: 28px; font-size: 12.5px; }

.kbd {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  background: var(--bg-sunken);
  border: 1px solid var(--border-default);
  border-radius: 4px;
  line-height: 1;
}

/* ---------- Avatar ---------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
}
.avatar--sm { width: 22px; height: 22px; font-size: 10px; }
.avatar--lg { width: 36px; height: 36px; font-size: 13px; }
.avatar--xl { width: 48px; height: 48px; font-size: 15px; }

/* ---------- Table ---------- */
.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  color: var(--fg-default);
}
.tbl thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-surface);
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}
.tbl tbody td {
  padding: var(--density-row-py) 12px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.tbl tbody tr:hover { background: var(--bg-hover); }
.tbl tbody tr.is-selected { background: var(--bg-selected); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .mono { font-family: var(--font-mono); font-size: 12px; }

/* ---------- StatCard ---------- */
.stat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  min-width: 0;
}
.stat__label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--fg-muted); font-weight: 500;
}
.stat__value {
  font-size: 26px; font-weight: 600; letter-spacing: -0.02em;
  color: var(--fg-strong); font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat__delta {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 12px; font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.stat__delta--up   { color: var(--green-700); }
.stat__delta--down { color: var(--red-700); }
.stat__delta--flat { color: var(--fg-muted); }
[data-theme="dark"] .stat__delta--up   { color: #6ee7b7; }
[data-theme="dark"] .stat__delta--down { color: #fca5a5; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border-default);
}
.tab {
  position: relative;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-muted);
  background: transparent;
  border: none;
  border-radius: 0;
  cursor: pointer;
  transition: color 120ms;
}
.tab:hover { color: var(--fg-default); }
.tab.is-active { color: var(--fg-strong); }
.tab.is-active::after {
  content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px;
  background: var(--accent); border-radius: 2px 2px 0 0;
}

/* Pill tabs (segmented) */
.seg {
  display: inline-flex;
  padding: 3px;
  background: var(--bg-sunken);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  gap: 0;
}
.seg__item {
  padding: 5px 10px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--fg-muted);
  background: transparent;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
}
.seg__item:hover { color: var(--fg-default); }
.seg__item.is-active {
  background: var(--bg-surface);
  color: var(--fg-strong);
  box-shadow: var(--shadow-xs);
}

/* ---------- Drawer / Overlay ---------- */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(2px);
  z-index: 90;
  animation: backdrop-in 200ms ease-out;
}
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 420px;
  max-width: 100%;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-default);
  box-shadow: var(--shadow-pop);
  z-index: 100;
  display: flex; flex-direction: column;
  animation: drawer-in 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes drawer-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Page header ---------- */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-app);
}
.page-header__crumbs {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--fg-muted); margin-bottom: 6px;
}
.page-header__crumbs .lucide { width: 12px; height: 12px; opacity: 0.6; }

/* ---------- Empty state ---------- */
.empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  padding: 48px 24px;
  gap: 12px;
}
.empty__icon {
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-sunken);
  border-radius: var(--radius-lg);
  color: var(--fg-muted);
}
.empty__title { font-size: 15px; font-weight: 600; color: var(--fg-strong); }
.empty__sub { font-size: 13px; color: var(--fg-muted); max-width: 320px; }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  height: 100vh;
  overflow: hidden;
}
.app[data-sidebar="collapsed"] { grid-template-columns: var(--sidebar-collapsed-w) 1fr; }

.app__sidebar { grid-row: 1 / span 2; grid-column: 1; border-right: 1px solid var(--border-default); background: var(--bg-surface); display: flex; flex-direction: column; min-height: 0; }
.app__topbar  { grid-row: 1; grid-column: 2; border-bottom: 1px solid var(--border-default); background: var(--bg-surface); display: flex; align-items: center; padding: 0 20px; gap: 12px; }
.app__main    { grid-row: 2; grid-column: 2; overflow: auto; background: var(--bg-app); min-width: 0; }

/* v2 page wrappers — override per-page max-width caps so content fills the main pane.
   Catches both `.v2-*` page classes (whose <style> blocks load after components.css)
   and the legacy pattern of inline `max-width: NNNNpx` on a top-level `.col` wrapper
   (dashboard, sow detail, etc.). Per-page styles load later so !important is required. */
.app__main [class^="v2-"],
.app__main [class*=" v2-"],
.app__main > .col > [style*="max-width"] {
  max-width: none !important;
}

/* sidebar internals */
.sb__brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--header-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border-default);
  flex-shrink: 0;
}
.sb__brand__link {
  display: flex; align-items: center; gap: 10px;
  flex: 1; min-width: 0;
  text-decoration: none; color: inherit;
  border-radius: var(--radius-sm);
  padding: 2px 4px; margin: 0 -4px;
}
.sb__brand__link:hover { background: var(--bg-sunken); }
.sb__brand__link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sb__brand__logo {
  width: 28px; height: 28px;
  object-fit: contain;
  flex-shrink: 0;
}
.sb__brand__mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 13px; letter-spacing: -0.02em;
  box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255,255,255,0.2);
  flex-shrink: 0;
}
.sb__brand__name { font-weight: 600; color: var(--fg-strong); font-size: 14px; letter-spacing: -0.01em; }
.sb__brand__sub { font-size: 11px; color: var(--fg-muted); font-variant: tabular-nums; }

.sb__org {
  display: flex; align-items: center; gap: 8px;
  margin: 12px;
  padding: 8px 10px;
  background: var(--bg-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.sb__org:hover { background: var(--bg-hover); }
.sb__org__icon {
  width: 26px; height: 26px;
  background: var(--accent-soft);
  color: var(--fg-accent);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sb__org__name {
  font-weight: 600; font-size: 13px; color: var(--fg-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.sb__org__sub  {
  font-size: 11px; color: var(--fg-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}

.sb__nav { padding: 4px 8px; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.sb__group__label {
  padding: 12px 12px 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.sb__item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  height: 32px;
  margin: 1px 0;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-default);
  background: transparent;
  border: none; text-align: left; cursor: pointer;
  position: relative;
}
.sb__item:hover { background: var(--bg-hover); color: var(--fg-strong); }
.sb__item .lucide { width: 16px; height: 16px; flex-shrink: 0; color: var(--fg-muted); }
.sb__item:hover .lucide { color: var(--fg-default); }
.sb__item.is-active {
  background: var(--bg-selected);
  color: var(--fg-accent);
}
.sb__item.is-active .lucide { color: var(--accent); }
.sb__item.is-active::before {
  content: ""; position: absolute; left: -8px; top: 6px; bottom: 6px; width: 2px;
  background: var(--accent); border-radius: 0 2px 2px 0;
}
.sb__item__count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 500;
  color: var(--fg-muted);
  background: var(--bg-sunken);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  font-variant-numeric: tabular-nums;
}
.sb__item.is-active .sb__item__count { background: var(--accent); color: white; border-color: var(--accent); }

.sb__sub { padding: 2px 0 4px 26px; }

/* Sidebar flyout — one nav row standing in for a whole group. The panel is
   position: fixed and placed by JS (V2 flyout code in main.js) because .sb__nav
   scrolls, and an absolutely-positioned panel would be clipped by its overflow.
   Works collapsed too: the trigger keeps its icon, the panel is unaffected. */
.sb__flyout { position: relative; }
.sb__flyout__chevron { width: 14px; height: 14px; flex-shrink: 0; color: var(--fg-subtle); }
/* Trigger rows carry a badge and a chevron as well as the label, so there is little text
   room left. Truncate rather than wrap — a wrapped label grows past the 32px row height
   and knocks the whole nav out of alignment. */
.sb__flyout__trigger span:not(.sb__item__count) {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sb__flyout.is-open > .sb__item { background: var(--bg-hover); color: var(--fg-strong); }
.sb__flyout__panel {
  display: none;
  position: fixed;
  z-index: 60;
  min-width: 236px;
  max-height: min(70vh, 560px);
  overflow-y: auto;
  padding: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}
.sb__flyout.is-open > .sb__flyout__panel { display: block; }
.sb__flyout__panel .sb__item { height: 30px; }
.sb__flyout__label {
  padding: 8px 10px 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.sb__flyout__label:first-child { padding-top: 4px; }
/* Footer row: the way through to the full hub page when the panel shows a subset.
   The separator and its spacing sit on this wrapper so the link inside keeps the same
   box as every other row — padding on the link would offset its content within its own
   hover highlight. */
.sb__flyout__more {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border-subtle);
}
.sb__flyout__more .sb__item { color: var(--fg-muted); }
.sb__flyout__more .sb__item:hover { color: var(--fg-strong); }
/* The active marker hangs off the left edge of a sidebar row; inside the panel
   there is no gutter for it, so it would sit outside the rounded border. */
.sb__flyout__panel .sb__item.is-active::before { display: none; }
[data-sidebar="collapsed"] .sb__flyout__chevron { display: none; }
/* The collapsed sidebar hides every .sb__item label and centres the icon. The panel
   is a floating menu, not part of the rail, so it keeps its labels and alignment.
   The :not() is needed to out-specify the collapsing rule further down this file —
   without it the two are equal weight and the later one wins, leaving an icon-only
   flyout that says nothing about where each row goes. */
[data-sidebar="collapsed"] .sb__flyout__panel .sb__item span:not(.sb__item__count) { display: inline; }
[data-sidebar="collapsed"] .sb__flyout__panel .sb__item { justify-content: flex-start; padding: 0 10px; }

/* Collapsible report sub-groups */
.sb__subgroup { margin: 1px 0; }
.sb__subgroup__summary {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  font-size: 12px; font-weight: 500;
  color: var(--fg-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  user-select: none;
  list-style: none;
}
.sb__subgroup__summary::-webkit-details-marker { display: none; }
.sb__subgroup__summary:hover { background: var(--bg-sunken); color: var(--fg-strong); }
.sb__subgroup__chevron {
  width: 14px; height: 14px;
  flex-shrink: 0;
  transition: transform 150ms ease;
}
.sb__subgroup[open] > .sb__subgroup__summary .sb__subgroup__chevron { transform: rotate(90deg); }
.sb__subgroup[open] > .sb__subgroup__summary { color: var(--fg-strong); }
.sb__subgroup__count {
  margin-left: auto;
  font-size: 10px;
  font-weight: 500;
  color: var(--fg-subtle);
  background: var(--bg-sunken);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  font-variant-numeric: tabular-nums;
}
.sb__subgroup__body { padding: 2px 0 4px 10px; }

[data-sidebar="collapsed"] .sb__subgroup__summary span,
[data-sidebar="collapsed"] .sb__subgroup__chevron,
[data-sidebar="collapsed"] .sb__subgroup__count {
  display: none;
}
[data-sidebar="collapsed"] .sb__subgroup__body { padding: 0; }
[data-sidebar="collapsed"] .sb__subgroup__summary { justify-content: center; padding: 0; }

.sb__footer {
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
/* Admin sits above Settings/Help down here. Weight and an accent icon mark it as the one
   that opens a whole section rather than a single page. The .is-active rules out-specify
   both, so the selected state still looks like every other row. */
.sb__footer__admin { color: var(--fg-strong); font-weight: 600; }
.sb__footer__admin .lucide { color: var(--accent); }

[data-sidebar="collapsed"] .sb__brand__name,
[data-sidebar="collapsed"] .sb__brand__sub,
[data-sidebar="collapsed"] .sb__group__label,
[data-sidebar="collapsed"] .sb__item span:not(.sb__item__count),
[data-sidebar="collapsed"] .sb__org__name,
[data-sidebar="collapsed"] .sb__org__sub,
[data-sidebar="collapsed"] .sb__item__count {
  display: none;
}
[data-sidebar="collapsed"] .sb__item { justify-content: center; padding: 0; }
[data-sidebar="collapsed"] .sb__org { justify-content: center; padding: 6px; gap: 0; }
/* Hide the trailing chevron so the org icon centres in its box when collapsed. */
[data-sidebar="collapsed"] .sb__org > .lucide { display: none; }

/* Collapsed brand: hide the logo mark and centre the toggle button so it stays
   on-screen and clickable — it's the only way to expand the sidebar again. */
[data-sidebar="collapsed"] .sb__brand { justify-content: center; padding: 0; gap: 0; }
[data-sidebar="collapsed"] .sb__brand__mark,
[data-sidebar="collapsed"] .sb__brand__link { display: none; }
[data-sidebar="collapsed"] .sb__brand > .btn { margin-left: 0 !important; }

/* topbar */
.tb__search {
  display: flex; align-items: center; gap: 8px;
  width: 360px;
  height: 30px;
  padding: 0 10px;
  background: var(--bg-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--fg-muted);
  cursor: pointer;
}
.tb__search:hover { background: var(--bg-hover); }
.tb__search .lucide { width: 14px; height: 14px; }

.tb__persona {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px 4px 4px;
  background: var(--bg-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-size: 12px;
  cursor: pointer;
}
.tb__persona:hover { background: var(--bg-hover); }
.tb__persona__chip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: var(--accent);
  color: white; font-size: 10px; font-weight: 600;
  border-radius: 50%;
}

/* Account dropdown (uses <details>/<summary>) */
.tb__persona-menu { position: relative; }
.tb__persona-menu > summary { list-style: none; }
.tb__persona-menu > summary::-webkit-details-marker { display: none; }
.tb__persona-menu[open] > .tb__persona { background: var(--bg-hover); }
.tb__persona-menu__panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 4px;
  z-index: 50;
  display: flex; flex-direction: column;
}
.tb__persona-menu__item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--fg-default);
  text-decoration: none;
  background: transparent;
  border: 0;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.tb__persona-menu__item:hover { background: var(--bg-hover); color: var(--fg-strong); }
.tb__persona-menu__item .lucide { width: 16px; height: 16px; color: var(--fg-muted); flex-shrink: 0; }
.tb__persona-menu__divider { height: 1px; background: var(--border-subtle); margin: 4px 2px; }
.tb__persona-menu__form { margin: 0; }

/* ---------- Misc components ---------- */
.kpi-spark {
  width: 100%;
  height: 32px;
  display: block;
}

.divider { height: 1px; background: var(--border-subtle); }
.divider-v { width: 1px; align-self: stretch; background: var(--border-subtle); }

/* AI surface marker — subtle gradient border for AI cards */
.ai-surface {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.ai-surface::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, var(--blue-400), transparent 40%, transparent 60%, var(--blue-400));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
  opacity: 0.4;
}
[data-theme="dark"] .ai-surface::before { opacity: 0.55; }

.ai-glyph {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
  color: white;
  flex-shrink: 0;
}
.ai-glyph .lucide { width: 13px; height: 13px; }

/* Sparkbar (mini bars under a number) */
.sparkbars { display: flex; align-items: flex-end; gap: 2px; height: 24px; }
.sparkbars span { flex: 1; background: var(--accent-soft-2); border-radius: 1px; min-height: 2px; }
.sparkbars span.is-now { background: var(--accent); }

/* ============================================================
   V2 shell mode — pill, accent stripe, switcher, back-to-admin
   Used by _Sidebar.cshtml and _Topbar.cshtml. Mode is set as a
   data attribute on .app__sidebar and .app__topbar (data-mode).
   ============================================================ */

.sb__mode-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    margin: 8px 12px 0;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    border: 1px solid transparent;
}
.sb__mode-pill::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
}
.app__sidebar[data-mode="admin"] .sb__mode-pill {
    background: var(--mode-admin-bg);
    color: var(--mode-admin-fg);
    border-color: var(--mode-admin-bd);
}
.app__sidebar[data-mode="admin"] .sb__mode-pill::before { background: var(--mode-admin-accent); }
.app__sidebar[data-mode="farm"] .sb__mode-pill {
    background: var(--mode-farm-bg);
    color: var(--mode-farm-fg);
    border-color: var(--mode-farm-bd);
}
.app__sidebar[data-mode="farm"] .sb__mode-pill::before { background: var(--mode-farm-accent); }

/* "Back to admin" exit — only shown in farm mode */
.sb__switch-mode {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 4px 12px 8px;
    padding: 6px 10px;
    border: 1px dashed var(--mode-admin-bd);
    border-radius: 6px;
    background: transparent;
    color: var(--mode-admin-fg);
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
}
.sb__switch-mode:hover {
    background: var(--mode-admin-bg);
    border-style: solid;
}

/* Topbar mode strip + chip */
.tb__mode {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-right: 12px;
    font-size: 12px;
    font-weight: 600;
}
.tb__mode-stripe {
    width: 3px;
    height: 20px;
    border-radius: 2px;
}
.app__topbar[data-mode="admin"] .tb__mode-stripe { background: var(--mode-admin-accent); }
.app__topbar[data-mode="admin"] .tb__mode { color: var(--mode-admin-fg); }
.app__topbar[data-mode="farm"] .tb__mode-stripe { background: var(--mode-farm-accent); }
.app__topbar[data-mode="farm"] .tb__mode { color: var(--mode-farm-fg); }

/* ── Kebab / actions dropdown ───────────────────────────────────────────── */
.v2-menu { position: relative; display: inline-block; }
.v2-menu__panel {
    position: absolute; top: calc(100% + 6px); right: 0; z-index: 50;
    min-width: 220px; padding: 6px;
    background: var(--bg-surface); border: 1px solid var(--border-subtle);
    border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    display: flex; flex-direction: column; gap: 2px;
}
.v2-menu__panel[hidden] { display: none; }
.v2-menu__item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: 7px;
    font-size: 13px; color: var(--fg-default); text-decoration: none;
    background: none; border: none; width: 100%; text-align: left; cursor: pointer;
}
.v2-menu__item:hover { background: var(--bg-sunken); }
.v2-menu__item .lucide { width: 16px; height: 16px; color: var(--fg-muted); }
.v2-menu__item--danger { color: #B91C1C; }
.v2-menu__item--danger .lucide { color: #B91C1C; }
.v2-menu__divider { height: 1px; background: var(--border-subtle); margin: 4px 0; }

/* Farm-mode containment: an admin-only link (Url.V2AdminHref) emits no href when the page is
   farm-scoped, so it renders as plain text instead of breaking the user out of farm mode. These
   anchors carry inline accent styling for their admin-mode (linked) state; when href is absent,
   neutralise it so the label reads as ordinary text, not a dead link. Scoped by file: the v2 CSS
   only loads on V2 pages, and V2 has no interactive href-less anchors. */
a:not([href]) {
    color: inherit !important;
    cursor: default !important;
    text-decoration: none !important;
}
