@font-face { font-family: 'Noto Sans Lao'; src: url('/static/fonts/NotoSansLao-Regular.ttf'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Noto Sans Lao'; src: url('/static/fonts/NotoSansLao-Bold.ttf'); font-weight: 700; font-display: swap; }

:root {
  --bg: #FAFAF7; --card: #FFFFFF; --ink: #141414; --muted: #6B6B6B; --line: #ECEAE4; --line2: #F1EFEA; --field: #DAD7CE;
  --hover: #F3F1EA; --gold: #8A6100; --ok: #2F5E3A; --okbg: #EEF4EE; --due: #7A5300; --duebg: #FFF2D6; --bad: #9B1C14; --badbg: #FDE8E6;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans Lao', 'Noto Sans Thai', sans-serif; -webkit-text-size-adjust: 100%; }
:lang(lo) body, body:lang(lo) { font-family: 'Noto Sans Lao', system-ui, sans-serif; }
h1 { margin: 0; font-size: 28px; font-weight: 700; }
h2 { margin: 0; font-size: 16px; font-weight: 600; }
a { color: var(--gold); }
button, input, select { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); } .sm { font-size: 13px; } .gold { color: var(--gold); } .big2 { font-size: 17px; } .xl2 { font-size: 20px; font-weight: 700; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; } .mono { font-family: 'Courier New', monospace; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .right { display: flex; flex-direction: column; align-items: flex-end; }

/* top bar */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.tabs { display: flex; gap: 4px; flex: 1 1 420px; overflow-x: auto; scrollbar-width: none; }
.tab { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 10px; color: #5C5C5C; text-decoration: none; font-weight: 500; white-space: nowrap; }
.tab:hover { background: var(--hover); color: var(--ink); }
.tab.on, .tab.on:hover { background: var(--ink); color: #FFF; }
.who { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.who select { min-height: 36px; border: 1px solid var(--field); border-radius: 8px; background: #FFF; padding: 0 6px; }

/* layout */
.page { max-width: 1240px; margin: 0 auto; padding: 22px 20px 60px; display: flex; flex-direction: column; gap: 18px; }
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px 16px; }
.head > div:first-child { display: flex; flex-direction: column; gap: 2px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.cols { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.main-col { flex: 3 1 520px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.side-col { flex: 2 1 330px; min-width: 0; display: flex; flex-direction: column; gap: 12px; order: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.row2 { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; } .row2 > * { flex: 1 1 140px; }
.row3 { display: grid; grid-template-columns: 1fr 1.3fr 1.3fr; gap: 10px; align-items: end; } .pname { display: flex; flex-direction: column; align-items: flex-start; }
.r { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; }
.soft { background: var(--bg); border-radius: 12px; padding: 12px; }
.strong { border: 2px solid var(--ink); }
.endy { align-items: flex-end; }
.scroll { overflow-x: auto; }

/* pieces */
.prices { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 36px; }
.prices > div:first-child { display: flex; flex-direction: column; gap: 2px; }
.price { display: flex; flex-direction: column; gap: 2px; font-variant-numeric: tabular-nums; }
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kv { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; } .kv.xl { font-size: 32px; }
.actions .btn { min-height: 56px; font-size: 17px; }
.lrow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 11px 0; border-bottom: 1px solid var(--line2); }
.lrow:last-child { border-bottom: 0; } .grow { flex: 1 1 220px; min-width: 0; } a.grow { color: inherit; text-decoration: none; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--hover); white-space: nowrap; }
.pill-ok { background: var(--okbg); color: var(--ok); } .pill-due { background: var(--duebg); color: var(--due); }
.pill-bad { background: var(--badbg); color: var(--bad); } .pill-mute { background: var(--line2); color: var(--muted); }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 20px; border: 0; border-radius: 12px; background: var(--ink); color: #FFF; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: #2B2B2B; color: #FFF; } .btn:disabled { opacity: .45; cursor: default; } .btn.xl { min-height: 58px; font-size: 18px; }
.btn2 { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--field); border-radius: 10px; background: #FFF; color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn2:hover { background: var(--hover); color: var(--ink); } .btn2.sm { min-height: 36px; padding: 0 12px; font-size: 13px; } .btn2.sq { min-width: 44px; padding: 0; font-size: 20px; }
.link { border: 0; background: none; padding: 6px 0; min-height: 36px; color: var(--gold); font-weight: 600; cursor: pointer; text-align: left; }
.link.bad { color: var(--bad); }
.fld { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: var(--muted); }
.fld input, .fld select { min-height: 46px; padding: 0 12px; border: 1px solid var(--field); border-radius: 10px; background: #FFF; color: var(--ink); font-size: 15px; width: 100%; }
.fld input:focus, .fld select:focus, .scan input:focus { outline: 2px solid var(--ink); outline-offset: 1px; }
.money { text-align: right; font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 8px; min-height: 40px; } .check input { width: 20px; height: 20px; accent-color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 42px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--field); background: #FFF; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; }
span.chip { cursor: default; font-weight: 500; }
.chip.on { background: var(--ink); color: #FFF; border-color: var(--ink); }

/* sell */
.scan { display: flex; align-items: center; gap: 12px; padding: 6px 16px; border: 2px solid var(--ink); }
.scan input { flex: 1; min-height: 52px; border: 0; background: transparent; font-size: 17px; outline: none; }
.wgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.wgrid:empty { display: none; }
.wbtn { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; border: 1px solid var(--field); border-radius: 12px; background: #FFF; cursor: pointer; min-height: 56px; }
.wbtn:hover { background: var(--hover); } .wbtn:disabled { opacity: .4; cursor: default; }
.qty { display: flex; align-items: center; gap: 10px; }
.totalbox { display: flex; flex-direction: column; gap: 2px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }

/* pawn, savings lists */
.prow { display: flex; flex-direction: column; gap: 6px; width: 100%; text-align: left; padding: 12px; margin-top: 6px; border-radius: 12px; border: 1px solid var(--line2); background: #FFF; cursor: pointer; }
.prow:hover { background: var(--bg); } .prow.on { border: 2px solid var(--ink); }
.pgrid { display: grid; grid-template-columns: .7fr 1.4fr 1.1fr .8fr .5fr 1.1fr 1fr; gap: 0 8px; align-items: center; font-variant-numeric: tabular-nums; }
.bar { display: block; height: 6px; border-radius: 99px; background: var(--line2); overflow: hidden; } .bar > span { display: block; height: 6px; background: #B8860B; }
.sv5 { display: grid; grid-template-columns: 1.4fr 1.1fr 1fr .8fr .5fr; gap: 0 8px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line2); font-variant-numeric: tabular-nums; }

/* stock */
.sgrid { display: grid; grid-template-columns: 1.6fr 1fr .7fr 1fr 1fr .5fr .5fr 1.6fr; gap: 0 8px; align-items: center; min-width: 880px; padding: 8px 4px; border-bottom: 1px solid var(--line2); }
.sghead { background: var(--bg); padding-top: 14px; border-bottom: 1px solid var(--line); } .shead { border-bottom: 1px solid var(--line); }
.span2 { grid-column: span 2; } .span4 { grid-column: span 4; }
.acts { display: flex; gap: 6px; justify-content: flex-end; }

/* login, dialog, toast */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login form { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 26px; }
dialog { border: 0; border-radius: 18px; padding: 0; width: min(480px, calc(100% - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,20,20,.45); }
.mform { display: flex; flex-direction: column; gap: 14px; padding: 22px; }
.mbody { display: flex; flex-direction: column; gap: 12px; } .mbody p { margin: 0; }
.merr { margin: 0; color: var(--bad); font-weight: 600; min-height: 1em; } .merr:empty { display: none; }
.mbtns { display: flex; gap: 10px; } .mbtns > * { flex: 1; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; padding: 12px 18px; border-radius: 12px; background: var(--ink); color: #FFF; font-weight: 600; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.err { background: var(--bad); }

@media (max-width: 640px) {
  .top { padding: 8px 12px; } .who .muted { display: none; } .page { padding: 16px 12px 60px; }
  h1 { font-size: 24px; } .kv { font-size: 21px; } .row3 { grid-template-columns: 1fr 1fr; } .row3 > b, .row3 > .pname { grid-column: span 2; } .row3 > .pname { flex-direction: row; justify-content: space-between; align-items: center; }
  .pgrid { grid-template-columns: .6fr 1.3fr .8fr 1fr .9fr; font-size: 14px; } .pgrid > :nth-child(3), .pgrid > :nth-child(5) { display: none; }
  .sv5 { grid-template-columns: 1.3fr 1fr .8fr .5fr; } .sv5 > :nth-child(3) { display: none; }
}
@media print { .top, .toast { display: none; } }

/* thin loading line under the top bar, only when the server is slow */
body.loading .top::after { content: ''; position: absolute; left: 0; bottom: -2px; height: 2px; width: 30%; background: var(--ink); animation: gsload 1s ease-in-out infinite; }
@keyframes gsload { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) { body.loading .top::after { animation: none; width: 100%; opacity: .4; } }
.sth { margin: 16px 0 2px; } .sth:first-child { margin-top: 0; }
.picwrap { max-height: 60vh; overflow: auto; background: #F3F1EA; border-radius: 12px; padding: 10px; }
.picwrap img { -webkit-touch-callout: default; display: block; width: 100%; max-width: 320px; margin: 0 auto; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
#picdlg { border: 0; border-radius: 16px; padding: 0; width: min(440px, calc(100% - 24px)); }
#picdlg::backdrop { background: rgba(20,20,20,.45); }
.rtab { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rtab th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.rtab td { padding: 9px 10px; border-bottom: 1px solid var(--line2); white-space: nowrap; }
.rtab tr:last-child td { border-bottom: 0; }
.rtab .num { text-align: right; }
