/* ============================================================
   Whangara Cropping Management Platform: Design System
   Brand colours sampled from Whangara Farms' own mark
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

:root, [data-theme='light'] {
  /* Surfaces */
  --color-bg: #F6F4EF;
  --color-surface: #FFFFFF;
  --color-surface-2: #FBFAF7;
  --color-surface-offset: #EFEBE3;
  --color-border: #DFDACF;
  --color-divider: #EAE6DC;

  /* Text */
  --color-text: #1F1B1C;
  --color-text-muted: #6B6560;
  --color-text-faint: #9C9690;
  --color-text-inverse: #FFFFFF;

  /* Primary, Whangara teal */
  --color-primary: #00726B;
  --color-primary-hover: #00584F;
  --color-primary-active: #00443C;
  --color-primary-light: #00AEA3;
  --color-primary-highlight: #DAEFEA;

  /* Secondary, Whangara sky blue (data / links) */
  --color-blue: #00769F;
  --color-blue-hover: #045A79;
  --color-blue-highlight: #D7E9F0;

  /* Warm neutral, Whangara tan */
  --color-tan: #B98A6F;
  --color-tan-highlight: #F1E5DB;

  /* Semantic */
  --color-success: #4C7A3D;
  --color-success-highlight: #E1EBDA;
  --color-warning: #A15A2E;
  --color-warning-highlight: #F0DFCF;
  --color-error: #A13544;
  --color-error-highlight: #F3DCDF;

  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.875rem;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(31,27,23,0.06);
  --shadow-md: 0 4px 14px rgba(31,27,23,0.08);
  --shadow-lg: 0 16px 40px rgba(31,27,23,0.14);

  --font-display: 'General Sans', 'Helvetica Neue', sans-serif;
  --font-body: 'Satoshi', 'Inter', sans-serif;

  --transition: 160ms cubic-bezier(0.16,1,0.3,1);
}

[data-theme='dark'] {
  --color-bg: #15181A;
  --color-surface: #1B1E20;
  --color-surface-2: #202426;
  --color-surface-offset: #262A2C;
  --color-border: #33383A;
  --color-divider: #2A2E30;

  --color-text: #E8E6E2;
  --color-text-muted: #9B9691;
  --color-text-faint: #6C6864;
  --color-text-inverse: #15181A;

  --color-primary: #3FBDB0;
  --color-primary-hover: #63CCC1;
  --color-primary-active: #82D8CE;
  --color-primary-light: #3FBDB0;
  --color-primary-highlight: #1E3532;

  --color-blue: #4FB3DE;
  --color-blue-hover: #74C4E6;
  --color-blue-highlight: #1B333E;

  --color-tan: #D2A88C;
  --color-tan-highlight: #332821;

  --color-success: #7FB068;
  --color-success-highlight: #263420;
  --color-warning: #D08956;
  --color-warning-highlight: #3A2A1E;
  --color-error: #D9707F;
  --color-error-highlight: #3A2226;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.4);
  --shadow-lg: 0 16px 40px rgba(0,0,0,0.5);
}

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

img, svg { display: block; max-width: 100%; }

h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.2; letter-spacing: -0.01em; }

a { color: inherit; text-decoration: none; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }

table { border-collapse: collapse; width: 100%; }

:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; border-radius: var(--radius-sm); }

.tabular { font-variant-numeric: tabular-nums lining-nums; }

/* ============================================================
   Layout: dashboard shell
   ============================================================ */

html, body.shell { height: 100%; overflow: hidden; }

.dashboard {
  display: grid;
  grid-template-columns: 216px 1fr;
  grid-template-rows: 52px 1fr;
  height: 100dvh;
}

.sidebar {
  grid-row: 1 / -1;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 20;
}

.topbar {
  grid-column: 2;
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.25rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 10;
}

.main {
  grid-column: 2;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.1rem 1.4rem 3rem;
}

.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  z-index: 15; opacity: 0; pointer-events: none; transition: opacity var(--transition);
}
.sidebar-overlay.open { opacity: 1; pointer-events: auto; }

@media (max-width: 900px) {
  .dashboard { grid-template-columns: 1fr; grid-template-rows: 56px 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(84vw, 300px);
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateX(-105%);
    transition: transform 240ms cubic-bezier(0.16,1,0.3,1);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { grid-column: 1; padding: 0 0.9rem; padding-top: env(safe-area-inset-top); }
  .main { grid-column: 1; padding: 1rem 0.9rem calc(3rem + env(safe-area-inset-bottom)); }
  .page-title { font-size: 0.95rem; }
}

/* Sidebar contents */
.brand {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--color-border); height: 52px;
}
.brand img { height: 30px; width: auto; }
[data-theme="dark"] .brand img { background: #F7F6F2; padding: 0.35rem 0.5rem; border-radius: var(--radius-md); }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 0.8rem; line-height: 1.15; color: var(--color-text); }
.brand-name span { display: block; font-family: var(--font-body); font-weight: 400; font-size: 0.68rem; color: var(--color-text-muted); margin-top: 1px; }

.nav-group { padding: 0.6rem 0.55rem 0.2rem; }
.nav-label { font-size: 0.63rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--color-text-faint); padding: 0 0.45rem; margin-bottom: 0.2rem; font-weight: 700; }
.nav-link {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.38rem 0.55rem; border-radius: var(--radius-sm);
  font-size: 0.81rem; color: var(--color-text-muted); font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.nav-link svg { width: 15px; height: 15px; flex-shrink: 0; opacity: 0.85; }
.nav-link:hover { background: var(--color-surface-offset); color: var(--color-text); }
.nav-link.active { background: var(--color-primary-highlight); color: var(--color-primary); }
[data-theme='dark'] .nav-link.active { color: var(--color-primary-active); }

.sidebar-footer {
  margin-top: auto; padding: 0.9rem; border-top: 1px solid var(--color-border);
  display: flex; align-items: center; gap: 0.6rem;
}
.avatar {
  width: 30px; height: 30px; border-radius: var(--radius-full);
  background: var(--color-primary-highlight); color: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 700; flex-shrink: 0;
}
.sidebar-footer .who { font-size: 0.78rem; font-weight: 600; }
.sidebar-footer .role { font-size: 0.68rem; color: var(--color-text-muted); }

/* Topbar */
.topbar-left { display: flex; align-items: center; gap: 0.8rem; }
.page-title { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; }
.icon-btn.menu-toggle { display: none; }
@media (max-width: 900px) { .icon-btn.menu-toggle { display: flex; } }
.icon-btn {
  width: 34px; height: 34px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-muted); transition: background var(--transition);
}
.icon-btn:hover { background: var(--color-surface-offset); color: var(--color-text); }
.icon-btn svg { width: 18px; height: 18px; }

.season-pill {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.4rem 0.7rem; border: 1px solid var(--color-border);
  border-radius: var(--radius-full); font-size: 0.78rem; font-weight: 600;
  background: var(--color-surface-2);
}
.season-pill svg { width: 14px; height: 14px; color: var(--color-text-muted); }

/* ============================================================
   Cards, KPIs, badges
   ============================================================ */

.grid { display: grid; gap: 0.7rem; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  /* KPIs read far better 2-up than as a long single column on a phone. */
  .grid-kpi { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
}

.card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: 0.85rem 1rem;
}
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-bottom: 0.65rem; }
.card-title { font-family: var(--font-display); font-size: 0.92rem; font-weight: 600; }
.card-sub { font-size: 0.75rem; color: var(--color-text-muted); margin-top: 0.15rem; }

.kpi-card { padding: 1.1rem 1.2rem; }
.kpi-label { font-size: 0.72rem; color: var(--color-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.55rem; }
.kpi-value { font-family: var(--font-display); font-size: 1.65rem; font-weight: 700; letter-spacing: -0.01em; }
.kpi-value.tabular { font-variant-numeric: tabular-nums; }
.kpi-delta { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.76rem; font-weight: 600; margin-top: 0.5rem; }
.kpi-delta.up { color: var(--color-success); }
.kpi-delta.down { color: var(--color-error); }
.kpi-delta.flat { color: var(--color-text-muted); }
.kpi-delta svg { width: 13px; height: 13px; }
.kpi-target { font-size: 0.72rem; color: var(--color-text-faint); margin-top: 0.3rem; }

.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.22rem 0.6rem; border-radius: var(--radius-full);
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.01em;
}
.badge-success { background: var(--color-success-highlight); color: var(--color-success); }
.badge-warning { background: var(--color-warning-highlight); color: var(--color-warning); }
.badge-error   { background: var(--color-error-highlight);   color: var(--color-error); }
.badge-blue    { background: var(--color-blue-highlight);    color: var(--color-blue); }
.badge-neutral { background: var(--color-surface-offset);    color: var(--color-text-muted); }
.badge-tan     { background: var(--color-tan-highlight);     color: var(--color-tan); }
.badge svg { width: 11px; height: 11px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.55rem 1rem; border-radius: var(--radius-md);
  font-size: 0.82rem; font-weight: 600; white-space: nowrap;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: var(--color-surface); border: 1px solid var(--color-border); color: var(--color-text); }
.btn-secondary:hover { background: var(--color-surface-offset); }
.btn-ghost { color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-surface-offset); color: var(--color-text); }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.76rem; }
.btn-danger { background: var(--color-error); color: #fff; }
.btn-danger:hover { filter: brightness(0.9); }
.btn-block { width: 100%; }

/* Tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--color-border); }
table.data { font-size: 0.8rem; background: var(--color-surface); }
table.data thead th {
  position: sticky; top: 0; text-align: left; font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted);
  background: var(--color-surface-2); padding: 0.45rem 0.8rem; font-weight: 700;
  border-bottom: 1px solid var(--color-border); white-space: nowrap;
}
table.data td { padding: 0.45rem 0.8rem; border-bottom: 1px solid var(--color-divider); white-space: nowrap; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--color-surface-2); }
.cell-strong { font-weight: 600; }
.cell-muted { color: var(--color-text-muted); }

/* Progress bar */
.progress-track { height: 6px; border-radius: var(--radius-full); background: var(--color-surface-offset); overflow: hidden; }
.progress-fill { height: 100%; border-radius: var(--radius-full); background: var(--color-primary); }

/* Bars (mini charts) */
.bars { display: flex; align-items: flex-end; gap: 0.5rem; height: 120px; }
.bars .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.4rem; height: 100%; justify-content: flex-end; }
.bars .bar-track { width: 100%; height: 96px; display: flex; align-items: flex-end; }
.bars .bar { width: 100%; border-radius: 5px 5px 0 0; background: var(--color-primary); min-height: 4px; }
.bars .bar.alt { background: var(--color-blue); }
.bars .bar-label { font-size: 0.68rem; color: var(--color-text-muted); }

/* Framework step tracker */
.phase-block { margin-bottom: 1.75rem; }
.phase-heading { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.75rem; }
.phase-dot { width: 9px; height: 9px; border-radius: 50%; }
.phase-title { font-family: var(--font-display); font-weight: 600; font-size: 0.88rem; }
.phase-tagline { font-size: 0.76rem; color: var(--color-text-muted); }

.step-row {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.8rem 1rem; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  margin-bottom: 0.5rem;
}
.step-num {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 700; background: var(--color-surface-offset); color: var(--color-text-muted);
}
.step-row.complete .step-num { background: var(--color-primary); color: #fff; }
.step-row.progress .step-num { background: var(--color-blue-highlight); color: var(--color-blue); }
.step-main { flex: 1; min-width: 0; }
.step-flow { font-size: 0.84rem; font-weight: 600; }
.step-meta { font-size: 0.72rem; color: var(--color-text-muted); margin-top: 0.15rem; }
.step-right { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }

@media (max-width: 700px) {
  .step-row { flex-wrap: wrap; }
  .step-right { width: 100%; justify-content: space-between; margin-top: 0.4rem; }
}

/* Forms */
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.78rem; font-weight: 600; margin-bottom: 0.4rem; }
.field .hint { font-size: 0.7rem; color: var(--color-text-muted); margin-top: 0.3rem; }
.input, select.input, textarea.input {
  width: 100%; padding: 0.65rem 0.8rem; border-radius: var(--radius-md);
  border: 1px solid var(--color-border); background: var(--color-surface);
  font-size: 0.88rem; color: var(--color-text);
}
.input:focus, select.input:focus, textarea.input:focus { outline: 2px solid var(--color-primary); outline-offset: 1px; }
.input-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
@media (max-width: 480px) { .input-row { grid-template-columns: 1fr; } }

.upload-box {
  border: 1.5px dashed var(--color-border); border-radius: var(--radius-md);
  padding: 1.5rem; text-align: center; color: var(--color-text-muted); font-size: 0.8rem;
}
.upload-box svg { width: 26px; height: 26px; margin: 0 auto 0.5rem; color: var(--color-text-faint); }

.segmented { display: flex; border: 1px solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; }
.segmented button { flex: 1; padding: 0.55rem 0.4rem; font-size: 0.78rem; font-weight: 600; color: var(--color-text-muted); }
.segmented button.active { background: var(--color-primary); color: #fff; }

/* Lock / no-export banner */
.lock-banner {
  display: flex; align-items: center; gap: 0.6rem;
  background: var(--color-tan-highlight); color: var(--color-tan);
  border: 1px solid transparent; border-radius: var(--radius-md);
  padding: 0.6rem 0.9rem; font-size: 0.76rem; font-weight: 600; margin-bottom: 1.25rem;
}
.lock-banner svg { width: 15px; height: 15px; flex-shrink: 0; }

.divider-label { display: flex; align-items: center; gap: 0.6rem; font-size: 0.68rem; color: var(--color-text-faint); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; margin: 1rem 0 0.55rem; }
.divider-label::after { content: ''; flex: 1; height: 1px; background: var(--color-divider); }

/* Empty / muted note */
.note { font-size: 0.78rem; color: var(--color-text-muted); }

/* Utility */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 0.85rem; }
.mt-sm { margin-top: 0.5rem; }
.mt-md { margin-top: 1rem; }
.mt-lg { margin-top: 1.75rem; }
.mb-sm { margin-bottom: 0.5rem; }
.mb-md { margin-bottom: 1rem; }
.mb-lg { margin-bottom: 1.75rem; }

/* ============================================================
   Login / role select screen
   ============================================================ */

.login-shell {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 2rem 1.25rem; background: var(--color-bg);
  background-image: radial-gradient(circle at 15% 10%, var(--color-primary-highlight), transparent 45%),
                     radial-gradient(circle at 85% 90%, var(--color-tan-highlight), transparent 45%);
}
.login-card {
  width: 100%; max-width: 420px; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: 2.25rem 2rem; box-shadow: var(--shadow-lg);
}
.login-logo { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 1.75rem; }
.login-logo img { height: 36px; }
.login-logo .div { width: 1px; height: 26px; background: var(--color-border); }
.login-logo .sf { font-family: var(--font-display); font-weight: 700; font-size: 0.85rem; color: var(--color-text-muted); }
.login-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 0.3rem; }
.login-sub { font-size: 0.82rem; color: var(--color-text-muted); margin-bottom: 1.75rem; }
.role-option {
  display: flex; align-items: center; gap: 0.85rem; width: 100%;
  padding: 0.85rem 1rem; border: 1px solid var(--color-border); border-radius: var(--radius-md);
  margin-bottom: 0.6rem; text-align: left; transition: border-color var(--transition), background var(--transition);
}
.role-option:hover { border-color: var(--color-primary); background: var(--color-primary-highlight); }
.role-icon {
  width: 36px; height: 36px; border-radius: var(--radius-md); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-surface-offset); color: var(--color-primary);
}
.role-icon svg { width: 18px; height: 18px; }
.role-name { font-size: 0.85rem; font-weight: 700; }
.role-desc { font-size: 0.72rem; color: var(--color-text-muted); }
.role-arrow { margin-left: auto; color: var(--color-text-faint); flex-shrink: 0; }
.role-arrow svg { width: 16px; height: 16px; }
.login-footnote { font-size: 0.7rem; color: var(--color-text-faint); text-align: center; margin-top: 1.5rem; }

/* ============================================================
   Mobile app-shell chrome (farm manager view on small screens)
   ============================================================ */

.mobile-header {
  position: sticky; top: 0; z-index: 10; background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: calc(0.7rem + env(safe-area-inset-top)) 1.1rem 0.7rem;
  display: flex; align-items: center; justify-content: space-between;
}
.mobile-header img { height: 24px; }
.mobile-body {
  padding: 0.8rem 0.85rem calc(5rem + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
}

/* Greeting hero at the top of the farm home screen */
.mobile-hero {
  border-radius: var(--radius-md);
  padding: 0.8rem 0.95rem;
  margin-bottom: 0.7rem;
  color: #fff;
  background:
    radial-gradient(circle at 85% 15%, rgba(255,255,255,0.16), transparent 50%),
    linear-gradient(135deg, var(--color-primary) 0%, #00584F 100%);
}
[data-theme='dark'] .mobile-hero { background: radial-gradient(circle at 85% 15%, rgba(255,255,255,0.08), transparent 50%), linear-gradient(135deg, #0B4F49 0%, #093A36 100%); }
.mobile-hero .kia-ora { font-size: 0.76rem; opacity: 0.85; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; }
.mobile-hero .hero-name { font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; margin: 0.05rem 0; }
.mobile-hero .hero-sub { font-size: 0.78rem; opacity: 0.9; }
.mobile-hero .hero-progress { margin-top: 0.6rem; }
.mobile-hero .progress-track { background: rgba(255,255,255,0.25); }
.mobile-hero .progress-fill { background: #fff; }
.mobile-hero .hero-progress-meta { display: flex; justify-content: space-between; font-size: 0.72rem; margin-top: 0.35rem; opacity: 0.9; font-weight: 600; }

/* Quick action grid (farm home) */
.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin-bottom: 0.8rem; }
.quick-action {
  display: flex; flex-direction: column; align-items: center; gap: 0.45rem;
  padding: 0.6rem 0.35rem; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  font-size: 0.68rem; font-weight: 700; color: var(--color-text);
  transition: border-color var(--transition), background var(--transition);
}
.quick-action:active { background: var(--color-surface-offset); }
.quick-action .qa-icon {
  width: 30px; height: 30px; border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  background: var(--color-primary-highlight); color: var(--color-primary);
}
.quick-action .qa-icon.warn { background: var(--color-error-highlight); color: var(--color-error); }
.quick-action .qa-icon.blue { background: var(--color-blue-highlight); color: var(--color-blue); }
.quick-action svg { width: 19px; height: 19px; }

.mobile-tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: color-mix(in srgb, var(--color-surface) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--color-border);
  display: flex; padding: 0.35rem 0.4rem calc(0.35rem + env(safe-area-inset-bottom));
}
.mobile-tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  padding: 0.35rem 0; font-size: 0.62rem; color: var(--color-text-faint); font-weight: 600;
  border-radius: var(--radius-md); transition: color var(--transition);
}
.mobile-tabbar a.active { color: var(--color-primary); }
.mobile-tabbar a .tab-icon { display: flex; align-items: center; justify-content: center; width: 44px; height: 26px; border-radius: var(--radius-full); transition: background var(--transition); }
.mobile-tabbar a.active .tab-icon { background: var(--color-primary-highlight); }
.mobile-tabbar svg { width: 19px; height: 19px; }

.task-tile {
  display: flex; align-items: center; gap: 0.65rem;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: 0.6rem 0.7rem; margin-bottom: 0.45rem;
}
.task-check {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--color-border);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.task-check.done { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.task-check svg { width: 13px; height: 13px; }
.task-title { font-size: 0.82rem; font-weight: 600; }
.task-meta { font-size: 0.68rem; color: var(--color-text-muted); }

.farm-chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: var(--color-primary-highlight); color: var(--color-primary);
  padding: 0.3rem 0.65rem; border-radius: var(--radius-full); font-size: 0.72rem; font-weight: 700;
}

/* ============================================================
   App shell loading state (before layout.js finishes fetching /api/auth/me)
   ============================================================ */
.shell-loading {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  color: var(--color-text-muted); font-size: 0.85rem;
}

/* ============================================================
   Toasts (success / error feedback after actions)
   ============================================================ */
.toast-stack {
  position: fixed; top: 1rem; right: 1rem; z-index: 100;
  display: flex; flex-direction: column; gap: 0.5rem; max-width: 340px;
}
.toast {
  display: flex; align-items: flex-start; gap: 0.6rem;
  padding: 0.75rem 0.9rem; border-radius: var(--radius-md);
  background: var(--color-surface); border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md); font-size: 0.82rem; font-weight: 600;
  animation: toast-in 160ms cubic-bezier(0.16,1,0.3,1);
}
.toast.success { border-color: var(--color-success); color: var(--color-success); }
.toast.error { border-color: var(--color-error); color: var(--color-error); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   Modal (add user, log risk, review contractor, etc.)
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 90;
  display: flex; align-items: center; justify-content: center; padding: 1.25rem;
}
.modal-card {
  width: 100%; max-width: 460px; max-height: 88vh; overflow-y: auto;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: 1.5rem; box-shadow: var(--shadow-lg);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.1rem; }
.modal-title { font-family: var(--font-display); font-size: 1.02rem; font-weight: 700; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.25rem; }

/* ============================================================
   Empty / error states
   ============================================================ */
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--color-text-muted); }
.empty-state svg { width: 32px; height: 32px; margin: 0 auto 0.75rem; color: var(--color-text-faint); }
.empty-state .title { font-size: 0.88rem; font-weight: 600; color: var(--color-text); margin-bottom: 0.25rem; }

.form-error {
  background: var(--color-error-highlight); color: var(--color-error);
  border-radius: var(--radius-md); padding: 0.6rem 0.85rem; font-size: 0.8rem; font-weight: 600;
  margin-bottom: 1rem;
}

/* Skeleton loading blocks */
.skeleton { background: linear-gradient(90deg, var(--color-surface-offset) 25%, var(--color-divider) 37%, var(--color-surface-offset) 63%); background-size: 400% 100%; animation: skeleton-pulse 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes skeleton-pulse { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* Star rating input (contractor reviews) */
.star-input { display: flex; gap: 0.3rem; }
.star-input button { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; color: var(--color-border); }
.star-input button.filled { color: var(--color-tan); }
.star-input svg { width: 20px; height: 20px; }

/* ============================================================
   Workboard (tasks): kanban on desktop, stacked lists on mobile
   ============================================================ */
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .board { grid-template-columns: 1fr; } }
.board-col {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: 0.85rem;
}
.board-col-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; padding: 0 0.2rem; }
.board-col-title { font-family: var(--font-display); font-size: 0.82rem; font-weight: 700; }
.board-count {
  min-width: 22px; height: 22px; padding: 0 0.4rem; border-radius: var(--radius-full);
  background: var(--color-surface-offset); color: var(--color-text-muted);
  display: inline-flex; align-items: center; justify-content: center; font-size: 0.7rem; font-weight: 700;
}
.board-dot { width: 8px; height: 8px; border-radius: 50%; }

.task-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: 0.8rem 0.9rem; margin-bottom: 0.6rem;
  box-shadow: var(--shadow-sm); cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.task-card:hover { border-color: var(--color-primary-light); box-shadow: var(--shadow-md); }
.task-card .tc-title { font-size: 0.84rem; font-weight: 600; line-height: 1.35; }
.task-card .tc-notes { font-size: 0.74rem; color: var(--color-text-muted); margin-top: 0.25rem; }
.task-card .tc-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.task-card .tc-meta .who { font-size: 0.7rem; color: var(--color-text-muted); font-weight: 600; margin-left: auto; }
.task-card.done .tc-title { text-decoration: line-through; color: var(--color-text-muted); }
.due-chip { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.68rem; font-weight: 700; color: var(--color-text-muted); }
.due-chip svg { width: 11px; height: 11px; }
.due-chip.overdue { color: var(--color-error); }
.due-chip.soon { color: var(--color-warning); }

/* Filter chip row (farm / status filters) */
.chip-row { display: flex; gap: 0.45rem; overflow-x: auto; padding-bottom: 0.25rem; margin-bottom: 1rem; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 0.4rem 0.85rem; border-radius: var(--radius-full);
  border: 1px solid var(--color-border); background: var(--color-surface);
  font-size: 0.76rem; font-weight: 600; color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.chip.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }

/* Crop plan stage pills */
.stage-pill { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.22rem 0.6rem; border-radius: var(--radius-full); font-size: 0.7rem; font-weight: 700; }
.stage-planned     { background: var(--color-surface-offset); color: var(--color-text-muted); }
.stage-prepared    { background: var(--color-tan-highlight); color: var(--color-tan); }
.stage-planted     { background: var(--color-blue-highlight); color: var(--color-blue); }
.stage-established { background: var(--color-primary-highlight); color: var(--color-primary); }
.stage-grazing     { background: var(--color-warning-highlight); color: var(--color-warning); }
.stage-finished    { background: var(--color-success-highlight); color: var(--color-success); }

/* Stage stepper (tap to advance a paddock through its stages) */
.stage-track { display: flex; gap: 0.25rem; margin-top: 0.5rem; }
.stage-track .seg { flex: 1; height: 5px; border-radius: var(--radius-full); background: var(--color-surface-offset); }
.stage-track .seg.on { background: var(--color-primary); }

/* Activity feed */
.feed-item { display: flex; gap: 0.75rem; padding: 0.7rem 0.15rem; border-bottom: 1px solid var(--color-divider); }
.feed-item:last-child { border-bottom: none; }
.feed-icon {
  width: 32px; height: 32px; border-radius: var(--radius-full); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-primary-highlight); color: var(--color-primary);
}
.feed-icon.warn { background: var(--color-error-highlight); color: var(--color-error); }
.feed-icon.blue { background: var(--color-blue-highlight); color: var(--color-blue); }
.feed-icon svg { width: 15px; height: 15px; }
.feed-main { min-width: 0; flex: 1; }
.feed-title { font-size: 0.8rem; font-weight: 600; }
.feed-detail { font-size: 0.74rem; color: var(--color-text-muted); margin-top: 0.1rem; overflow-wrap: anywhere; }
.feed-time { font-size: 0.68rem; color: var(--color-text-faint); flex-shrink: 0; white-space: nowrap; }

/* Inline-editable KPI inputs (admin) */
.kpi-edit-input { width: 90px; padding: 0.35rem 0.5rem; font-size: 0.8rem; text-align: right; }

/* Section header shared by the new pages */
.page-intro { margin-bottom: 1.25rem; }
.page-intro h2 { font-size: 1.15rem; font-weight: 700; }
.page-intro p { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.2rem; max-width: 60ch; }

/* Comfortable touch targets on phones */
@media (max-width: 900px) {
  .btn { padding: 0.65rem 1.05rem; }
  .btn-sm { padding: 0.5rem 0.85rem; }
  .icon-btn { width: 38px; height: 38px; }
  .input, select.input, textarea.input { padding: 0.75rem 0.85rem; font-size: 16px; } /* 16px stops iOS zoom-on-focus */
  .segmented button { padding: 0.7rem 0.4rem; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-card {
    max-width: none; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 92dvh; padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    animation: sheet-up 220ms cubic-bezier(0.16,1,0.3,1);
  }
  .toast-stack { left: 1rem; right: 1rem; top: calc(0.75rem + env(safe-area-inset-top)); max-width: none; }
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }

/* Print (reporting exports): show only the page content */
@media print {
  .sidebar, .topbar, .sidebar-overlay, .mobile-tabbar, .mobile-header, .btn, .lock-banner { display: none !important; }
  html, body.shell { height: auto; overflow: visible; }
  .dashboard { display: block; height: auto; }
  .main { overflow: visible; padding: 0; }
  .card { break-inside: avoid; box-shadow: none; }
  body { background: #fff; }
}

/* ============================================================
   Density layer: compact, information-dense components.
   These replace the card-per-item patterns that made earlier
   screens read as long stacks of mostly-empty boxes.
   ============================================================ */

/* Page header: title, context and actions on one line */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.85rem;
  padding-bottom: 0.7rem; border-bottom: 1px solid var(--color-border);
}
.page-head h2 { font-size: 1.02rem; font-weight: 700; letter-spacing: -0.015em; }
.page-head .sub { font-size: 0.76rem; color: var(--color-text-muted); margin-top: 0.1rem; }
.page-head .actions { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

/* Metric strip: one bordered row, hairline-divided. Replaces a row of
   large KPI cards that spent ~130px of height on a single number each. */
.metric-strip {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); overflow: hidden; margin-bottom: 0.9rem;
}
.metric {
  padding: 0.55rem 0.85rem; border-left: 1px solid var(--color-divider);
  display: flex; flex-direction: column; gap: 0.1rem; min-width: 0;
}
.metric:first-child { border-left: none; }
.metric .m-label {
  font-size: 0.63rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--color-text-faint); font-weight: 700; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.metric .m-value {
  font-family: var(--font-display); font-size: 1.18rem; font-weight: 700;
  letter-spacing: -0.02em; line-height: 1.15;
}
.metric .m-foot { font-size: 0.68rem; color: var(--color-text-muted); }
.metric.alert .m-value { color: var(--color-error); }
.metric.good .m-value { color: var(--color-success); }
a.metric:hover { background: var(--color-surface-2); }
@media (max-width: 900px) {
  .metric-strip { grid-auto-flow: row; grid-template-columns: repeat(2, 1fr); grid-auto-columns: auto; }
  .metric { border-left: 1px solid var(--color-divider); border-top: 1px solid var(--color-divider); }
  .metric:nth-child(odd) { border-left: none; }
  .metric:nth-child(-n+2) { border-top: none; }
}

/* Dense list: hairline-separated rows inside one border, instead of
   giving every item its own card and margin. */
.list {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); overflow: hidden;
}
.list-row {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.45rem 0.8rem; border-bottom: 1px solid var(--color-divider);
  min-height: 38px; font-size: 0.82rem;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--color-surface-2); }
.list-row .lr-main { flex: 1; min-width: 0; }
.list-row .lr-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .lr-sub { font-size: 0.72rem; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .lr-right { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }
.list-row.is-done .lr-title { color: var(--color-text-muted); }

/* Group heading inside a list (phase names, farm names) */
.list-group {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.35rem 0.8rem; background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-divider);
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--color-text-muted);
}
.list-group .g-count { margin-left: auto; font-weight: 600; letter-spacing: 0; text-transform: none; }

/* Compact numbered marker for framework steps */
.marker {
  width: 20px; height: 20px; border-radius: var(--radius-full); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 700;
  background: var(--color-surface-offset); color: var(--color-text-muted);
}
.marker.done { background: var(--color-primary); color: #fff; }
.marker.doing { background: var(--color-blue-highlight); color: var(--color-blue); }
.marker svg { width: 11px; height: 11px; }

/* Micro status control: three small toggles instead of a select per row */
.status-set { display: inline-flex; border: 1px solid var(--color-border); border-radius: var(--radius-sm); overflow: hidden; }
.status-set button {
  padding: 0.18rem 0.45rem; font-size: 0.68rem; font-weight: 600;
  color: var(--color-text-muted); border-left: 1px solid var(--color-border);
  transition: background var(--transition), color var(--transition);
}
.status-set button:first-child { border-left: none; }
.status-set button:hover { background: var(--color-surface-offset); }
.status-set button.on { background: var(--color-primary); color: #fff; }
.status-set button.on.blue { background: var(--color-blue); }
.status-set button.on.grey { background: var(--color-text-faint); }

/* Needs-attention block on the overview */
.attention { display: flex; flex-direction: column; }
.attention-row {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.5rem 0.8rem; border-bottom: 1px solid var(--color-divider);
  font-size: 0.82rem;
}
.attention-row:last-child { border-bottom: none; }
.attention-row:hover { background: var(--color-surface-2); }
.attention-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; background: var(--color-text-faint); }
.attention-dot.high { background: var(--color-error); }
.attention-dot.med { background: var(--color-warning); }
.attention-row .ar-main { flex: 1; min-width: 0; }
.attention-row .ar-title { font-weight: 600; }
.attention-row .ar-sub { font-size: 0.72rem; color: var(--color-text-muted); }
.attention-row .ar-go { color: var(--color-text-faint); flex-shrink: 0; }
.attention-row .ar-go svg { width: 14px; height: 14px; }

/* Two-column working layout that collapses cleanly */
.cols { display: grid; grid-template-columns: 1.6fr 1fr; gap: 0.7rem; align-items: start; }
@media (max-width: 1100px) { .cols { grid-template-columns: 1fr; } }

/* ============================================================
   Mobile gestures
   ============================================================ */

/* Horizontal swipe between farm tabs */
.swipe-area { touch-action: pan-y; }
.tab-panel { will-change: transform; }
.tab-panel.sliding { transition: transform 220ms cubic-bezier(0.16,1,0.3,1); }

/* Swipe a task row sideways to complete it */
.swipe-item { position: relative; overflow: hidden; border-radius: var(--radius-md); margin-bottom: 0.45rem; }
.swipe-item .swipe-behind {
  position: absolute; inset: 0; display: flex; align-items: center;
  padding: 0 1.1rem; background: var(--color-success); color: #fff;
  font-size: 0.78rem; font-weight: 700; gap: 0.4rem;
}
.swipe-item .swipe-behind.undo { background: var(--color-text-faint); justify-content: flex-end; }
.swipe-item .swipe-behind svg { width: 16px; height: 16px; }
.swipe-item .swipe-front {
  position: relative; background: var(--color-surface);
  touch-action: pan-y; will-change: transform;
}
.swipe-item .swipe-front.settling { transition: transform 200ms cubic-bezier(0.16,1,0.3,1); }

/* Pull to refresh */
.ptr {
  position: absolute; top: 0; left: 0; right: 0; height: 44px;
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-muted); font-size: 0.72rem; font-weight: 600;
  opacity: 0; pointer-events: none;
}
.ptr svg { width: 15px; height: 15px; margin-right: 0.35rem; }
.ptr.spin svg { animation: ptr-spin 700ms linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* A hint shown once so the gestures are discoverable rather than hidden */
.gesture-hint {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.7rem; color: var(--color-text-faint);
  padding: 0.3rem 0.1rem 0.5rem;
}
.gesture-hint svg { width: 13px; height: 13px; }

/* ============================================================
   Charts. Marks carry the data colour; all text stays in text
   tokens. Bars are capped thin with a 4px rounded data-end and a
   square baseline, and touching marks are separated by a 2px gap
   in the surface colour rather than by a stroke.
   ============================================================ */

/* Horizontal bars: label | track | value */
.viz-bars { display: flex; flex-direction: column; gap: 0.3rem; }
.viz-bar-row {
  display: grid; grid-template-columns: 84px 1fr auto; align-items: center;
  gap: 0.55rem; min-height: 24px; /* comfortable hover target, not the 14px mark */
  border-radius: var(--radius-sm);
}
.viz-bar-row:hover { background: var(--color-surface-2); }
.viz-bar-label {
  font-size: 0.74rem; color: var(--color-text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.viz-bar-track { position: relative; height: 14px; display: flex; align-items: center; }
.viz-bar-fill {
  height: 14px; border-radius: 0 4px 4px 0; /* rounded data-end, square at baseline */
  transition: width 260ms cubic-bezier(0.16,1,0.3,1);
}
.viz-bar-value { font-size: 0.76rem; font-weight: 600; min-width: 44px; text-align: right; }
.viz-unit { color: var(--color-text-faint); font-weight: 500; }

/* Stacked bar for ordered stages */
.viz-stack {
  display: flex; height: 18px; border-radius: 4px; overflow: hidden;
  background: var(--color-surface-offset); gap: 2px; /* 2px surface gap between segments */
}
.viz-stack-seg {
  display: flex; align-items: center; justify-content: center;
  min-width: 7px; transition: flex 260ms cubic-bezier(0.16,1,0.3,1);
}
.viz-stack-seg:first-child { border-radius: 4px 0 0 4px; }
.viz-stack-seg:last-child { border-radius: 0 4px 4px 0; }
.viz-stack-inline { font-size: 0.65rem; font-weight: 700; color: #fff; }

/* Legend: identity never rests on colour alone */
.viz-legend { display: flex; flex-wrap: wrap; gap: 0.4rem 0.85rem; margin-top: 0.5rem; }
.viz-key { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.7rem; color: var(--color-text-muted); }
.viz-swatch { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.viz-key-n { font-weight: 700; color: var(--color-text); }

/* Bullet: actual against target */
.viz-bullet { padding: 0.45rem 0; border-bottom: 1px solid var(--color-divider); }
.viz-bullet:last-child { border-bottom: none; }
.viz-bullet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.3rem; }
.viz-bullet-label { font-size: 0.76rem; color: var(--color-text-muted); }
.viz-bullet-value { font-size: 0.95rem; font-weight: 700; }
.viz-bullet-track {
  position: relative; height: 12px; border-radius: 4px;
  background: var(--color-surface-offset); overflow: hidden;
}
.viz-bullet-fill { position: absolute; inset: 0 auto 0 0; border-radius: 0 4px 4px 0; }
.viz-bullet-target {
  position: absolute; top: -2px; bottom: -2px; width: 2px;
  background: var(--color-text); opacity: 0.75;
}
.viz-bullet-foot { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.68rem; margin-top: 0.25rem; }
.viz-bullet-foot .is-good { color: var(--color-success); font-weight: 700; }
.viz-bullet-foot .is-off { color: var(--color-warning); font-weight: 700; }

/* Pipeline of discrete steps */
.viz-pipeline { display: flex; gap: 2px; }
.viz-cell { flex: 1; height: 20px; border-radius: 2px; background: var(--color-surface-offset); min-width: 5px; }
.viz-cell.is-empty { background: var(--color-surface-offset); }
.viz-cell:first-child { border-radius: 4px 2px 2px 4px; }
.viz-cell:last-child { border-radius: 2px 4px 4px 2px; }

/* Meter: fill and track are the same hue, different steps */
.viz-meter { height: 6px; border-radius: var(--radius-full); background: var(--color-surface-offset); overflow: hidden; margin-top: 0.35rem; }
.viz-meter-fill { display: block; height: 100%; border-radius: var(--radius-full); transition: width 260ms cubic-bezier(0.16,1,0.3,1); }

/* Hover tooltip: an HTML chart is interactive by default */
.viz-tip {
  position: fixed; z-index: 200; pointer-events: none;
  background: var(--color-text); color: var(--color-bg);
  padding: 0.28rem 0.5rem; border-radius: var(--radius-sm);
  font-size: 0.72rem; font-weight: 600; white-space: nowrap;
  opacity: 0; transition: opacity 120ms ease; box-shadow: var(--shadow-md);
}
.viz-tip.on { opacity: 1; }

/* Stat tile: label, value, and a visual that carries the shape of the number */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 0.7rem; margin-bottom: 0.9rem; }
.tile {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: 0.7rem 0.8rem;
  display: flex; flex-direction: column; gap: 0.1rem;
}
a.tile:hover { border-color: var(--color-primary-light); }
.tile-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-faint); font-weight: 700; }
.tile-value { font-family: var(--font-display); font-size: 1.45rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.tile-value .tile-of { font-size: 0.85rem; font-weight: 600; color: var(--color-text-faint); }
.tile-foot { font-size: 0.68rem; color: var(--color-text-muted); margin-top: 0.15rem; }
.tile-foot.alert { color: var(--color-error); font-weight: 700; }
.tile-foot.good { color: var(--color-success); font-weight: 600; }
.tile-viz { margin-top: 0.4rem; }
@media (max-width: 640px) { .tile-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; } }

/* KPI bullets in columns; each keeps its own divider within a column */
.bullet-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 1.5rem; }
@media (max-width: 700px) { .bullet-grid { grid-template-columns: 1fr; } }

/* Sidebar identity must not wrap now the rail is narrower */
.sidebar-footer > div { min-width: 0; }
.sidebar-footer .who, .sidebar-footer .role {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 118px;
}

/* ============================================================
   Update available bar
   ============================================================ */
.update-bar {
  position: fixed; z-index: 150;
  left: 50%; bottom: 1rem; transform: translate(-50%, 140%);
  display: flex; align-items: center; gap: 0.6rem;
  max-width: calc(100vw - 1.6rem);
  padding: 0.5rem 0.6rem 0.5rem 0.9rem;
  background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border); border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg); font-size: 0.8rem; font-weight: 600;
  transition: transform 260ms cubic-bezier(0.16,1,0.3,1), opacity 200ms ease;
  opacity: 0;
}
.update-bar.on { transform: translate(-50%, 0); opacity: 1; }
.update-bar .ub-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.update-bar .ub-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-highlight);
}
.update-bar .ub-close { width: 28px; height: 28px; flex-shrink: 0; }
.update-bar .ub-close svg { width: 15px; height: 15px; }
.update-bar .btn { flex-shrink: 0; }

/* Clear the farm app's bottom tab bar and the phone's home indicator. */
@media (max-width: 900px) {
  .update-bar {
    left: 0.8rem; right: 0.8rem; transform: translateY(140%);
    max-width: none; justify-content: space-between;
    bottom: calc(4.4rem + env(safe-area-inset-bottom));
  }
  .update-bar.on { transform: translateY(0); }
  .update-bar .ub-text { white-space: normal; }
}
/* Roles without the mobile tab bar can sit lower. */
@media (max-width: 900px) {
  body.shell .update-bar { bottom: calc(1rem + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .update-bar { transition: opacity 200ms ease; transform: none; }
  .update-bar.on { transform: none; }
}

/* ============================================================
   Narrow-screen fit-and-finish.

   The list row hands its right-hand controls a fixed width, which on a phone
   left the title and detail fighting over what was left - a gate row gave its
   description 20% of the space it needed. Below 640px the controls drop to
   their own line so the text gets the full width.
   ============================================================ */

@media (max-width: 640px) {
  .list-row {
    flex-wrap: wrap;
    padding: 0.55rem 0.75rem;
    row-gap: 0.1rem;
  }
  .list-row .lr-main { flex: 1 1 60%; }
  /* A 100% basis forces the controls onto their own line, full width. */
  .list-row .lr-right {
    flex: 1 1 100%;
    justify-content: flex-end;
    margin-top: 0.4rem;
  }
  /* Two lines of detail beats one hard-truncated line. */
  .list-row .lr-sub,
  .attention-row .ar-sub,
  .task-card .tc-notes {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .list-row .lr-title { white-space: normal; }
  .list-group { flex-wrap: wrap; row-gap: 0.15rem; }
  .list-group .g-count { margin-left: 0; width: 100%; }
}

/* Touch targets: everything interactive clears ~32px on a phone. */
@media (max-width: 900px) {
  .status-set button {
    padding: 0.45rem 0.75rem;
    font-size: 0.74rem;
    min-height: 34px;
  }
  .status-set { width: 100%; }
  .status-set button { flex: 1; }
  .task-check { width: 28px; height: 28px; }
  .viz-legend { gap: 0.35rem 0.7rem; }
  .tile-viz .viz-stack { height: 14px; }
}

/* Selects sitting inside data tables: sized from CSS so they can grow on touch. */
.cell-select {
  width: auto;
  padding: 0.22rem 0.45rem;
  font-size: 0.74rem;
}
@media (max-width: 900px) {
  .cell-select { min-height: 34px; padding: 0.35rem 0.5rem; font-size: 0.8rem; }
}

/* Small inline links need a real hit area, not just their text box. */
.link-action {
  color: var(--color-blue);
  font-weight: 600;
  padding: 0.35rem 0.2rem;
  display: inline-flex;
  align-items: center;
  min-height: 28px;
}
.link-action:hover { text-decoration: underline; }

/* The bar chart's label column is a big share of a 320px screen. */
@media (max-width: 640px) {
  .viz-bar-row { grid-template-columns: 68px 1fr auto; gap: 0.4rem; }
  .viz-bar-label { font-size: 0.7rem; }
  .viz-bar-value { font-size: 0.72rem; min-width: 38px; }
}

/* Modal action rows must not squeeze their buttons on a narrow sheet. */
@media (max-width: 480px) {
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1 1 auto; justify-content: center; }
  .page-head { gap: 0.5rem; }
  .page-head .actions { width: 100%; }
  /* Full-width buttons must be allowed to stack. Without a basis they each
     claim 100% of the row and the last ones run off the screen. */
  .page-head .actions .btn { flex: 1 1 100%; width: auto; justify-content: center; }
}

/* ============================================================
   Users & access groups
   ============================================================ */

/* Both halves of a list row's main column stack, whether they are spans or
   divs, so a row reads as title-over-detail everywhere it is used. */
.list-row .lr-title, .list-row .lr-sub { display: block; }
.list-row.is-muted .lr-title, .list-row.is-muted .lr-sub { color: var(--color-text-muted); }
.list-tight .list-row { padding: 0.4rem 0.8rem; min-height: 34px; }

.avatar-sm {
  width: 28px; height: 28px; border-radius: var(--radius-full); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-surface-offset); color: var(--color-text-muted);
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.02em;
}

/* Badges under a row title. Unlike .chip-row this wraps rather than scrolling,
   because a row is not a scroll container. */
.tag-row { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.25rem; }
.tag-row .badge { font-size: 0.65rem; padding: 0.14rem 0.45rem; }

.back-link {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.76rem; font-weight: 600; color: var(--color-text-muted);
  margin-bottom: 0.6rem; min-height: 30px;
}
.back-link:hover { color: var(--color-text); }
.back-link svg { width: 14px; height: 14px; }

/* Label/value pairs on a detail card: side by side when there is room,
   stacked once the value would be squeezed. */
.kv {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.45rem 0; border-bottom: 1px solid var(--color-divider);
  font-size: 0.82rem; flex-wrap: wrap;
}
.kv:last-child { border-bottom: none; }
.kv-label { flex: 0 0 140px; color: var(--color-text-muted); font-weight: 600; font-size: 0.76rem; }
.kv-value { flex: 1 1 180px; min-width: 0; word-break: break-word; }

.toggle-cell { display: inline-flex; align-items: center; gap: 0.5rem; }
.toggle-label {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--color-text-muted);
}

/* Switch: a real checkbox, visually a track and thumb. */
.switch { display: inline-flex; align-items: center; cursor: pointer; flex-shrink: 0; position: relative; }
/* The input covers the whole control rather than being a 0x0 box tucked behind
   it, so the thing that receives the tap is the checkbox itself. */
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch-track {
  position: relative; display: block; width: 38px; height: 22px;
  border-radius: var(--radius-full); background: var(--color-surface-offset);
  border: 1px solid var(--color-border); transition: background var(--transition), border-color var(--transition);
}
.switch-thumb {
  position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: var(--radius-full); background: var(--color-surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform var(--transition);
}
.switch input:checked + .switch-track { background: var(--color-primary); border-color: var(--color-primary); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--color-blue); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: 0.5; cursor: not-allowed; }

/* Checkbox with a wrapping explanation, for modals. */
.check-line {
  display: flex; align-items: flex-start; gap: 0.55rem;
  font-size: 0.8rem; margin-bottom: 0.85rem; cursor: pointer;
}
.check-line input { width: 16px; height: 16px; flex-shrink: 0; margin-top: 0.1rem; accent-color: var(--color-primary); }
.check-line span { min-width: 0; }

/* Permission matrix. A table would need horizontal scrolling on a phone, so
   this is a grid that turns each right into a labelled box below the page name. */
.perm-list { border: 1px solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; }
.perm-head, .perm-row {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.45rem 0.8rem; border-bottom: 1px solid var(--color-divider);
}
.perm-row:last-child { border-bottom: none; }
.perm-head {
  background: var(--color-surface-2);
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--color-text-muted);
}
.perm-page { flex: 1; min-width: 0; font-size: 0.82rem; font-weight: 600; }
.perm-head .perm-page { font-size: 0.68rem; font-weight: 700; }
.perm-cols { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }
.perm-cols > span { width: 56px; text-align: center; }
.perm-box { display: flex; flex-direction: column; align-items: center; gap: 0.15rem; }
.perm-box input { width: 18px; height: 18px; accent-color: var(--color-primary); cursor: pointer; }
/* The column headings carry the labels on a wide screen, so the per-box tags
   only appear once the headings are gone. */
.perm-tag { display: none; font-size: 0.6rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted); }

@media (max-width: 640px) {
  .perm-head { display: none; }
  .perm-row { flex-wrap: wrap; row-gap: 0.5rem; padding: 0.6rem 0.7rem; }
  .perm-page { flex: 1 1 100%; }
  .perm-cols { width: 100%; justify-content: flex-start; gap: 1.1rem; }
  .perm-cols > span { width: auto; }
  .perm-tag { display: block; }
  .perm-box { min-width: 44px; min-height: 40px; justify-content: center; }
  .kv-label { flex: 1 1 100%; }
  .kv-value { flex: 1 1 100%; }
}

/* Row-level edit and remove. Small on a desktop row, but never below the
   44px touch target on a phone. */
.icon-btn-sm { width: 28px; height: 28px; border-radius: var(--radius-sm); }
.icon-btn-sm svg { width: 14px; height: 14px; }
.icon-btn.danger:hover { background: var(--color-error-highlight); color: var(--color-error); }
@media (max-width: 900px) {
  .icon-btn-sm { width: 36px; height: 36px; }
  .icon-btn-sm svg { width: 16px; height: 16px; }
}

/* A table cell holding a button plus its row tools. */
.cell-tools { white-space: nowrap; }
.cell-tools > * { vertical-align: middle; }
.cell-tools .icon-btn-sm { display: inline-flex; margin-left: 0.15rem; }

/* An empty state that also offers a way out of itself. */
.empty-action { display: flex; justify-content: center; margin-top: -1rem; padding-bottom: 1rem; }

/* Touch targets for checkboxes and switches.

   A checkbox that is visually 18px is fine; a tap target that is 18px is not.
   Each of these sits inside a label, so the label carries the hit area while
   the control keeps its size. */
.perm-box { cursor: pointer; min-width: 44px; min-height: 34px; justify-content: center; }
.check-line { min-height: 34px; align-items: center; }
.switch { min-width: 44px; min-height: 34px; justify-content: flex-end; }

@media (max-width: 900px) {
  .perm-box { min-height: 44px; }
  .perm-box input { width: 20px; height: 20px; }
  .check-line { min-height: 44px; padding: 0.2rem 0; }
  .check-line input { width: 20px; height: 20px; margin-top: 0; }
  .switch { min-height: 44px; }
}
