:root {
  --ground: #F4F6F8; --surface: #FFFFFF; --surface-2: #EDF1F4; --border: #DCE3E9;
  --ink: #14293D; --ink-2: #45586B; --muted: #78899A;
  --accent: #C2782A; --accent-soft: #F5E7D5; --water: #1C7686; --water-soft: #DCEDEF;
  --good: #2E7D57; --warn: #B7841D; --bad: #C0392B;
  --shadow: 0 1px 2px rgba(20,41,61,.06), 0 8px 24px rgba(20,41,61,.05);
  --r: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0E1620; --surface: #16212E; --surface-2: #1E2C3B; --border: #2A3B4D;
    --ink: #E7EDF3; --ink-2: #AABAC8; --muted: #6E8092;
    --accent: #E0964A; --accent-soft: #33261A; --water: #45A6B8; --water-soft: #16303A;
    --good: #4FB07E; --warn: #E0A94A; --bad: #E5695C;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.28);
  }
}
:root[data-theme="light"] {
  --ground: #F4F6F8; --surface: #FFFFFF; --surface-2: #EDF1F4; --border: #DCE3E9;
  --ink: #14293D; --ink-2: #45586B; --muted: #78899A;
  --accent: #C2782A; --accent-soft: #F5E7D5; --water: #1C7686; --water-soft: #DCEDEF;
  --good: #2E7D57; --warn: #B7841D; --bad: #C0392B;
  --shadow: 0 1px 2px rgba(20,41,61,.06), 0 8px 24px rgba(20,41,61,.05);
}
:root[data-theme="dark"] {
  --ground: #0E1620; --surface: #16212E; --surface-2: #1E2C3B; --border: #2A3B4D;
  --ink: #E7EDF3; --ink-2: #AABAC8; --muted: #6E8092;
  --accent: #E0964A; --accent-soft: #33261A; --water: #45A6B8; --water-soft: #16303A;
  --good: #4FB07E; --warn: #E0A94A; --bad: #E5695C;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.28);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--ground); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
.num { font-variant-numeric: tabular-nums; }
a { color: var(--accent); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 70% -10%, color-mix(in srgb, var(--water) 20%, transparent), transparent 60%), var(--ground); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 30px 28px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand .logo { width: 42px; height: 42px; border-radius: 11px; background: linear-gradient(150deg, var(--water), var(--accent)); display: grid; place-items: center; color: #fff; font-size: 21px; }
.login-brand b { font-size: 17px; display: block; }
.login-brand small { color: var(--muted); font-size: 12.5px; }
.login-card h1 { font-size: 18px; margin-bottom: 4px; }
.login-card .lead { color: var(--muted); font-size: 13.5px; margin-bottom: 20px; }
.login-err { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); border-radius: 9px; padding: 9px 12px; font-size: 13.5px; margin-bottom: 14px; display: none; }
.login-err.show { display: block; }
.demo-note { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); line-height: 1.7; }
.demo-note code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; color: var(--ink-2); }

/* ---------- Top bar ---------- */
header { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 14px; padding: 11px 20px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 11px; margin-right: auto; }
.logo { width: 34px; height: 34px; border-radius: 9px; flex: none; background: linear-gradient(150deg, var(--water), var(--accent)); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 17px; object-fit: cover; }
img.logo { background: none; }
.brand b { font-size: 15.5px; letter-spacing: -.01em; }
.brand small { display: block; color: var(--muted); font-size: 11.5px; font-weight: 500; }
.who-badge { display: flex; align-items: center; gap: 9px; padding: 5px 6px 5px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: 13px; }
.who-badge .role { color: var(--muted); font-size: 11.5px; }
.who-badge .av { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); cursor: pointer; font-size: 16px; transition: .15s; }
.icon-btn:hover { color: var(--ink); border-color: var(--muted); }

nav { display: flex; gap: 4px; padding: 0 14px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; position: sticky; top: 59px; z-index: 40; }
nav button { appearance: none; border: 0; background: none; cursor: pointer; padding: 13px 15px; font-size: 14.5px; font-weight: 550; color: var(--muted); border-bottom: 2.5px solid transparent; white-space: nowrap; font-family: inherit; transition: .15s; }
nav button:hover { color: var(--ink); }
nav button.active { color: var(--accent); border-bottom-color: var(--accent); }
nav button[hidden] { display: none; }

main { max-width: 1120px; margin: 0 auto; padding: 22px 20px 80px; }
.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view.active { animation: none; } }

.page-head { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h2 { font-size: 21px; }
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 13.5px; }
.spacer { margin-left: auto; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); }
.card-h { padding: 15px 18px 0; }
.card-h h3 { font-size: 14px; }
.card-h .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
@media (max-width: 760px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { padding: 15px 16px 16px; }
.stat .lbl { color: var(--muted); font-size: 12.5px; font-weight: 550; display: flex; align-items: center; gap: 7px; }
.stat .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.stat .val { font-size: 27px; font-weight: 700; margin-top: 9px; letter-spacing: -.02em; }
.stat .unit { font-size: 13px; font-weight: 550; color: var(--muted); margin-left: 3px; }
.stat .meta { color: var(--muted); font-size: 12px; margin-top: 5px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }
.chart { padding: 15px 18px 18px; }
.bars { margin-top: 12px; display: flex; flex-direction: column; gap: 11px; }
.bar-row { display: grid; grid-template-columns: 96px 1fr auto; align-items: center; gap: 11px; }
.bar-row .name { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 22px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; min-width: 3px; transition: width .5s cubic-bezier(.2,.7,.2,1); -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.dot, .tb, .pill, .tag { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.bar-row .v { font-size: 13px; font-weight: 600; min-width: 58px; text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: 13.5px; text-align: center; padding: 26px 10px; }
.trend { display: flex; align-items: flex-end; gap: 4px; height: 96px; margin-top: 14px; }
.trend .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; min-width: 0; }
.trend .tb { width: 74%; max-width: 20px; border-radius: 4px 4px 2px 2px; min-height: 2px; transition: height .5s; }
.trend .tl { font-size: 9.5px; color: var(--muted); white-space: nowrap; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; padding: 16px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 550; color: var(--ink-2); }
input, select, textarea { font-family: inherit; font-size: 14.5px; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; width: 100%; transition: .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: var(--muted); }
input:disabled, select:disabled { opacity: .55; cursor: not-allowed; }
.form-actions { padding: 0 18px 16px; display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.btn { appearance: none; font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer; border-radius: 9px; padding: 9px 16px; border: 1px solid transparent; transition: .15s; display: inline-flex; align-items: center; gap: 7px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; filter: none; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--ink-2); }
.btn-ghost:hover { border-color: var(--muted); color: var(--ink); }
.btn-block { width: 100%; justify-content: center; padding: 11px; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { text-align: left; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.link-btn { background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 15px; padding: 4px 6px; border-radius: 6px; }
.link-btn:hover { background: var(--surface-2); color: var(--ink); }
.link-btn.del:hover { color: var(--bad); }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 6px; font-size: 12px; font-weight: 600; background: var(--water-soft); color: var(--water); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.toolbar input[type=date] { width: auto; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 6px 13px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; font-family: inherit; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.att-list { display: flex; flex-direction: column; }
.att-row { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.att-row:last-child { border-bottom: 0; }
.att-row .who { margin-right: auto; }
.att-row .who b { font-size: 14.5px; font-weight: 600; }
.att-row .who small { display: block; color: var(--muted); font-size: 12px; }
.att-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.att-seg button { border: 0; background: var(--surface); padding: 7px 12px; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; font-family: inherit; border-right: 1px solid var(--border); }
.att-seg button:last-child { border-right: 0; }
.att-seg button:disabled { cursor: not-allowed; }
.att-seg button.on-full { background: var(--good); color: #fff; }
.att-seg button.on-half { background: var(--warn); color: #fff; }
.att-seg button.on-off { background: var(--muted); color: #fff; }
.ot { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); }
.ot input { width: 62px; padding: 6px 8px; }

.live-dot { font-size: 11.5px; font-weight: 600; color: var(--good); vertical-align: middle; margin-left: 8px; letter-spacing: .01em; opacity: .55; transition: opacity .3s; }
.live-dot.on { opacity: 1; animation: livepulse 1.6s ease-in-out infinite; }
@keyframes livepulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .live-dot.on { animation: none; } }

.recent-feed { margin-top: 8px; max-height: 320px; overflow-y: auto; }
.recent-feed .rf-row { display: flex; align-items: center; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--border); }
.recent-feed .rf-row:last-child { border-bottom: 0; }
.recent-feed .rf-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; width: 44px; flex: none; }
.recent-feed .rf-boat { font-weight: 600; font-size: 13.5px; margin-right: auto; }
.recent-feed .rf-vol { font-weight: 700; font-size: 14px; color: var(--water); font-variant-numeric: tabular-nums; }
.recent-feed .rf-vol small { color: var(--muted); font-weight: 500; }

.pl-body { padding: 6px 18px 16px; }
.pl-line { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.pl-line:last-child { border-bottom: 0; }
.pl-line .pl-label { color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.pl-line .pl-val { font-variant-numeric: tabular-nums; font-weight: 600; }
.pl-line.pl-sum { margin-top: 4px; padding-top: 13px; border-top: 2px solid var(--border); border-bottom: 0; font-size: 16px; }
.pl-line.pl-sum .pl-label { color: var(--ink); font-weight: 700; }
.pl-line.pl-sum .pl-val { font-weight: 800; }
.pl-chip { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.pl-pos { color: var(--good); }
.pl-neg { color: var(--bad); }

.suggest-body { padding: 8px 18px 16px; display: flex; flex-direction: column; gap: 8px; }
.suggest-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: 9px; font-size: 13.5px; line-height: 1.45; }
.suggest-item .si-ic { font-size: 15px; flex: none; line-height: 1.4; }
.suggest-item.sev-high { background: color-mix(in srgb, var(--bad) 13%, transparent); }
.suggest-item.sev-mid { background: color-mix(in srgb, var(--warn) 15%, transparent); }
.suggest-item.sev-low { background: var(--surface-2); }
.suggest-item b { font-weight: 650; }
.settings-help { margin: 0 18px 16px; padding: 12px 14px; background: var(--surface-2); border-radius: 9px; font-size: 12.5px; line-height: 1.7; color: var(--ink-2); }
.settings-help code { background: var(--surface); padding: 1px 6px; border-radius: 5px; color: var(--accent); }
.inv-neg { color: var(--bad); font-weight: 700; }
.inv-low { color: var(--warn); font-weight: 700; }
.inv-ok { color: var(--good); font-weight: 700; }
.rf-row.rf-new { animation: rfflash 1.4s ease; }
@keyframes rfflash { from { background: var(--water-soft); } to { background: transparent; } }

.mini-stats { display: flex; gap: 22px; flex-wrap: wrap; padding: 14px 18px; }
.mini-stats div { font-size: 13px; color: var(--muted); }
.mini-stats b { display: block; font-size: 19px; color: var(--ink); font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }

.locked-note { background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--warn); border-radius: 9px; padding: 10px 14px; font-size: 13px; margin: 0 18px 14px; display: flex; gap: 8px; align-items: center; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--ground); padding: 11px 20px; border-radius: 10px; font-size: 14px; font-weight: 550; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .3s; z-index: 100; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--bad); color: #fff; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10,20,30,.5); display: none; place-items: center; z-index: 90; padding: 20px; }
.modal-bg.show { display: grid; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 420px; overflow: hidden; }
.modal h3 { padding: 18px 20px 0; font-size: 16px; }
.modal .modal-body { padding: 14px 20px; display: flex; flex-direction: column; gap: 12px; }
.modal .modal-foot { padding: 0 20px 18px; display: flex; gap: 9px; justify-content: flex-end; }

/* In ấn / xuất PDF: chỉ giữ nội dung báo cáo */
@media print {
  header, nav, .no-print, #dash-period, #dash-date, #report-period, #report-date, #report-month, .toolbar, [data-edit-card] { display: none !important; }
  body { background: #fff; color: #000; }
  main { max-width: none; padding: 8px 0; }
  .card { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  .view:not(.active) { display: none !important; }
  .page-head .spacer { display: none; }
}

/* Ảnh chứng từ */
.photo-input { font-size: 13px; }
.photo-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.ph-thumb { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.ph-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph-thumb b { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; display: grid; place-items: center; cursor: pointer; }
.ph-badge { display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px; border-radius: 6px; background: var(--water-soft); color: var(--water); font-size: 12px; font-weight: 600; cursor: pointer; }
.photo-modal { position: fixed; inset: 0; background: rgba(6,12,20,.9); display: none; align-items: center; justify-content: center; z-index: 120; padding: 16px; overflow: auto; }
.photo-modal.show { display: flex; }
.pm-inner { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; max-width: 100%; }
.pm-inner img { max-width: 46vw; max-height: 86vh; border-radius: 10px; box-shadow: 0 8px 40px rgba(0,0,0,.5); }
@media (max-width: 640px) { .pm-inner img { max-width: 92vw; } }
