:root {
  --bg: #0f1419; --panel: #1a222c; --panel2: #232d39; --line: #2f3b49; --text: #eef2f6; --muted: #93a1b1;
  --yellow: #ffc61a; --green: #2fbf71; --red: #ff5c5c; --blue: #4ea1ff; --orange: #ff9f43;
  --r: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; }
a { color: var(--blue); }
.hidden { display: none !important; }
.wrap { max-width: 720px; margin: 0 auto; padding: 12px 16px 96px; }
.topbar { position: sticky; top: 0; z-index: 10; background: rgba(15,20,25,.96); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .who { color: var(--muted); font-size: 14px; }
.iconbtn { background: var(--panel2); border-radius: 10px; padding: 8px 12px; min-height: 40px; }
.sync { font-size: 14px; padding: 8px 16px; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--line); }
.sync.ok { background: #13281d; color: #8ee3b3; }
.sync.wait { background: #33280e; color: #ffd978; }
.sync.off { background: #3a1616; color: #ffb3b3; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin: 10px 0; }
.field { display: block; margin: 12px 0; }
.field > span { display: block; color: var(--muted); font-size: 14px; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=tel], input[type=number], input[type=date], input[type=search], select {
  width: 100%; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 18px; outline: none; }
input:focus, select:focus { border-color: var(--blue); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 12px 18px; border-radius: 12px; background: var(--panel2); font-weight: 600; font-size: 17px; }
.btn.block { width: 100%; }
.btn.primary { background: var(--yellow); color: #1b1b1b; }
.btn.green { background: var(--green); color: #06170d; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: .35; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; }
.tab { background: var(--panel2); border-radius: 999px; padding: 8px 14px; white-space: nowrap; font-size: 15px; }
.tab.on { background: var(--yellow); color: #1b1b1b; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; min-width: 58px; min-height: 46px; padding: 8px 10px; font-weight: 700; }
.chip.on { background: var(--blue); border-color: var(--blue); color: #04121f; }

/* Danh sách tuyến */
.route { display: block; width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; margin: 10px 0; }
.route .code { font-weight: 800; font-size: 18px; letter-spacing: .3px; }
.route .meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.prog { display: flex; gap: 4px; margin-top: 10px; }
.prog i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.prog i.on { background: var(--green); }
.prog i.pend { background: var(--yellow); }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); margin-left: 6px; vertical-align: middle; }
.badge.green { background: #173a27; color: #8ee3b3; }
.badge.yellow { background: #3a3012; color: #ffd978; }
.badge.red { background: #3e1a1a; color: #ffb3b3; }
.badge.blue { background: #10283f; color: #9ccaff; }

/* Chi tiết tuyến */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 15px; }
.kv b { font-weight: 600; }
.step { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; margin: 10px 0; }
.step.done { border-color: #245c3d; }
.step.pend { border-color: #6a5717; }
.step .num { width: 34px; height: 34px; border-radius: 50%; background: var(--panel2); display: grid; place-items: center; font-weight: 800; flex: none; }
.step.done .num { background: var(--green); color: #06170d; }
.step.pend .num { background: var(--yellow); color: #1b1b1b; }
.step .title { font-weight: 700; }
.step .sub { color: var(--muted); font-size: 13px; }
.step .time { font-size: 22px; font-weight: 800; }
.thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--panel2); flex: none; }
.warn { background: #3a2a10; border: 1px solid #6a5717; color: #ffe29a; border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }
.err { background: #3e1a1a; border: 1px solid #7a2e2e; color: #ffc2c2; border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }
.kpi { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi .card { margin: 0; text-align: center; }
.kpi .v { font-size: 26px; font-weight: 800; }
.kpi .ok { color: var(--green); } .kpi .bad { color: var(--red); }

/* Camera */
#cam { position: fixed; inset: 0; background: #000; z-index: 100; display: flex; flex-direction: column; }
#cam video { flex: 1; width: 100%; height: 100%; object-fit: cover; min-height: 0; }
#cam .ov { position: absolute; left: 0; right: 0; bottom: calc(118px + env(safe-area-inset-bottom)); padding: 0 14px 10px; pointer-events: none; }
#cam .ov .lab { display: inline-flex; border-radius: 8px; overflow: hidden; font-weight: 800; }
#cam .ov .lab span:first-child { background: var(--yellow); color: #1b1b1b; padding: 6px 10px; font-size: 16px; display: flex; align-items: center; }
#cam .ov .lab span:last-child { background: #fff; color: #132a5e; padding: 2px 10px; font-size: 28px; }
#cam .ov .lines { border-left: 3px solid var(--yellow); padding-left: 10px; margin-top: 8px; text-shadow: 0 1px 3px #000; font-size: 14px; }
#cam .ov .lines div:first-child { font-weight: 700; font-size: 15px; }
#cam .hint { position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 12px; right: 12px; text-align: center; background: rgba(0,0,0,.55); border-radius: 12px; padding: 8px 12px; font-size: 15px; }
#cam .bar { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 24px calc(18px + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: space-between; background: linear-gradient(transparent, rgba(0,0,0,.7)); }
#cam .shutter { width: 80px; height: 80px; border-radius: 50%; background: #fff; border: 6px solid rgba(255,255,255,.35); background-clip: padding-box; }
#cam .shutter:active { transform: scale(.94); background: var(--yellow); }
#cam .side { width: 80px; color: #fff; background: rgba(255,255,255,.12); border-radius: 12px; padding: 10px 0; }
#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 200; transition: opacity .25s; }
#flash.on { opacity: .8; transition: none; }

#toasts { position: fixed; left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #2a3440; color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.4); max-width: 520px; transition: opacity .4s; font-size: 15px; }
.toast.ok { background: #1c5b3a; } .toast.err { background: #7a2525; } .toast.warn { background: #6b5211; }
.toast.hide { opacity: 0; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
.tablewrap { overflow: auto; max-height: 60vh; border: 1px solid var(--line); border-radius: 12px; }
td.bad { color: var(--red); font-weight: 700; } td.ok { color: var(--green); font-weight: 700; }
@media print { body { background: #fff; color: #000; } .noprint { display: none !important; } }
