@font-face {
    font-family: 'LaoUI';
    src: url('fonts/NotoSansLao-Regular.ttf') format('truetype');
    font-display: swap;
}

:root {
    --primary: #1257c7;
    --primary-dark: #0b3f96;
    --primary-soft: #e8f0fd;
    --plate: #ffd400;
    --plate-ink: #111;
    --bg: #eef2f7;
    --surface: #fff;
    --text: #17202c;
    --muted: #6a7686;
    --line: #dfe5ee;
    --ok: #12905a;
    --ok-soft: #e3f6ec;
    --danger: #d23a3a;
    --danger-soft: #fdeaea;
    --warn: #c47a00;
    --radius: 16px;
    --shadow: 0 2px 10px rgba(16, 38, 77, .08);
    --appbar-h: 58px;
    --tabbar-h: 64px;
    --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; }

body {
    font-family: 'LaoUI', 'Noto Sans Lao', 'Phetsarath OT', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.3; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

.ic { width: 22px; height: 22px; flex: none; }

/* ---------------------------------------------------------- app chrome */
.appbar {
    position: sticky; top: 0; z-index: 50;
    height: var(--appbar-h);
    display: flex; align-items: center; gap: 10px;
    padding: 0 12px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
.appbar-logo, .appbar-btn {
    width: 38px; height: 38px; border-radius: 12px;
    display: grid; place-items: center;
    background: rgba(255, 255, 255, .16); color: #fff;
}
.appbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.appbar-title strong { font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-title small { opacity: .8; font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-user {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--plate); color: var(--plate-ink);
    display: grid; place-items: center; font-weight: 700;
}

.page {
    max-width: 760px;
    margin: 0 auto;
    padding: 12px 12px calc(var(--tabbar-h) + var(--safe-b) + 16px);
}
body.no-tabbar .page { padding-bottom: 24px; }

.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    height: calc(var(--tabbar-h) + var(--safe-b));
    padding-bottom: var(--safe-b);
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(16, 38, 77, .06);
}
.tabbar a {
    flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); font-size: .72rem; white-space: nowrap;
}
.tabbar a.active { color: var(--primary); font-weight: 700; }
.tabbar a.active .ic { background: var(--primary-soft); border-radius: 12px; padding: 3px 10px; width: 44px; height: 28px; }

/* --------------------------------------------------------------- cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
    margin-bottom: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ------------------------------------------------------------- buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 44px; padding: 0 16px;
    border: 0; border-radius: 12px;
    background: var(--primary-soft); color: var(--primary);
    font: inherit; font-weight: 700;
    cursor: pointer; user-select: none;
    transition: transform .06s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-light { background: #f1f4f9; color: var(--text); }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 1.1rem; border-radius: 14px; }
.btn-sm { min-height: 34px; padding: 0 10px; font-size: .85rem; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

/* --------------------------------------------------------------- forms */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.input, select.input, textarea.input {
    width: 100%; min-height: 46px;
    padding: 10px 12px;
    border: 1.5px solid var(--line); border-radius: 12px;
    background: #fff; color: var(--text);
    font: inherit;
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.type-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.3fr) minmax(0, .8fr) auto auto; gap: 6px; align-items: center; margin-bottom: 8px; }
.type-row .input { padding: 8px; min-height: 40px; }
.type-card { border: 1.5px solid var(--line); border-radius: 14px; padding: 10px; margin-bottom: 10px; }
.type-card.type-new { border-style: dashed; }
.type-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.type-grid .tg-name { grid-column: span 2; }
.type-grid label span { display: block; font-size: .72rem; color: var(--muted); margin-bottom: 2px; }
.type-grid .input { padding: 8px; min-height: 40px; }
.type-grid .dim { opacity: .55; }
.type-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; }
.switch input { width: 22px; height: 22px; accent-color: var(--primary); }

/* ---------------------------------------------------------------- chips */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
    flex: none; padding: 6px 12px; border-radius: 999px;
    background: #fff; border: 1.5px solid var(--line); color: var(--text);
    font-size: .85rem; white-space: nowrap; cursor: pointer;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-void { background: var(--danger-soft); color: var(--danger); }
.badge-admin { background: #fff3cd; color: #8a5a00; }

/* ===================================================== ticket entry (car) */
.entry { display: flex; flex-direction: column; gap: 10px; }

.types { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.type-btn {
    position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 64px; padding: 6px;
    border-radius: 14px; border: 2px solid var(--line);
    background: #fff; color: var(--text); font: inherit; cursor: pointer;
}
.type-btn strong { font-size: 1.05rem; }
.type-btn span { font-size: .82rem; color: var(--muted); }
.type-btn.active { border-color: var(--primary); background: var(--primary-soft); }
.type-btn.active strong { color: var(--primary); }
.type-btn.active::after {
    content: '✓'; position: absolute; top: 4px; right: 8px; color: var(--primary); font-weight: 700;
}

.plate {
    background: var(--plate);
    border: 4px solid #111;
    border-radius: 14px;
    padding: 6px 10px 10px;
    box-shadow: inset 0 0 0 2px var(--plate), inset 0 0 0 4px rgba(0, 0, 0, .55), var(--shadow);
    color: var(--plate-ink);
}
.plate-province {
    width: 100%;
    border: 0; background: transparent;
    font: inherit; font-weight: 700; font-size: 1.1rem; text-align: center; text-align-last: center;
    color: var(--plate-ink);
    padding: 4px 24px; appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23111' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 6px center;
    border-bottom: 2px solid rgba(0, 0, 0, .7);
    cursor: pointer;
}
.plate-main { display: flex; align-items: stretch; justify-content: center; gap: 10px; margin-top: 6px; }
.plate-slot {
    flex: 1; min-width: 0;
    display: flex; align-items: center; justify-content: center;
    min-height: 64px;
    border-radius: 10px;
    font-size: 2.4rem; font-weight: 700; letter-spacing: 2px; line-height: 1;
    cursor: pointer;
    border: 2px dashed transparent;
}
.plate-slot.letters { flex: 0 0 38%; }
.plate-slot.focus { border-color: rgba(0, 0, 0, .55); background: rgba(255, 255, 255, .35); }
.plate-slot .ph { opacity: .3; }

.today-strip {
    display: flex; justify-content: space-between; align-items: center;
    font-size: .85rem; color: var(--muted); padding: 0 4px;
}
.today-strip b { color: var(--text); }

.kp-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.kp-tabs button { min-height: 38px; border-radius: 10px; border: 0; background: #e3e9f2; font: inherit; color: var(--muted); cursor: pointer; }
.kp-tabs button.active { background: #26303d; color: #fff; font-weight: 700; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad.letters { grid-template-columns: repeat(6, 1fr); gap: 6px; }
.key {
    min-height: 58px;
    border: 0; border-radius: 14px;
    background: #fff; color: var(--text);
    font: inherit; font-size: 1.6rem; font-weight: 700;
    box-shadow: 0 2px 0 #cfd8e5;
    cursor: pointer; user-select: none;
    display: flex; align-items: center; justify-content: center;
}
.keypad.letters .key { min-height: 46px; font-size: 1.3rem; border-radius: 10px; }
.key:active { transform: translateY(2px); box-shadow: none; background: #f2f5fa; }
.key.fn { background: #e3e9f2; font-size: 1.05rem; color: var(--muted); }
.key.fn .ic { width: 26px; height: 26px; }

.save-btn {
    min-height: 62px; width: 100%;
    border: 0; border-radius: 16px;
    background: linear-gradient(135deg, #16a765, #0f8a52);
    color: #fff; font: inherit; font-size: 1.2rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    box-shadow: 0 4px 14px rgba(18, 144, 90, .35);
    cursor: pointer;
}
.save-btn:active { transform: scale(.98); }
.save-btn:disabled { filter: grayscale(.6); opacity: .7; }
.save-btn .amt { background: rgba(255, 255, 255, .2); padding: 2px 10px; border-radius: 999px; font-size: 1rem; }

/* --------------------------------------------------------- bottom sheet */
.sheet-backdrop {
    position: fixed; inset: 0; z-index: 90;
    background: rgba(10, 20, 35, .45);
    opacity: 0; pointer-events: none; transition: opacity .2s;
}
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
    max-width: 560px; margin: 0 auto;
    max-height: 92vh; overflow-y: auto;
    background: var(--surface);
    border-radius: 22px 22px 0 0;
    padding: 10px 16px calc(16px + var(--safe-b));
    transform: translateY(105%); transition: transform .25s ease;
}
.sheet::before { content: ''; display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
.sheet-open .sheet { transform: translateY(0); }
.sheet-success { text-align: center; color: var(--ok); font-weight: 700; margin-bottom: 8px; font-size: 1.05rem; }

/* ----------------------------------------------- on-screen receipt view */
.receipt-preview {
    width: 100%; max-width: 300px; margin: 0 auto 12px;
    background: #fff; border: 1px solid var(--line); border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .08);
    padding: 6px;
}
.receipt-preview canvas { width: 100%; height: auto; display: block; }

/* ---------------------------------------------------------- list items */
.filters { display: flex; flex-direction: column; gap: 8px; }
.search-box { position: relative; }
.search-box .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; }
.search-box .input { padding-left: 38px; }

.summary-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat {
    background: var(--surface); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow);
    min-width: 0;
}
.stat small { display: block; color: var(--muted); font-size: .75rem; }
.stat b { display: block; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat.primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; }
.stat.primary small { color: rgba(255, 255, 255, .8); }

.tlist { list-style: none; margin: 0; padding: 0; }
.titem {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 2px; border-bottom: 1px solid var(--line);
}
.titem:last-child { border-bottom: 0; }
.titem.void { opacity: .6; }
.titem.void .tplate { text-decoration: line-through; }
.tplate-badge {
    flex: none; min-width: 74px; padding: 4px 6px;
    background: var(--plate); border: 2px solid #111; border-radius: 8px;
    text-align: center; line-height: 1.15; font-weight: 700;
}
.tplate-badge small { display: block; font-size: .6rem; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 80px; }
.tinfo { flex: 1; min-width: 0; }
.tinfo .t1 { font-weight: 700; }
.tinfo .t2 { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tamt { text-align: right; font-weight: 700; white-space: nowrap; }
.tactions { display: flex; gap: 4px; }
.icon-btn {
    width: 38px; height: 38px; border-radius: 10px; border: 0;
    display: grid; place-items: center; background: #f1f4f9; color: var(--text); cursor: pointer;
}
.icon-btn.danger { color: var(--danger); background: var(--danger-soft); }
.icon-btn .ic { width: 19px; height: 19px; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.pager { display: flex; justify-content: center; gap: 8px; margin-top: 10px; }

/* -------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th, .tbl td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.tbl th { color: var(--muted); font-weight: 400; font-size: .78rem; }
.tbl td.num, .tbl th.num { text-align: right; white-space: nowrap; }
.tbl tfoot td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--text); }
.bar { height: 8px; border-radius: 4px; background: var(--primary); min-width: 2px; }
.bar-track { background: #eef2f7; border-radius: 4px; }

.hours { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; align-items: end; height: 90px; }
.hours div { background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; }
.hours-axis { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; font-size: .6rem; color: var(--muted); text-align: center; }

/* ---------------------------------------------------------- exit / scan */
.exit-card { border-top: 6px solid var(--line); }
.exit-card.exit-ok { border-top-color: var(--ok); }
.exit-card.exit-bad { border-top-color: var(--danger); background: #fffafa; }
.exit-card .save-btn { margin-top: 10px; }
.exit-card.exit-warn { border-top-color: var(--warn); background: #fffdf5; }
.ot-due {
    margin-top: 10px; padding: 10px 14px; border-radius: 14px;
    background: #fff3cd; color: #6b4500; text-align: center;
}
.ot-due small { display: block; font-size: .8rem; }
.ot-due b { display: block; font-size: 1.9rem; line-height: 1.2; }
.save-btn.ot-btn { background: linear-gradient(135deg, #e69500, #c47a00); box-shadow: 0 4px 14px rgba(196, 122, 0, .35); }
.exit-card .list-menu li { padding: 6px 0; }
.exit-plate {
    margin: 0 auto; max-width: 280px;
    background: var(--plate); border: 4px solid #111; border-radius: 14px;
    text-align: center; padding: 4px 10px 8px; line-height: 1.2;
}
.exit-plate small { display: block; font-weight: 700; border-bottom: 2px solid rgba(0, 0, 0, .7); padding-bottom: 2px; }
.exit-plate b { display: block; font-size: 2.3rem; letter-spacing: 2px; }

.scanner {
    position: fixed; inset: 0; z-index: 300; background: #000;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
    position: relative; width: min(70vw, 300px); aspect-ratio: 1;
    border-radius: 20px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .45);
    border: 3px solid #fff;
}
.scan-frame::after {
    content: ''; position: absolute; left: 8%; right: 8%; height: 3px; top: 10%;
    background: #3cf08a; box-shadow: 0 0 12px #3cf08a; animation: scanline 1.8s ease-in-out infinite alternate;
}
@keyframes scanline { to { top: 88%; } }
.scan-hint { position: relative; color: #fff; margin-top: 18px; font-size: 1rem; text-shadow: 0 1px 4px #000; }
.scanner .btn { position: absolute; bottom: calc(24px + var(--safe-b)); left: 50%; transform: translateX(-50%); min-width: 160px; }

.badge-park { background: #fff3cd; color: #8a5a00; }

/* --------------------------------------------------------------- login */
.login-wrap {
    min-height: 100vh; display: flex; flex-direction: column; justify-content: center;
    padding: 24px 18px;
    background: linear-gradient(160deg, var(--primary) 0%, var(--primary-dark) 55%, #082a63 100%);
}
.login-card { width: 100%; max-width: 380px; margin: 0 auto; background: #fff; border-radius: 22px; padding: 26px 20px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.login-logo { width: 72px; height: 72px; border-radius: 20px; margin: 0 auto 10px; background: var(--plate); display: grid; place-items: center; border: 3px solid #111; }
.login-logo .ic { width: 40px; height: 40px; color: #111; }
.login-card h1 { text-align: center; font-size: 1.25rem; margin-bottom: 2px; }
.login-card h1.brand { font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; font-size: 1.7rem; font-weight: 800; letter-spacing: -.5px; color: var(--primary-dark); }
.login-card p.sub { text-align: center; color: var(--muted); margin: 0 0 18px; font-size: .88rem; }
.alert { padding: 10px 12px; border-radius: 12px; margin-bottom: 12px; font-size: .9rem; }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--primary-soft); color: var(--primary-dark); }

/* --------------------------------------------------------------- toast */
.toast {
    position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); z-index: 200;
    transform: translate(-50%, 20px);
    max-width: 92vw; padding: 10px 18px; border-radius: 12px;
    background: #1d2633; color: #fff; font-size: .92rem;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .25);
    opacity: 0; pointer-events: none; transition: all .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--ok); }

/* ----------------------------------------------------- settings tiles */
.list-menu { list-style: none; margin: 0; padding: 0; }
.list-menu li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-menu li:last-child { border-bottom: 0; }
details.card > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; font-weight: 700; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: '▾'; color: var(--muted); transition: transform .2s; }
details.card[open] > summary { margin-bottom: 12px; }
details.card[open] > summary::after { transform: rotate(180deg); }

/* --------------------------------------------- small phones / big POS */
@media (max-height: 680px) {
    .key { min-height: 50px; font-size: 1.4rem; }
    .plate-slot { min-height: 54px; font-size: 2.1rem; }
    .type-btn { min-height: 54px; }
    .save-btn { min-height: 54px; }
}
@media (min-width: 700px) {
    .entry-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
}

/* ================================================================ PRINT */
#print-area { display: none; }

@media print {
    /* ບີນ 58/80mm (JS ໃສ່ @page size ໃຫ້) */
    body.print-receipt { background: #fff !important; margin: 0; }
    body.print-receipt > *:not(#print-area) { display: none !important; }
    body.print-receipt #print-area { display: block !important; margin: 0 auto; }
    body.print-receipt #print-area img { width: 100%; display: block; }

    /* ພິມໜ້າປົກກະຕິ (ລາຍງານ A4) */
    body:not(.print-receipt) { background: #fff !important; }
    body:not(.print-receipt) .appbar,
    body:not(.print-receipt) .tabbar,
    body:not(.print-receipt) .toast,
    body:not(.print-receipt) .no-print,
    body:not(.print-receipt) #print-area { display: none !important; }
    body:not(.print-receipt) .page { max-width: none; padding: 0; }
    body:not(.print-receipt) .card,
    body:not(.print-receipt) .stat { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
    body:not(.print-receipt) .stat.primary { background: #fff; color: #000; }
    body:not(.print-receipt) .stat.primary small { color: #555; }
    .print-only { display: block !important; }
}
.print-only { display: none; }

.login-body .page { padding: 0; max-width: none; }
