:root {
  /* Colors from the הנהגת השחר logo: deep red-brown, burnt orange and the pale sun, on beige. */
  --brown: #5e1f12;
  --brown-soft: #f1e2d6;
  --orange: #d9772f;
  --orange-dark: #9c4a14;   /* orange for text on beige */
  --orange-soft: #fbe9d6;
  --sun: #f6e3a1;
  --ok: #1d7a46;
  --ok-soft: #e4f5ea;
  --warn: #8a5a00;
  --warn-soft: #fff5d6;
  --bad: #b3261e;
  --bad-soft: #fde8e7;
  --ink: #2f1d14;
  --muted: #6d5a4b;
  --line: #e8dccb;
  --field: #d8c7b2;      /* input and button borders */
  --bg: #f7f0e6;         /* beige */
  --card: #fffcf7;
  --tint: #faf4ea;       /* table headers, hovered rows */
  --radius: 14px;
  --shadow: 0 4px 18px rgba(94, 31, 18, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Heebo', system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brown); }
h1, h2, h3 { margin: 0 0 0.5em; line-height: 1.25; }
h1 { font-size: 1.5rem; font-weight: 800; }
h2 { font-size: 1.15rem; font-weight: 700; }
p { line-height: 1.55; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.num { direction: ltr; unicode-bidi: isolate; white-space: nowrap; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--brown); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.1rem; }
.brand-logo { width: 34px; height: 34px; border-radius: 50%; display: block; box-shadow: 0 0 0 2px var(--sun); }
.login-logo { display: block; width: 112px; height: 112px; margin: 0 auto 12px; border-radius: 50%; }
.nav { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav a {
  color: #f1dccb; text-decoration: none; padding: 6px 12px; border-radius: 999px; white-space: nowrap; font-weight: 500;
}
.nav a.active { background: rgba(255, 255, 255, 0.16); color: #fff; }
.who { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; color: #f1dccb; }
.who button { background: none; border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: 999px; padding: 4px 12px; cursor: pointer; font: inherit; }
@media (max-width: 640px) {
  .top { gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  .who { margin-inline-start: auto; }
}

.main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- building blocks ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px;
}
.narrow { max-width: 440px; margin: 40px auto; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }

label { display: block; font-weight: 500; font-size: 0.9rem; margin-bottom: 12px; }
label > input, label > select { margin-top: 4px; }
.pw-row { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.pw-row input { flex: 1; min-width: 0; }
.pw-row .btn { flex: none; }
input, select {
  width: 100%; font: inherit; padding: 9px 11px; border: 1px solid var(--field); border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--orange); outline-offset: 1px; border-color: transparent; }
input.ltr { direction: ltr; text-align: right; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters label { margin: 0; flex: 1 1 150px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 700; padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
  background: var(--brown); color: #fff; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: default; filter: none; }
.btn.dawn { background: var(--orange); color: #2a1206; }
.btn.ghost { background: #fff; color: var(--brown); border-color: var(--field); }
.btn.danger { background: #fff; color: var(--bad); border-color: #e9b4b0; }
.btn.small { padding: 5px 10px; font-size: 0.85rem; font-weight: 500; }
.btn.big { width: 100%; padding: 16px; font-size: 1.1rem; }
.linkbtn { background: none; border: 0; color: var(--brown); text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }

.notice { border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; line-height: 1.5; }
.notice.ok { background: var(--ok-soft); color: #11512d; }
.notice.warn { background: var(--warn-soft); color: #5e3d00; }
.notice.bad { background: var(--bad-soft); color: #7d1a14; }
.notice.info { background: var(--brown-soft); color: var(--brown); }
.notice h2 { margin-bottom: 4px; }
.notice ul { margin: 6px 0 0; padding-inline-start: 20px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; white-space: nowrap; }
.badge.matched { background: var(--brown-soft); color: var(--brown); }
.badge.paid { background: #e8eef7; color: #2f5683; }
.badge.settled { background: var(--ok-soft); color: var(--ok); }
.badge.close { background: var(--warn-soft); color: var(--warn); }
tr.close-row td { background: #fffbea; }
.badge.manual { background: #ffe2c4; color: #8a3d00; }
tr.manual-row td { background: #fff0e0; }
.badge.orphaned { background: var(--warn-soft); color: var(--warn); }
.badge.unmatched { background: var(--bad-soft); color: var(--bad); }
.picker-search { margin-bottom: 4px; }
.pick-box { max-height: 55vh; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.option > span { flex: 1; min-width: 0; }
.badge.receipt { background: var(--orange-soft); color: var(--orange-dark); }
.badge.off { background: #efe7dc; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: right; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-weight: 700; color: var(--muted); font-size: 0.8rem; background: var(--tint); position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover, th.sortable:focus-visible { color: var(--brown); }
th.sortable::after { content: '↕'; opacity: 0.35; margin-inline-start: 4px; font-size: 0.75em; }
th[data-sort-dir="asc"]::after { content: '▲'; opacity: 1; color: var(--orange-dark); }
th[data-sort-dir="desc"]::after { content: '▼'; opacity: 1; color: var(--orange-dark); }
tr:hover td { background: var(--tint); }
td.actions { white-space: nowrap; }
.sum-row td { font-weight: 700; background: var(--tint); }

.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { flex: 1 1 140px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat b { display: block; font-size: 1.35rem; }
.stat span { color: var(--muted); font-size: 0.85rem; }

/* ---------- upload flow ---------- */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center;
  border: 2px dashed #cdb8a0; border-radius: var(--radius); padding: 36px 16px; background: var(--card); cursor: pointer;
}
.drop.over { border-color: var(--orange); background: var(--orange-soft); }
.pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.drop.camera-only { border-style: solid; border-color: var(--orange); background: var(--orange-soft); }
/* A computer (mouse, no rear camera) gets only the file picker. */
@media (hover: hover) and (pointer: fine) { .camera-only { display: none; } }
.drop .ico { font-size: 2.6rem; }
.review { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 760px) { .review { grid-template-columns: 1fr; } }
.preview { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; max-height: 70vh; overflow-y: auto; }
.preview img { display: block; width: 100%; }
.ai-hint { font-size: 0.8rem; color: var(--muted); margin-top: -8px; margin-bottom: 12px; }
.spinner {
  width: 38px; height: 38px; border-radius: 50%; border: 4px solid var(--brown-soft); border-top-color: var(--orange);
  animation: spin 0.9s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.options { display: grid; gap: 10px; margin: 12px 0; }
.option {
  display: flex; gap: 12px; align-items: center; text-align: right; width: 100%;
  border: 1px solid var(--field); border-radius: 12px; padding: 12px 14px; background: #fff; cursor: pointer; font: inherit;
}
.option:hover { border-color: var(--orange); background: var(--orange-soft); }

.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .main-col { flex: 1; min-width: 0; }
.list-item .title { font-weight: 700; }
/* On phones the text takes the whole first line; the state and buttons wrap below it. */
@media (max-width: 640px) {
  .list-item { flex-wrap: wrap; gap: 8px; }
  .list-item .main-col { flex-basis: 100%; }
}

/* ---------- dialog & toast ---------- */
.dialog { border: 0; border-radius: var(--radius); padding: 22px; max-width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(47, 29, 20, 0.45); }
.dialog h2 { margin-bottom: 8px; }
.dialog .row { margin-top: 16px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 40px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; transition: 0.25s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Test site only (see showTestBanner). */
.test-banner {
  position: relative; z-index: 11;
  padding: 6px 16px; text-align: center; font-weight: 800; color: #1d1d1d;
  background: repeating-linear-gradient(-45deg, #ffd23f 0 18px, #ffe27a 18px 36px);
  border-bottom: 2px solid #1d1d1d;
}
