:root {
  --bg: #faf7f3;
  --surface: #ffffff;
  --text: #2b2118;
  --muted: #7a6b5d;
  --line: #eadfd3;
  --brand: #8a5a2b;
  --brand-strong: #6f4620;
  --brand-soft: #f6e9da;
  --gradient: linear-gradient(90deg, #fcc897, #c6955f);
  --ok: #2f7a4a;      --ok-soft: #e3f3e8;
  --warn: #9a5b00;    --warn-soft: #fff1d6;
  --danger: #b3261e;  --danger-soft: #fde7e5;
  --info: #285e9c;    --info-soft: #e5effa;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(43 33 24 / 6%), 0 4px 16px rgb(43 33 24 / 5%);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
}
a { color: var(--brand); }
h1 { font-size: 1.5rem; margin: 0; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h2 { font-size: 1.05rem; margin: 0; }
p { margin: 0; }
small { font-size: .82rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.grow { flex: 1; }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .5rem 1rem; background: var(--surface);
  border-bottom: 3px solid; border-image: var(--gradient) 1;
}
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--text); }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand small { color: var(--muted); }
.nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.nav a { padding: .45rem .75rem; border-radius: 8px; text-decoration: none; color: var(--text); white-space: nowrap; }
.nav a.active, .nav a:hover { background: var(--brand-soft); color: var(--brand-strong); }
.account { display: flex; gap: .75rem; }
.page { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.page > * + * { margin-top: 1rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.narrow { max-width: 640px; }
.stack > * + * { margin-top: .75rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; }
.grid-2 { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.detail-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }

/* Forms */
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; font-size: .92rem; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%;
  padding: .6rem .7rem; border: 1px solid #d8c9b9; border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input[type="file"] { padding: .45rem; }
input[type="date"], input[type="datetime-local"] {
  -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%; min-height: 2.75rem; text-align: left;
}
input::-webkit-date-and-time-value { text-align: left; margin: 0; }
.hint { font-size: .9rem; color: var(--muted); }
.hint.ok { color: var(--ok); }
.hint.warn { color: var(--warn); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1rem; border-radius: 10px;
  border: 1px solid #d8c9b9; background: #fff; color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; list-style: none;
}
.btn::-webkit-details-marker { display: none; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); }
.btn.danger { color: var(--danger); border-color: #efc2be; }
.btn.danger:not(summary)[type="submit"] { background: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; min-width: 44px; }
.btn.big { min-height: 56px; font-size: 1.1rem; width: 100%; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

.alert { background: var(--danger-soft); color: var(--danger); padding: .7rem 1rem; border-radius: 10px; }
.notice { background: var(--ok-soft); color: var(--ok); padding: .7rem 1rem; border-radius: 10px; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }

/* Chips & status */
.chip { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--brand-soft); color: var(--brand-strong); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.muted-chip { background: #eee; color: #666; }
.status-new { background: var(--info-soft); color: var(--info); }
.status-received { background: #efe7fb; color: #5b3a99; }
.status-packed { background: var(--brand-soft); color: var(--brand-strong); }
.status-dispatched { background: #e2f4f6; color: #1d6973; }
.status-delivered { background: var(--ok-soft); color: var(--ok); }
.status-on_hold { background: var(--warn-soft); color: var(--warn); }
.status-cancelled, .status-returned { background: #eee; color: #555; }
.due { font-weight: 600; font-size: .9rem; }
.due.soon { color: var(--warn); }
.due.overdue { color: var(--danger); }
.count { font-size: .9rem; background: var(--brand-soft); color: var(--brand-strong); border-radius: 999px; padding: .05rem .6rem; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: .65rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fdfbf8; }
tbody tr:last-child td { border-bottom: 0; }
tr[data-href] { cursor: pointer; }
tr[data-href]:hover { background: #fdf8f2; }
tr.flag td { background: var(--danger-soft); }

/* Filters */
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.filters select { width: auto; }
.filters input[type="search"] { flex: 1; min-width: 200px; }
.tabs { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tab { flex-direction: row; padding: .4rem .8rem; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: .9rem; }
.tab { position: relative; }
.tab input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.tab.active { background: var(--brand); color: #fff; }

/* Order form & detail */
.item-row { display: grid; grid-template-columns: 1fr 90px 44px; gap: .5rem; }
.item-row + .item-row { margin-top: .5rem; }
.actions-bar { position: sticky; bottom: 0; padding: .75rem 0; background: linear-gradient(transparent, var(--bg) 30%); }
.items-list { list-style: none; padding: 0; margin: 0; }
.items-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px dashed var(--line); }
.items-list li:last-child { border-bottom: 0; }
.items-list.compact li { padding: .2rem 0; font-size: .95rem; }
.note { background: #fdfbf8; border-left: 3px solid var(--brand); padding: .5rem .75rem; }
.deadline-box { display: flex; flex-direction: column; align-items: flex-end; }
.status-actions { display: flex; flex-direction: column; gap: .5rem; }
.status-actions form:first-child .btn.big { width: 100%; }
.status-actions .with-reason details[open] summary { display: none; }
.reason { display: flex; gap: .5rem; }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 .9rem 1rem; display: flex; flex-direction: column; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline time { font-size: .8rem; color: var(--muted); }

/* Staff task cards */
.task-list { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.task header { display: flex; justify-content: space-between; align-items: start; gap: .5rem; }
.task-title { color: var(--text); text-decoration: none; font-size: 1.05rem; }
.task > * + * { margin-top: .6rem; }
.task.is-overdue { border-color: #efc2be; box-shadow: inset 4px 0 0 var(--danger), var(--shadow); }
.done summary { cursor: pointer; color: var(--muted); }

/* People */
.people { display: grid; gap: .75rem; }
.person header { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; align-items: center; }
.person.inactive { opacity: .6; }
.person-actions { margin-top: .75rem; }
.person-actions input, .person-actions select { width: auto; flex: 1; }

/* Auth */
.auth { max-width: 380px; margin: 6vh auto 0; }
.auth > * + * { margin-top: 1rem; }
.auth-logo { display: block; margin: 0 auto; height: 140px; width: auto; }

@media (max-width: 640px) {
  .page { padding: 1rem 1rem 4rem; }
  .topbar { gap: .5rem; }
  .brand small { display: none; }
  .nav { order: 3; flex-basis: 100%; }
  .account { margin-left: auto; }
  .detail-grid, .task-list { grid-template-columns: 1fr; }
  .deadline-box { align-items: flex-start; }
  .orders th:nth-child(3), .orders td:nth-child(3) { display: none; }
}

/* Invoices */
.warning { background: var(--warn-soft); color: var(--warn); padding: .6rem 1rem; border-radius: 10px; }
.grid-3 { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }
.item-row { grid-template-columns: minmax(120px, 1fr) minmax(120px, 1.4fr) 80px 44px; }
.money { margin: 0; border-top: 1px solid var(--line); padding-top: .5rem; }
.money div { display: flex; justify-content: space-between; padding: .15rem 0; }
.money dt { color: var(--muted); }
.money dd { margin: 0; font-weight: 600; }
.money .due-amount dd, .collect { color: var(--danger); font-weight: 700; }
.upload-box input[type="file"] { padding: 1rem; border-style: dashed; background: #fdfbf8; }
@media (max-width: 640px) {
  .item-row { grid-template-columns: 1fr 70px 44px; }
  .item-row input[name="description"] { grid-column: 1 / 3; grid-row: 2; }
}

/* After delivery, alerts, points */
.status-issue { background: var(--danger-soft); color: var(--danger); }
.status-closed { background: #e8eee9; color: #3d5a45; }
.due.ontime { color: var(--ok); }
.badge { display: inline-block; min-width: 1.3rem; padding: 0 .35rem; border-radius: 999px; background: var(--danger); color: #fff; font-size: .75rem; font-weight: 700; text-align: center; line-height: 1.3rem; }
.points-badge { font-weight: 700; color: var(--ok); background: var(--ok-soft); padding: .3rem .8rem; border-radius: 999px; }
.points-badge.negative, .negative { color: var(--danger); }
.positive { color: var(--ok); }
.deadline-edit { margin-top: .4rem; text-align: right; }
.deadline-edit form { margin-top: .5rem; min-width: 260px; }
.alert-list { display: grid; gap: .6rem; }
.alert-item { display: flex; justify-content: space-between; gap: 1rem; align-items: start; border-left: 4px solid var(--line); }
.alert-item.is-read { opacity: .65; }
.alert-main > * + * { margin-top: .25rem; }
.alert-main a { color: var(--text); text-decoration: none; }
.kind-overdue, .kind-issue { border-left-color: var(--danger); }
.kind-overdue .alert-kind, .kind-issue .alert-kind { background: var(--danger-soft); color: var(--danger); }
.kind-due_soon, .kind-late_delivery { border-left-color: #e0a100; }
.kind-due_soon .alert-kind, .kind-late_delivery .alert-kind { background: var(--warn-soft); color: var(--warn); }
.tabs a.tab { text-decoration: none; color: inherit; }
tr.selected td { background: var(--brand-soft); }
.status-actions summary.big { min-height: 56px; width: 100%; font-size: 1.05rem; }
.late-points { color: var(--danger); font-weight: 600; font-size: .92rem; }

/* Attendance */
.row.between { justify-content: space-between; align-items: center; }
.attendance-list { display: grid; gap: .5rem; }
.attendance-row { display: grid; grid-template-columns: minmax(160px, 1fr) auto minmax(160px, 1fr); gap: .75rem; align-items: center; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 10px; }
.attendance-row.unmarked { border-style: dashed; background: #fdfbf8; }
.who { display: flex; flex-direction: column; }
.warn-text { color: var(--warn); }
.choices { display: flex; gap: .35rem; flex-wrap: wrap; }
.choice { flex-direction: row; cursor: pointer; }
.choice { position: relative; }
.choice input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.choice span { display: inline-block; padding: .45rem .8rem; border: 1px solid #d8c9b9; border-radius: 999px; font-weight: 600; font-size: .9rem; background: #fff; }
.choice input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 1px; }
.choice-present input:checked + span { background: var(--ok); border-color: var(--ok); color: #fff; }
.choice-half_day input:checked + span { background: #e0a100; border-color: #e0a100; color: #fff; }
.choice-absent input:checked + span { background: var(--danger); border-color: var(--danger); color: #fff; }
.choice-leave input:checked + span { background: var(--info); border-color: var(--info); color: #fff; }
.attendance-row .note { width: 100%; }
@media (max-width: 760px) {
  .attendance-row { grid-template-columns: 1fr; }
}

/* Navigation: full menu bar on laptops; ☰ menu at the top left on phones and small tablets */
.menu { display: contents; }
.menu-toggle, .back-button { display: none; }

@media (max-width: 900px) {
  html, body { overflow-x: clip; }
  .topbar { flex-wrap: nowrap; gap: .6rem; padding: .5rem .75rem; }
  .brand small { display: none; }
  .desktop-only { display: none; }
  .back-button {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
  }
  .menu-toggle {
    display: inline-flex; align-items: center; justify-content: center; position: relative;
    width: 44px; height: 44px; flex: none; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer;
  }
  .menu-toggle .bars, .menu-toggle .bars::before, .menu-toggle .bars::after {
    display: block; width: 20px; height: 2px; border-radius: 2px; background: var(--text); content: "";
  }
  .menu-toggle .bars { position: relative; }
  .menu-toggle .bars::before { position: absolute; top: -6px; }
  .menu-toggle .bars::after { position: absolute; top: 6px; }
  .menu-open .menu-toggle .bars { background: transparent; }
  .menu-open .menu-toggle .bars::before { transform: translateY(6px) rotate(45deg); }
  .menu-open .menu-toggle .bars::after { transform: translateY(-6px) rotate(-45deg); }
  .menu-dot { position: absolute; top: 7px; right: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); border: 2px solid #fff; }

  .menu {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; background: var(--surface); border-bottom: 1px solid var(--line);
    box-shadow: 0 12px 24px rgb(43 33 24 / 12%); padding: .5rem .75rem .75rem; max-height: calc(100dvh - 64px); overflow-y: auto;
  }
  .menu-open .menu { display: flex; }
  .menu .nav { flex-direction: column; gap: 2px; overflow: visible; order: 0; flex-basis: auto; }
  .menu .nav a { padding: .8rem .75rem; font-size: 1.05rem; display: flex; justify-content: space-between; align-items: center; }
  .menu .account { margin: .5rem 0 0; padding-top: .75rem; border-top: 1px solid var(--line); justify-content: space-between; }
  .menu .account .link { padding: .5rem .75rem; font-size: 1rem; }

  /* Nothing may be wider than the screen */
  .page { padding: 1rem .9rem 4rem; }
  .page-head { align-items: flex-start; }
  .page-head .row { flex-wrap: wrap; }
  .filters { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
  .filters .tabs { grid-column: 1 / -1; overflow-x: auto; scrollbar-width: none; }
  .filters .tabs::-webkit-scrollbar { display: none; }
  .filters .tab { white-space: nowrap; }
  .filters select { grid-column: 1 / -1; width: 100%; }
  .filters input[type="search"] { min-width: 0; }
  .deadline-box form { min-width: 0; }
  .reason input { min-width: 0; }
  .person-actions .row > *, .person-actions input, .person-actions select { min-width: 0; }
  .grid-2 { grid-template-columns: 1fr; }

  /* Order list as cards: number + status, customer, then staff + deadline */
  .table-wrap:has(> table.orders) { border: 0; background: none; overflow: visible; }
  table.orders, table.orders tbody { display: block; }
  table.orders thead { display: none; }
  table.orders tr {
    display: grid; grid-template-columns: 1fr auto; gap: .3rem .75rem; align-items: center;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; margin-bottom: .6rem;
  }
  table.orders td { display: block; padding: 0; border: 0; }
  table.orders td:nth-child(1) { white-space: nowrap; }
  table.orders td:nth-child(1) br, table.orders td:nth-child(1) small { display: none; }
  table.orders td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  table.orders td:nth-child(3) { display: none; }
  table.orders td:nth-child(4) { grid-column: 2; grid-row: 1; justify-self: end; }
  table.orders td:nth-child(5) { grid-row: 3; font-size: .92rem; }
  table.orders td:nth-child(6) { grid-row: 3; justify-self: end; text-align: right; }

  /* Invoice review queue as cards: number + total, customer, then flags + Review button */
  .table-wrap:has(> table.imports) { border: 0; background: none; overflow: visible; }
  table.imports, table.imports tbody { display: block; }
  table.imports thead { display: none; }
  table.imports tr {
    display: grid; grid-template-columns: 1fr auto; gap: .35rem .75rem; align-items: start;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; margin-bottom: .6rem;
  }
  table.imports td { display: block; padding: 0; border: 0; }
  table.imports td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  table.imports td:nth-child(3) { display: none; }
  table.imports td:nth-child(4) { grid-column: 2; grid-row: 1; font-weight: 700; }
  table.imports td:nth-child(5) { grid-column: 1 / -1; grid-row: 3; display: flex; gap: .5rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
  table.imports td:nth-child(5) .btn { margin-left: auto; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}
.kind-delivered { border-left-color: var(--ok); }
.kind-delivered .alert-kind { background: var(--ok-soft); color: var(--ok); }
