/* styles.css — near-black dark theme, purple accent, IBM Plex type. Mobile-first. */
:root {
  --accent: #a78bfa;          /* purple */
  --accent-press: #9170f5;
  --accent-soft: rgba(167, 139, 250, 0.14);
  --accent-line: rgba(167, 139, 250, 0.35);

  --bg: #08080a;
  --shell: #0e0e11;
  --surface: #161619;
  --surface-2: #1c1c20;
  --raised: #222227;
  --line: #2a2a30;
  --line-soft: #202024;

  --text: #ededf0;
  --text-2: #c2c2ca;        /* secondary text — lifted for readability */
  --muted: #9a9aa6;         /* labels/hints/icons — was too dim (#7d7d87) */
  --faint: #76767f;         /* placeholders/empty states — was too dim (#56565e) */

  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;

  --r-sm: 10px; --r: 14px; --r-lg: 20px; --r-xl: 26px;
  --pad: 16px;            /* density-controlled */
  --gap: 12px;
  --tap: 52px;            /* min touch target */
  --font: "IBM Plex Sans", "IBM Plex Sans Thai", "Noto Sans Myanmar", "Noto Sans Lao", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 18px 40px -24px rgba(0,0,0,0.9);
}

/* ---- light theme: overrides the :root variables when html has .light ---- */
html.light {
  /* deeper purple in light mode: reads as accent TEXT on white (prices/links).
     As a button/segment FILL it now carries white text (see overrides below). */
  --accent: #6d4fd0;
  --accent-press: #5d3fc4;

  --bg: #f4f4f6;
  --shell: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f4f6;
  --raised: #ececef;
  --line: #d7d7de;
  --line-soft: #e8e8ed;

  --text: #18181c;
  --text-2: #3c3c45;        /* darker for crisp secondary text on white */
  --muted: #5f5f6a;         /* labels/hints/icons — darkened so they read on white */
  --faint: #82828c;         /* placeholders/empty states — was too pale (#9a9aa4) */

  /* status colours re-tuned darker so coloured text/badges read on a white background
     (the bright dark-mode tones above wash out on light surfaces) */
  --ok: #0f9d6b;
  --warn: #b9770a;
  --danger: #d6332f;

  --shadow: 0 1px 0 rgba(0,0,0,0.02) inset, 0 18px 40px -24px rgba(0,0,0,0.28);
}
/* accent-filled controls: white label on the deeper light-mode purple (dark label
   would be too low-contrast on it; the dark-mode accent is light enough for dark text) */
html.light .btn-primary { color: #fff; }
html.light .seg-ctrl button.on { color: #fff; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
:lang(my) { line-height: 1.7; }
:lang(lo) { line-height: 1.6; }

/* inherit color so button text follows the theme; without this the browser
   defaults <button> text to black, which is invisible in dark mode (specific
   button styles below still override with their own colors) */
button { font-family: inherit; cursor: pointer; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; }
::selection { background: var(--accent-soft); }

/* ---- shell: centered phone-width column ---- */
#root { height: 100%; }
.viewport {
  height: 100%; position: relative;
  display: flex; align-items: stretch; justify-content: center;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(167,139,250,0.06), transparent 60%),
    var(--bg);
}
.app {
  width: 100%; max-width: 480px;
  height: 100%;
  background: var(--shell);
  display: flex; flex-direction: column;
  position: relative;
  border-left: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft);
  overflow: hidden;
}
@media (min-width: 520px) {
  .viewport { padding: 0; }
}

/* ---- top bar ---- */
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 14px var(--pad);
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent);
  position: relative; z-index: 5;
}
.topbar .tb-title { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.topbar .tb-sub { font-size: 11.5px; color: var(--muted); }
.icon-btn {
  width: 40px; height: 40px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text-2);
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.95); }

/* ---- pull-to-refresh indicator ---- */
.ptr {
  position: absolute; top: 8px; left: 50%; z-index: 60;
  pointer-events: none;
  width: 34px; height: 34px; border-radius: 999px;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: 0 6px 18px rgba(0,0,0,0.22);
}
.ptr-ring {
  width: 16px; height: 16px; border-radius: 999px;
  border: 2px solid var(--line); border-top-color: var(--accent);
}
.ptr-ring.spin { animation: ptr-rot .7s linear infinite; }
@keyframes ptr-rot { to { transform: rotate(360deg); } }

/* ---- scroll body ---- */
.scroll {
  flex: 1 1 auto; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: var(--pad);
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.stack-lg { display: flex; flex-direction: column; gap: 20px; }

/* ---- typography ---- */
.h1 { font-size: 25px; font-weight: 600; letter-spacing: -0.02em; margin: 0; line-height: 1.2; }
.h2 { font-size: 19px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.lead { color: var(--text-2); font-size: 14.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); font-feature-settings: "tnum"; }
.num { font-family: var(--mono); font-feature-settings: "tnum"; letter-spacing: -0.01em; }

/* ---- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: var(--pad);
}
.card.flat { background: var(--surface); border-color: var(--line-soft); }
.card.pad-lg { padding: 20px; }
.tap-card {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--r-lg); padding: 18px;
  color: var(--text);
  transition: border-color .15s, background .15s, transform .1s;
}
.tap-card:hover { border-color: var(--line); background: var(--surface-2); }
.tap-card:active { transform: scale(.99); }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: var(--tap); padding: 0 20px;
  border-radius: var(--r); border: 1px solid transparent;
  font-size: 16px; font-weight: 600; letter-spacing: -0.01em;
  transition: background .15s, border-color .15s, transform .08s, opacity .15s;
  width: 100%;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #14121f; }
.btn-primary:hover:not(:disabled) { background: var(--accent-press); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-quiet { background: transparent; color: var(--text-2); border-color: transparent; }
.btn-quiet:hover { color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(248,113,113,0.3); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: auto; flex: 1; }
.btn-sm { min-height: 40px; padding: 0 14px; font-size: 14px; border-radius: 11px; }

/* ---- form fields ---- */
.field { display: flex; flex-direction: column; gap: 7px; }
.label { font-size: 13px; font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 7px; }
.label .req { color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); }
.control, .select, textarea.control {
  width: 100%; min-height: var(--tap);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 0 15px; outline: none;
  transition: border-color .15s, background .15s;
}
textarea.control { padding: 13px 15px; min-height: 80px; line-height: 1.5; resize: vertical; }
.control::placeholder { color: var(--faint); }
/* dropdown list items: theme them explicitly — otherwise the browser renders
   <option> text in default black, which is invisible on the dark dropdown */
.select option, .control option {
  background: var(--surface); color: var(--text);
}
.select option:disabled { color: var(--faint); }
.control:focus, .select:focus, textarea.control:focus { border-color: var(--accent-line); background: var(--surface); }
.select { appearance: none; background-image: none; padding-right: 42px; }
.select-wrap { position: relative; }
.select-wrap::after {
  content: ""; position: absolute; right: 16px; top: 50%; width: 9px; height: 9px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-65%) rotate(45deg); pointer-events: none;
}
.input-suffix { position: relative; }
.input-suffix .suffix { position: absolute; right: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; }

/* big number-friendly input for prices */
.control.big-num { font-family: var(--mono); font-size: 22px; font-weight: 600; text-align: right; padding-right: 56px; }

/* ---- chips / badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--text-2); background: var(--surface-2);
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.badge.is-draft { color: var(--text-2); }
.badge.is-pending { color: var(--warn); border-color: rgba(251,191,36,0.3); background: rgba(251,191,36,0.08); }
.badge.is-pending .dot { background: var(--warn); }
.badge.is-approved { color: var(--ok); border-color: rgba(52,211,153,0.3); background: rgba(52,211,153,0.08); }
.badge.is-approved .dot { background: var(--ok); }
.badge.is-rejected { color: var(--danger); border-color: rgba(248,113,113,0.3); background: rgba(248,113,113,0.08); }
.badge.is-rejected .dot { background: var(--danger); }
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2);
  font-size: 13px; color: var(--text-2);
}

/* ---- doc type tiles ---- */
.tile-icon {
  width: 50px; height: 50px; flex: 0 0 auto; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--accent-soft); border: 1px solid var(--accent-line); color: var(--accent);
}

/* ---- progress / steps ---- */
.steps { display: flex; align-items: center; gap: 6px; }
.steps .seg { height: 4px; flex: 1; border-radius: 999px; background: var(--line); overflow: hidden; }
.steps .seg.done > i { display: block; height: 100%; background: var(--accent); }
.steps .seg.done { background: var(--accent); }

/* ---- list rows ---- */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line-soft);
  color: var(--text);   /* <button class="row"> wouldn't inherit page color — defaults to black otherwise */
}
.row .grow { flex: 1; min-width: 0; }
.row .ix {
  width: 26px; height: 26px; flex: 0 0 auto; border-radius: 8px;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: var(--raised); color: var(--text-2); font-family: var(--mono);
}
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* divider */
.hr { height: 1px; background: var(--line-soft); border: 0; margin: 4px 0; }
.dl { display: flex; justify-content: space-between; gap: 14px; padding: 9px 0; font-size: 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; text-align: right; color: var(--text); }

/* sticky footer action area inside .app */
.action-bar {
  flex: 0 0 auto;
  padding: 14px var(--pad) calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line-soft);
  background: linear-gradient(0deg, var(--shell), rgba(14,14,17,0.85));
  display: flex; flex-direction: column; gap: 10px;
}

/* photo capture */
.photo-slot {
  position: relative; width: 100%; aspect-ratio: 4/3;
  border-radius: var(--r); overflow: hidden;
  border: 1.5px dashed var(--line); background: var(--surface-2);
  display: grid; place-items: center; color: var(--muted);
}
.photo-slot.filled { border-style: solid; border-color: var(--line); }
.photo-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-slot .meta {
  position: absolute; left: 8px; bottom: 8px;
  font-family: var(--mono); font-size: 10.5px; padding: 3px 8px; border-radius: 7px;
  background: rgba(8,8,10,0.78); color: var(--text-2); backdrop-filter: blur(4px);
}
.photo-slot .x {
  position: absolute; right: 8px; top: 8px; width: 30px; height: 30px;
  border-radius: 50%; border: 0; background: rgba(8,8,10,0.7); color: #fff;
  display: grid; place-items: center; backdrop-filter: blur(4px);
}
.photo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* signature pad */
.sig-pad {
  width: 100%; height: 150px; border-radius: var(--r);
  background: #f7f7f4; border: 1px solid var(--line); touch-action: none; display: block;
}
.sig-stored {
  height: 88px; border-radius: var(--r); border: 1px dashed var(--line);
  display: grid; place-items: center; background: var(--surface-2);
  font-family: "Brush Script MT", "Segoe Script", cursive; font-size: 30px; color: var(--text);
}
.sig-stored.signed { border-style: solid; border-color: var(--accent-line); background: var(--accent-soft); }

/* sheet / modal */
.sheet-bg {
  position: absolute; inset: 0; background: rgba(4,4,6,0.6);
  backdrop-filter: blur(3px); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
.sheet {
  width: 100%; max-width: 480px; max-height: 92%; overflow-y: auto;
  background: var(--shell); border-top-left-radius: var(--r-xl); border-top-right-radius: var(--r-xl);
  border-top: 1px solid var(--line); padding: 8px var(--pad) calc(20px + env(safe-area-inset-bottom));
  animation: slideup .26s cubic-bezier(.2,.8,.2,1);
}
.sheet .grip { width: 38px; height: 4px; border-radius: 999px; background: var(--line); margin: 8px auto 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(18px); opacity: .6; } }
.fade-in { animation: fade .22s ease; }
.slide-in { animation: slidein .26s cubic-bezier(.2,.8,.2,1); }
@keyframes slidein { from { transform: translateX(14px); opacity: 0; } }

/* segmented */
.seg-ctrl { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 13px; }
.seg-ctrl button { flex: 1; min-height: 38px; border: 0; background: transparent; color: var(--text-2); border-radius: 10px; font-weight: 600; font-size: 13.5px; transition: background .15s, color .15s; }
.seg-ctrl button.on { background: var(--accent); color: #14121f; }

/* lang menu */
.lang-list { display: flex; flex-direction: column; gap: 6px; }
.lang-opt { display: flex; align-items: center; justify-content: space-between; padding: 15px 16px; border-radius: var(--r); border: 1px solid var(--line-soft); background: var(--surface); color: var(--text); }
.lang-opt.on { border-color: var(--accent-line); background: var(--accent-soft); }
.lang-opt .en { font-size: 12px; color: var(--muted); }

/* small helper */
.center { text-align: center; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.right { text-align: right; }
.gap-sm { gap: 8px; }
.wfull { width: 100%; }
.spin { width: 38px; height: 38px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: rot 0.7s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ---- paper document ---- */
.paper {
  background: #fff; color: #1a1a1c;
  border-radius: 0; border: 1px solid #d8d7d0;   /* square sheet edge, not a rounded card */
  padding: 22px 22px; font-size: 10.5px; line-height: 1.4;
  max-width: 560px; margin: 0 auto;              /* height grows with content; PDF paginates */
}
.paper .num, .paper .mono { font-family: var(--mono); font-feature-settings: "tnum"; }
.pp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding-bottom: 9px; border-bottom: 2px solid #1a1a1c; }
.pp-title { font-size: 14px; font-weight: 700; letter-spacing: -0.01em; text-wrap: balance; }
.pp-no { font-size: 9.5px; font-weight: 600; color: #555; white-space: nowrap; }
.pp-meta { display: flex; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px solid #ddd; }
.pp-co-name { font-weight: 700; font-size: 11px; }
.pp-co-line { color: #555; font-size: 9px; margin-top: 1px; text-wrap: pretty; }
.pp-date { text-align: right; display: flex; flex-direction: column; gap: 1px; white-space: nowrap; }
.pp-date .pp-k { font-size: 8.5px; color: #888; text-transform: uppercase; letter-spacing: 0.08em; }
.pp-date .num { font-weight: 600; }
.pp-rows { margin-top: 9px; }
.pp-row { display: grid; gap: 5px; align-items: start; padding: 4px 0; border-bottom: 1px solid #ececec; }
.pp-row.fgr { grid-template-columns: 18px 1fr 54px 62px 56px; }
.pp-row.opx { grid-template-columns: 18px 1fr 62px 40px 64px; }
.pp-row.simple { grid-template-columns: 18px 1fr 88px; }
.pp-row.pp-row-h { font-size: 8px; text-transform: uppercase; letter-spacing: 0.05em; color: #999; font-weight: 600; border-bottom-color: #ccc; }
.pp-row .r { text-align: right; }
.pp-row .pp-ix { color: #999; }
.pp-row .pp-desc { font-weight: 600; text-wrap: pretty; }
.pp-row .pp-desc em { font-weight: 400; font-style: normal; color: #777; }
.pp-totals { margin-top: 8px; display: flex; flex-direction: column; gap: 3px; align-items: flex-end; }
.pp-tl { display: flex; justify-content: space-between; gap: 24px; min-width: 210px; font-size: 10px; color: #555; }
.pp-tl.pp-grand { font-size: 12px; font-weight: 700; color: #1a1a1c; padding-top: 6px; border-top: 2px solid #1a1a1c; margin-top: 3px; }
.pp-cert { margin: 12px 0 0; padding: 9px 11px; background: transparent; border: 1px solid #e2e1da; border-radius: 6px; font-size: 9.5px; line-height: 1.5; color: #333; text-wrap: pretty; }
.pp-sec { font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; color: #999; font-weight: 700; margin-bottom: 7px; }
.pp-photos { margin-top: 12px; }
/* ~2in x 2in evidence thumbnail, whole photo (never cropped) */
.pp-line-photo { display: block; width: 150px; height: 150px; object-fit: contain; background: #fff; border: 1px solid #e2e1da; border-radius: 4px; margin-top: 6px; }
.pp-photo-grid { display: grid; grid-template-columns: repeat(auto-fill, 150px); gap: 12px; }
.pp-photo-grid figure { margin: 0; }
.pp-photo-grid img { width: 150px; height: 150px; object-fit: contain; background: #fff; border: 1px solid #e2e1da; border-radius: 4px; display: block; }
.pp-photo-grid figcaption { font-size: 9px; color: #777; margin-top: 4px; text-align: center; max-width: 150px; }
.pp-signs { margin-top: 14px; display: flex; gap: 12px; flex-wrap: wrap; }
.pp-sign { flex: 1; min-width: 88px; text-align: center; }
.pp-sign-mark { height: 38px; display: grid; place-items: center; }
.pp-sign-mark img { max-height: 38px; max-width: 100%; mix-blend-mode: multiply; }
.pp-script { font-family: "Brush Script MT", "Segoe Script", cursive; font-size: 20px; color: #1a1a3a; }
.pp-sign-empty { color: #bbb; letter-spacing: 1px; }
.pp-sign-line { border-top: 1px dotted #999; margin: 2px 6px 0; }
.pp-sign-label { font-size: 9px; color: #777; margin-top: 5px; }
.pp-sign-name { font-size: 9.5px; font-weight: 600; margin-top: 1px; text-wrap: pretty; }

/* ---- browser print -> clean white A4 (only the document prints) ---- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  body * { visibility: hidden; }
  .paper, .paper * { visibility: visible; }
  .paper {
    position: absolute; left: 0; top: 0; width: 100%;
    background: #fff; border: none; box-shadow: none; border-radius: 0; padding: 0;
  }
  /* never break through a line/photo/signature block */
  .pp-row, .pp-signs, .pp-photo-grid figure, .pp-cert { break-inside: avoid; page-break-inside: avoid; }
}

/* density variants set via body class */
body.dense { --pad: 13px; --gap: 9px; --tap: 46px; }
body.comfy { --pad: 20px; --gap: 16px; --tap: 56px; }
