/* Sổ Công Trình – mobile-first, high contrast for outdoor use, big touch targets. */
:root {
  --bg: #F8FAFC;
  --card: #FFFFFF;
  --text: #111827;
  --muted: #6B7280;
  --line: #E5E7EB;
  --accent: #F59E0B;
  --accent-ink: #111827;
  --accent-soft: #FEF3C7;
  --ok: #16A34A;
  --ok-soft: #DCFCE7;
  --warn: #DC2626;
  --warn-soft: #FEE2E2;
  --info: #2563EB;
  --info-soft: #DBEAFE;
  --top: #1F2937;
  --top-ink: #F9FAFB;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.05);
  --radius: 14px;
  --tap: 48px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1220; --card: #151D2E; --text: #F3F4F6; --muted: #9CA3AF; --line: #273246;
    --accent: #FBBF24; --accent-ink: #111827; --accent-soft: #3B2F0B;
    --ok: #4ADE80; --ok-soft: #10351F; --warn: #F87171; --warn-soft: #3F1414;
    --info: #60A5FA; --info-soft: #14284A; --top: #0F172A; --top-ink: #F9FAFB;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0B1220; --card: #151D2E; --text: #F3F4F6; --muted: #9CA3AF; --line: #273246;
  --accent: #FBBF24; --accent-ink: #111827; --accent-soft: #3B2F0B;
  --ok: #4ADE80; --ok-soft: #10351F; --warn: #F87171; --warn-soft: #3F1414;
  --info: #60A5FA; --info-soft: #14284A; --top: #0F172A; --top-ink: #F9FAFB;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--info); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--top); color: var(--top-ink);
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
}
.proj-btn {
  flex: 1; min-width: 0; text-align: left; background: transparent; border: 0; color: inherit; padding: 6px 4px;
  display: flex; flex-direction: column; gap: 1px;
}
.proj-name { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj-sub { font-size: 12px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: transparent; border: 0; color: inherit; width: var(--tap); height: var(--tap); display: grid; place-items: center; border-radius: 12px; }
.icon-btn:active { background: rgba(255,255,255,.12); }

/* Main view */
.view { max-width: 560px; margin: 0 auto; padding: 12px 16px 24px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h2 > span.muted { font-size: 12px; font-weight: 500; text-align: right; }
.card h2 .link { text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
.bold { font-weight: 700; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* Buttons */
.btn {
  min-height: var(--tap); padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.dark { background: var(--top); border-color: var(--top); color: var(--top-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--warn); border-color: var(--warn); }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--info); padding: 4px 0; font-weight: 600; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions .btn { width: 100%; }
.actions.three { grid-template-columns: 1fr 1fr 1fr; }

/* Date nav */
.datenav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.datenav .btn { min-width: var(--tap); padding: 0 12px; }
.datenav .date { flex: 1; text-align: center; font-weight: 700; font-size: 18px; }
.datenav .date small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.datenav input[type="date"] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.today-chip { font-size: 12px; background: var(--accent-soft); color: var(--text); padding: 2px 8px; border-radius: 999px; margin-left: 6px; }

/* Worker attendance chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: var(--tap); padding: 6px 14px; border-radius: 999px; border: 2px solid var(--line);
  background: var(--card); display: inline-flex; align-items: center; gap: 8px; font-weight: 600; user-select: none;
}
.chip .st { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); }
.chip[data-v="1"] { border-color: var(--ok); background: var(--ok-soft); }
.chip[data-v="1"] .st { background: var(--ok); color: #fff; }
.chip[data-v="0.5"] { border-color: var(--accent); background: var(--accent-soft); }
.chip[data-v="0.5"] .st { background: var(--accent); color: var(--accent-ink); }
.chip[data-v="1.5"] { border-color: var(--info); background: var(--info-soft); }
.chip[data-v="1.5"] .st { background: var(--info); color: #fff; }
.chip.add { border-style: dashed; color: var(--muted); font-weight: 500; }
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* Weather segmented */
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; min-height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 14px; }
.seg button.on { background: var(--top); color: var(--top-ink); border-color: var(--top); }

/* Note */
textarea.note { width: 100%; min-height: 84px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--bg); resize: vertical; }
.mic { position: relative; }
.mic.listening { color: var(--warn); border-color: var(--warn); }

/* Photos */
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photos .ph { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--line); border: 0; padding: 0; }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .ph .cap { position: absolute; left: 0; right: 0; bottom: 0; font-size: 11px; background: rgba(0,0,0,.55); color: #fff; padding: 2px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.photos .add { aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 10px; background: transparent; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.photos .add span { font-size: 26px; display: block; text-align: center; }

/* Lists */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); min-height: 52px; }
.item:first-child { border-top: 0; }
.item .t { flex: 1; min-width: 0; }
.item .t .d { font-size: 13px; color: var(--muted); }
.item .amt { font-weight: 700; white-space: nowrap; }
.amt.in { color: var(--ok); }
.amt.out { color: var(--warn); }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge.pending { background: var(--accent-soft); color: var(--text); }
.badge.confirmed { background: var(--ok-soft); color: var(--ok); }
.badge.rejected { background: var(--warn-soft); color: var(--warn); }
.x { background: transparent; border: 0; color: var(--muted); width: 36px; height: 36px; border-radius: 8px; font-size: 18px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 17px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .v.in { color: var(--ok); } .stat .v.out { color: var(--warn); }

/* Tables */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl tfoot td { font-weight: 700; border-bottom: 0; }

/* Period picker */
.period { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.period button { white-space: nowrap; min-height: 38px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 14px; font-weight: 600; }
.period button.on { background: var(--top); color: var(--top-ink); border-color: var(--top); }
.range { display: flex; gap: 8px; margin-top: 8px; }
.range input { flex: 1; min-height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; background: var(--bg); }

/* Diary timeline */
.day { border-top: 1px solid var(--line); padding: 10px 0; }
.day:first-child { border-top: 0; }
.day .dh { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.day .dh b { font-size: 15px; }
.day .dl { font-size: 14px; margin-top: 4px; }
.day .mini { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; }
.day .mini img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; }

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button { background: transparent; border: 0; min-height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; padding: 0 2px; color: var(--muted); font-weight: 600; }
.tabbar button .ic { font-size: 22px; line-height: 1; }
.tabbar button.active { color: var(--text); }
.tabbar button.active::after { content: ""; width: 24px; height: 3px; background: var(--accent); border-radius: 3px; margin-top: 2px; }

/* Dialog */
.dlg { border: 0; border-radius: 18px 18px 0 0; padding: 0; width: 100%; max-width: 560px; margin: auto auto 0; background: var(--card); color: var(--text); max-height: 92vh; }
@media (min-width: 600px) { .dlg { border-radius: 18px; margin: auto; } }
.dlg::backdrop { background: rgba(0,0,0,.45); }
.dlg form, .dlg .pane { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.dlg h3 { margin: 0 0 12px; font-size: 18px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field input, .field select, .field textarea { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; background: var(--bg); }
.field textarea { min-height: 70px; }
.field .inl { display: flex; gap: 8px; }
.field .inl > * { flex: 1; }
.dlg .actions { margin-top: 8px; }
.menu { display: flex; flex-direction: column; }
.menu button { text-align: left; background: transparent; border: 0; border-top: 1px solid var(--line); min-height: 52px; padding: 10px 4px; font-size: 16px; display: flex; align-items: center; gap: 12px; }
.menu button:first-child { border-top: 0; }
.menu button .ic { width: 28px; text-align: center; }
.menu button.on { font-weight: 700; }
.menu button.danger { color: var(--warn); }

/* Toast */
.toast { position: fixed; left: 50%; top: calc(76px + env(safe-area-inset-top)); transform: translateX(-50%) translateY(-12px); background: var(--top); color: var(--top-ink); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 60; display: flex; flex-direction: column; }
.lightbox[hidden] { display: none; }
.lightbox img { flex: 1; min-height: 0; object-fit: contain; width: 100%; }
.lightbox .lb-bar { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: #000; }
.lightbox .lb-bar input { flex: 1; min-height: 44px; border-radius: 10px; border: 1px solid #333; background: #111; color: #fff; padding: 6px 10px; }
.lightbox .lb-bar .btn { background: #222; color: #fff; border-color: #333; }

/* Onboarding */
.hero { text-align: center; padding: 28px 8px 16px; }
.hero .logo { width: 88px; height: 88px; border-radius: 22px; margin: 0 auto 12px; }
.hero h1 { font-size: 24px; margin: 0 0 6px; }
.hero p { color: var(--muted); margin: 0 auto; max-width: 380px; }
.feat { display: grid; gap: 8px; margin: 16px 0; }
.feat div { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.feat .ic { font-size: 20px; width: 28px; text-align: center; flex: 0 0 auto; }

/* Print: Nhật ký thi công */
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0; }
  .topbar, .tabbar, .no-print, .toast, .dlg { display: none !important; }
  .print-only { display: block; }
  .view { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .pday { page-break-inside: avoid; border: 1px solid #999; padding: 10px 12px; margin-bottom: 10px; border-radius: 0; }
  .pday h3 { margin: 0 0 6px; font-size: 15px; }
  .pday table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
  .pday td { border: 1px solid #bbb; padding: 4px 6px; vertical-align: top; }
  .pday td:first-child { width: 150px; font-weight: 600; background: #f3f3f3; }
  .pday .pimgs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
  .pday .pimgs img { width: 110px; height: 82px; object-fit: cover; border: 1px solid #ccc; }
  .sig { display: flex; justify-content: space-between; margin-top: 10px; font-size: 12px; text-align: center; }
  .sig div { width: 45%; padding-top: 48px; border-top: 1px dotted #999; }
}
.pday { border: 1px solid var(--line); padding: 10px 12px; margin-bottom: 10px; border-radius: 10px; }
.pday h3 { margin: 0 0 6px; font-size: 15px; }
.pday table { width: 100%; border-collapse: collapse; font-size: 13px; }
.pday td { border: 1px solid var(--line); padding: 4px 6px; vertical-align: top; }
.pday td:first-child { width: 130px; font-weight: 600; background: var(--bg); }
.pday .pimgs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pday .pimgs img { width: 90px; height: 68px; object-fit: cover; border-radius: 6px; }
.sig { display: flex; justify-content: space-between; margin-top: 10px; font-size: 12px; text-align: center; color: var(--muted); }
.sig div { width: 45%; padding-top: 36px; border-top: 1px dotted var(--line); }

/* Đợt 2 */
.row.wrap { flex-wrap: wrap; }
.chip .ot { font-size: 11px; font-weight: 700; color: var(--info); }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--info-soft); color: var(--text); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.banner.warn { background: var(--accent-soft); }
.bar { height: 12px; background: var(--line); border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 6px; transition: width .3s; }
.tstat { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); background: var(--card); font-weight: 700; flex: 0 0 auto; color: var(--muted); }
.tstat.doing { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.tstat.done { border-color: var(--ok); background: var(--ok); color: #fff; }
.t .done { text-decoration: line-through; color: var(--muted); }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; background: var(--line); cursor: pointer; }
.search { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; background: var(--bg); margin-top: 10px; }
.num.neg { color: var(--warn); }
.x:disabled { opacity: .3; }
.dlg .tbl select, .dlg .tbl input { min-height: 38px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; background: var(--bg); width: 100%; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
@media (max-width: 360px) { .tabbar button span:not(.ic) { font-size: 10px; } }

/* Đợt 3: tối ưu */
:root[data-big] { font-size: 18px; }
:root[data-big] body { font-size: 18px; }
:root[data-big] .chip { padding: 8px 16px; }
.fab { position: fixed; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 26px; box-shadow: 0 6px 18px rgba(0,0,0,.25); z-index: 15; }
.fab:active { transform: scale(.95); }
.toast.action { display: flex; align-items: center; gap: 14px; pointer-events: auto; padding-right: 8px; }
.toast .undo { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 6px 12px; font-weight: 700; }
.money-preview { font-size: 13px; color: var(--ok); font-weight: 700; min-height: 16px; margin-top: 3px; font-variant-numeric: tabular-nums; }
@media (min-width: 600px) { .fab { right: calc(50% - 280px + 16px); } }
.view.has-fab { padding-bottom: 96px; }

/* Đợt 4: an toàn dữ liệu, góp ý */
.banner.danger { background: var(--warn-soft); }
.banner span { min-width: 0; }
.banner .btn { flex: 0 0 auto; }
ol.steps { padding-left: 20px; margin: 0 0 10px; line-height: 1.6; font-size: 15px; }
ol.steps li { margin-bottom: 6px; }
.kbd { display: inline-block; border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; font-size: 13px; background: var(--bg); }
.pre { white-space: pre-wrap; font-size: 12px; background: var(--bg); padding: 8px; border-radius: 8px; margin: 6px 0 0; }
details summary { cursor: pointer; }
.tbl-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; -webkit-overflow-scrolling: touch; }
.tbl.pay td, .tbl.pay th { padding-left: 3px; padding-right: 3px; white-space: nowrap; }
.tbl.pay td:first-child { white-space: normal; }
.tbl.pay .link { padding: 0 2px; font-size: 15px; }
html, body { overflow-x: hidden; }
