/* Mak Lyhour — staff app. Phone first; becomes a sidebar layout on the counter tablet/desktop.

   The system in one breath:
   - Ivory surfaces for everyday work, kept quiet so numbers are easy to read.
   - Ink panels with gold type are reserved for money that matters
     (the gold rate, the amount due). If it's dark, it's the thing to look at.
   - Noto Serif Khmer for titles and amounts, Kantumruy Pro for everything else.
     Khmer stacks vowels above and below the line, so sizes stay at 13px or more
     and line-height stays generous.
   - Colour in components always comes from the tokens below. */
:root {
  /* surfaces */
  --bg: #F7F2E8;
  --card: #FFFDF8;
  --fill: #EDE5D5;
  --fill-soft: #F4EEE1;
  --bar: rgba(255, 252, 245, 0.94);
  --sep: #E2D8C5;

  /* text */
  --text: #211B13;
  --muted: #6A5F50;
  --faint: #7A6E5C;
  --chev: #B9AD98;

  /* ink + gold */
  --ink: #1D1811;
  --ink-2: #2E2619;
  --on-ink: #FBF6EA;
  --on-ink-muted: #C9BDA6;
  --gold: #E3C27A;
  --gold-line: rgba(227, 194, 122, 0.26);
  --accent: #80590F;
  --accent-ink: #4E3808;
  --accent-tint: #F0E3C6;

  /* status */
  --amber: #C77700;  --amber-text: #8A5200;
  --red: #B3261E;    --red-tint: #FBEAE7;
  --green: #1F6F3D;  --green-tint: #E5F1E7;

  /* shape + depth */
  --r-group: 14px;
  --r-btn: 14px;
  --hair: 1px solid var(--sep);
  --shadow-card: 0 1px 2px rgba(60, 44, 18, .05), 0 6px 18px -10px rgba(60, 44, 18, .16);
  --shadow-ink: 0 14px 28px -16px rgba(29, 24, 17, .6);

  /* type */
  --font-body: "Kantumruy Pro", -apple-system, system-ui, sans-serif;
  --font-display: "Noto Serif Khmer", "Kantumruy Pro", Georgia, serif;

  --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom);
  --ease: 160ms cubic-bezier(.2, .7, .3, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, p { margin: 0; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- page shell */
.page { max-width: 620px; margin: 0 auto; padding: 8px 16px 32px; }
.with-tabbar .page { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 32px); }
.with-actionbar .page { padding-bottom: calc(var(--bar-h, 78px) + var(--safe-b) + 32px); }
.page:has(.actionbar-note + .actionbar-inner) { --bar-h: 116px; }  /* a note above the button */

/* top bar on the Today / Search screens */
.topbar { display: flex; justify-content: space-between; align-items: center; min-height: 52px; padding-top: env(safe-area-inset-top); }
.brand { display: inline-flex; align-items: center; gap: 10px; }
.shop-name { font-family: var(--font-display); font-size: 16px; font-weight: 600; color: var(--text); }
.icon-link { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; margin-right: -8px; border-radius: 50%; color: var(--accent); transition: background var(--ease); }
.icon-link svg { width: 22px; height: 22px; }

.large-title { font-family: var(--font-display); font-size: 30px; font-weight: 600; line-height: 1.5; }
.subtitle { font-size: 15px; color: var(--muted); margin-bottom: 16px; }

/* navigation bar on forms and detail screens */
.navbar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  min-height: 54px; padding: env(safe-area-inset-top) 8px 0;
  background: var(--bar); border-bottom: var(--hair);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.navbar h1 { font-family: var(--font-display); font-size: 17px; font-weight: 600; text-align: center; }
.nav-left { justify-self: start; display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 8px; border-radius: 10px; text-decoration: none; color: var(--accent); }
.nav-left svg { width: 22px; height: 22px; stroke-width: 2.2; margin-left: -6px; }
.navbar + .page { padding-top: 20px; }

/* ---------- grouped lists */
.group { background: var(--card); border-radius: var(--r-group); overflow: hidden; box-shadow: var(--shadow-card); }
.group-header { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 8px; font-size: 14px; font-weight: 500; color: var(--muted); }
.group-header span + span {
  min-width: 26px; padding: 0 8px; border-radius: 13px; background: var(--fill);
  font-size: 13px; font-weight: 600; line-height: 24px; text-align: center; color: var(--text);
}
.group-footer { padding: 8px 4px 0; font-size: 14px; color: var(--muted); }
.group-footer.error { color: var(--red); font-weight: 500; }
.section { margin-top: 26px; }
.page > .section:first-child, .page > form > .section:first-of-type,
.banner + .section, .page > form > .banner + .section { margin-top: 0; }

.cell {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; margin-left: 16px; padding: 7px 16px 7px 0;
  border-bottom: var(--hair);
}
.cell:last-child { border-bottom: 0; }
.cell .label { color: var(--muted); }
.cell .value { text-align: right; }
.cell.strong .label { color: var(--text); font-weight: 500; }
.cell.strong .value { font-family: var(--font-display); font-size: 20px; font-weight: 600; }

/* list rows (tap to open) */
.row { display: flex; align-items: center; gap: 12px; padding-left: 16px; color: var(--text); text-decoration: none; transition: background var(--ease); }
.row:active { background: var(--fill-soft); }
.row:focus-visible { outline-offset: -2px; border-radius: var(--r-group); }
.row-body { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; min-height: 68px; padding: 8px 12px 8px 0; border-bottom: var(--hair); }
.row:last-child .row-body { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 500; }
.row-sub { font-size: 14px; color: var(--muted); }
.row-end { font-size: 15px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.chev { width: 14px; height: 14px; stroke: var(--chev); stroke-width: 2.5; }
.empty-cell { padding: 14px 16px; font-size: 15px; color: var(--faint); }

/* status: a dot + coloured text */
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--chev); }
.tone-due_today .dot, .dot.tone-due_today { background: var(--amber); box-shadow: 0 0 0 3px rgba(199, 119, 0, .16); }
.tone-forfeited .dot, .dot.tone-forfeited { background: var(--red); }
.tone-redeemed .dot, .dot.tone-redeemed { background: var(--green); }
.text-due_today { color: var(--amber-text); }
.text-forfeited { color: var(--red); }
.text-redeemed { color: var(--green); }
.text-active, .text-due_soon { color: var(--muted); }

/* ---------- ink panels: the shared look of "money that matters" */
.hero {
  background-color: var(--ink);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200' fill='none' stroke='%23E3C27A' stroke-opacity='.2'%3E%3Ccircle cx='100' cy='100' r='70'/%3E%3Ccircle cx='100' cy='100' r='96'/%3E%3C/svg%3E"),
    linear-gradient(150deg, var(--ink-2), var(--ink) 70%);
  background-repeat: no-repeat;
  background-position: right -120px top -90px, 0 0;
  background-size: 220px 220px, auto;
  color: var(--on-ink);
  border-radius: 18px;
  box-shadow: inset 0 0 0 1px var(--gold-line), var(--shadow-ink);
}

/* ---------- Today */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

/* ---------- buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; min-height: 54px; padding: 4px 12px; border: 0; border-radius: var(--r-btn);
  font-size: 17px; font-weight: 600; line-height: 1.3; text-decoration: none; cursor: pointer;
  transition: transform var(--ease), background var(--ease), box-shadow var(--ease);
}
.btn:active { transform: scale(.98); }
.btn svg { width: 20px; height: 20px; stroke-width: 2.2; }
.btn-primary { background: var(--ink); color: var(--on-ink); box-shadow: var(--shadow-ink); }
.btn-primary svg { color: var(--gold); }
.btn-tinted { background: var(--accent-tint); color: var(--accent-ink); }
.btn-plain { background: var(--card); color: var(--red); box-shadow: var(--shadow-card); }
.btn:disabled { opacity: .6; cursor: default; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: var(--bar); border-top: var(--hair);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.actionbar-inner { max-width: 588px; margin: 0 auto; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; }
.actionbar form { display: contents; }
.actionbar-note { max-width: 588px; margin: 0 auto; text-align: center; font-size: 15px; font-weight: 500; color: var(--red); padding: 4px 0 8px; }

/* ---------- forms */
.field-cell { position: relative; cursor: text; }
.field-cell::before {
  content: ""; position: absolute; left: -16px; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--accent); opacity: 0; transition: opacity var(--ease);
}
.field-cell:focus-within::before { opacity: 1; }
.field-cell input {
  flex: 1; min-width: 0; height: 34px; padding: 0;
  border: 0; outline: 0; background: transparent; text-align: right; font-weight: 500;
}
.field-cell input::placeholder { color: var(--faint); font-weight: 400; }
.field-cell input[type="date"] { flex: 0 0 auto; height: 38px; padding: 0 12px; border-radius: 9px; background: var(--fill-soft); text-align: center; }
.field-cell.has-error .label { color: var(--red); }
.field-cell.has-error::before { background: var(--red); opacity: 1; }

.amount { display: flex; align-items: baseline; gap: 6px; padding: 12px 16px; transition: box-shadow var(--ease); }
.amount:focus-within { box-shadow: inset 0 0 0 2px var(--accent), var(--shadow-card); }
.amount span { font-family: var(--font-display); font-size: 28px; font-weight: 600; color: var(--accent); }
.amount input { flex: 1; min-width: 0; border: 0; outline: 0; padding: 0; background: transparent; font-family: var(--font-display); font-size: 36px; font-weight: 600; line-height: 1.4; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--fill); }
.segmented label, .segmented a { position: relative; display: flex; align-items: center; justify-content: center; min-height: 44px; border-radius: 10px; font-size: 15px; font-weight: 500; color: var(--text); text-decoration: none; cursor: pointer; transition: background var(--ease), color var(--ease); }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented label:has(input:checked), .segmented a[aria-current] { background: var(--ink); color: var(--on-ink); font-weight: 600; }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photos.single { grid-template-columns: 1fr; }
.photo-tile {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  aspect-ratio: 4 / 3; border: 1.5px dashed var(--chev); border-radius: var(--r-group); background: var(--fill-soft);
  color: var(--accent); font-size: 15px; font-weight: 500; overflow: hidden; cursor: pointer; transition: border-color var(--ease), background var(--ease);
}
.photos.single .photo-tile { aspect-ratio: 16 / 9; }
.photo-tile svg { width: 26px; height: 26px; }
.photo-tile input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.photo-tile:focus-within { border-color: var(--accent); border-style: solid; }
.photo-tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-tile.has-error { border-color: var(--red); color: var(--red); background: var(--red-tint); }
.photo-view { display: block; aspect-ratio: 4 / 3; border-radius: var(--r-group); overflow: hidden; background: var(--fill); box-shadow: var(--shadow-card); }
.photo-view { position: relative; }
.photo-view img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-label { position: absolute; left: 8px; bottom: 8px; padding: 1px 10px; border-radius: 12px; background: var(--ink); color: var(--on-ink); font-size: 13px; font-weight: 500; }

/* full-size photo, opened over the page */
.viewer { width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: var(--ink); }
.viewer[open] { display: flex; align-items: center; justify-content: center; }
.viewer::backdrop { background: var(--ink); }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-close { position: fixed; top: calc(env(safe-area-inset-top) + 12px); right: 12px; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: var(--ink-2); color: var(--on-ink); box-shadow: inset 0 0 0 1px var(--gold-line); cursor: pointer; }
.viewer-close:focus-visible { outline-color: var(--gold); }

/* ---------- detail */
.hero { text-align: center; margin-bottom: 26px; padding: 24px 16px 22px; }
.hero + .section { margin-top: 0; }
.hero small { display: block; font-size: 15px; color: var(--on-ink-muted); }
.hero strong { display: block; font-family: var(--font-display); font-size: 42px; font-weight: 600; line-height: 1.4; color: var(--gold); }
.hero .status { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; padding: 2px 12px; border-radius: 15px; background: var(--on-ink); font-size: 14px; font-weight: 500; }
.call { width: 44px; height: 44px; border-radius: 50%; background: var(--green-tint); color: var(--green); display: flex; align-items: center; justify-content: center; transition: transform var(--ease); }
.call:active { transform: scale(.94); }
.call svg { width: 20px; height: 20px; }
.customer small { display: block; font-size: 14px; color: var(--muted); }

/* ---------- search */
.search-field { display: flex; align-items: center; gap: 8px; height: 50px; padding: 0 14px; border-radius: var(--r-btn); background: var(--card); color: var(--faint); margin-bottom: 12px; box-shadow: var(--shadow-card); transition: box-shadow var(--ease); }
.search-field:focus-within { box-shadow: inset 0 0 0 2px var(--accent), var(--shadow-card); }
.search-field svg { width: 20px; height: 20px; }
.search-field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 17px; color: var(--text); }
.search-field input::placeholder { color: var(--faint); }
.search-field { padding-right: 4px; }
.search-go { flex-shrink: 0; min-width: 56px; height: 42px; padding: 0 14px; border: 0; border-radius: 11px; background: var(--ink); color: var(--on-ink); font-size: 15px; font-weight: 600; cursor: pointer; }

/* ---------- messages */
.banner { margin-bottom: 16px; padding: 12px 16px; border-radius: var(--r-group); background: var(--green-tint); color: var(--green); font-size: 15px; font-weight: 500; }
.banner.error { background: var(--red-tint); color: var(--red); }

/* ---------- login: the one fully dark screen */
.auth { background: var(--ink); color: var(--on-ink); }
.auth :focus-visible { outline-color: var(--gold); }
.login { min-height: 100vh; min-height: 100dvh; max-width: 400px; margin: 0 auto; display: flex; flex-direction: column; justify-content: center; padding-bottom: 12vh; }
.login .large-title { text-align: center; }
.login .subtitle { text-align: center; margin-bottom: 26px; color: var(--on-ink-muted); }
.login .group { color: var(--text); }
.login .btn { margin-top: 18px; }
.login .btn-primary { background: var(--gold); color: var(--ink); box-shadow: none; }

/* ---------- tab bar (becomes a sidebar on wide screens) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--bar); border-top: var(--hair);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 13px; font-weight: 500; line-height: 1.3; color: var(--faint); text-decoration: none; transition: color var(--ease); }
.tabbar a[aria-current] { color: var(--accent); font-weight: 600; }
.tabbar a[aria-current]::before { content: ""; position: absolute; top: 0; left: 50%; width: 28px; height: 3px; margin-left: -14px; border-radius: 0 0 3px 3px; background: var(--accent); }
.tabbar a:focus-visible { outline-offset: -3px; }
.tabbar .tabbar-brand { display: none; }
/* The Save / Pay bar sits on top of the tab bar. */
.with-tabbar .actionbar { bottom: calc(var(--tab-h) + var(--safe-b)); padding-bottom: 12px; }
.with-tabbar.with-actionbar .page { padding-bottom: calc(var(--bar-h, 78px) + var(--tab-h) + var(--safe-b) + 32px); }

/* ---------- pointer devices */
@media (hover: hover) {
  .row:hover { background: var(--fill-soft); }
  .icon-link:hover { background: var(--fill); }
  .nav-left:hover { background: var(--fill-soft); }
  .btn-primary:hover { background: var(--ink-2); }
  .btn-tinted:hover { background: #E9D9B4; }
  .photo-tile:hover { border-color: var(--accent); }
  .segmented a:not([aria-current]):hover, .segmented label:not(:has(input:checked)):hover { background: var(--fill-soft); }
  .tabbar a:hover { color: var(--accent); }
  .login .btn-primary:hover { background: #EBCF90; }
}

/* ---------- the counter: tablet landscape and desktop */
@media (min-width: 960px) {
  body.with-tabbar { padding-left: 232px; }
  .with-tabbar .page { padding: 16px 32px 40px; }
  .with-tabbar.with-actionbar .page { padding-bottom: calc(var(--bar-h, 78px) + 40px); }
  .with-tabbar .actionbar { left: 232px; bottom: 0; }
  .with-tabbar .page-wide { max-width: 1040px; }
  .with-tabbar .topbar .brand { visibility: hidden; }

  .tabbar {
    top: 0; right: auto; bottom: 0; width: 232px; height: auto; padding: 20px 12px;
    grid-template-columns: 1fr; grid-auto-rows: min-content; gap: 4px;
    background: var(--ink); border-top: 0;
  }
  .tabbar .tabbar-brand { display: flex; flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 56px; margin-bottom: 18px; padding: 0 10px; font-family: var(--font-display); font-size: 17px; font-weight: 600; color: var(--on-ink); }
  .tabbar a:not(.tabbar-brand) { flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 48px; padding: 0 12px; border-radius: 12px; font-size: 16px; color: var(--on-ink-muted); transition: background var(--ease), color var(--ease); }
  .tabbar a[aria-current] { background: var(--ink-2); color: var(--gold); }
  .tabbar a[aria-current]::before { top: 12px; left: 0; width: 3px; height: 24px; margin-left: 0; border-radius: 0 3px 3px 0; background: var(--gold); }
  .tabbar a:focus-visible { outline-color: var(--gold); }
  .tabbar a:not(.tabbar-brand):hover { color: var(--on-ink); background: var(--ink-2); }

  .today-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 26px 20px; align-items: start; margin-top: 26px; }
  .today-lists .section { margin-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

/* ---------- owner-only buttons on the pawn screen */
.owner-actions form + form { margin-top: 10px; }
