:root {
  --bg: #f3f5f4; --panel: #ffffff; --ink: #18211f; --muted: #66726f; --line: #dde3e1;
  --brand: #0f3d3e; --brand-2: #1a5e60; --accent: #e8a33d; --ok: #1f8a5b; --err: #c4423a; --warn: #b7791f;
  --soft: #eaf2f1; --radius: 10px; --nav-w: 220px; --top-h: 54px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", Roboto, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
a { color: var(--brand-2); }
h1 { font-size: 1.35rem; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h2 { font-size: 1.08rem; margin: 26px 0 10px; }
h3 { font-size: .98rem; margin: 18px 0 8px; }
.muted { color: var(--muted); } .sm { font-size: .85rem; } .big { font-size: 1.1rem; } .nowrap { white-space: nowrap; }
.strike { text-decoration: line-through; color: var(--muted); }
code { background: var(--soft); padding: 1px 5px; border-radius: 4px; font-size: .85em; }

/* top bar */
.top { position: fixed; inset: 0 0 auto 0; height: calc(var(--top-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 12px 0;
  background: var(--brand); color: #fff; display: flex; align-items: center; gap: 10px; z-index: 30; }
.brand { font-weight: 700; letter-spacing: .3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp { flex: 1; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 1.25rem; width: 40px; height: 40px; border-radius: 8px; cursor: pointer; }
.icon-btn:hover { background: rgba(0,0,0,.06); }
.top .icon-btn:hover { background: rgba(255,255,255,.12); }
#menuBtn { display: none; }
.pill { background: rgba(255,255,255,.14); color: #fff; border: 0; border-radius: 999px; padding: 7px 12px; font: inherit; font-size: .9rem; cursor: pointer; white-space: nowrap; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
.login .pill { background: var(--soft); color: var(--brand); }
.user { position: relative; }
.menu { position: absolute; right: 0; top: 44px; background: #fff; color: var(--ink); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 8px; min-width: 210px; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 10px; font: inherit; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--soft); }
.menu .muted { padding: 4px 10px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

/* nav */
.nav { position: fixed; top: calc(var(--top-h) + env(safe-area-inset-top)); bottom: 0; left: 0; width: var(--nav-w); background: #fff; border-right: 1px solid var(--line);
  overflow-y: auto; padding: 10px 8px; z-index: 20; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: var(--soft); }
.nav a.on { background: var(--brand); color: #fff; }
.nav .ni { width: 22px; text-align: center; }
.badge { margin-left: auto; background: var(--accent); color: #fff; font-style: normal; font-size: .75rem; font-weight: 700; min-width: 22px; text-align: center; padding: 1px 6px; border-radius: 999px; }
.scrim { display: none; }
main { margin-left: var(--nav-w); padding: calc(var(--top-h) + env(safe-area-inset-top) + 20px) 24px 60px; max-width: calc(1100px + var(--nav-w)); }

@media (max-width: 860px) {
  #menuBtn { display: inline-block; }
  .nav { transform: translateX(-105%); transition: transform .2s ease; width: 260px; box-shadow: 4px 0 24px rgba(0,0,0,.15); }
  body.nav-open .nav { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 15; }
  main { margin-left: 0; padding: calc(var(--top-h) + env(safe-area-inset-top) + 14px) 12px 70px; }
}

/* panels & forms */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.panel.narrow { max-width: 440px; }
label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea, .plate-field { margin-top: 4px; }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: #fff; border: 1px solid #c9d2cf; border-radius: 8px; padding: 9px 11px; min-height: 42px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
input:disabled { background: var(--bg); color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: .95rem; margin: 6px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; min-height: 0; margin: 0; flex: none; }
.check.big { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; flex-wrap: wrap; }
.check.big:has(input:checked) { border-color: var(--brand-2); background: var(--soft); }
.grid2, .grid3, .grid4 { display: grid; gap: 0 14px; }
.grid2 { grid-template-columns: repeat(2, 1fr); } .grid3 { grid-template-columns: repeat(3, 1fr); } .grid4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 860px) { .grid3, .grid4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; border-radius: 8px; padding: 10px 16px; min-height: 42px; border: 1px solid transparent; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--brand); color: #fff; } .btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: #fff; border-color: #c9d2cf; color: var(--ink); } .btn.ghost:hover { background: var(--soft); }
.btn.danger { color: var(--err); border-color: #e7c1be; }
.btn.big { width: 100%; padding: 13px; font-size: 1.05rem; margin-top: 8px; }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: .88rem; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.loading::after { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; flex: 0 1 auto; }
.toolbar input[type=search] { flex: 1 1 240px; }
.toolbar .check input, .tbl .check input { width: 20px; min-width: 0; }

.hint { background: var(--soft); color: var(--brand); border-radius: 8px; padding: 9px 12px; font-size: .9rem; margin-bottom: 12px; }
.hint.nocard { background: #fdf3e2; color: #8a5a12; }
.alert { background: #fbeceb; color: #8e2a24; border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
.alert.sm { font-size: .88rem; padding: 6px 10px; }
.note { background: #fffbea; border-radius: 6px; padding: 6px 10px; margin: 6px 0; font-size: .92rem; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }
.loading-page { height: 120px; }
.count { background: var(--accent); color: #fff; font-size: .85rem; border-radius: 999px; padding: 1px 10px; }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; }

/* segmented type selector */
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.seg button { font: inherit; padding: 9px 14px; border-radius: 999px; border: 1px solid #c9d2cf; background: #fff; cursor: pointer; }
.seg button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs a.on { color: var(--brand); border-color: var(--brand); font-weight: 600; }

/* plates */
.plate-field { display: flex; align-items: center; gap: 8px; }
.plate-field input { text-transform: uppercase; font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .5px; }
.plate-prev { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; color: var(--ok); white-space: nowrap; min-width: 0; }
.plate-prev.bad { color: var(--err); }
.prow { display: grid; grid-template-columns: 1fr 130px 40px; gap: 8px; align-items: center; margin-bottom: 8px; }
@media (max-width: 520px) { .prow { grid-template-columns: 1fr 110px 36px; } .plate-field { flex-wrap: wrap; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { background: var(--soft); border-radius: 6px; padding: 3px 8px; font-size: .88rem; font-family: ui-monospace, Menlo, Consolas, monospace; }
.chip.dim { opacity: .6; }
.vt { font-family: inherit; font-size: .75rem; color: var(--muted); background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }

/* account picker */
.acc-results { display: grid; gap: 6px; }
.acc-item { text-align: left; font: inherit; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.acc-item:hover { border-color: var(--brand-2); background: var(--soft); }
.picked { background: var(--soft); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.acc-line { margin: 6px 0; display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }

/* orders */
.order { position: relative; }
.ohead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.st, .tt { display: inline-block; font-size: .78rem; font-weight: 600; border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.tt { background: #e7eef9; color: #2a4f8a; }
.tt-new_account, .tt-add_plate, .tt-card_damage { background: #e5f3ec; color: #1d6b48; }
.tt-cancel_plate, .tt-cancel_account { background: #fbeceb; color: #8e2a24; }
.tt-topup { background: #fdf3e2; color: #8a5a12; }
.st { background: #eef0ef; color: #4b5653; }
.st-awaiting_card, .st-awaiting_entry, .st-r_submitted, .st-a_pending, .st-p_pending { background: #fdf3e2; color: #8a5a12; }
.st-card_made { background: #e7eef9; color: #2a4f8a; }
.st-completed, .st-r_approved, .st-a_active, .st-p_active { background: #e5f3ec; color: #1d6b48; }
.st-void, .st-r_rejected, .st-a_cancelled, .st-p_cancelled, .st-p_void, .st-a_void { background: #fbeceb; color: #8e2a24; }
.items { width: 100%; border-collapse: collapse; margin: 8px 0; }
.items td { padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; }
.copy { cursor: copy; border-bottom: 1px dotted transparent; }
.copy:hover { border-bottom-color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 8px 0; }
.kv span { color: var(--muted); font-size: .9rem; }
.sumline { background: var(--soft); border-radius: 8px; padding: 8px 12px; margin: 6px 0 10px; min-height: 1em; }
.sumline:empty { display: none; }

/* card scanning */
.card-rows { display: grid; gap: 8px; margin-top: 10px; }
.card-row { display: grid; grid-template-columns: minmax(140px, 1fr) 2fr; gap: 10px; align-items: center; background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.card-row .plate { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.15rem; }
.card-in { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.1rem; letter-spacing: .5px; }
.card-in:focus { outline: 3px solid var(--accent); background: #fffaf0; }
.card-in.dupe { border-color: var(--err); background: #fbeceb; }
@media (max-width: 520px) { .card-row { grid-template-columns: 1fr; } }

/* months */
.months { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.mchip { font: inherit; padding: 8px 12px; border-radius: 8px; border: 1px solid #c9d2cf; background: #fff; cursor: pointer; font-variant-numeric: tabular-nums; }
.mchip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* shift report */
.inc { border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; background: #fffdf8; }
.inc-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.inc-head select { flex: 1; font-weight: 600; }
.addinc { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.photos, .newph { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.ph { position: relative; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; background: var(--line); }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.phx { position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: .8rem; }
.file-btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border: 1px dashed var(--brand-2); color: var(--brand-2); border-radius: 8px; cursor: pointer; font-size: .92rem; margin: 4px 0; }
.rrow { display: grid; gap: 4px; }
.rrow .btn { justify-self: start; margin-top: 4px; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); background: #f8faf9; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.link { cursor: pointer; } .tbl tr.link:hover { background: var(--soft); }
.tbl td input { min-height: 34px; padding: 5px 8px; }
.tbl .roles { display: flex; flex-wrap: wrap; gap: 2px 10px; }
.tbl .roles .check { font-size: .85rem; margin: 2px 0; }
.tbl .detail { max-width: 360px; font-size: .8rem; color: var(--muted); word-break: break-all; }
.roles { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 6px 0 10px; }
details > summary { cursor: pointer; list-style: none; }
details[open] > summary { margin-bottom: 12px; }

/* home */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 18px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-decoration: none; color: var(--ink); }
.tile .n { font-size: 2rem; font-weight: 700; color: var(--brand); font-variant-numeric: tabular-nums; }
.tile.warn { border-color: var(--accent); } .tile.warn .n { color: var(--warn); }
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.qbtn { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); font-weight: 600; text-align: center; }
.qbtn span { font-size: 1.6rem; }
.qbtn:hover { border-color: var(--brand-2); }

/* daily */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.sl { color: var(--muted); font-size: .85rem; } .sv { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; } .ss { font-size: .8rem; color: var(--muted); }
.preview { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: .92rem; max-width: 620px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand) 0%, #164e4f 55%, var(--bg) 55.1%); }
.login { width: 100%; max-width: 380px; padding: 24px; box-shadow: 0 18px 50px rgba(0,0,0,.15); }
.login-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.logo { width: 44px; height: 44px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.4rem; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* toasts */
#toasts { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(92vw, 440px); }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); transition: opacity .4s, transform .4s; white-space: pre-line; }
.toast.ok { background: var(--ok); } .toast.err { background: var(--err); }
.toast.out { opacity: 0; transform: translateY(8px); }

@media print { .top, .nav, .actions, .toolbar { display: none !important; } main { margin: 0; padding: 0; } }

/* ===== v2: plate type input ===== */
.pin { flex: 1; min-width: 0; }
.kinds { display: flex; gap: 4px; margin-bottom: 6px; }
.kinds button { flex: 1; font: inherit; font-size: .9rem; padding: 8px 6px; border: 1px solid #c9d2cf; background: #fff; border-radius: 8px; cursor: pointer; }
.kinds button.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pin-f input { font-family: ui-monospace, Menlo, Consolas, monospace; text-transform: uppercase; letter-spacing: .5px; }
.pin-f.gov { display: grid; grid-template-columns: 1fr auto 1fr auto 2fr; gap: 6px; align-items: center; }
.pin-f.gov[hidden] { display: none; }
.pin-f.gov span { font-size: 1.3rem; color: var(--muted); }
.pin-f.gov input { text-align: center; }
.pin-st { font-size: .85rem; color: var(--muted); margin-top: 4px; font-family: ui-monospace, Menlo, Consolas, monospace; min-height: 1.2em; }
.pin-st.ok { color: var(--ok); font-weight: 600; } .pin-st.bad { color: var(--err); font-weight: 600; }
.prow2 { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: #fbfcfc; }
.prow2-top { display: grid; grid-template-columns: 1fr 120px 36px; gap: 8px; align-items: start; }
.prow2-top select { margin-top: 0; }
@media (max-width: 520px) { .prow2-top { grid-template-columns: 1fr 36px; } .prow2-top select { grid-row: 2; grid-column: 1 / 3; } }
.areas-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.achip { margin: 0; cursor: pointer; }
.achip input { position: absolute; opacity: 0; width: 0; height: 0; min-height: 0; }
.achip span { display: inline-block; padding: 6px 12px; border: 1px solid #c9d2cf; border-radius: 999px; color: var(--ink); font-size: .88rem; background: #fff; }
.achip input:checked + span { background: #000; color: #fff; border-color: #000; font-weight: 700; }
.achip input:focus-visible + span { outline: 2px solid var(--brand-2); }
.printed { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: #e5f3ec; color: #1d6b48; border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; }

/* 2FA */
.mfa h1 { font-size: 1.15rem; }
.qrbox { text-align: center; }
.qrbox .qr { width: 200px; height: 200px; margin: 6px auto 10px; display: block; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 8px; }
.steps { text-align: left; padding-left: 20px; margin: 6px 0; font-size: .92rem; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1rem; letter-spacing: 1px; background: var(--soft); padding: 8px; border-radius: 6px; margin: 6px 0; word-break: break-all; user-select: all; }
.otp { font-size: 1.8rem !important; letter-spacing: .5em; text-align: center; font-family: ui-monospace, Menlo, Consolas, monospace; margin: 8px 0 4px; }
.mfa #lo { margin-top: 10px; }

/* settings assets */
.assets { display: flex; gap: 16px; flex-wrap: wrap; margin: 8px 0 4px; }
.asset { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.asset img { max-height: 90px; max-width: 160px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }

/* report image preview */
.rimg-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; margin-bottom: 12px; }
.rimg { width: 100%; max-width: 1000px; display: block; border-radius: 6px; }
h2 .btn { margin-left: 8px; vertical-align: middle; }
