/* =========================================================================
   CRIA — DESIGN SYSTEM
   Subject: field-operations ERP for a working farm. Two audiences share
   one system: a Supervisor thumbing a cracked-screen phone in a plot, and
   a Director reading cost/yield numbers at a desk. The throughline is the
   thing the whole spec keeps returning to — replacing paper registers
   with something just as fast to mark, but accountable. Every status in
   this app (present, issued, returned, overdue) reads as an ink stamp on
   a ledger page, not a colored pill.

   Palette is the client's own semantic system (spec S13) — we did not
   invent a new one, we gave it a home: warm ledger-paper canvas, navy
   chrome, and the five status inks.
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  /* ---- Color: 6 named tokens ---- */
  --cria-canvas: #F1EEE6;        /* ledger paper */
  --cria-canvas-raised: #FFFFFF;
  --cria-ink-navy: #0C1B33;      /* chrome, headers, primary text */
  --cria-navy-soft: #16294A;
  --cria-emerald: #16A34A;       /* active / healthy / complete */
  --cria-red: #EF4444;           /* risk / alert / overdue */
  --cria-blue: #3B82F6;          /* irrigation / water */
  --cria-copper: #B87333;        /* finance / yield / cost */

  /* ---- Derived surfaces ---- */
  --cria-line: #DDD6C7;          /* hairline ledger rule on canvas */
  --cria-line-dark: rgba(255,255,255,0.10);
  --cria-text: #1B2333;
  --cria-text-muted: #6B7385;
  --cria-text-on-navy: #EDEFF5;
  --cria-text-on-navy-muted: #9AA6C2;

  --cria-emerald-tint: #E4F5EA;
  --cria-red-tint: #FCE9E8;
  --cria-blue-tint: #E7F0FE;
  --cria-copper-tint: #F3E8DC;

  /* ---- Type ---- */
  --font-display: 'Sora', -apple-system, sans-serif;
  --font-body: 'Inter', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;

  /* ---- Radius / shadow / spacing tokens ---- */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-pill: 999px;

  --shadow-card: 0 1px 2px rgba(12,27,51,0.06), 0 8px 24px -12px rgba(12,27,51,0.18);
  --shadow-raised: 0 4px 10px rgba(12,27,51,0.10), 0 16px 40px -16px rgba(12,27,51,0.28);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
}

/* Dark mode — swap the surface tokens, keep status inks identical so a
   stamp means the same thing in either theme. */
[data-theme="dark"] {
  --cria-canvas: #0C1B33;
  --cria-canvas-raised: #16294A;
  --cria-line: rgba(255,255,255,0.10);
  --cria-text: #EDEFF5;
  --cria-text-muted: #9AA6C2;
  --cria-emerald-tint: rgba(22,163,74,0.16);
  --cria-red-tint: rgba(239,68,68,0.16);
  --cria-blue-tint: rgba(59,130,246,0.16);
  --cria-copper-tint: rgba(184,115,51,0.18);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--cria-canvas);
  color: var(--cria-text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}
body { font-size: 15px; line-height: 1.5; }

h1, h2, h3, h4, .cria-display {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--cria-ink-navy);
  margin: 0 0 var(--space-2);
}
[data-theme="dark"] h1, [data-theme="dark"] h2, [data-theme="dark"] h3 { color: var(--cria-text-on-navy); }
h1 { font-size: 34px; line-height: 1.1; }
h2 { font-size: 24px; line-height: 1.2; }
h3 { font-size: 18px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }

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

/* Tabular numerals everywhere numbers appear — spec S15 UI principle */
.num, .cria-table td.num, td.num, .stat-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* Visible keyboard focus, always */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--cria-blue);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* =========================================================================
   SIGNATURE ELEMENT — the ledger stamp
   Every status in the app (attendance, tool issue/return, alerts) renders
   through this one component. It is meant to feel like the mark a
   supervisor used to make in a paper register — round, inked, slightly
   imperfect — so the digital version reads as continuous with the
   practice it replaces, not a generic colored chip.
   ========================================================================= */
.stamp {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 14px 5px 12px;
  border-radius: var(--r-pill);
  border: 1.5px solid currentColor;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  transform: rotate(-1.4deg);
  white-space: nowrap;
}
.stamp::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.stamp-emerald { color: var(--cria-emerald); background: var(--cria-emerald-tint); }
.stamp-red     { color: var(--cria-red); background: var(--cria-red-tint); }
.stamp-blue    { color: var(--cria-blue); background: var(--cria-blue-tint); }
.stamp-copper  { color: var(--cria-copper); background: var(--cria-copper-tint); }
.stamp-navy    { color: var(--cria-ink-navy); background: rgba(12,27,51,0.06); }
[data-theme="dark"] .stamp-navy { color: var(--cria-text-on-navy); background: rgba(255,255,255,0.08); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14.5px;
  padding: 11px 20px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--cria-ink-navy); color: #fff; }
.btn-primary:hover { background: var(--cria-navy-soft); }
.btn-emerald { background: var(--cria-emerald); color: #fff; }
.btn-emerald:hover { filter: brightness(1.06); }
.btn-outline { background: transparent; border-color: var(--cria-line); color: var(--cria-text); }
.btn-outline:hover { border-color: var(--cria-ink-navy); }
.btn-ghost { background: transparent; color: var(--cria-text-muted); }
.btn-ghost:hover { color: var(--cria-text); }
.btn-danger { background: var(--cria-red); color: #fff; }
.btn-block { width: 100%; }
.btn-lg { padding: 16px 24px; font-size: 16px; border-radius: var(--r-lg); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-loading { pointer-events: none; opacity: 0.75; cursor: wait; }
.btn-spinner {
  display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: cria-spin 0.65s linear infinite;
}
@keyframes cria-spin { to { transform: rotate(360deg); } }

#cria-nav-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0%;
  background: linear-gradient(90deg, var(--cria-emerald), var(--cria-blue));
  z-index: 9999; opacity: 0; pointer-events: none;
}
#cria-nav-progress.active {
  width: 70%; opacity: 1;
  transition: width 4s cubic-bezier(0.1, 0.6, 0.3, 1), opacity 0.2s ease;
}

/* ---- Cards ---- */
.card {
  background: var(--cria-canvas-raised);
  border: 1px solid var(--cria-line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
a.card:hover, .card.roster-row:hover, .card.checkout-row:hover, .card.card-pad:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-raised);
  border-color: var(--cria-emerald);
}
.card-pad { padding: var(--space-5); }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--cria-line);
}

/* ---- Dashboard quick stats ---- */
.dash-stats {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3);
  margin-bottom: var(--space-5);
}
@media (min-width: 640px) { .dash-stats { grid-template-columns: repeat(4, 1fr); } }
.dash-stat {
  background: var(--cria-canvas-raised); border: 1px solid var(--cria-line);
  border-radius: var(--r-lg); padding: var(--space-4);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.dash-stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-raised); border-color: var(--cria-ink-navy); }
.dash-stat-value {
  font-family: var(--font-display); font-weight: 800; font-size: 30px; line-height: 1;
  color: var(--cria-ink-navy); font-variant-numeric: tabular-nums;
}
.dash-stat-label { color: var(--cria-text-muted); font-size: 12.5px; margin-top: 6px; font-weight: 500; }
.dash-stat-alert .dash-stat-value { color: var(--cria-red); }
.dash-stat-alert:hover { border-color: var(--cria-red); }
.dash-stat-icon {
  width: 34px; height: 34px; border-radius: var(--r-md); display: flex; align-items: center; justify-content: center;
  background: var(--cria-copper-tint); color: var(--cria-copper); margin-bottom: 10px;
}
.dash-stat-alert .dash-stat-icon { background: rgba(200,60,60,0.1); color: var(--cria-red); }
.roadmap-card { opacity: 0.72; cursor: default; }
.roadmap-card:hover { transform: none; box-shadow: var(--shadow-card); border-color: var(--cria-line); }

/* ---- Crop stage stepper ---- */
.stage-stepper { display: flex; align-items: flex-start; }
.stage-step { display: flex; flex-direction: column; align-items: center; flex: 1; position: relative; }
.stage-node {
  width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 15px;
  border: 2.5px solid var(--cria-line); background: var(--cria-canvas-raised); color: var(--cria-text-muted);
  transition: all 0.25s ease; z-index: 1;
}
.stage-step.complete .stage-node { background: var(--cria-emerald); border-color: var(--cria-emerald); color: #fff; }
.stage-step.current .stage-node {
  background: var(--cria-ink-navy); border-color: var(--cria-ink-navy); color: #fff;
  box-shadow: 0 0 0 5px var(--cria-copper-tint); transform: scale(1.08);
}
.stage-connector {
  position: absolute; top: 19px; left: calc(-50% + 20px); right: calc(50% + 20px);
  height: 2.5px; background: var(--cria-line); z-index: 0;
}
.stage-step.complete .stage-connector { background: var(--cria-emerald); }
.stage-label { margin-top: 10px; font-size: 12.5px; font-weight: 600; text-align: center; color: var(--cria-text-muted); }
.stage-step.current .stage-label, .stage-step.complete .stage-label { color: var(--cria-text); }
@media (max-width: 480px) {
  .stage-node { width: 32px; height: 32px; font-size: 13px; }
  .stage-connector { top: 15px; }
  .stage-label { font-size: 11px; }
}

/* ---- Hours-by-worker chart ---- */
.hours-chart-row { display: grid; grid-template-columns: 120px 1fr 50px; align-items: center; gap: 12px; margin-bottom: 10px; }
.hours-chart-name { font-size: 13px; color: var(--cria-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hours-chart-track { background: var(--cria-canvas); border-radius: 999px; height: 14px; overflow: hidden; }
.hours-chart-bar { background: linear-gradient(90deg, var(--cria-copper), #d99a4e); height: 100%; border-radius: 999px; transition: width 0.4s ease; }

/* ---- Analytics trend charts (Manager/Director/Super Admin dashboard) ---- */
.trend-chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding: var(--space-4) var(--space-2) 0; }
.trend-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.trend-bar-value { font-size: 10.5px; font-weight: 700; color: var(--cria-text); margin-bottom: 5px; white-space: nowrap; }
.trend-bar-track { width: 100%; max-width: 34px; flex: 1; display: flex; align-items: flex-end; }
.trend-bar {
  width: 100%; border-radius: 7px 7px 3px 3px; min-height: 4px;
  background: linear-gradient(180deg, var(--cria-emerald) 0%, #0e8a3e 100%);
  box-shadow: 0 2px 6px rgba(22,163,74,0.25);
  transition: height 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.trend-bar.alert { background: linear-gradient(180deg, var(--cria-red) 0%, #a82a2a 100%); box-shadow: 0 2px 6px rgba(200,60,60,0.25); }
.trend-bar-label { font-size: 10px; color: var(--cria-text-muted); margin-top: 8px; text-align: center; white-space: nowrap; }
@media (max-width: 640px) {
  .trend-chart { gap: 3px; height: 120px; }
  .trend-bar-value { font-size: 9px; }
  .trend-bar-label { font-size: 8.5px; }
}
.hours-chart-value { font-size: 12.5px; color: var(--cria-text-muted); text-align: right; }

/* ---- Forms ---- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--cria-text-muted);
  text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
input, select, textarea {
  width: 100%; font-family: var(--font-body); font-size: 15px;
  padding: 12px 14px; border-radius: var(--r-md);
  border: 1.5px solid var(--cria-line);
  background: var(--cria-canvas-raised); color: var(--cria-text);
}
input:focus, select:focus, textarea:focus { border-color: var(--cria-ink-navy); }
.field { margin-bottom: var(--space-4); }
.field-row { display: flex; gap: var(--space-3); }
.field-row > .field { flex: 1; }
.hint { font-size: 12.5px; color: var(--cria-text-muted); margin-top: 4px; }
.field-error { font-size: 12.5px; color: var(--cria-red); margin-top: 4px; display: none; }

/* ---- Ledger table (hairline-row, not boxed) — used on desktop/dashboard views ---- */
.cria-table { width: 100%; border-collapse: collapse; }
.cria-table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--cria-text-muted); font-weight: 600; padding: 10px 14px;
  border-bottom: 1.5px solid var(--cria-line);
}
.cria-table td { padding: 13px 14px; border-bottom: 1px solid var(--cria-line); font-size: 14.5px; }
.cria-table tr:hover td { background: rgba(12,27,51,0.02); }
[data-theme="dark"] .cria-table tr:hover td { background: rgba(255,255,255,0.03); }

/* ---- Empty state ---- */
.empty-state { text-align: center; padding: var(--space-7) var(--space-4); color: var(--cria-text-muted); }
.empty-state .stamp { margin-bottom: var(--space-3); }

/* ---- Toast ---- */
#cria-toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: var(--cria-ink-navy); color: #fff; padding: 12px 20px; border-radius: var(--r-md);
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow-raised);
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 999; max-width: 90vw;
}
#cria-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#cria-toast.error { background: var(--cria-red); }
