/* Giao diện dùng chung — cùng khung với Bảng giá Đức Hạnh, đổi màu cho app bảo hành ắc quy */
:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --ink: #1d2420;
  --muted: #66716b;
  --line: #dfe5e0;
  --brand: #14532d;
  --brand-ink: #ffffff;
  --accent: #c76a05;
  --danger: #b3261e;
  --ok: #1e7b3c;
  --ok-bg: #e3f3e8;
  --warn: #9a5b00;
  --warn-bg: #fff1d6;
  --bad: #b3261e;
  --bad-bg: #fde6e3;
  --zalo: #0068ff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(10, 40, 20, .06), 0 4px 14px rgba(10, 40, 20, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1411; --surface: #19201b; --ink: #ecf2ee; --muted: #a2b0a7; --line: #2c3730;
    --brand: #5fc98a; --brand-ink: #08130c; --accent: #f3a945; --danger: #ff8a7a; --ok: #6fd896; --ok-bg: #16301f;
    --warn: #f3b45a; --warn-bg: #33270f; --bad: #ff8a7a; --bad-bg: #3a1714;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.spacer { flex: 1; }
[hidden] { display: none !important; }
a { color: var(--accent); }

/* ===== Đầu trang khách ===== */
.hero { background: var(--brand); color: var(--brand-ink); padding: 24px 0 20px; }
.hero h1 { margin: 0; font-size: clamp(1.7rem, 6vw, 2.6rem); line-height: 1.1; font-weight: 800; }
.eyebrow { margin: 0 0 4px; text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; opacity: .85; }
.contact { margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .95rem; }
.contact a { color: inherit; font-weight: 600; text-decoration: none; }
.status { text-align: center; color: var(--muted); padding: 28px 0; margin: 0; }
.status.error { color: var(--danger); }
.foot { color: var(--muted); font-size: .8rem; padding: 8px 16px 32px; text-align: center; }

.viewer { border: 0; padding: 0; background: transparent; max-width: min(96vw, 900px); max-height: 94vh; }
.viewer::backdrop { background: rgba(0,0,0,.88); }
.viewer img { max-height: 88vh; width: auto; margin: 0 auto; border-radius: 8px; background: #fff; }
.viewer-close { position: fixed; top: 12px; right: 12px; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.15); color: #fff; font-size: 28px; cursor: pointer; }

/* ===== Nút & form chung ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px;
  padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; text-decoration: none; font-weight: 600; white-space: nowrap; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: .85rem; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0 4px; min-height: 36px; }
.danger-text { color: var(--danger) !important; }
.btn:disabled { opacity: .55; cursor: progress; }
.icon-btn { border: 0; background: none; font-size: 28px; line-height: 1; width: 40px; height: 40px; cursor: pointer; color: var(--muted); }

label { display: flex; flex-direction: column; gap: 4px; font-size: .875rem; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 10px 12px; font-size: 16px; font-weight: 400; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 1px; border-color: var(--accent); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; align-self: end; min-height: 44px; }
label.check input { width: 20px; height: 20px; }
.form-msg { margin: 4px 0 0; min-height: 1.2em; color: var(--danger); font-size: .9rem; }
.form-msg.ok { color: var(--ok); }
code { background: var(--line); padding: 1px 5px; border-radius: 4px; }

/* ===== Quản trị ===== */
.auth-box { max-width: 380px; margin: 10vh auto; padding: 28px 22px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); }
.auth-box h1 { margin: 0 0 4px; font-size: 1.5rem; }
.auth-box form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
@media (max-width: 420px) { .auth-box { margin: 24px 12px; } }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-in { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 10px; padding-bottom: 6px; }
#app-user { overflow: hidden; text-overflow: ellipsis; max-width: 40vw; white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: none; padding: 10px 12px; border-bottom: 3px solid transparent; cursor: pointer; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brand); }

.tab { padding: 16px 0 40px; }
.row-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.row-tools input[type=search], .row-tools input[type=text] { flex: 1 1 200px; }
.row-tools select { flex: 0 1 200px; width: auto; }

.plist, .clist { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.prow-btn { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; padding: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.prow-btn img, .thumb-empty { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex: none; background: var(--line); }
.prow-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.prow-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow-sub { color: var(--muted); font-size: .8rem; }
.prow-price { color: var(--price); font-weight: 700; white-space: nowrap; }
.hidden-item .prow-btn { opacity: .55; border-style: dashed; }

.crow { display: grid; grid-template-columns: 1fr 72px auto auto auto; gap: 6px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
@media (max-width: 520px) { .crow { grid-template-columns: 1fr 64px; } .crow .muted { grid-column: 1; } }

.card-form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; max-width: 460px; display: flex; flex-direction: column; gap: 12px; }
.card-form h2 { margin: 0; font-size: 1.1rem; }

.editor { border: 0; padding: 0; border-radius: var(--radius); width: min(560px, 100vw); max-height: 92vh;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.editor::backdrop { background: rgba(20, 10, 5, .55); }
.editor form { display: flex; flex-direction: column; max-height: 92vh; }
.editor-head, .editor-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.editor-foot { border-bottom: 0; border-top: 1px solid var(--line); }
.editor-head h2 { margin: 0; font-size: 1.15rem; flex: 1; }
.editor-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
@media (max-width: 600px) {
  .editor { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; }
  .editor form { max-height: 100dvh; height: 100%; }
  .editor-body { flex: 1; }
}
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.img-preview { width: 120px; height: 120px; border-radius: 12px; background: var(--line); overflow: hidden;
  display: grid; place-items: center; flex: none; color: var(--muted); font-size: .8rem; text-align: center; }
.img-preview img { width: 100%; height: 100%; object-fit: cover; }
.img-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.img-actions label.btn { flex-direction: row; font-size: .95rem; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 140%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600;
  transition: transform .25s ease; z-index: 50; max-width: 92vw; text-align: center; }
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; scrollbar-width: none; flex-wrap: wrap; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 7px 14px; cursor: pointer; white-space: nowrap; font-size: .9rem; min-height: 38px; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tabs { overflow-x: auto; scrollbar-width: none; }
.tabs button { white-space: nowrap; flex: none; }
.form-msg { white-space: pre-line; }
.card-form.wide { max-width: 900px; }
.card-form label.check { align-self: flex-start; min-height: 0; }
@media (max-width: 520px) { .two { grid-template-columns: 1fr; } }

/* ===== Danh sách phiếu (quản lý) ===== */
.big-add { width: 100%; min-height: 56px; font-size: 1.1rem; margin-bottom: 14px; border-radius: 14px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; }
.stat b { font-size: 1.35rem; line-height: 1.2; }
.stat span { font-size: .75rem; color: var(--muted); }
.stat[aria-pressed="true"] { outline: 2px solid var(--brand); outline-offset: -1px; }
.stat.s-warn b { color: var(--warn); } .stat.s-bad b { color: var(--bad); } .stat.s-ok b { color: var(--ok); }
.prow-btn img, .thumb-empty { width: 60px; height: 60px; }
.thumb-empty { display: grid; place-items: center; font-size: 1.6rem; }
.prow-name { white-space: normal; }
.empty-li { text-align: center; color: var(--muted); padding: 30px 8px; }
.badge { font-size: .75rem; font-weight: 700; padding: 4px 9px; border-radius: 999px; white-space: nowrap; flex: none; align-self: flex-start; }
.b-ok { background: var(--ok-bg); color: var(--ok); } .b-warn { background: var(--warn-bg); color: var(--warn); } .b-bad { background: var(--bad-bg); color: var(--bad); }

/* ===== Hộp tạo phiếu ===== */
.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .photos { grid-template-columns: 1fr; } }
.photo-box { border: 1px dashed var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.photo-title { font-weight: 700; font-size: .9rem; }
.photo-box .img-preview { width: 100%; height: 150px; }
.photo-box .img-preview img { object-fit: contain; background: #fff; }
.photo-box .img-actions { flex-direction: row; flex-wrap: wrap; }
.ai-msg { margin: 0; padding: 10px 12px; border-radius: 10px; font-size: .92rem; background: var(--line); }
.ai-msg.busy { background: var(--warn-bg); color: var(--warn); }
.ai-msg.ok { background: var(--ok-bg); color: var(--ok); }
.ai-msg.err { background: var(--bad-bg); color: var(--bad); }
input.autofill, select.autofill, textarea.autofill { background: color-mix(in srgb, #ffd54a 30%, var(--surface)); border-color: #e0a800; }
.month-chips { margin-top: -6px; }
.expiry { border-radius: 12px; padding: 12px 14px; background: var(--line); display: flex; flex-direction: column; }
.expiry span { font-size: .85rem; font-weight: 600; }
.expiry strong { font-size: 1.6rem; line-height: 1.2; }
.expiry small { font-size: .85rem; }
.expiry.e-ok { background: var(--ok-bg); color: var(--ok); }
.expiry.e-warn { background: var(--warn-bg); color: var(--warn); }
.expiry.e-bad { background: var(--bad-bg); color: var(--bad); }

/* ===== Chia sẻ ===== */
.btn.zalo { background: var(--zalo); border-color: var(--zalo); color: #fff; }
.btn.zalo-outline { border-color: var(--zalo); color: var(--zalo); }
.share .editor-body > .btn { width: 100%; min-height: 50px; }
.share-link input { font-size: .9rem; }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin: 4px 0; }
pre.msg { white-space: pre-wrap; font: inherit; font-size: .88rem; background: var(--bg); padding: 10px; border-radius: 10px; margin: 8px 0 0; }

/* ===== Chính sách ===== */
.policy h3 { margin: 6px 0 0; font-size: 1rem; }
.policy ul, .t-sec ul { margin: 0; padding-left: 20px; }
.policy li, .t-sec li { margin: 3px 0; }

/* ===== Trang khách: phiếu bảo hành ===== */
.lookup { margin: 20px auto; }
.ticket { max-width: 640px; margin: 16px auto 8px; display: flex; flex-direction: column; gap: 14px; }
.t-status { border-radius: var(--radius); padding: 18px; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.t-status.t-ok { background: var(--ok-bg); color: var(--ok); }
.t-status.t-warn { background: var(--warn-bg); color: var(--warn); }
.t-status.t-bad { background: var(--bad-bg); color: var(--bad); }
.t-badge { font-weight: 800; font-size: 1.05rem; text-transform: uppercase; letter-spacing: .04em; }
.t-exp-label { font-size: .85rem; margin-top: 6px; }
.t-exp { font-size: 2.3rem; line-height: 1.1; font-weight: 800; }
.t-left { font-size: .95rem; font-weight: 600; }
.t-info { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin: 0; padding: 6px 16px;
  display: grid; grid-template-columns: auto 1fr; }
.t-info dt, .t-info dd { padding: 9px 0; border-bottom: 1px solid var(--line); margin: 0; }
.t-info dt { color: var(--muted); padding-right: 14px; font-size: .92rem; }
.t-info dd { font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.t-info dt:nth-last-of-type(1), .t-info dd:last-of-type { border-bottom: 0; }
.t-photos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.t-photos figure { margin: 0; }
.t-img { border: 0; padding: 0; width: 100%; aspect-ratio: 1 / 1; border-radius: 12px; overflow: hidden; background: #fff; cursor: zoom-in; box-shadow: var(--shadow); }
.t-img img { width: 100%; height: 100%; object-fit: cover; }
.t-photos figcaption { text-align: center; font-size: .82rem; color: var(--muted); margin-top: 4px; }
.t-sec { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.t-sec h2 { font-size: 1.05rem; margin: 0 0 8px; }
.t-sec h3 { font-size: .95rem; margin: 10px 0 4px; }
.t-sec details summary { cursor: pointer; color: var(--accent); font-weight: 600; margin-top: 8px; }
.t-contact .btn { flex: 1 1 180px; min-height: 48px; }
.pre { white-space: pre-line; margin: 0; }
@media print { .t-contact, .viewer, .foot { display: none !important; } .hero { background: none; color: #000; } }

/* ===== Mã bình (quan trọng nhất) & ảnh phiếu ===== */
.key-field { color: var(--danger); }
.key-field input { border: 2px solid var(--danger); font-weight: 700; font-size: 1.1rem; letter-spacing: .03em; }
.card-img { background: var(--bg); border-radius: 12px; min-height: 160px; display: grid; place-items: center; overflow: hidden; }
.card-img img { width: 100%; height: auto; display: block; }
.share .editor-body > a.btn, .share .editor-body > button.btn:not(.link) { width: 100%; min-height: 50px; }
