/* Green Spot — mobile-first UI. Phone is the primary entry device (SRS §3.3). */
:root {
  --bg: #f5f6f2;
  --surface: #ffffff;
  --surface-2: #f0f2ec;
  --line: #dfe3d8;
  --ink: #1d2419;
  --ink-2: #4c5646;
  --ink-3: #7a8373;
  --brand: #2e7d32;
  --brand-ink: #ffffff;
  --brand-soft: #e3f1e1;
  --bar: #3f8f45;
  --good: #1f7a3a;
  --good-bg: #e2f3e6;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --bad: #b3261e;
  --bad-bg: #fde7e5;
  --info-bg: #e7eef9;
  --info: #1f4f99;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 10, .06), 0 2px 8px rgba(20, 30, 10, .04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Malayalam", "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121510;
    --surface: #1a1e17;
    --surface-2: #22271e;
    --line: #333a2d;
    --ink: #e8ece3;
    --ink-2: #b7bfae;
    --ink-3: #8a9480;
    --brand: #5cb85f;
    --brand-ink: #0d1a0c;
    --brand-soft: #1f3320;
    --bar: #6cc06f;
    --good: #7fd08e;
    --good-bg: #173222;
    --warn: #f0c060;
    --warn-bg: #3a2e12;
    --bad: #ff8a80;
    --bad-bg: #3d1a17;
    --info-bg: #17263d;
    --info: #9cc0f5;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 var(--font); background: var(--bg); color: var(--ink); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
small, .muted { color: var(--ink-3); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { display: none; }
.main { flex: 1; min-width: 0; padding: 0 16px 96px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0 10px; }
.topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 14px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font-size: 11px; color: var(--ink-2); text-decoration: none; }
.bottom-nav a.on { color: var(--brand); font-weight: 600; }
.bottom-nav svg, .sidebar svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.menu-sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.35); display: none; }
.menu-sheet.open { display: block; }
.menu-sheet .panel { position: absolute; left: 0; right: 0; bottom: 0; background: var(--surface); border-radius: 16px 16px 0 0; padding: 12px 16px 24px; max-height: 80vh; overflow: auto; }
.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.menu-grid a { display: block; padding: 12px 8px; text-align: center; border-radius: 10px; background: var(--surface-2); color: var(--ink); font-size: 13px; }
.menu-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin: 14px 0 6px; }

@media (min-width: 960px) {
  .sidebar { display: block; width: 232px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--line); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
  .sidebar .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 4px 8px 16px; color: var(--ink); }
  .sidebar a.nav { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-size: 14px; }
  .sidebar a.nav:hover { background: var(--surface-2); text-decoration: none; }
  .sidebar a.nav.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
  .sidebar svg { width: 18px; height: 18px; }
  .sidebar .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin: 14px 10px 4px; }
  .bottom-nav, .topbar .brand { display: none; }
  .main { padding: 0 28px 40px; }
}

/* ---------- Cards, grids ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card.tight { padding: 0; overflow: hidden; }
.card.tight > h2 { padding: 14px 16px 0; }
.grid { display: grid; gap: 12px; }
.grid-2 { display: grid; gap: 12px; grid-template-columns: 1fr; }
.grid-3 { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .grid-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 14px; align-items: start; } }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 900px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.tile .label { font-size: 12px; color: var(--ink-3); }
.tile .value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--ink-3); background: var(--surface-2); position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
tfoot td { font-weight: 700; background: var(--surface-2); }
tr.inactive td { opacity: .5; }
.kv { width: 100%; }
.kv td { border: 0; padding: 4px 0; }
.kv td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.kv tr.total td { border-top: 1px solid var(--line); padding-top: 8px; font-weight: 700; }

/* list rows for mobile-first daily lists */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rows li:last-child { border-bottom: 0; }
.rows .title { font-weight: 600; }
.rows .meta { font-size: 12px; color: var(--ink-3); }
.rows .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--ink-3); }
.field .err, .err { font-size: 12px; color: var(--bad); }
input, select, textarea { min-width: 0; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
input[type=checkbox] { width: auto; min-height: auto; }
input.big, .big input { font-size: 1.15rem; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
input[readonly] { background: var(--surface-2); }
.is-invalid { border-color: var(--bad) !important; }
.inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline .field { margin-bottom: 0; flex: 1; min-width: 130px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: 14px; border-radius: 10px; min-height: 44px; padding: 0 16px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.sm { min-height: 34px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.xl { min-height: 54px; font-size: 16px; padding: 0 24px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; cursor: pointer; }
.linkbtn.danger { color: var(--bad); }

/* ---------- Status ---------- */
.alert { border-radius: 10px; padding: 10px 14px; margin: 0 0 12px; font-size: 14px; display: flex; gap: 8px; align-items: flex-start; }
.alert.ok { background: var(--good-bg); color: var(--good); }
.alert.error { background: var(--bad-bg); color: var(--bad); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.info { background: var(--info-bg); color: var(--info); }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); letter-spacing: .02em; }
.badge.ok { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 14px; overflow-x: auto; }
.tabs a, .tabs button { flex: 1; text-align: center; padding: 9px 12px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--ink-2); background: none; border: 0; cursor: pointer; white-space: nowrap; text-decoration: none; }
.tabs .on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.date-nav { display: flex; align-items: center; gap: 6px; }
.date-nav input { width: auto; min-width: 150px; }

/* ---------- Day closing ---------- */
.denoms { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 560px) { .denoms { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.denom { display: grid; grid-template-columns: 54px minmax(0, 1fr); align-items: center; gap: 6px; background: var(--surface-2); border-radius: 10px; padding: 6px 8px; }
.denom b { font-variant-numeric: tabular-nums; }
.denom input { text-align: center; font-size: 1.1rem; font-weight: 600; min-height: 42px; padding: 6px; }
.denom .sub { grid-column: 2; font-size: 11px; color: var(--ink-3); text-align: center; margin-top: -3px; }
.result { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.result:last-child { border-bottom: 0; }
.result .v { font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.result.hero .v { font-size: 1.5rem; color: var(--brand); }
.sticky-actions { position: sticky; bottom: 64px; z-index: 5; background: linear-gradient(transparent, var(--bg) 30%); padding: 16px 0 8px; display: flex; gap: 10px; }
@media (min-width: 960px) { .sticky-actions { bottom: 0; } }
.sticky-actions .btn { flex: 1; }

.dsr { font: 13.5px/1.55 var(--mono); white-space: pre-wrap; background: var(--surface-2); border-radius: 10px; padding: 14px; margin: 0; overflow-x: auto; }

/* ---------- Attendance ---------- */
.att-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { font: inherit; font-weight: 700; min-width: 52px; min-height: 44px; border: 0; background: var(--surface); color: var(--ink-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on[data-v=P] { background: var(--good-bg); color: var(--good); }
.seg button.on[data-v=H] { background: var(--warn-bg); color: var(--warn); }
.seg button.on[data-v=A] { background: var(--bad-bg); color: var(--bad); }

/* ---------- Purchase lines ---------- */
.line { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 10px; background: var(--surface-2); border-radius: 10px; margin-bottom: 8px; position: relative; }
.line .full { grid-column: 1 / -1; }
.line .field { margin: 0; }
.line .rm { position: absolute; top: 6px; right: 8px; }
.line .amount { font-weight: 700; text-align: right; align-self: end; padding-bottom: 10px; font-variant-numeric: tabular-nums; }
@media (min-width: 900px) {
  .line { grid-template-columns: 3fr 1fr .8fr 1fr 1fr 1fr; align-items: end; }
  .line .full { grid-column: auto; }
  .line .rm { position: static; }
}

/* ---------- Chart ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 180px; overflow: visible; }
.chart .bar { fill: var(--bar); }
.chart .bar.empty { fill: var(--line); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .grp:hover .bar { filter: brightness(.9); }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--ink-3); font-size: 10px; }
.chart .tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 12px; padding: 5px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); display: none; }

/* ---------- Misc ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.pill-links { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.pill-links a { padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); font-size: 13px; text-decoration: none; }
.pill-links a.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.report-list a { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.report-list .code { font: 600 12px var(--mono); color: var(--ink-3); width: 34px; }
details summary { cursor: pointer; font-weight: 600; }
.offline-bar { position: fixed; top: 0; left: 0; right: 0; background: var(--warn-bg); color: var(--warn); text-align: center; font-size: 13px; padding: 4px; z-index: 50; display: none; }
body.offline .offline-bar { display: block; }
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
nav[role=navigation] svg { width: 16px; height: 16px; }
@media print { .sidebar, .bottom-nav, .topbar, .no-print, .page-head .actions { display: none !important; } .main { padding: 0; } .card { box-shadow: none; } }

.result > span:first-child { min-width: 0; }
.card, .tile { min-width: 0; }
.alert { overflow-wrap: anywhere; }
