:root {
  --bg: #f4f7f4;
  --card: #ffffff;
  --text: #1d2b22;
  --muted: #5d6f63;
  --line: #dbe4dd;
  --grid: #e3ebe5;          /* light table grid lines */
  --row-alt: #f8fbf8;       /* every other table row */
  --brand: #1f7a4d;
  --brand-dark: #165c3a;
  --danger: #b3261e;
  --warn: #9a6700;
  --radius: 10px;
  font-family: "Noto Sans Devanagari", "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }

/* layout */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--brand); color: #fff;
}
.topbar .title { font-weight: 700; font-size: 1.1rem; }
.topbar .who { font-size: .9rem; opacity: .9; }
.topbar button { background: rgba(255,255,255,.15); color: #fff; border-color: rgba(255,255,255,.4); }
.container { max-width: 1100px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 420px; margin: 40px auto; padding: 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 180px; }
.muted { color: var(--muted); font-size: .9rem; }
.hidden { display: none !important; }
.center { text-align: center; }

/* forms */
label { display: block; font-size: .9rem; font-weight: 600; margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
button {
  font: inherit; padding: 10px 16px; border-radius: 8px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff; cursor: pointer; font-weight: 600;
}
button:hover { background: var(--brand-dark); }
button.secondary { background: #fff; color: var(--brand); }
button.danger { background: var(--danger); border-color: var(--danger); }
button.small { padding: 4px 10px; font-size: .85rem; }
button:disabled { opacity: .6; cursor: wait; }
.full { width: 100%; margin-top: 16px; }
.links { display: flex; justify-content: space-between; margin-top: 14px; font-size: .9rem; }
.hint { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.hint.bad { color: var(--danger); }
.hint.good { color: var(--brand); }

/* table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 10px; border: 1px solid var(--grid); white-space: nowrap; vertical-align: top; }
th { background: #eef4ef; font-weight: 600; border-color: #dce7df; }
tbody tr:nth-child(even) > td { background: var(--row-alt); }
tbody tr:hover > td { background: #f0f6f1; }
.table-wrap > table { border: 1px solid var(--grid); }
/* long text columns (notes, descriptions) may wrap so the table fits the card */
th.wrap, td.wrap { white-space: normal; min-width: 90px; }
td .actions { flex-wrap: nowrap; }
td .actions { display: flex; gap: 6px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; background: #e6efe8; }
.badge.disabled { background: #f6dedc; color: var(--danger); }
.badge.locked { background: #fbefd5; color: var(--warn); }

/* dialog + toast */
dialog { border: none; border-radius: var(--radius); padding: 20px; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 1000;
  max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); }
.secret { font-family: ui-monospace, monospace; font-size: 1.4rem; letter-spacing: .15em; background: #eef4ef; padding: 8px 12px; border-radius: 8px; display: inline-block; }

/* ── Phase 2 additions ── */
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.topbar-link { color: #fff; font-size: .9rem; }
.lang-switch { width: auto; padding: 4px 8px; font-size: .9rem; border-radius: 6px; }
.topbar .lang-switch { background: rgba(255,255,255,.15); color: #fff; border-color: rgba(255,255,255,.4); }
.topbar .lang-switch option { color: var(--text); }

.tabs { display: flex; gap: 2px; overflow-x: auto; background: #fff; border-bottom: 1px solid var(--line); padding: 0 8px; }
.tabs a { padding: 12px 14px; white-space: nowrap; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 600; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

.row.between { justify-content: space-between; align-items: center; }
.row > .grow-0, .grow-0 { flex: 0 1 auto; min-width: 0; max-width: 100%; }
.center-y { align-items: center; }
.filters { margin-top: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: 0 14px; }
.form-grid .field:has(textarea) { grid-column: 1 / -1; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-top: 12px; }
label.check input { width: auto; }
.dlg-actions { margin-top: 16px; justify-content: flex-end; }
.dlg-actions > button { flex: 0 0 auto; }
dialog.wide { width: min(900px, calc(100vw - 32px)); }
dialog h4 { margin: 14px 0 6px; }

td.r, th.r, .r { text-align: right; }
.actions.wrap { flex-wrap: wrap; }
.bad { color: var(--danger); }
.good { color: var(--brand); }
a.button {
  display: inline-block; text-decoration: none; padding: 10px 16px; border-radius: 8px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff; font-weight: 600;
}
a.button.secondary { background: #fff; color: var(--brand); }
a.button.small { padding: 4px 10px; font-size: .85rem; }

/* item editor */
.item-row { display: grid; grid-template-columns: minmax(180px, 3fr) 90px minmax(110px, 1fr) minmax(120px, 1.2fr) 40px; gap: 8px; align-items: center; margin-bottom: 8px; }
.item-row:not(:has([data-price])) { grid-template-columns: minmax(180px, 3fr) 90px minmax(120px, 1.2fr) 40px; }
.item-row .line-total { font-size: .88rem; }
.totals-box { margin-top: 12px; padding: 10px 12px; background: #eef4ef; border-radius: 8px; text-align: right; }
@media (max-width: 640px) {
  /* phone: product on its own line; qty | price | ✕ below; line total under that */
  .item-row, .item-row:not(:has([data-price])) { grid-template-columns: 1fr 1fr 44px; }
  .item-row select { grid-column: 1 / -1; grid-row: 1; }
  .item-row [data-qty] { grid-column: 1; grid-row: 2; }
  .item-row:not(:has([data-price])) [data-qty] { grid-column: 1 / 3; }
  .item-row [data-price] { grid-column: 2; grid-row: 2; }
  .item-row [data-remove] { grid-column: 3; grid-row: 2; width: 44px; }
  .item-row .line-total { grid-column: 1 / -1; grid-row: 3; }
  .topbar { flex-wrap: wrap; }
}

/* summary tiles */
.stats { display: flex; gap: 12px; flex-wrap: wrap; }
.stat { flex: 1 1 160px; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.stat-value { font-size: 1.5rem; font-weight: 700; }

/* ── Phase 3 additions ── */
button.big { font-size: 1.3rem; padding: 18px 36px; border-radius: 12px; }
.subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.subtabs button.active { background: var(--brand); color: #fff; }
.checks { display: flex; gap: 4px 16px; flex-wrap: wrap; }
.checks label.check { margin-top: 4px; }
.warn-box { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: #fbefd5; color: var(--warn); }
.progress { display: inline-block; width: 90px; height: 8px; background: #e6efe8; border-radius: 4px; overflow: hidden; vertical-align: middle; margin-right: 6px; }
.progress > div { height: 100%; background: var(--brand); }
input.qty-input { width: 100px; text-align: right; padding: 6px 8px; }
.stat-label { color: var(--muted); font-size: .85rem; }

/* ── Phase 4 additions ── */
:root { --series-1: #2a78d6; --grid: #e6e9e6; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 0 16px; }
a.stat.link { text-decoration: none; color: inherit; }
a.stat.link:hover { border-color: var(--brand); }
.chart-host { position: relative; }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart .grid { stroke: var(--grid); stroke-width: 1; }
svg.chart .axis { fill: var(--muted); font-size: 11px; }
svg.chart .axis.strong { fill: var(--text); font-size: 12px; }
svg.chart .value-label { fill: var(--text); font-size: 11px; font-weight: 600; }
svg.chart .hit { fill: transparent; }
svg.chart g[data-i]:hover path { opacity: .85; }
.chart-tip { position: absolute; pointer-events: none; background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; box-shadow: 0 4px 14px rgba(0,0,0,.12); font-size: .85rem; white-space: nowrap; z-index: 5; }
.chart-tip-value { font-weight: 700; }
.chart-table { margin-top: 8px; font-size: .9rem; }
.chart-table summary { cursor: pointer; color: var(--muted); }
.pre { white-space: pre-wrap; max-width: 420px; }

/* public farmer page */
.hero h2 { color: var(--brand); }
.steps { margin: 8px 0 0; padding-left: 20px; color: var(--muted); }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr)); gap: 12px; margin-top: 12px; }
.product-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.product-card.selected, .dist-card.selected { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(31,122,77,.15); }
.product-name { font-weight: 700; }
.product-price { font-weight: 600; }
.qty-row { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.qty-row input { width: 70px; text-align: center; padding: 6px; }
.dist-list { display: grid; gap: 10px; margin-top: 12px; }
.dist-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.success-box { margin-top: 12px; padding: 12px; border-radius: 8px; background: #e6f4ea; }
.narrow-card { max-width: 440px; margin: 24px auto; }
.bar-list { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 40%) 1fr auto; gap: 8px; align-items: center; padding: 2px 0; }
.bar-label { font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }
.bar-track { display: block; height: 14px; }
.bar-fill { display: block; height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-value { font-size: .85rem; font-weight: 600; min-width: 48px; }
.bar-row:hover .bar-fill { opacity: .85; }
.product-card .badge { align-self: flex-start; }

/* ── Consistent spacing + CSV / auto-translate ── */
.container > div > .card:last-child { margin-bottom: 0; }
.card > h2, .card > h3, .card .row.between > h2, .card .row.between > h3 { margin: 0; }
.card .row.between { align-items: center; row-gap: 10px; }
.card .row.between + * { margin-top: 12px; }
.filters { margin-top: 12px; }
.filters > div { min-width: 0; }
.card > .table-wrap, [data-list] > .table-wrap, .filters + [data-list] { margin-top: 12px; }
.card[data-list] > .table-wrap:first-child { margin-top: 0; }
.btn-group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.btn-group > .btn-group { display: contents; }
.btn-group > button, .btn-group > a.button { flex: 0 0 auto; max-width: 100%; }
.links { gap: 12px; }
dialog h3 { margin-bottom: 12px; }
dialog p { margin: 8px 0; }
input.auto-filled { background: #f1f8f3; border-color: #a9cdb6; }
.import-result { margin-top: 12px; }
.import-errors { max-height: 220px; overflow: auto; margin: 6px 0 0; padding-left: 20px; font-size: .88rem; }
.import-errors li { margin-bottom: 4px; }
@media (max-width: 640px) {
  .container { padding: 12px; }
  .card { padding: 16px; }
  .card .row.between > h2 { flex: 1 1 100%; }
  .btn-group { justify-content: flex-start; }
  .card .row.between > .btn-group, .card .row.between > .row { flex: 1 1 100%; }
  .topbar-right { gap: 8px; }
}

/* ── Vertical side menu (☰ hides / shows it) + profile menu ── */
.topbar { position: sticky; top: 0; z-index: 20; }
.topbar .title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-toggle { flex: 0 0 auto; padding: 4px 10px; font-size: 1.2rem; line-height: 1; }
.nav-toggle[aria-expanded="false"] { background: rgba(255,255,255,.3); }

.shell { display: flex; align-items: flex-start; }
.shell > main { flex: 1 1 auto; min-width: 0; }
.sidebar {
  position: sticky; top: var(--topbar-h, 52px); height: calc(100vh - var(--topbar-h, 52px));
  flex: 0 0 230px; width: 230px; overflow-y: auto; scrollbar-width: thin;
  display: flex; flex-direction: column; gap: 2px; padding: 10px 8px;
  background: #fff; border-right: 1px solid var(--line);
}
.sidebar a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 600; white-space: nowrap;
}
.sidebar a:hover { background: #f4f7f4; color: var(--brand); }
.sidebar a.active { background: #e6f4ea; color: var(--brand); box-shadow: inset 3px 0 0 var(--brand); }
.nav-icon { font-size: 1.1rem; width: 1.4em; text-align: center; flex: 0 0 auto; }
.nav-backdrop { display: none; }
body.nav-hidden .sidebar { display: none; }

/* Phones / small tablets: the menu slides in over the page and closes after a choice. */
@media (max-width: 800px) {
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-h, 52px); bottom: 0; height: auto; z-index: 25; width: 260px;
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: 4px 0 18px rgba(0,0,0,.15);
  }
  body.nav-hidden .sidebar { display: flex; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: var(--topbar-h, 52px) 0 0 0; background: rgba(0,0,0,.3); z-index: 24; }
}

.profile { position: relative; }
.profile > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
  padding: 4px 8px 4px 4px; border-radius: 999px; background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.4);
}
.profile > summary::-webkit-details-marker { display: none; }
.profile > summary:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #fff; color: var(--brand); display: grid; place-items: center; font-weight: 700; }
.profile-name { font-size: .9rem; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-menu {
  position: absolute; right: 0; top: calc(100% + 8px); width: 250px; background: #fff; color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: 8px; z-index: 30;
}
.profile-head { padding: 6px 8px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.profile-lang { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0; padding: 6px 8px; font-weight: 500; }
.profile-menu .lang-switch { background: #fff; color: var(--text); border-color: var(--line); }
.profile-item {
  display: block; width: 100%; text-align: left; padding: 8px; border-radius: 6px; border: none;
  background: none; color: var(--text); font-weight: 500; text-decoration: none; font-size: .95rem;
}
.profile-item:hover { background: #eef4ef; }
.topbar .profile-item { background: none; color: var(--text); border: none; }
.topbar .profile-item:hover { background: #eef4ef; }
.profile-build { border-top: 1px solid var(--line); margin-top: 6px; padding: 8px 8px 2px; font-size: .78rem; color: var(--muted); }
@media (max-width: 640px) {
  .topbar { flex-wrap: nowrap; padding: 8px 10px; }
  .profile-name, .profile .caret { display: none; }
  .profile > summary { padding: 3px; }
}

/* ── Daily attendance (tick + submit) ── */
.att-day { list-style: none; margin: 12px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; }
.att-day li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.att-day li:last-child { border-bottom: none; }
.att-day li.is-present { background: #f1f8f3; }
.att-day label.check { flex: 1 1 auto; margin: 0; font-weight: 600; cursor: pointer; }
.att-day label.check input { width: 22px; height: 22px; accent-color: var(--brand); }
.att-day .att-meta { font-size: .85rem; color: var(--muted); text-align: right; }
.att-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.att-head label.check { margin: 0; }
.att-actions { position: sticky; bottom: 0; background: var(--card); padding: 12px 0 0; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* ── Location picker (Google Maps link / address → lat, lng) ── */
.geo-box { grid-column: 1 / -1; margin-top: 10px; padding: 10px 12px; border: 1px dashed #a9cdb6; border-radius: 8px; background: #f7fbf8; }
.geo-box label { margin-top: 0; }
.geo-row { display: flex; gap: 8px; flex-wrap: wrap; }
.geo-row input { flex: 1 1 220px; }
.geo-row button { flex: 0 0 auto; }
.perm-table td, .perm-table th { text-align: center; }
.perm-table td:first-child, .perm-table th:first-child { text-align: left; }
.perm-table input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--brand); }
/* ❓ "How to use this page" help (js/help.js) */
.help-fab {
  position: fixed; right: 16px; bottom: 16px; z-index: 50;
  border-radius: 999px; padding: 10px 16px; box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.container { padding-bottom: 72px; }
.help-langs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.help-langs > button { flex: 0 0 auto; }
.help-body h4 { color: var(--brand); }
.help-steps { padding-left: 1.4em; margin: 6px 0; }
.help-steps li { margin: 6px 0; }
.help-tips { background: #fbf6e6; border: 1px solid #efe1b5; border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; }
.help-tips ul { margin: 6px 0 0; padding-left: 1.2em; }
@media print { .help-fab { display: none; } }

/* Phones: tables with more than 3 columns become one card per row, so nothing hides off the right edge */
@media (max-width: 640px) {
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border: 1px solid var(--grid); border-radius: 10px; padding: 6px 12px; margin-bottom: 10px; background: var(--card); }
  .table-wrap > table.stack { border: none; }
  table.stack tbody tr > td, table.stack tbody tr:hover > td { background: transparent; }
  /* label on the left (40 %), the cell's own content — however many lines — on the right */
  table.stack td {
    position: relative; min-height: 1.6em; border: none; padding: 5px 0 5px 42%;
    text-align: right; white-space: normal; overflow-wrap: anywhere;
  }
  table.stack td + td { border-top: 1px dashed var(--grid); }
  table.stack td::before {
    content: attr(data-label); position: absolute; left: 0; top: 5px; width: 40%;
    text-align: left; color: var(--muted); font-size: .85rem; white-space: normal;
  }
  table.stack td[data-label=""] { padding-left: 0; }
  table.stack td[data-label=""]::before { display: none; }
  table.stack td:empty, table.stack td:has(> :empty:only-child) { display: none; }
  table.stack td.empty-row { padding-left: 0; text-align: center; }
  table.stack td.empty-row::before { display: none; }
  table.stack td .actions { flex-wrap: wrap; justify-content: flex-end; }
  table.stack td input, table.stack td select { max-width: 100%; }
}
.shop-title { color: var(--brand); margin: 0; }

/* item editor: instant stock check under each product row */
.item-row .stock-msg { grid-column: 1 / -1; font-size: .85rem; margin-top: -2px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.item-row .stock-msg:empty { display: none; }
.item-row .stock-msg.bad { color: var(--danger); font-weight: 600; }
.item-row .stock-msg.good { color: var(--brand); }
.item-row .stock-msg button { font-weight: 500; }
.item-row input.over { border-color: var(--danger); background: #fdf1f0; }

/* columns that give way on small laptops / tablets (phones show them in the card layout) */
@media (min-width: 641px) and (max-width: 1100px) { th.hide-md, td.hide-md { display: none; } }
