/* ---------------------------------------------------------------------------
   Forest Corporation — design tokens
   Deep forest green for chrome, warm neutrals for surfaces. Sizing is tuned for
   gloved hands on mid-range Android phones: 48px minimum touch targets,
   16px base font so mobile browsers never zoom on focus.
--------------------------------------------------------------------------- */
:root {
  --green-900: #0f3d1a;
  --green-800: #17512a;
  --green-700: #1d6435;
  --green-600: #2a7d45;
  --green-100: #e6f2e9;
  --green-050: #f2f8f4;

  --amber-600: #b45309;
  --amber-100: #fef3e2;
  --red-600: #b91c1c;
  --red-100: #fdecec;
  --blue-600: #1d4ed8;
  --blue-100: #e8eeff;

  --ink-900: #14181a;
  --ink-700: #364046;
  --ink-500: #64717a;
  --ink-300: #9aa6ad;

  --surface: #ffffff;
  --surface-alt: #f6f8f7;
  --bg: #eef1ef;
  --border: #dde3df;
  --border-strong: #c4cec8;

  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 32, 22, 0.06), 0 1px 3px rgba(16, 32, 22, 0.04);
  --shadow-md: 0 4px 12px rgba(16, 32, 22, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 32, 22, 0.14);
}

* { box-sizing: border-box; }

/* .btn and .tabbar set an explicit display, which otherwise beats the browser's
   default [hidden] rule and leaves "hidden" elements on screen. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, 'Noto Sans Devanagari', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink-900);
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------- App bar ------------------------------- */
.topbar {
  background: linear-gradient(180deg, var(--green-800), var(--green-900));
  color: #fff;
  padding: 0 20px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; flex: none;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 10px;
  display: grid; place-items: center;
}
.brand-text { min-width: 0; }
.brand-name { font-weight: 700; font-size: 1.02rem; letter-spacing: 0.2px; line-height: 1.2; white-space: nowrap; }
.brand-sub { font-size: 0.74rem; color: rgba(255,255,255,0.72); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.28);
  background: rgba(255,255,255,0.10);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.lang-toggle:hover { background: rgba(255,255,255,0.2); }
.lang-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--green-600);
  border: 1px solid rgba(255,255,255,0.3);
  display: grid; place-items: center;
  font-weight: 700; font-size: 0.85rem; color: #fff;
  flex: none;
}
.user-meta { line-height: 1.25; text-align: right; }
.user-name { font-size: 0.86rem; font-weight: 600; }
.user-role { font-size: 0.72rem; color: rgba(255,255,255,0.75); }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.24);
  background: rgba(255,255,255,0.08);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,0.18); }

/* -------------------------------- Nav --------------------------------- */
.nav {
  display: flex;
  gap: 4px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  position: sticky;
  top: 64px;
  z-index: 40;
}
.nav::-webkit-scrollbar { display: none; }
.nav.hidden { display: none; }
.nav a {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px;
  text-decoration: none;
  color: var(--ink-700);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.nav a:hover { color: var(--green-700); background: var(--green-050); }
.nav a.active { color: var(--green-800); border-bottom-color: var(--green-600); }
.nav a svg { flex: none; }

/* ------------------------------- Layout -------------------------------- */
.app { max-width: 1320px; margin: 0 auto; padding: 24px 24px 72px; }

.page-head { margin-bottom: 18px; }
.page-title { font-size: 1.4rem; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.2px; }
.page-sub { color: var(--ink-500); font-size: 0.9rem; margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
  margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-title { font-size: 1.02rem; font-weight: 700; margin: 0; }

/* ------------------------------- Forms --------------------------------- */
.field { margin-bottom: 16px; }
.field-label { display: block; font-weight: 600; font-size: 0.88rem; color: var(--ink-700); margin-bottom: 6px; }
.field-hint { font-size: 0.78rem; color: var(--ink-500); margin-top: 5px; }

input, select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink-900);
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--ink-300); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green-600);
  box-shadow: 0 0 0 3px rgba(42, 125, 69, 0.15);
}
input::placeholder, textarea::placeholder { color: var(--ink-300); }
textarea { min-height: 84px; resize: vertical; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364717a' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  padding-right: 40px;
}

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0 16px; }

/* PIN field with visibility toggle */
.input-affix { position: relative; }
.input-affix input { padding-right: 52px; }
.affix-btn {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 38px; height: 38px;
  border: none; background: transparent;
  color: var(--ink-500);
  display: grid; place-items: center;
  border-radius: 9px; cursor: pointer;
}
.affix-btn:hover { color: var(--green-700); background: var(--green-050); }
.affix-btn:focus-visible { outline: 2px solid var(--green-600); outline-offset: 1px; }

/* ------------------------------- Buttons ------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 48px;
  padding: 0 22px;
  font-size: 0.98rem;
  font-family: inherit;
  font-weight: 650;
  color: #fff;
  background: var(--green-700);
  border: 1px solid var(--green-800);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover:not(:disabled) { background: var(--green-800); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--green-600); outline-offset: 2px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--surface); color: var(--ink-700); border-color: var(--border-strong); }
.btn.secondary:hover:not(:disabled) { background: var(--surface-alt); color: var(--green-800); }
.btn.ghost-danger {
  background: transparent; color: var(--red-600);
  border-color: transparent; min-height: 40px; padding: 0 10px;
}
.btn.ghost-danger:hover:not(:disabled) { background: var(--red-100); }
.btn.is-loading { cursor: progress; }

.spinner {
  width: 17px; height: 17px; flex: none;
  border: 2.5px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: fc-spin 0.65s linear infinite;
}
.btn.secondary .spinner { border-color: rgba(0,0,0,0.15); border-top-color: var(--green-700); }
@keyframes fc-spin { to { transform: rotate(360deg); } }

/* Top progress bar during any request */
.route-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: linear-gradient(90deg, var(--green-600), #7ed09a);
  z-index: 100;
  transition: width 0.25s ease, opacity 0.3s ease;
  opacity: 0;
}
.route-progress.active { opacity: 1; }

/* ------------------------------- Stepper ------------------------------- */
.stepper { display: flex; align-items: stretch; gap: 8px; }
.stepper button {
  width: 52px; min-height: 48px; flex: none;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--radius);
  font-size: 1.35rem; font-weight: 600; color: var(--green-800);
  cursor: pointer;
}
.stepper button:hover { background: var(--green-050); border-color: var(--green-600); }
.stepper input { text-align: center; font-size: 1.12rem; font-weight: 700; }

/* -------------------------------- Stats -------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 14px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--green-600);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat.amber { border-left-color: var(--amber-600); }
.stat.blue { border-left-color: var(--blue-600); }
.stat .num { font-size: 1.85rem; font-weight: 750; line-height: 1.15; letter-spacing: -0.5px; }
.stat .label { font-size: 0.79rem; color: var(--ink-500); font-weight: 600; margin-top: 2px; }

/* -------------------------------- Table -------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; background: var(--surface); }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th {
  background: var(--surface-alt);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-500);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--green-050); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty-row td { text-align: center; color: var(--ink-500); padding: 28px; }

/* Matrix entry grid */
.matrix-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.matrix { border-collapse: separate; border-spacing: 0; }
.matrix th, .matrix td { padding: 8px; white-space: nowrap; }
.matrix tbody th {
  position: sticky; left: 0; z-index: 2;
  background: var(--surface-alt);
  text-align: left; text-transform: none;
  font-size: 0.85rem; color: var(--ink-900);
  border-right: 1px solid var(--border);
}
.matrix input {
  width: 72px; min-height: 42px; padding: 8px;
  text-align: center; font-variant-numeric: tabular-nums;
}
.matrix input[data-filled="1"] { border-color: var(--green-600); background: var(--green-050); font-weight: 700; }
.matrix tfoot td { background: var(--green-050); font-weight: 700; }

/* ------------------------------- Badges -------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.74rem; font-weight: 700; letter-spacing: 0.2px;
}
.badge.ok { background: var(--green-100); color: var(--green-800); }
.badge.warn { background: var(--amber-100); color: var(--amber-600); }
.badge.bad { background: var(--red-100); color: var(--red-600); }
.badge.info { background: var(--blue-100); color: var(--blue-600); }

/* ------------------------------- Alerts -------------------------------- */
.msg {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 13px 15px;
  border-radius: var(--radius);
  font-size: 0.9rem; font-weight: 500;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.msg.error { background: var(--red-100); color: var(--red-600); border-color: #f3c9c9; }
.msg.success { background: var(--green-100); color: var(--green-800); border-color: #bfe0ca; }
.msg.info { background: var(--blue-100); color: var(--blue-600); border-color: #ccd8fb; }
.msg svg { flex: none; margin-top: 1px; }

/* ------------------------------- Login --------------------------------- */
.login-wrap {
  min-height: calc(100vh - 64px);
  display: grid; place-items: center;
  padding: 24px 16px 60px;
  background:
    radial-gradient(1100px 420px at 50% -8%, rgba(42,125,69,0.13), transparent 70%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
}
.login-logo {
  width: 58px; height: 58px; margin: 0 auto 14px;
  background: linear-gradient(180deg, var(--green-700), var(--green-900));
  border-radius: 15px;
  display: grid; place-items: center;
  box-shadow: var(--shadow-md);
}
.login-head { text-align: center; margin-bottom: 24px; }
.login-head h1 { font-size: 1.3rem; font-weight: 700; margin: 0 0 4px; }
.login-head p { color: var(--ink-500); font-size: 0.88rem; margin: 0; }

.demo-box {
  margin-top: 22px; padding: 13px 15px;
  background: var(--surface-alt);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  font-size: 0.79rem; color: var(--ink-500);
}
.demo-box strong { color: var(--ink-700); display: block; margin-bottom: 5px; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.5px; }
.demo-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; font-variant-numeric: tabular-nums; }
.demo-row code { color: var(--green-800); font-weight: 700; }

/* ------------------ Position Receipt: entry flow ----------------------- */
.req { color: var(--red-600); font-weight: 700; }
.btn-sm { min-height: 38px; padding: 0 14px; font-size: 0.85rem; }

.step-dot {
  display: inline-grid;
  place-items: center;
  width: 24px; height: 24px;
  margin-right: 9px;
  border-radius: 50%;
  background: var(--green-700);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  vertical-align: middle;
}

.section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 0 14px;
  border: none;
  background: none;
  font: inherit;
  color: var(--ink-900);
  cursor: pointer;
  text-align: left;
}
.section-toggle-label { font-size: 1.02rem; font-weight: 700; }
.section-toggle .chevron { color: var(--ink-500); transition: transform 0.18s ease; }
.section-toggle[aria-expanded="false"] .chevron { transform: rotate(-90deg); }

/* Entry list — the phone-first shape of the species x class matrix */
.entry-list { margin-bottom: 14px; }
.empty-hint {
  margin: 0 0 4px;
  padding: 22px 16px;
  text-align: center;
  color: var(--ink-500);
  font-size: 0.9rem;
  background: var(--surface-alt);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.entry-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--surface);
}
.entry-main { flex: 1; min-width: 0; }
.entry-species { font-weight: 650; font-size: 1rem; }
.entry-class { font-size: 0.82rem; color: var(--ink-500); margin-top: 1px; }
.entry-count { min-width: 56px; text-align: right; line-height: 1.1; }
.entry-count-num {
  display: block;
  font-size: 1.35rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  color: var(--green-800);
}
.entry-count-label { display: block; font-size: 0.7rem; font-weight: 600; color: var(--ink-500); }
.add-entry-btn { border-style: dashed; }

.entry-picker {
  margin-top: 14px;
  padding: 16px;
  background: var(--green-050);
  border: 1.5px solid var(--green-600);
  border-radius: var(--radius-lg);
}
.entry-picker[hidden] { display: none; }
.picker-step { margin-bottom: 16px; }
.picker-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ink-500);
  margin-bottom: 8px;
}

/* Big tap targets instead of a dropdown — faster with gloves, no keyboard */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 46px;
  padding: 0 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink-700);
  cursor: pointer;
}
.chip:hover { border-color: var(--green-600); color: var(--green-800); }
.chip.selected {
  background: var(--green-700);
  border-color: var(--green-800);
  color: #fff;
}

.stepper.big button { width: 64px; min-height: 56px; font-size: 1.6rem; }
.stepper.big input { min-height: 56px; font-size: 1.5rem; font-weight: 750; }

.picker-actions { display: flex; gap: 10px; }
.picker-actions .btn { flex: 1; }

/* Sticky totals + submit, always reachable with a thumb */
.submit-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  margin: 0 -16px -16px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(16, 32, 22, 0.07);
  z-index: 30;
}
.submit-total {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 0.95rem;
  color: var(--ink-700);
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
.submit-total strong { font-size: 1.3rem; font-weight: 750; color: var(--green-800); }
.submit-sub { display: block; font-size: 0.78rem; color: var(--ink-500); }
.submit-bar .btn { flex: none; }


/* ------------------------- Add-entry wizard ---------------------------- */
/* One question per screen. A field officer seeing this for the first time
   should be able to be taught it in one sentence: tap the species, tap the
   class, set the number, press Add. */
.wizard {
  margin-top: 14px;
  padding: 18px 16px 16px;
  background: var(--surface);
  border: 2px solid var(--green-600);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.wizard[hidden] { display: none; }

.wizard-progress {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 16px;
}
.wiz-dot {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  flex: none;
  border-radius: 50%;
  background: var(--surface-alt);
  border: 2px solid var(--border-strong);
  color: var(--ink-300);
  font-size: 0.85rem;
  font-weight: 700;
}
.wiz-dot.current { background: var(--green-700); border-color: var(--green-800); color: #fff; }
.wiz-dot.done { background: var(--green-100); border-color: var(--green-600); color: var(--green-800); }
.wiz-line { width: 34px; height: 2.5px; background: var(--border-strong); flex: none; }
.wiz-line.done { background: var(--green-600); }

.wizard-chosen { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.wizard-chosen:empty { display: none; }
.chosen-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: var(--green-050);
  border: 1.5px solid var(--green-600);
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.chosen-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-500); }
.chosen-value { flex: 1; font-size: 1rem; font-weight: 700; color: var(--green-800); }
.chosen-edit { font-size: 0.8rem; font-weight: 700; color: var(--green-700); text-decoration: underline; }

.wiz-question {
  margin: 0 0 14px;
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
  color: var(--ink-900);
}

/* Equal-width buttons that tile the row — no ragged wrapping, and every
   target is the same size regardless of how long the species name is. */
.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 62px;
  padding: 10px 8px;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  font: inherit;
  font-size: 1rem;
  font-weight: 650;
  color: var(--ink-900);
  cursor: pointer;
  text-align: center;
  line-height: 1.25;
}
.option:hover { border-color: var(--green-600); background: var(--green-050); }
.option:active { transform: scale(0.98); }
.option.selected { background: var(--green-700); border-color: var(--green-800); color: #fff; }
.option-sub { font-size: 0.72rem; font-weight: 600; color: var(--ink-500); }
.option.selected .option-sub { color: rgba(255,255,255,0.8); }

.wiz-calc {
  margin: 12px 0 0;
  text-align: center;
  font-size: 1rem;
  color: var(--ink-500);
  font-variant-numeric: tabular-nums;
}
.wiz-calc strong { color: var(--green-800); font-size: 1.15rem; }

.wiz-actions { display: flex; gap: 10px; margin-top: 18px; }
.wiz-actions .btn { flex: 1; }

@media (max-width: 420px) {
  .option-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .option { min-height: 58px; font-size: 0.95rem; }
  .wiz-question { font-size: 1.05rem; }
}

/* ------------------- Field / Depot simplified home --------------------- */
.section-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ink-500);
  margin: 26px 0 12px;
}

.field-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.fstat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.fstat.danger { border-color: #f0c4c4; background: var(--red-100); }
.fnum { display: block; font-size: 1.7rem; font-weight: 750; line-height: 1.1; letter-spacing: -0.5px; }
.fstat.danger .fnum { color: var(--red-600); }
.flabel { display: block; font-size: 0.74rem; font-weight: 600; color: var(--ink-500); margin-top: 3px; }

/* Big, unmistakable action tiles — the main field-officer interaction */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.tile {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 84px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: var(--ink-900);
  transition: border-color 0.15s ease, transform 0.08s ease, box-shadow 0.15s ease;
}
.tile:hover { border-color: var(--green-600); box-shadow: var(--shadow-md); }
.tile:active { transform: translateY(1px); }
.tile-icon {
  width: 52px; height: 52px; flex: none;
  display: grid; place-items: center;
  background: var(--green-100);
  color: var(--green-800);
  border-radius: 14px;
}
.tile-icon svg { width: 26px; height: 26px; }
.tile-label { flex: 1; font-size: 1.05rem; font-weight: 650; line-height: 1.3; }
.tile-go { font-size: 1.3rem; color: var(--ink-300); }

.simple-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.simple-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  min-height: 68px;
}
.simple-row:last-child { border-bottom: none; }
.simple-row.link { text-decoration: none; color: inherit; }
.simple-row.link:hover { background: var(--green-050); }
.simple-title { font-weight: 650; font-size: 1rem; }
.simple-sub { font-size: 0.82rem; color: var(--ink-500); margin-top: 2px; }
.simple-value { text-align: right; font-size: 1.3rem; font-weight: 750; line-height: 1.1; }
.simple-value span { display: block; font-size: 0.7rem; font-weight: 600; color: var(--ink-500); }

@media (max-width: 420px) {
  .fnum { font-size: 1.4rem; }
  .flabel { font-size: 0.68rem; }
  .tile { min-height: 76px; padding: 14px; }
  .tile-icon { width: 46px; height: 46px; }
  .tile-label { font-size: 0.98rem; }
}


/* ----------------------- Phone bottom tab bar -------------------------- */
/* Fixed, thumb-reachable, one button per permitted screen. Hidden on
   desktop, where the tab strip under the app bar is the better shape. */
.tabbar { display: none; }

@media (max-width: 760px) {
  /* The scrolling top tab strip is replaced entirely on phones. */
  .nav { display: none !important; }

  .tabbar {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 14px rgba(16, 32, 22, 0.10);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 9px 2px 8px;
    min-height: 60px;
    text-decoration: none;
    color: var(--ink-500);
    font-size: 0.68rem;
    font-weight: 650;
    border-top: 2.5px solid transparent;
  }
  .tabbar a span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .tabbar a svg { width: 21px; height: 21px; }
  .tabbar a.active { color: var(--green-800); border-top-color: var(--green-600); background: var(--green-050); }
  .tabbar a:active { background: var(--green-100); }

  /* Keep content and the sticky submit bar clear of the tab bar. */
  body.has-tabbar .app { padding-bottom: 88px; }
  body.has-tabbar .footer { padding-bottom: 80px; }
  body.has-tabbar .submit-bar { bottom: calc(60px + env(safe-area-inset-bottom)); }
}


/* App bar had no flex floor, so a long brand name pushed the language toggle
   and avatar off the right edge on a 375px screen. */
.brand { min-width: 0; flex: 1 1 auto; overflow: hidden; }
.brand-name { overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { flex: 0 0 auto; }

@media (max-width: 620px) {
  .lang-toggle { padding: 0 10px; }
  .lang-toggle span { display: none; }   /* icon alone is enough beside a globe */
  .brand-mark { width: 34px; height: 34px; }
  .brand-mark svg { width: 19px; height: 19px; }
  .brand-name { font-size: 0.95rem; }
}

@media (max-width: 380px) {
  .brand-name { font-size: 0.88rem; }
  .topbar { gap: 8px; }
}

/* Badges stay on one line in tables, but in list rows a long status
   ("Discrepancy Damaged") must be allowed to wrap on a 320px phone instead of
   pushing past the screen edge. */
.badge { white-space: nowrap; }
.simple-row > div:first-child { min-width: 0; flex: 1 1 auto; }
.simple-row .simple-title, .simple-row .simple-sub { overflow-wrap: anywhere; }
.simple-row .badge { flex: 0 1 auto; white-space: normal; text-align: center; max-width: 48%; }


/* ------------------------ Filters, search, staff ----------------------- */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0 14px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.search-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-box { position: relative; flex: 1 1 220px; min-width: 0; }
.search-box svg {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--ink-500); pointer-events: none;
}
.search-box input { padding-left: 42px; }
.search-row .btn { flex: none; }

.user-row.inactive { opacity: 0.6; background: var(--surface-alt); }
.user-row .btn-sm { flex: none; }

.check-row {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 0 0; font-weight: 600; font-size: 0.92rem; cursor: pointer;
}
.check-row input { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--green-700); }

@media (max-width: 620px) {
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar .field { min-width: 0; }
  .search-row .btn { flex: 1 1 auto; }
  .user-row { flex-wrap: wrap; }
}


/* ------------------------- Dashboard & reports ------------------------- */
.page-head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  padding: 18px 20px;
}
.kpi-icon { width: 44px; height: 44px; flex: none; border-radius: 12px; display: grid; place-items: center; }
.kpi-icon svg { width: 22px; height: 22px; }
.kpi-icon.green { background: var(--green-100); color: var(--green-800); }
.kpi-icon.amber { background: var(--amber-100); color: var(--amber-600); }
.kpi-icon.blue { background: var(--blue-100); color: var(--blue-600); }
.kpi-icon.purple { background: #f1e9fb; color: #6d28d9; }
.kpi-body { min-width: 0; flex: 1; }
.kpi-label { font-size: 0.8rem; font-weight: 650; color: var(--ink-500); }
.kpi-num { font-size: 1.75rem; font-weight: 760; letter-spacing: -0.5px; line-height: 1.2; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 0.78rem; color: var(--ink-500); margin-top: 4px; }
.kpi-bar { height: 6px; background: var(--surface-alt); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.kpi-bar span { display: block; height: 100%; background: var(--amber-600); border-radius: 99px; }

.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.dash-grid > .card { margin-bottom: 0; min-width: 0; }
.dash-wide { grid-column: 1 / -1; }

.card-link { font-size: 0.85rem; font-weight: 650; color: var(--green-700); text-decoration: none; white-space: nowrap; }
.card-link:hover { text-decoration: underline; }

.progress-col { width: 30%; min-width: 150px; }
.progress-cell { display: flex; align-items: center; gap: 10px; }
.bar { flex: 1; height: 8px; background: var(--surface-alt); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--green-600), #5cb97a); border-radius: 99px; }
.bar-pct { font-size: 0.8rem; font-weight: 700; color: var(--ink-700); min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.no-activity { font-size: 0.8rem; color: var(--ink-300); font-style: italic; }
.muted-row td { color: var(--ink-500); }
.muted-row strong { color: var(--ink-500); font-weight: 600; }
.total-row td { background: var(--green-050); font-weight: 750; border-top: 2px solid var(--border-strong); }
.cell-sub { font-size: 0.75rem; color: var(--ink-500); margin-top: 2px; font-weight: 500; }

.alert-list { display: flex; flex-direction: column; gap: 10px; }
.alert-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--border); }
.alert-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; }
.alert-item.bad { background: var(--red-100); border-color: #f3c9c9; }
.alert-item.bad .alert-dot { background: var(--red-600); }
.alert-item.warn { background: var(--amber-100); border-color: #f5d7ab; }
.alert-item.warn .alert-dot { background: var(--amber-600); }
.alert-item.ok { background: var(--green-050); border-color: #bfe0ca; }
.alert-item.ok .alert-dot { background: var(--green-600); }
.alert-title { font-weight: 700; font-size: 0.92rem; }
.alert-body { font-size: 0.82rem; color: var(--ink-700); margin-top: 2px; }

.hbar-list { display: flex; flex-direction: column; gap: 12px; }
.hbar-row { display: grid; grid-template-columns: minmax(90px, 140px) 1fr 48px; align-items: center; gap: 12px; }
.hbar-label { font-size: 0.88rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 12px; background: var(--surface-alt); border-radius: 99px; overflow: hidden; }
.hbar-track span { display: block; height: 100%; background: var(--green-600); border-radius: 99px; }
.hbar-val { font-size: 0.88rem; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 620px) {
  .app { padding: 16px 12px 60px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi-num { overflow-wrap: anywhere; }
  .kpi { padding: 14px; flex-direction: column; gap: 8px; }
  .kpi-icon { width: 36px; height: 36px; }
  .kpi-num { font-size: 1.35rem; }
  .progress-col { min-width: 120px; }
}


/* Mobile page padding is 12px, so the full-bleed submit bar must pull back by
   exactly that much or it overhangs the screen edge. */
@media (max-width: 620px) {
  .submit-bar { margin: 0 -12px -12px; }
}
.kpi-grid > .kpi, .search-row > *, .filter-bar > * { min-width: 0; }

/* ------------------------------- Footer -------------------------------- */
.footer { text-align: center; color: var(--ink-300); font-size: 0.76rem; padding: 26px 16px; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-alt) 25%, #eceeed 50%, var(--surface-alt) 75%);
  background-size: 200% 100%;
  animation: fc-shimmer 1.3s infinite;
  border-radius: 8px; height: 18px; margin-bottom: 10px;
}
@keyframes fc-shimmer { to { background-position: -200% 0; } }

@media (max-width: 620px) {
  .topbar { height: 58px; padding: 0 12px; }
  .nav { top: 58px; }
  .brand-sub, .user-meta { display: none; }
  .app { padding: 16px 12px 60px; }
  .card { padding: 16px; border-radius: var(--radius); }
  .page-title { font-size: 1.2rem; }
  .stat .num { font-size: 1.55rem; }
}

.sync-pill{position:fixed;top:10px;left:50%;transform:translateX(-50%);z-index:60;border:0;border-radius:999px;padding:6px 14px;font:600 13px/1.2 inherit;background:#b45309;color:#fff;box-shadow:0 2px 8px rgba(0,0,0,.2);cursor:pointer;max-width:calc(100vw - 32px)}
.sync-pill.is-failed{background:#b91c1c}
.sync-pill[hidden]{display:none}
.pending-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center;justify-content:space-between;padding:12px 0;border-top:1px solid var(--border)}
.pending-row:first-child{border-top:0}
.pending-main{flex:1 1 220px;min-width:0}
.pending-date{margin-left:8px;color:var(--ink-500,#64748b);font-size:13px}
.pending-reason{margin-top:4px;font-size:13px;color:var(--ink-500,#64748b);overflow-wrap:anywhere}
.pending-reason.is-failed{color:var(--red-600)}
.pending-actions{display:flex;gap:8px}

/* ===== Possession receipt (rc_) and volume charts (vc_) ===== */
.rc-chart-notice .msg { margin: 8px 0 0; }
.rc-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.rc-grid .rc-lbl { font-size: 0.78rem; color: var(--ink-500); text-align: right; padding-right: 6px; }
.rc-grid .rc-vol-row td { background: var(--surface-alt); color: var(--ink-700); font-variant-numeric: tabular-nums; }
.rc-grid .rc-vol-row .row-vol, .rc-grid tfoot .num { font-weight: 700; }

/* Receipt sheet: the same block is shown on screen and printed on A4. */
.rc-sheet { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.rc-title { text-align: center; font-size: 1.15rem; margin: 0 0 12px; }
.rc-head-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 18px; margin-bottom: 12px; font-size: 0.92rem; }
.rc-meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 18px; margin-bottom: 14px; }
.rc-meta { display: flex; gap: 8px; font-size: 0.85rem; border-bottom: 1px dotted var(--border-strong); padding: 3px 0; }
.rc-meta-k { color: var(--ink-500); flex: none; }
.rc-meta-v { margin-left: auto; text-align: right; font-weight: 600; overflow-wrap: anywhere; }
.rc-print-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.rc-print-table th, .rc-print-table td { border: 1px solid var(--border-strong); padding: 4px 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rc-print-table thead th, .rc-print-table tfoot th, .rc-print-table tfoot td { background: var(--surface-alt); font-weight: 700; }
.rc-print-table tbody th { text-align: left; }
.rc-print-table .num { text-align: right; }
.rc-sign { display: flex; justify-content: space-between; gap: 24px; margin-top: 56px; }
.rc-sign-box { flex: 1; text-align: center; font-size: 0.88rem; }
.rc-sign-line { border-top: 1px solid var(--ink-900); margin-bottom: 6px; }
.rc-sign-cap { font-weight: 700; }
.rc-sign-name { color: var(--ink-500); min-height: 1.2em; }

/* Volume charts admin */
.vc-banner { display: flex; gap: 10px; align-items: flex-start; background: var(--amber-100); color: var(--amber-600); border: 1px solid #f3d9a8; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; font-weight: 600; }
.vc-banner svg { flex: none; margin-top: 2px; }
.vc-scroll { overflow: auto; max-height: 65vh; border: 1px solid var(--border); border-radius: var(--radius); }
.vc-table { border-collapse: separate; border-spacing: 0; }
.vc-table th, .vc-table td { padding: 6px; white-space: nowrap; border-bottom: 1px solid var(--border); }
.vc-table thead th { position: sticky; top: 0; background: var(--surface-alt); z-index: 2; }
.vc-table tbody th { position: sticky; left: 0; background: var(--surface); text-align: left; z-index: 1; border-right: 1px solid var(--border); font-size: 0.85rem; }
.vc-table td { position: relative; }
.vc-in { width: 76px; min-height: 40px; padding: 6px; text-align: right; font-variant-numeric: tabular-nums; }
.vc-flagged .vc-in { border-color: var(--amber-600); background: var(--amber-100); }
.vc-mark { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; background: var(--amber-600); color: #fff; font-weight: 800; font-size: 0.8rem; line-height: 20px; cursor: pointer; }
.vc-note { margin-top: 12px; padding: 12px 14px; border: 1px solid #f3d9a8; background: var(--amber-100); border-radius: var(--radius); }
.vc-note p { margin: 6px 0 10px; overflow-wrap: anywhere; }
.vc-add-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-bottom: 14px; }
.vc-add-cell { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--ink-700); }
.vc-add-cell input { width: 100%; min-width: 0; }
.vc-unit-row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.vc-unit-row:first-child { border-top: 0; }
.vc-unit-name { flex: 1 1 140px; min-width: 0; }
.vc-unit-row select { flex: 1 1 180px; min-width: 0; }
@media (max-width: 620px) {
  .rc-sheet { padding: 12px; }
  .rc-print-wrap { overflow-x: auto; }
  .rc-sign { margin-top: 36px; gap: 12px; }
}
@media print {
  @page { size: A4 portrait; margin: 12mm; }
  .topbar, .nav, .tabbar, .footer, .no-print, .sync-pill, .route-progress { display: none !important; }
  body, body.has-tabbar { background: #fff; padding: 0 !important; }
  .app { padding: 0; max-width: none; }
  .rc-sheet { border: 0; padding: 0; margin: 0; }
  .rc-print-wrap { overflow: visible; border: 0; }
  .rc-print-table { font-size: 8.5pt; }
  .rc-print-table th, .rc-print-table td { padding: 2px 3px; }
  .rc-title { font-size: 14pt; }
}
