/* Sổ Công — giao diện tối giản. Nền phẳng, không hiệu ứng kính mờ, một màu nhấn trung tính. */

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-2: #efefef;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e2e2e2;
  --accent: #1a1a1a;
  --accent-text: #ffffff;
  --danger: #b42318;
  --focus: #1a1a1a;
  --backdrop: rgba(0, 0, 0, 0.35);
  --radius: 10px;
  --ledger-bg: #e9f6ec;
  --gutter: 16px;
  color-scheme: light;
}

/* Dark mode: theo hệ thống, trừ khi người dùng chọn sáng */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f0f;
    --surface: #1a1a1a;
    --surface-2: #242424;
    --text: #f2f2f2;
    --muted: #9a9a9a;
    --border: #2e2e2e;
  --ledger-bg: #1d2e23;
    --accent: #f2f2f2;
    --accent-text: #111111;
    --danger: #ff8a80;
    --focus: #f2f2f2;
    --backdrop: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

/* Dark mode khi người dùng chọn tối tường minh */
:root[data-theme="dark"] {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-2: #242424;
  --text: #f2f2f2;
  --muted: #9a9a9a;
  --border: #2e2e2e;
  --ledger-bg: #1d2e23;
  --accent: #f2f2f2;
  --accent-text: #111111;
  --danger: #ff8a80;
  --focus: #f2f2f2;
  --backdrop: rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; }

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.icon.sm { width: 18px; height: 18px; }

/* ---------- Khung ứng dụng ---------- */

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: calc(env(safe-area-inset-top) + 12px) var(--gutter) 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.topbar-actions .icon-btn { flex: 0 0 auto; }

.content {
  flex: 1;
  padding: var(--gutter) var(--gutter) calc(96px + env(safe-area-inset-bottom));
}

.bottomnav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 5;
}
.bottomnav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  border-radius: 8px;
}
.bottomnav a[aria-current="page"] { color: var(--text); font-weight: 600; }
.bottomnav.manager-nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.bottomnav.manager-nav a { font-size: 11px; }
.project-report-row { padding: 9px 0; border-bottom: 1px solid var(--border); }
.project-report-row:last-of-type { border-bottom: 0; }
button.project-report-row { width: 100%; border-top: 0; border-left: 0; border-right: 0; border-radius: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
button.project-report-row-clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.list-item.read { opacity: .58; }
.list-item.read .title { font-weight: 400; }
.list-item.unread { border-color: var(--accent); background: var(--surface-2); }
.list-item.unread .title { font-weight: 700; }

/* ---------- Thành phần chung ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.stack > * + * { margin-top: 12px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.neg { color: var(--danger); }
.h2 { font-size: 15px; margin: 18px 0 8px; font-weight: 600; }

.label-sm {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}
.value-lg {
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.value-md {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  margin: 2px 0;
}

/* Dải số liệu ngắn trên đầu màn: 3 ô, phone xếp 3 cột nhỏ */
.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  min-width: 0;
}
.stat .label-sm { margin-bottom: 0; }
.stat .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}
.grid-2 > * { min-width: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  line-height: 1.25;
  white-space: normal;
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
}
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }
.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.field textarea { min-height: 72px; resize: vertical; }

.form { display: flex; flex-direction: column; gap: 14px; }

.form-error {
  color: var(--danger);
  font-size: 14px;
  margin: 0;
}

.list { display: flex; flex-direction: column; }
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}
.list-item:last-child { border-bottom: none; }
.list-item .main { min-width: 0; }
.list-item .title {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-item .amount { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

.tag {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  margin-right: 6px;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
  background: var(--surface-2);
}
/* Accordion trạng thái duyệt (issue #32): mỗi lần chỉ mở một khung */
.acc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.acc-head[aria-expanded="true"] { background: var(--surface-2); }
.acc-count {
  min-width: 28px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 13px;
  text-align: center;
}
.acc-head[aria-expanded="true"] .acc-count { background: var(--accent); color: var(--accent-text); }
.acc-body { padding-top: 4px; }

.reject-box { margin-top: 2px; }
.reject-box > summary { cursor: pointer; padding: 6px 0; }
.reject-box[open] > summary { margin-bottom: 6px; }
.pane-tabs button { white-space: nowrap; font-size: 14px; padding: 0 4px; }
.segmented button {
  min-height: 38px;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  padding: 0 8px;
}
.segmented button[aria-checked="true"] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 12px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.tabs button[aria-selected="true"] {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

/* ---------- Lịch ngày công ---------- */

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.month-nav strong { font-size: 17px; }

.cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal .dow {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 0;
}
.cal button {
  aspect-ratio: 1 / 1;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  padding: 2px;
}
.cal button.empty { background: transparent; border-color: transparent; cursor: default; }
.cal button .d { font-size: 14px; font-variant-numeric: tabular-nums; }
.cal button .u { font-size: 11px; color: var(--muted); }
.cal button .u.work { color: var(--danger); }
.cal button.has { border-color: var(--text); }
.cal button.today { box-shadow: inset 0 0 0 2px var(--text); }
.cal button.off { color: var(--muted); }
.cal-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cal-legend .sw { display: inline-block; width: 14px; height: 14px; border: 1px solid var(--border); border-radius: 4px; box-sizing: border-box; }
.cal-legend .sw.has { border-color: var(--text); }
.cal-legend .sw.pending { border-style: dashed; }
.cal-legend .sw.today { box-shadow: inset 0 0 0 2px var(--text); }

.quick-units {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.quick-units button {
  min-height: 72px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.quick-units button:hover { background: var(--surface-2); }

/* ---------- Sheet (hộp thoại dưới) ---------- */

.sheet-root { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
}
.sheet {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 8px var(--gutter) calc(20px + env(safe-area-inset-bottom));
  border: 1px solid var(--border);
  border-bottom: none;
}
.sheet-grab {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 4px auto 8px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 600; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(90px + env(safe-area-inset-bottom));
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 30;
  max-width: calc(100% - 32px);
  text-align: center;
}

/* ---------- Màn hình đăng nhập ---------- */

.auth {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px var(--gutter);
  max-width: 420px;
  margin: 0 auto;
}
.auth .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.auth .brand h1 { margin: 0; font-size: 22px; font-weight: 600; }
.auth .foot { margin-top: 20px; font-size: 13px; color: var(--muted); }

/* ---------- Trang nhỏ ---------- */

.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; }

.empty-note {
  text-align: center;
  color: var(--muted);
  padding: 28px 0;
  font-size: 14px;
}

.bar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
  margin-top: 6px;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--text);
}

@media (min-width: 560px) {
  .sheet { border-radius: 16px; bottom: 16px; max-height: 80vh; }
}

@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: rise 0.18s ease-out; }
  @keyframes rise { from { transform: translate(-50%, 16px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
}

/* ---------- Ngoại tuyến / đồng bộ ---------- */

.sync-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px var(--gutter);
  border: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.sync-banner .icon { flex: none; }
.sync-banner span:nth-child(2) { flex: 1; min-width: 0; }
.sync-banner.warn { color: var(--danger); }
.day.pending { border-style: dashed; }
.list-item.pending { opacity: 0.85; cursor: default; }

/* Hộp thoại giới thiệu (iframe tới /gioi-thieu/) */
.intro-dialog {
  width: min(720px, calc(100% - 24px));
  height: min(85vh, 760px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.intro-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

/* Hộp thông báo khóa mức lương: giữ tới khi người dùng bấm Đóng */
.notice-dialog {
  width: min(420px, calc(100% - 32px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
.notice-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.intro-frame { flex: 1; width: 100%; min-height: 0; border: 0; background: var(--bg); }
.intro-footer { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); }
.intro-footer label { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* Khung Tổng quan kiểu sổ sách */
.ledger { padding: 14px 16px 16px; }
.ledger-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 8px 0; }
.ledger-sub { border-top: 1px dashed var(--border); }
.ledger-sum { border-top: 2px solid var(--text); font-weight: 600; }
.ledger-units { font-size: 22px; font-weight: 700; }
.ledger-carry { width: 100%; background: none; border: 0; border-top: 1px dashed var(--border); color: inherit; font: inherit; text-align: left; cursor: pointer; padding: 8px 0; }
.ledger-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ledger-strip { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; padding: 12px 14px; background: var(--ledger-bg); border-radius: var(--radius); }
.ledger-big { font-size: 24px; font-weight: 700; }


/* Biểu đồ tiền công 6 tháng */
.work-chart {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 5px;
  align-items: end;
  padding: 12px 8px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.work-chart-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: end;
  gap: 4px;
  padding: 5px 1px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
}
.work-chart-col.selected { border-color: var(--accent); background: var(--surface-2); }
.work-chart-amount { max-width: 100%; font-size: 10px; line-height: 1.2; font-variant-numeric: tabular-nums; white-space: nowrap; }
.work-chart-track { width: min(100%, 28px); height: 94px; display: flex; align-items: end; justify-content: center; }
.work-chart-bar { width: 100%; min-height: 4px; border-radius: 4px 4px 1px 1px; background: var(--accent); opacity: .75; }
.work-chart-col.selected .work-chart-bar { opacity: 1; }
.work-chart-col.zero .work-chart-bar { opacity: .2; }
.work-chart-month { font-size: 11px; font-weight: 600; }
.work-chart-units { max-width: 100%; font-size: 9px; line-height: 1.2; color: var(--muted); white-space: nowrap; }
.work-chart-summary { margin: 0; }
@media (max-width: 390px) {
  .work-chart { gap: 2px; padding-inline: 4px; }
  .work-chart-amount { font-size: 9px; }
  .work-chart-units { font-size: 8px; }
}

/* Quản lý công nhân và công trình */
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.row-actions .btn { min-height: 36px; padding: 6px 10px; }

/* Thông báo */
.notif-anchor { position: relative; }
.notif-badge {
  position: absolute;
  top: 2px;
  right: 0;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
}
.notif-badge[hidden] { display: none; }
.list-item.unread .title { font-weight: 700; }

/* Xuất báo cáo */
.export-preview { width: 100%; height: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }

/* Mục thu gọn kiểu accordion (Hồ sơ, trang quản trị): mặc định đóng */
details.acc > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary::after { content: '+'; font-size: 20px; color: var(--muted); }
details.acc[open] > summary::after { content: '–'; }
details.acc > summary h2 { margin: 0; font-size: 16px; }
details.acc[open] > summary { margin-bottom: 12px; }

/* Thẻ thợ ở tab Thợ của công trình (issue #54, gói 2) */
.list-item.worker-item { flex-wrap: wrap; align-items: flex-start; }
.worker-item .main { flex: 1 1 100%; }
.worker-item .row { flex: 1 1 100%; flex-wrap: wrap; }
.worker-card .kv { font-size: 13px; }
.worker-card .kv dd { white-space: normal; }
.rate-now { background: var(--surface-2); border-left: 3px solid var(--accent); border-radius: 8px; padding: 8px 10px; font-weight: 700; }
.kv .strong { font-weight: 700; color: var(--text); }
