/* Crouchley Receipts - brand: St. Johns tower green #709372, silver #C0C0C0, Playfair Display */

:root {
  --brand: #709372;
  --silver: #c0c0c0;
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Playfair Display", Georgia, serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg: #111513;
  --surface: #191f1b;
  --surface-2: #212923;
  --border: #2e3831;
  --text: #e8ece9;
  --muted: #a3ada6;
  --accent: #86a888;          /* green for text/icons on dark */
  --btn: #709372;             /* primary button fill */
  --btn-text: #0d110f;
  --input: #141916;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.25);
  --st-submitted: #e0b25a; --st-submitted-bg: rgba(224,178,90,.14);
  --st-needs: #ef8a74;     --st-needs-bg: rgba(239,138,116,.14);
  --st-approved: #8fc092;  --st-approved-bg: rgba(143,192,146,.14);
  --st-entered: #b9c2bb;   --st-entered-bg: rgba(192,192,192,.12);
  --danger: #ef8a74;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --border: #dde2dc;
  --text: #1b221d;
  --muted: #5d6860;
  --accent: #4b6d4e;
  --btn: #557858;
  --btn-text: #ffffff;
  --input: #ffffff;
  --shadow: 0 1px 2px rgba(20,30,22,.06), 0 6px 18px rgba(20,30,22,.06);
  --st-submitted: #8a5d00; --st-submitted-bg: #fbf0d9;
  --st-needs: #a2361c;     --st-needs-bg: #fbe3dc;
  --st-approved: #2f6a33;  --st-approved-bg: #e1f0e1;
  --st-entered: #4c5550;   --st-entered-bg: #e9ecea;
  --danger: #b33a1f;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; }
a { color: var(--accent); }
img { max-width: 100%; display: block; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- header / nav ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); min-width: 0; }
.brand .tower { width: 18px; height: 46px; color: var(--brand); flex: none; }
.brand .name { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; color: var(--brand); white-space: nowrap; }
.brand .sub { font-family: var(--serif); font-style: italic; font-size: .8rem; color: var(--silver); display: block; margin-top: -2px; }
[data-theme="light"] .brand .sub { color: #8d948f; }
[data-theme="light"] .brand .name { color: var(--accent); }
.topnav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.topnav a, .icon-btn {
  color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: var(--radius-sm);
  font-weight: 500; font-size: .95rem; background: none; border: 0; cursor: pointer; font-family: inherit;
}
.topnav a:hover, .icon-btn:hover { background: var(--surface-2); color: var(--text); }
.topnav a.active { color: var(--text); background: var(--surface-2); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; padding: 8px; }
.icon-btn svg { width: 22px; height: 22px; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--st-submitted); color: #1a1405; font-size: .72rem; font-weight: 700; text-align: center; line-height: 20px; margin-left: 4px; }

.bottomnav { display: none; }
@media (max-width: 760px) {
  .topnav .nav-link { display: none; }
  .bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + var(--safe-b));
  }
  .bottomnav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 500; padding: 4px 0; position: relative;
  }
  .bottomnav a svg { width: 24px; height: 24px; }
  .bottomnav a.active { color: var(--accent); }
  .bottomnav a.new svg { width: 30px; height: 30px; color: var(--btn); }
  .bottomnav .badge { position: absolute; top: -2px; left: 54%; margin: 0; }
  main { padding-bottom: calc(90px + var(--safe-b)) !important; }
}

/* ---------- layout ---------- */
main { max-width: 980px; margin: 0 auto; padding: 20px 16px 40px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.hint.warn { color: var(--st-submitted); }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* 16px stops iOS zoom */
  color: var(--text); background: var(--input);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px 12px;
  appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.money { position: relative; }
.money span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money input { padding-left: 26px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer; text-decoration: none;
  padding: 11px 18px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); min-height: 44px;
}
.btn:hover { filter: brightness(1.08); }
.btn.primary { background: var(--btn); border-color: var(--btn); color: var(--btn-text); }
.btn.danger { color: var(--danger); background: transparent; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }

.error-box { background: var(--st-needs-bg); color: var(--st-needs); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 14px; font-size: .9rem; }

/* ---------- auth screens ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: 100%; max-width: 400px; }
.auth .logo { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 22px; }
.auth .logo .tower { width: 42px; height: 108px; color: var(--brand); margin-bottom: 12px; }
.auth .logo .since { font-family: var(--serif); font-style: italic; color: var(--silver); font-size: .95rem; }
[data-theme="light"] .auth .logo .since { color: #8d948f; }
.auth .logo .co { font-family: var(--serif); font-weight: 700; color: var(--brand); font-size: 1.55rem; line-height: 1.15; }
[data-theme="light"] .auth .logo .co { color: var(--accent); }
.auth .logo .app { margin-top: 6px; font-size: .8rem; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

/* ---------- tabs / filters ---------- */
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--radius-sm); margin-bottom: 14px; overflow-x: auto; }
.tabs button { flex: 1; white-space: nowrap; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; font-size: .88rem; padding: 8px 12px; border-radius: 6px; cursor: pointer; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.filters.more { grid-template-columns: 1fr 1fr 1fr 1fr; }
.searchrow { display: flex; gap: 8px; }
.searchrow input { flex: 1; }
.filt-toggle { display: none; }
.date-f { position: relative; margin: 0; }
.date-f span { position: absolute; left: 12px; top: 3px; font-size: .65rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.date-f input { padding-top: 16px; padding-bottom: 6px; }
@media (max-width: 760px) {
  .filters, .filters.more { grid-template-columns: 1fr 1fr; }
  .filters .wide { grid-column: 1 / -1; }
  .filt-toggle { display: inline-flex; min-height: 0; }
  .filters > :not(.wide) { display: none; }
  .filters.open > :not(.wide) { display: block; }
}
.totals { display: flex; gap: 16px; align-items: baseline; margin: 4px 2px 10px; font-size: .9rem; color: var(--muted); }
.totals strong { color: var(--text); font-size: 1.05rem; }

/* ---------- receipt list ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; text-decoration: none; color: inherit;
}
.item:hover { border-color: var(--brand); }
.thumb { width: 56px; height: 56px; border-radius: 8px; background: var(--surface-2) center/cover no-repeat; display: grid; place-items: center; color: var(--muted); overflow: hidden; }
.thumb svg { width: 24px; height: 24px; }
.item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.item .amt { font-weight: 700; font-variant-numeric: tabular-nums; }

.chip { display: inline-flex; align-items: center; gap: 5px; font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 20px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.submitted { color: var(--st-submitted); background: var(--st-submitted-bg); }
.chip.needs_info { color: var(--st-needs); background: var(--st-needs-bg); }
.chip.approved { color: var(--st-approved); background: var(--st-approved-bg); }
.chip.entered { color: var(--st-entered); background: var(--st-entered-bg); }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; margin-bottom: 8px; opacity: .6; }

/* ---------- photos ---------- */
.photo-drop {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 18px; text-align: center;
  background: var(--surface-2); cursor: pointer;
}
.photo-drop:hover { border-color: var(--brand); }
.photo-drop svg { width: 30px; height: 30px; color: var(--accent); }
.photo-drop .btns { display: flex; gap: 8px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 10px; }
.photos .ph { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; }
.photos .ph .pdf { display: grid; place-items: center; height: 100%; font-weight: 700; color: var(--muted); }
.photos .ph button { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 18px; line-height: 28px; cursor: pointer; }
.photos.large { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.photos.large .ph { cursor: zoom-in; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 100; display: grid; place-items: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 92vh; object-fit: contain; border-radius: 6px; }
.lightbox .close { position: absolute; top: calc(env(safe-area-inset-top,0px) + 12px); right: 12px; color: #fff; background: rgba(255,255,255,.15); border: 0; width: 44px; height: 44px; border-radius: 50%; font-size: 24px; cursor: pointer; }
.lightbox .open { position: absolute; bottom: calc(var(--safe-b) + 16px); color: #fff; }

/* ---------- detail ---------- */
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; margin: 0; }
.dl dt { color: var(--muted); font-size: .88rem; }
.dl dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
@media (max-width: 500px) { .dl { grid-template-columns: 110px 1fr; } }
.big-amt { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 20px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand); }
.timeline .who { font-weight: 600; font-size: .9rem; }
.timeline .when { font-size: .78rem; color: var(--muted); }
.timeline .what { font-size: .9rem; margin-top: 2px; }
.review-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 600px) { .review-actions { grid-template-columns: 1fr 1fr; } }
.review-actions .btn.on { outline: 2px solid var(--brand); outline-offset: 1px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.inactive td { opacity: .5; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 90; display: grid; place-items: end center; }
@media (min-width: 600px) { .modal-back { place-items: center; } }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px 16px 0 0; width: 100%; max-width: 480px; padding: 20px 18px calc(20px + var(--safe-b)); max-height: 92vh; overflow-y: auto; }
@media (min-width: 600px) { .modal { border-radius: 16px; } }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* ---------- toast / progress ---------- */
#toast { position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); bottom: calc(96px + var(--safe-b)); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: .9rem; opacity: 0; pointer-events: none; transition: .2s; z-index: 200; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.theme-switch { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--radius-sm); }
.theme-switch button { flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; padding: 8px; border-radius: 6px; cursor: pointer; }
.theme-switch button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.menu-list a, .menu-list button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 4px; border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--text); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; text-align: left; }
.menu-list svg { width: 22px; height: 22px; color: var(--accent); }

/* ---------- v2: offline queue, payment, returns, review tabs, alerts ---------- */
.obbar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 14px; border-radius: var(--radius-sm);
  background: var(--st-submitted-bg); color: var(--st-submitted); font-size: .88rem; font-weight: 500; }
.obbar svg { width: 22px; height: 22px; flex: none; }
.obbar span { flex: 1; }
.obbar strong { font-weight: 800; }
.obbar.off { background: var(--surface-2); color: var(--muted); }
.info-box { background: var(--st-submitted-bg); color: var(--text); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 14px; font-size: .9rem; }
.item.queued { border-style: dashed; border-color: var(--st-submitted); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 46px; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--input); font-weight: 600; font-size: .88rem; cursor: pointer; line-height: 1.2; }
.seg input:checked + span { border-color: var(--btn); background: var(--btn); color: var(--btn-text); }
.seg input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.check { display: flex !important; align-items: center; gap: 8px; font-weight: 500 !important; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--btn); margin: 0; }

.amt.neg, .big-amt.neg { color: var(--st-needs); }
.chip.ret { color: var(--st-needs); background: var(--st-needs-bg); }
.chip.owed { color: var(--st-submitted); background: var(--st-submitted-bg); }
.chip.paid { color: var(--st-entered); background: var(--st-entered-bg); }
.chip.waiting { color: var(--st-submitted); background: transparent; border: 1px dashed currentColor; }

.tcount { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--border); color: var(--text); font-size: .72rem; line-height: 18px; }
.selrow { display: flex; align-items: center; gap: 10px; }
.selrow > .sel { width: 22px; height: 22px; flex: none; accent-color: var(--btn); }
.selrow > .item { flex: 1; min-width: 0; }
.bulkbar { position: sticky; bottom: 12px; z-index: 15; margin-top: 12px; display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); }
.bulkbar #selcount { flex: 1; color: var(--muted); font-size: .9rem; }
@media (max-width: 760px) { .bulkbar { bottom: calc(80px + var(--safe-b)); } }

.ni-title { display: flex; align-items: center; gap: 10px; color: var(--st-needs); }
.ni-title svg { width: 26px; height: 26px; flex: none; }
.ni-title h2 { color: var(--text); }
.ni-list { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.ni-row { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-2); }
.ni-head { display: flex; justify-content: space-between; gap: 8px; }
.ni-note { margin: 6px 0 8px; font-style: italic; }
.dupe-list { padding-left: 18px; margin: 8px 0; }
.dupe-list li { margin-bottom: 4px; }
.tabs .tcount { background: var(--surface-2); }
.tabs button.active .tcount { background: var(--brand); color: var(--btn-text); }
