/* Sổ tay xe — app.css (mobile-first, iOS PWA) */
:root {
  --bg: #f1f3f8; --card: #fff; --card2: #f6f7fb; --text: #0f172a; --muted: #5b6678; --faint: #67738a;
  --line: #e3e7ef; --star-off: #b7c0d0; --accent: #3355d8; --accent-ink: #fff; --accent-soft: #e6ebff;
  --red: #d92d20; --red-soft: #fee4e2; --amber: #b54708; --amber-soft: #fef0c7; --green: #067647; --green-soft: #d3f8df;
  --blue: #175cd3; --blue-soft: #e0ecff; --grey-soft: #eceff5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 18px rgba(16, 24, 40, .06);
  --r: 16px; --r-sm: 12px;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --tabh: 56px; --bar: rgba(255, 255, 255, .86);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b0f17; --card: #151b27; --card2: #1b2231; --text: #e8ecf4; --muted: #9aa6bb; --faint: #8793a8; --star-off: #4a566e;
  --line: #263044; --accent: #7e9bff; --accent-ink: #0b1020; --accent-soft: #1d2a52;
  --red: #ff8a80; --red-soft: #4a1d1a; --amber: #ffc069; --amber-soft: #43300f; --green: #5fd49a; --green-soft: #12382a;
  --blue: #8ab4ff; --blue-soft: #1a2c52; --grey-soft: #222b3c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .35);
  --bar: rgba(21, 27, 39, .86);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, [data-go], [data-act] { cursor: pointer; }
button { -webkit-touch-callout: none; touch-action: manipulation; }
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; }
.hide { display: none !important; }
body.kb #tabbar { display: none; }
body.kb #view { padding-bottom: 24px; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); } .faint { color: var(--faint); }
.small { font-size: 13px; } .tiny { font-size: 12px; }
.b { font-weight: 600; } .bb { font-weight: 700; }
.right { text-align: right; } .center { text-align: center; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; } .mt24 { margin-top: 24px; }
.mb8 { margin-bottom: 8px; }
.flex { display: flex; } .between { justify-content: space-between; } .gap8 { gap: 8px; } .gap12 { gap: 12px; } .aic { align-items: center; } .wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- khung ---------- */
#app { max-width: 680px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; }
#view { padding: 0 calc(16px + var(--sar)) calc(var(--tabh) + var(--sab) + 28px) calc(16px + var(--sal)); }
#view.notab { padding-bottom: calc(var(--sab) + 40px); }
.top {
  position: sticky; top: 0; z-index: 20; margin: 0 calc(-16px - var(--sar)) 0 calc(-16px - var(--sal)); padding: calc(var(--sat) + 6px) calc(12px + var(--sar)) 6px calc(12px + var(--sal));
  display: flex; align-items: center; gap: 8px; min-height: calc(var(--sat) + 52px);
  background: var(--bg);
  border-bottom: 1px solid transparent;
}
.top.scrolled { border-bottom-color: var(--line); }
.top .t { flex: 1; min-width: 0; text-align: center; font-weight: 700; font-size: 17px; }
.top .l, .top .r { min-width: 64px; display: flex; }
.top .r { justify-content: flex-end; }
.tbtn { border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 16px; padding: 8px 6px; min-height: 40px; border-radius: 10px; }
.tbtn:active { opacity: .5; }
.tbtn.danger { color: var(--red); }
.tbtn:disabled { opacity: .4; }
.h1 { font-size: 30px; line-height: 1.15; font-weight: 800; letter-spacing: -.02em; margin: 14px 0 4px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.sec { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 4px 8px; }
.sec h2 { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.sec .more { font-size: 14px; font-weight: 600; }

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center;
  background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line); padding-bottom: var(--sab);
}
#tabbar .in { width: 100%; max-width: 680px; height: var(--tabh); display: grid; grid-template-columns: 1fr 1fr 64px 1fr 1fr; align-items: center; }
#tabbar button { border: 0; background: none; color: var(--faint); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; padding: 6px 0; height: 100%; }
#tabbar button svg { width: 25px; height: 25px; }
#tabbar button.on { color: var(--accent); }
#tabbar button:active { opacity: .6; }
#tabbar .plus { position: relative; }
#tabbar .plus span {
  position: absolute; top: -14px; left: 50%; transform: translateX(-50%); width: 54px; height: 54px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: 0 6px 16px rgba(51, 85, 216, .4);
}
#tabbar .plus span svg { width: 28px; height: 28px; }
#tabbar .plus:active span { transform: translateX(-50%) scale(.94); }
#tabbar .badge { position: absolute; top: 3px; margin-left: 15px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
#tabbar .tabi { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; }

/* ---------- card / list ---------- */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.card + .card { margin-top: 12px; }
.list { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 54px; position: relative; background: none; border: 0; width: 100%; text-align: left; }
.list > .row + .row, .list > * + .row { border-top: 1px solid var(--line); }
.row[data-go], .row[data-act], .row.tap { cursor: pointer; }
.row[data-go]:active, .row[data-act]:active, .row.tap:active { background: var(--card2); }
.row .ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 20px; background: var(--grey-soft); flex: none; }
.row .main { flex: 1; min-width: 0; }
.row .ttl { font-weight: 600; }
.row .meta { color: var(--muted); font-size: 13px; }
.row.wrapacts { flex-wrap: wrap; row-gap: 6px; }
.row.wrapacts .main { flex: 1 1 120px; }
.row .acts { display: flex; align-items: center; gap: 2px; margin-left: auto; flex: none; }
.row .chev { color: var(--faint); flex: none; width: 18px; height: 18px; }
.row.alert-over .ico { background: var(--red-soft); } .row.alert-soon .ico { background: var(--amber-soft); }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--grey-soft); color: var(--muted); }
.pill.red { background: var(--red-soft); color: var(--red); } .pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.green { background: var(--green-soft); color: var(--green); } .pill.blue { background: var(--blue-soft); color: var(--blue); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--faint); }
.dot.red { background: var(--red); } .dot.amber { background: #f79009; } .dot.green { background: #12b76a; }
.kbd { font-variant-numeric: tabular-nums; }

/* ---------- nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 13px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px; text-align: center;
}
.btn:active { filter: brightness(.9); transform: scale(.985); }
.btn.block { display: flex; width: 100%; }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.grey { background: var(--grey-soft); color: var(--text); }
.btn.red { background: var(--red-soft); color: var(--red); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .45; }
.btn svg { width: 20px; height: 20px; }
.btns { display: flex; gap: 10px; } .btns > * { flex: 1; } .btns > .btn { padding: 0 10px; font-size: 15px; }

/* ---------- form ---------- */
.field { margin: 0 0 14px; }
.field > label, .lbl { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px 2px; }
.field .hint { margin: 5px 2px 0; }
.hint { font-size: 12px; color: var(--faint); }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--card);
  font-size: 16px; /* >=16px để iOS không tự phóng to */ -webkit-appearance: none; appearance: none;
}
textarea.input { min-height: 84px; resize: vertical; }
select.input { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%2394a0b4' stroke-width='2'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
input[type="date"].input { display: block; min-height: 46px; line-height: 24px; text-align: left; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.input.err { border-color: var(--red); }
.input::placeholder { color: var(--faint); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.with-unit { position: relative; } .with-unit .input { padding-right: 52px; } .with-unit.cur .input { padding-right: 30px; }
.with-unit .u { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); font-size: 14px; pointer-events: none; }
.seg { display: flex; background: var(--grey-soft); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 6px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); min-height: 36px; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 7px 12px; border-radius: 99px; font-size: 14px; font-weight: 600; min-height: 36px; }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.warn { border-color: var(--amber); }
.hscroll { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.hscroll::-webkit-scrollbar { display: none; }
.hscroll > * { flex: none; }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; z-index: 1; }
.switch i { position: absolute; inset: 0; background: #c7ccd6; border-radius: 99px; transition: .2s; }
.switch i::after { content: ""; position: absolute; width: 27px; height: 27px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: .2s; box-shadow: 0 2px 4px rgba(0, 0, 0, .25); }
.switch input:checked + i { background: #30b66a; } .switch input:checked + i::after { transform: translateX(20px); }
.stars { display: inline-flex; gap: 2px; } .stars button { border: 0; background: none; font-size: 26px; padding: 2px; color: var(--star-off); line-height: 1; }
.stars button.on { color: #f5a623; } .stars.ro button { font-size: 14px; padding: 0; pointer-events: none; }
.formline { background: var(--card2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px; margin-bottom: 10px; }
.formline .x { border: 0; background: none; color: var(--faint); font-size: 22px; line-height: 1; padding: 4px 8px; }
.err-msg { color: var(--red); font-size: 13px; margin: 6px 2px 0; }
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r); font-size: 14px; margin-bottom: 12px; background: var(--blue-soft); color: var(--text); }
.banner .x { border: 0; background: none; color: var(--muted); font-size: 22px; line-height: 1; margin-left: auto; padding: 0 4px; }
.banner.warn { background: var(--amber-soft); } .banner.bad { background: var(--red-soft); } .banner.ok { background: var(--green-soft); }
.banner .btn { margin-top: 8px; }

/* ---------- thành phần domain ---------- */
.vcard { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); margin-bottom: 10px; }
.vcard .ph { width: 64px; height: 64px; border-radius: 14px; background: var(--grey-soft); display: grid; place-items: center; font-size: 32px; overflow: hidden; flex: none; }
.vcard .ph img { width: 100%; height: 100%; object-fit: cover; }
.plate { display: inline-block; font-weight: 700; font-size: 12px; letter-spacing: .04em; padding: 1px 7px; border: 1.5px solid var(--text); border-radius: 5px; background: var(--card); }
.vhero { position: relative; border-radius: var(--r); overflow: hidden; background: linear-gradient(135deg, #3355d8, #1b2a78); color: #fff; padding: 16px; margin-top: 6px; box-shadow: var(--shadow); }
.vhero .photo { position: absolute; inset: 0; opacity: .38; }
.vhero .photo img { width: 100%; height: 100%; object-fit: cover; }
.vhero .in { position: relative; }
.vhero .plate { color: #fff; border-color: rgba(255, 255, 255, .8); background: rgba(255, 255, 255, .14); }
.vhero .odo { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.vhero .btn { background: rgba(255, 255, 255, .2); color: #fff; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 12px 14px; }
.stat .v { font-size: 22px; font-weight: 800; letter-spacing: -.02em; } .stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.bar { height: 6px; border-radius: 3px; background: var(--grey-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: #12b76a; }
.bar.amber > i { background: #f79009; } .bar.red > i { background: #f04438; } .bar.blue > i { background: var(--accent); }
.tabs { display: flex; gap: 0; overflow-x: auto; margin: 14px -16px 12px; padding: 0 8px; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 1 0 auto; text-align: center; border: 0; background: none; padding: 10px 7px; font-weight: 600; font-size: 14px; color: var(--muted); border-bottom: 2.5px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .cnt.amber { background: #b54708; }
.tabs .cnt { font-size: 11px; background: #d92d20; color: #fff; border-radius: 9px; padding: 1px 6px; margin-left: 4px; }
.group-h { font-size: 13px; font-weight: 700; color: var(--muted); margin: 18px 4px 8px; display: flex; align-items: center; gap: 6px; }
.empty { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty .big { font-size: 46px; margin-bottom: 6px; }
.empty h3 { margin: 4px 0 6px; color: var(--text); font-size: 18px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 15px; }
.kv .k { color: var(--muted); } .kv .v { word-break: break-word; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.photos .ph { width: 76px; height: 76px; border-radius: 12px; background: var(--grey-soft); overflow: hidden; position: relative; border: 0; padding: 0; }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; }
.photos .ph .x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff; border: 0; font-size: 14px; line-height: 1; display: grid; place-items: center; }
.photos .add { border: 2px dashed var(--line); color: var(--faint); font-size: 28px; display: grid; place-items: center; background: none; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.hbar { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; }
.hbar + .hbar { border-top: 1px solid var(--line); }
.chart text { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart .bar-rect { fill: var(--accent); } .chart .bar-rect.cur { fill: var(--accent); } .chart .bar-rect.old { opacity: .45; }
.chart .grid { stroke: var(--line); stroke-width: 1; }

/* ---------- sheet / toast / dialog ---------- */
#layer { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
.scrim { position: absolute; inset: 0; background: rgba(8, 12, 22, .45); opacity: 0; transition: opacity .2s; pointer-events: auto; }
.scrim.in { opacity: 1; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 680px; max-height: 86vh; max-height: 86dvh; overflow: auto; pointer-events: auto;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 8px 16px calc(var(--sab) + 16px); transform: translateY(100%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.sheet.in { transform: none; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { margin: 0 0 10px; font-size: 18px; }
.sheet .opt { display: flex; align-items: center; gap: 14px; width: 100%; padding: 13px 8px; border: 0; background: none; text-align: left; border-radius: 12px; font-size: 17px; font-weight: 600; min-height: 52px; }
.sheet .opt:active { background: var(--card2); }
.sheet .opt .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); font-size: 20px; flex: none; }
.sheet .opt small { display: block; color: var(--muted); font-weight: 400; font-size: 13px; }
.dlg { position: absolute; left: 24px; right: 24px; top: 50%; transform: translateY(-50%) scale(.96); max-width: 400px; margin: 0 auto; background: var(--card); border-radius: 20px; padding: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); opacity: 0; transition: .18s; pointer-events: auto; }
.dlg.in { opacity: 1; transform: translateY(-50%) scale(1); }
.dlg h3 { margin: 0 0 8px; font-size: 18px; } .dlg p { margin: 0 0 16px; color: var(--muted); }
#toast { position: fixed; left: 0; right: 0; bottom: calc(var(--tabh) + var(--sab) + 14px); z-index: 70; display: flex; justify-content: center; pointer-events: none; padding: 0 16px; }
#toast.notab { bottom: calc(var(--sab) + 84px); }
#toast .t { background: #1c2333; color: #fff; padding: 12px 16px; border-radius: 14px; font-size: 15px; box-shadow: 0 8px 24px rgba(0, 0, 0, .3); display: flex; gap: 14px; align-items: center; pointer-events: auto; max-width: 560px; animation: tin .22s ease-out; }
#toast .t button { border: 0; background: none; color: #9db5ff; font-weight: 700; font-size: 15px; padding: 2px 4px; }
@keyframes tin { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- misc ---------- */
.sticky-actions { position: sticky; bottom: 0; margin: 20px -16px 0; padding: 12px 16px calc(var(--sab) + 12px); background: var(--bar); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); border-top: 1px solid var(--line); z-index: 10; }
.total-box { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 14px; border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.total-box .v { font-size: 22px; font-weight: 800; }
.install { display: flex; gap: 12px; }
.install ol { margin: 6px 0 0; padding-left: 20px; font-size: 14px; }
.sp { height: 1px; background: var(--line); margin: 14px 0; border: 0; }
@media (min-width: 700px) { body { background: var(--bg); } #app { box-shadow: 0 0 0 1px var(--line); background: var(--bg); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print {
  #tabbar, .top, #toast, #layer, .noprint { display: none !important; }
  :root, :root[data-theme="dark"] { --bg: #fff; --card: #fff; --card2: #fff; --text: #111; --muted: #555; --line: #ccc; --shadow: none; color-scheme: light; }
  body { background: #fff; color: #111; }
  #view { padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; background: #fff; }
}
