/* Unicold Checklist — giao diện nhạt, tông xanh theo logo */
:root {
  --brand: #1bb1ff;          /* xanh da trời của logo */
  --brand-deep: #0a6fb0;     /* dùng cho nút / chữ để đủ tương phản */
  --brand-ink: #1233c9;      /* xanh đậm của logo, dùng rất ít */
  --brand-soft: #e9f7ff;
  --bg: #f5f9fc;
  --surface: #ffffff;
  --border: #dce9f2;
  --text: #22384a;
  --muted: #6b8293;
  --ok: #1d8f5a;   --ok-soft: #e7f6ee;
  --bad: #c93c3c;  --bad-soft: #fdeeee;
  --warn: #9a6a12; --warn-soft: #fff5df;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(18, 51, 80, .05), 0 2px 8px rgba(18, 51, 80, .04);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--brand-deep); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 1.05rem; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar::after { content: ""; display: block; height: 3px; background: linear-gradient(90deg, var(--brand), #7fd3ff 60%, var(--brand-soft)); }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 8px 16px;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand img { height: 34px; width: auto; display: block; }
.brand span { font-weight: 600; font-size: .95rem; color: var(--muted); border-left: 1px solid var(--border); padding-left: 10px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--text); font-size: .92rem; }
.nav a:hover { background: var(--brand-soft); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-deep); font-weight: 600; }
.user-box { display: flex; align-items: center; gap: 10px; font-size: .88rem; }
.user-box form { margin: 0; }

/* ---------- Layout ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }
.container.narrow { max-width: 820px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Alerts ---------- */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: var(--ok-soft); color: var(--ok); border-color: #c9ebd8; }
.alert-error { background: var(--bad-soft); color: var(--bad); border-color: #f5d0d0; }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: #f3e0b5; }
.alert-info { background: var(--brand-soft); color: var(--brand-deep); border-color: #cbe9fb; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: .92rem;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--brand-soft); text-decoration: none; }
.btn-primary { background: var(--brand-deep); border-color: var(--brand-deep); color: #fff; }
.btn-primary:hover { background: #085d94; }
.btn-soft { background: var(--brand-soft); border-color: #cbe9fb; color: var(--brand-deep); }
.btn-danger { background: var(--surface); border-color: #f0c4c4; color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #177a4c; }
.btn-sm { padding: 4px 10px; font-size: .84rem; }
.btn-block { width: 100%; padding: 12px; font-size: 1rem; }
.btn-link { background: none; border: 0; padding: 0; color: var(--brand-deep); cursor: pointer; font: inherit; }

/* ---------- Forms ---------- */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: #fbfdff; color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(27, 177, 255, .18); background: #fff; }
textarea { resize: vertical; min-height: 40px; }
.field { margin-bottom: 12px; }
.field-error { color: var(--bad); font-size: .82rem; margin-top: 3px; }
.checkbox { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .92rem; }
.filters { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; background: #f8fbfe; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.is-abnormal td { background: var(--bad-soft); }
.table tr.is-abnormal td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.table tbody tr:hover td { background: #f3f9fd; }
.table tr.is-abnormal:hover td { background: #fbe4e4; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-submitted { background: var(--warn-soft); color: var(--warn); }
.badge-approved { background: var(--ok-soft); color: var(--ok); }
.badge-rejected { background: var(--bad-soft); color: var(--bad); }
.badge-todo { background: #eef2f5; color: var(--muted); }
.badge-bad { background: var(--bad); color: #fff; }
.badge-brand { background: var(--brand-soft); color: var(--brand-deep); }

/* ---------- Stats ---------- */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 1.5rem; font-weight: 600; line-height: 1.2; }
.stat span { color: var(--muted); font-size: .82rem; }
.stat.bad b { color: var(--bad); }
.stat.warn b { color: var(--warn); }
.stat.ok b { color: var(--ok); }

/* ---------- Driver: ca làm việc ---------- */
.shift-card { border-left: 4px solid var(--brand); }
.shift-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.form-link {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; margin-top: 8px; color: var(--text); background: #fbfdff;
}
.form-link:hover { background: var(--brand-soft); text-decoration: none; }
.form-link .code { font-size: .78rem; color: var(--muted); }
.form-link .grow { flex: 1; min-width: 0; }

/* ---------- Checklist ---------- */
.section-title { background: var(--brand-soft); color: var(--brand-deep); font-weight: 600; padding: 8px 14px; font-size: .9rem; border-top: 1px solid var(--border); }
.section-title:first-child { border-top: 0; }
.check-item { padding: 12px 14px; border-top: 1px solid var(--border); display: grid; grid-template-columns: 34px 1fr auto; gap: 6px 10px; align-items: center; }
.check-item .no { color: var(--muted); font-size: .85rem; }
.check-item .options { display: flex; gap: 6px; }
.check-item .note, .check-item .add-note { grid-column: 2 / -1; }
.check-item .add-note { justify-self: start; color: var(--muted); }
.check-item .add-note:hover { color: var(--brand-deep); }
.check-item.is-abnormal { background: var(--bad-soft); }
.check-item.is-abnormal .no { color: var(--bad); font-weight: 600; }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt span {
  display: inline-block; min-width: 86px; text-align: center; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text); cursor: pointer; font-size: .9rem; user-select: none;
}
.opt input:focus-visible + span { box-shadow: 0 0 0 3px rgba(27, 177, 255, .3); }
.opt input:checked + span.safe { background: var(--ok-soft); border-color: #9fd9bb; color: var(--ok); font-weight: 600; }
.opt input:checked + span.unsafe { background: var(--bad-soft); border-color: #eab0b0; color: var(--bad); font-weight: 600; }
.answer-view { font-weight: 600; }
.answer-view.ok { color: var(--ok); }
.answer-view.bad { color: var(--bad); }

.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.doc-list li:first-child { border-top: 0; }
.doc-list .grow { flex: 1; min-width: 0; }
.mono { font-family: Consolas, "SFMono-Regular", Menlo, monospace; word-break: break-all; }
.filter-toggle { display: none; }
.form-actions { display: flex; align-items: center; gap: 8px; }
.bottom-nav { display: none; }

/* =====================================================================
   Điện thoại 6.4"–6.7" (bề rộng CSS ~360–430px). Mọi màn hình ≤ 640px.
   - Chữ 16px, ô nhập 16px (iOS không tự phóng to), vùng chạm ≥ 44–48px
   - Menu chuyển xuống thanh điều hướng dưới đáy, chừa vùng an toàn (tai thỏ / thanh home)
   - Bảng chuyển thành thẻ; nút gửi phiếu dính đáy màn hình
   ===================================================================== */
@media (max-width: 640px) {
  :root { --nav-h: 60px; }
  body { font-size: 16px; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
  body.no-bottom-nav { padding-bottom: env(safe-area-inset-bottom); }
  h1 { font-size: 1.3rem; line-height: 1.3; }
  h2 { font-size: 1.08rem; }

  .container, .container.narrow { padding: 12px 12px 24px; }
  .card { padding: 14px; margin-bottom: 12px; border-radius: 12px; }
  .page-head { margin-bottom: 12px; align-items: stretch; }
  .page-head > .btn, .page-head > .row { width: 100%; }
  .page-head > .row .btn { flex: 1; }

  /* Header gọn, không dính để nhường chỗ cho nội dung */
  .topbar { position: static; }
  .topbar-inner { padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); gap: 8px; flex-wrap: nowrap; }
  .brand img { height: 28px; }
  .brand span { display: none; }
  .nav { display: none; }
  .user-box { margin-left: auto; min-width: 0; font-size: .85rem; }
  .user-box > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46vw; }
  .user-box .role { display: none; }

  /* Thanh điều hướng dưới đáy */
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: rgba(255, 255, 255, .97); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom); overflow-x: auto; scrollbar-width: none;
    box-shadow: 0 -2px 10px rgba(18, 51, 80, .05);
  }
  .bottom-nav::-webkit-scrollbar { display: none; }
  .bottom-nav a {
    flex: 1 0 auto; min-width: 72px; height: var(--nav-h); display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: .72rem; text-decoration: none;
  }
  .bottom-nav a svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }
  .bottom-nav a.active { color: var(--brand-deep); font-weight: 600; }
  .bottom-nav a.active svg { stroke-width: 2.2; }
  body.no-bottom-nav .bottom-nav { display: none; }

  /* Nút & ô nhập: vùng chạm lớn */
  .btn { min-height: 44px; padding: 10px 16px; font-size: .95rem; border-radius: 10px; }
  .btn-sm { min-height: 38px; padding: 7px 12px; font-size: .88rem; }
  input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], select, textarea {
    font-size: 16px; min-height: 46px; padding: 10px 12px; border-radius: 10px;
  }
  textarea { min-height: 70px; }
  .checkbox { min-height: 44px; }
  .checkbox input { width: 20px; height: 20px; }

  /* Bộ lọc thu gọn */
  .filter-toggle { display: flex; width: 100%; justify-content: space-between; }
  .filters-panel[data-collapsed="1"] .filters { display: none; }
  .filters-panel .filters { margin-top: 12px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters > div:has(select[name=driver_id]), .filters > div:has(.checkbox), .filters > .row { grid-column: 1 / -1; }
  .filters > .row .btn { flex: 1; }

  .grid-4 { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: 1.35rem; }

  /* Bảng -> thẻ */
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: 12px 14px; border-bottom: 1px solid var(--border); position: relative; display: flex; flex-direction: column; }
  .table-stack td.cell-title { order: -1; }
  .table-stack td.cell-actions { order: 10; }
  .table-stack td[data-label=""]:empty { display: none; }
  .table-stack tr:last-child { border-bottom: 0; }
  .table-stack td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table-stack td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; text-align: left; flex-shrink: 0; }
  .table-stack td[data-label=""]::before, .table-stack td:not([data-label])::before { content: none; }
  .table-stack td.cell-title { display: block; text-align: left; font-size: 1rem; padding-bottom: 6px; }
  .table-stack td.cell-actions { justify-content: stretch; padding-top: 10px; }
  .table-stack td.cell-actions > * { flex: 1; }
  .table-stack td.cell-actions form { display: flex; }
  .table-stack td.cell-actions .btn { width: 100%; min-height: 42px; }
  .table-stack td input, .table-stack td select { max-width: 62%; }
  .table-stack td input[type=checkbox] { width: 22px; height: 22px; min-height: 0; }
  .table-stack tr.is-abnormal td, .table-stack tbody tr:hover td { background: transparent; }
  .table-stack tr.is-abnormal { background: var(--bad-soft); box-shadow: inset 4px 0 0 var(--bad); }
  .table-stack tr.is-abnormal td:first-child { box-shadow: none; }
  .table-stack td.section-title { display: block; text-align: left; margin: -12px -14px; padding: 8px 14px; }

  /* Phiếu kiểm tra */
  .shift-card { border-left-width: 4px; }
  .form-link { padding: 14px; min-height: 64px; }
  .section-title { position: sticky; top: 0; z-index: 2; padding: 10px 14px; }
  .check-item { grid-template-columns: 24px 1fr; gap: 8px 8px; padding: 14px 12px; }
  .check-item > div:nth-child(2) { font-size: 1rem; line-height: 1.4; }
  .check-item .options { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .check-item .note, .check-item .add-note { grid-column: 1 / -1; }
  .check-item .add-note { min-height: 32px; }
  .check-item .answer-view { grid-column: 2; }
  .opt { display: block; }
  .opt span { display: flex; align-items: center; justify-content: center; width: 100%; min-width: 0; min-height: 48px; font-size: 1rem; border-radius: 10px; }

  .info-list { grid-template-columns: 1fr 1fr; }
  .sign-box canvas { height: 220px; }
  .signatures { gap: 8px; font-size: .9rem; }
  .sign-img { max-width: 100%; }

  /* Thanh gửi phiếu dính đáy */
  .card.flush { overflow: clip; }
  .form-actions.card {
    position: sticky; bottom: 0; z-index: 5; margin: 0 -12px -24px; padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    background: #fff; border: 0; border-top: 1px solid var(--border); border-radius: 0;
    box-shadow: 0 -2px 10px rgba(18, 51, 80, .06); flex-wrap: wrap; gap: 4px 8px;
  }
  .form-actions .spacer { display: none; }
  .form-actions [data-progress] { width: 100%; text-align: center; }
  .form-actions.has-bad [data-progress] { color: var(--bad); font-weight: 600; }
  .form-actions .btn { flex: 1; min-height: 50px; font-size: 1rem; }
  .btn-block { min-height: 50px; }

  .doc-list li { flex-wrap: wrap; }
  .doc-list .btn { width: 100%; }
  .pagination { justify-content: center; }
  .pagination a, .pagination span { min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }
  .login-card .logo { width: 180px; }
  .alert { font-size: .92rem; }
}

/* Máy nhỏ hơn (≤ 370px, VD 6.1" cũ) vẫn dùng được */
@media (max-width: 370px) {
  .grid-4, .filters, .info-list { grid-template-columns: 1fr; }
  .bottom-nav a { min-width: 64px; font-size: .68rem; }
}

/* ---------- License box ---------- */
.info-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.info-list div span { display: block; font-size: .8rem; color: var(--muted); }
.info-list div b { font-weight: 600; }

/* ---------- Signature ---------- */
.sign-box { border: 1px dashed #9fcfeb; border-radius: 8px; background: #fbfdff; position: relative; }
.sign-box canvas { display: block; width: 100%; height: 180px; touch-action: none; cursor: crosshair; }
.sign-box .hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #a9c3d4; pointer-events: none; font-size: .95rem; }
.sign-box.signed .hint { display: none; }
.sign-img { max-height: 90px; max-width: 220px; display: block; margin: 6px auto; }
.signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: center; }
.signatures .who { font-weight: 600; }
.signatures > div { min-width: 0; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0 6px 16px; border-left: 2px solid var(--border); position: relative; font-size: .9rem; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, #eaf7ff 0%, var(--bg) 55%); }
.login-card { width: 100%; max-width: 380px; }
.login-card .logo { display: block; width: 210px; max-width: 80%; margin: 4px auto 6px; }

.pagination { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 12px; }
.pagination a, .pagination span { padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; font-size: .88rem; }
.pagination .current { background: var(--brand-soft); color: var(--brand-deep); font-weight: 600; }
