/*
 * Handoff -- Rickezza Admin (phone). Colours come from the brand's own
 * assets: the favicon's warm paper (#F6F3EE) and gold lotus (#CE9869),
 * and the logo's ink (#231F20). Gold is kept for the brand mark and the
 * active tab only; status colours (green/red) are reserved for meaning.
 * System font on purpose: nothing to download, so the app opens offline.
 */

:root {
  --paper: #F6F3EE;
  --surface: #FFFFFF;
  --ink: #231F20;
  --muted: #6E6862;
  --line: #E6E0D7;
  --gold: #CE9869;
  --gold-ink: #8A5A2E;      /* gold that passes contrast as text on white */
  --gold-tint: #F5EADF;
  --ok: #2E7D4F;
  --bad: #B3432C;
  --bad-tint: #FBEEEA;
  --warn-ink: #8A5A10;
  --warn-tint: #FBF1DE;
  --radius-lg: 14px;
  --radius-sm: 8px;
  --tabbar-h: 62px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171514;
    --surface: #211E1C;
    --ink: #F2EDE6;
    --muted: #A39B92;
    --line: #35302C;
    --gold: #D9A677;
    --gold-ink: #E2B88F;
    --gold-tint: #3A2E24;
    --ok: #5CC28A;
    --bad: #F08A73;
    --bad-tint: #3B2320;
    --warn-ink: #F0C27A;
    --warn-tint: #3A2F1D;
    color-scheme: dark;
  }
  .login__logo { filter: invert(1) brightness(0.95); }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
}

button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ------------------------------ buttons ------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 18px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; cursor: pointer;
}
.btn--primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn--ghost { background: transparent; }
.btn--block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ------------------------------- login ------------------------------- */
.login {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; justify-content: center;
  padding: max(32px, env(safe-area-inset-top)) 28px 32px;
  max-width: 420px; margin: 0 auto;
}
.login__logo { width: 190px; height: auto; margin: 0 auto 40px; display: block; }
.login__form { display: flex; flex-direction: column; }
.login__form label { font-size: 14px; color: var(--muted); margin: 14px 0 6px; }
.login__form input {
  height: 50px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); font-size: 17px;
}
.login__form .btn { margin-top: 24px; }
.login__error {
  margin: 16px 0 0; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--bad-tint); color: var(--bad); font-size: 14px;
}
.login__note { text-align: center; color: var(--muted); font-size: 13px; margin: 16px 0 0; }

/* ------------------------------- shell ------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.topbar__mark { width: 30px; height: auto; }
.topbar__title { flex: 1; margin: 0; font-size: 19px; font-weight: 650; letter-spacing: -0.01em; }

.conn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 13px; cursor: pointer;
}
.conn__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.conn[data-state="online"] .conn__dot { background: var(--ok); }
.conn[data-state="offline"] { border-color: var(--bad); color: var(--bad); }
.conn[data-state="offline"] .conn__dot { background: var(--bad); }

.iconbtn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border: 0; background: transparent; border-radius: 50%; cursor: pointer;
}
.is-offline .iconbtn { opacity: 0.4; }

.offline-banner {
  padding: 10px 16px; font-size: 14px;
  background: var(--bad-tint); color: var(--bad);
  border-bottom: 1px solid var(--line);
}

.view {
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 720px; margin: 0 auto;
}

/* ------------------------------ tab bar ------------------------------ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a, .tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; color: var(--muted); text-decoration: none;
  font-size: 11.5px; cursor: pointer;
}
.tabbar svg {
  width: 24px; height: 24px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.tabbar .is-on { color: var(--gold-ink); font-weight: 650; }
.tabbar .is-on svg { stroke-width: 2.2; }

/* ------------------------------- sheet ------------------------------- */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet__backdrop { position: absolute; inset: 0; background: rgba(20, 16, 12, 0.4); }
.sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 10px 8px calc(env(safe-area-inset-bottom) + 16px);
  animation: sheet-up 0.18s ease-out;
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) { .sheet__panel { animation: none; } }
.sheet__item {
  display: block; padding: 15px 16px; border-radius: 10px;
  color: var(--ink); text-decoration: none; font-size: 17px;
}
.sheet__item.is-on { background: var(--gold-tint); color: var(--gold-ink); font-weight: 600; }
.sheet__foot { border-top: 1px solid var(--line); margin-top: 8px; padding: 14px 8px 0; }
.sheet__who { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.sheet__ver { margin: 12px 0 0; text-align: center; color: var(--muted); font-size: 12px; }

/* ------------------------------ overview ----------------------------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 36px; padding: 0 14px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px; cursor: pointer;
}
.chip--on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.ov-custom { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.ov-custom label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.ov-custom input {
  height: 44px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface);
}

.ov-hero { padding: 26px 4px 22px; }
.ov-hero__label { margin: 0; color: var(--muted); font-size: 14px; }
.ov-hero__value {
  margin: 4px 0 2px; font-size: clamp(38px, 11vw, 52px); font-weight: 700;
  letter-spacing: -0.03em; line-height: 1.05;
}
.ov-hero__sub { margin: 0; font-size: 17px; }
.updated, .stale { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.stale { color: var(--warn-ink); }

.block { margin-top: 12px; }
.block__title { margin: 0 0 8px 4px; font-size: 15px; font-weight: 650; color: var(--muted); }

.rows {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  overflow: hidden;
}
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  padding: 13px 14px; border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row__main { display: flex; flex-direction: column; min-width: 0; }
.row__name { font-weight: 600; }
.row__meta { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__end { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row__amount { font-weight: 650; }
.row--online { background: var(--gold-tint); }

.pill {
  font-size: 12px; padding: 2px 8px; border-radius: 10px;
  color: var(--muted); border: 1px solid var(--line); background: transparent;
}
.pill--warn {
  color: var(--warn-ink); background: var(--warn-tint); border-color: transparent;
  font-weight: 650; cursor: pointer; min-height: 28px;
}
.drill { grid-column: 1 / -1; margin-top: 8px; }

.status { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.status--refunded, .status--cancelled { color: var(--bad); }

table.mini { width: 100%; border-collapse: collapse; font-size: 14px; }
table.mini th { text-align: left; font-weight: 500; color: var(--muted); padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.mini td { padding: 6px 4px; border-bottom: 1px solid var(--line); word-break: break-all; }
table.mini .num { text-align: right; white-space: nowrap; }

.loading, .empty { padding: 18px 14px; color: var(--muted); font-size: 14px; }
.error {
  padding: 14px; border-radius: var(--radius-lg);
  background: var(--bad-tint); color: var(--bad); font-size: 14px;
}

.soon { text-align: center; padding: 60px 24px; color: var(--muted); }
.soon img { width: 56px; opacity: 0.8; margin-bottom: 12px; }

/* ------------------------------- toast ------------------------------- */
.toast {
  position: fixed; left: 16px; right: 16px; z-index: 30;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  padding: 12px 14px; border-radius: 12px;
  background: var(--ink); color: var(--paper); font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.toast--error { background: #B3432C; color: #fff; } /* fixed, readable in dark mode too */

/* =========================== phase 2 (m2) =========================== */

.muted { color: var(--muted); }
.neg { color: var(--bad); }
.count { margin: 0 0 8px 4px; font-size: 13px; color: var(--muted); }
.note { margin: 10px 0; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.note--bad { background: var(--bad-tint); color: var(--bad); border-color: transparent; }

/* fields */
.field-inline { display: flex; align-items: center; gap: 10px; margin: 12px 0 0; font-size: 14px; color: var(--muted); }
.field-inline select, .filters select, .filters input, .search, .searchbar input, .confirm input {
  flex: 1; min-width: 0; height: 44px; padding: 0 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 16px; /* 16px stops Android zooming into the field */
}
.search { width: 100%; margin-bottom: 10px; }
.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar .btn { min-height: 44px; }
.chips + .chips { margin-top: 8px; }
.chip--sm { height: 32px; padding: 0 12px; font-size: 13px; }
.chips + .ov-custom, .ov-custom + .filter-toggle { margin-top: 12px; }

.filter-toggle {
  display: flex; align-items: center; gap: 8px; margin-top: 12px;
  height: 40px; padding: 0 14px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px; cursor: pointer;
}
.filter-toggle__count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--ink); color: var(--paper); font-size: 12px; display: grid; place-items: center;
}
.filters {
  display: grid; gap: 12px; margin-top: 10px; padding: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.filters select, .filters input { flex: none; width: 100%; }
.filters__actions { display: flex; justify-content: flex-end; }

/* autocomplete */
.ac { position: relative; }
.ac__list {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 5; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12); max-height: 280px; overflow-y: auto;
}
.ac__item { display: block; width: 100%; text-align: left; padding: 12px; border: 0; border-top: 1px solid var(--line); background: none; font-size: 15px; color: var(--ink); cursor: pointer; }
.ac__item:first-child { border-top: 0; }
.ac__none { margin: 0; padding: 12px; color: var(--muted); font-size: 14px; }

/* stat grid */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stats--3 { grid-template-columns: repeat(3, 1fr); }
.stats:empty { display: none; }
.stat { padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); min-width: 0; }
.stat--wide { grid-column: 1 / -1; }
.stat__label { margin: 0; font-size: 12.5px; color: var(--muted); }
.stat__value { margin: 2px 0 0; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.stat--wide .stat__value { font-size: 28px; }
.stat__value--sm { font-size: 16px; }
.stat__sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.stat--warn .stat__value { color: var(--warn-ink); }
.stat--bad .stat__value { color: var(--bad); }

/* rows */
.row--tap { cursor: pointer; }
.row--tap:active { background: var(--gold-tint); }
.row--void .row__name, .row--void .row__amount { text-decoration: line-through; color: var(--muted); }
.row__meta--bad { color: var(--bad); }
.row__meta--wrap { white-space: normal; }
.pill--ok { color: var(--ok); border-color: transparent; background: transparent; }
.more-btn { margin-top: 12px; }
.diff { font-weight: 650; }
.diff--small { font-size: 12.5px; font-weight: 500; }
.diff.neg { color: var(--bad); }
.diff.pos { color: var(--ok); }
.status--flagged, .status--rejected, .status--partially_refunded { color: var(--bad); }
.status--pending, .status--processing, .status--waiting_pickup { color: var(--warn-ink); }

/* detail sheet */
.dlg { position: fixed; inset: 0; z-index: 25; background: var(--paper); }
.dlg__panel { height: 100%; display: flex; flex-direction: column; }
.dlg__head {
  display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px 6px;
  border-bottom: 1px solid var(--line); background: var(--paper);
}
.dlg__title { margin: 0; font-size: 18px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg__body { flex: 1; overflow-y: auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px); max-width: 720px; width: 100%; margin: 0 auto; }
.dlg__body > .btn { margin: 4px 0 14px; }
.dlg__body .block__title { margin-top: 20px; }
body.has-dialog { overflow: hidden; }
.detail-status { margin: 0 0 8px; }
.detail-status .status { margin: 0; font-size: 14px; }

.kv { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.kv__row { display: flex; justify-content: space-between; gap: 16px; padding: 11px 14px; border-top: 1px solid var(--line); }
.kv__row:first-child { border-top: 0; }
.kv dt { color: var(--muted); font-size: 14px; flex: none; }
.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.kv--totals { margin-top: 10px; }
.kv__row--strong dt, .kv__row--strong dd { color: var(--ink); font-weight: 700; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--gold-ink); text-decoration: underline; font: inherit; cursor: pointer; }

/* =========================== phase 3 (m3) =========================== */
.sheet__item--btn { width: 100%; text-align: left; border: 0; background: none; font: inherit; font-size: 17px; cursor: pointer; color: var(--ink); }
.callout {
  display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; padding: 14px;
  background: var(--gold-tint); border-radius: var(--radius-lg);
}
.callout p { margin: 0; font-size: 15px; }
.callout .btn { align-self: flex-start; }
.warn-text { color: var(--warn-ink); }
.row--attn { box-shadow: inset 3px 0 0 var(--warn-ink); }
.lead { margin: 0 0 14px; font-size: 16px; }
.small { font-size: 13px; }
.toggles { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); margin-bottom: 14px; }
.toggle { display: flex; gap: 12px; align-items: flex-start; padding: 13px 14px; border-top: 1px solid var(--line); font-size: 15px; }
.toggle:first-child { border-top: 0; }
.toggle input { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--ink); flex: none; }
.toggle--off { opacity: 0.55; }
.dlg__body > .btn + .btn { margin-top: 0; }
