/* Sổ theo dõi: giấy trắng, mực xanh, dấu đỏ. Mực xanh cho số liệu, dấu đỏ chỉ dành cho điều cần chú ý. */
:root {
  --paper: #f3f5f1; --sheet: #ffffff; --ink: #14213f; --ink-2: #55607c; --rule: #d8dce4; --blue: #1f3a93;
  --seal: #c2182b; --ok: #17724a; --mute: #dfe3ea; --focus: #e0a100;
  --font: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #0e1524; --sheet: #151e33; --ink: #e9edf7; --ink-2: #a2acc4; --rule: #2a3552; --blue: #8aa4f6; --seal: #ff6f7d; --ok: #55c795; --mute: #27324d; --focus: #ffcc4d; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 15px/1.5 var(--font); font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
h1, h2, h3, p, dl, dd, ul { margin: 0; padding: 0; }
h1 { font-size: 22px; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 17px; line-height: 1.3; font-weight: 700; }
h3 { font-size: 14px; font-weight: 600; margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--rule); }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.seal { width: 44px; height: 44px; flex: none; fill: none; stroke: var(--seal); stroke-width: 2.4; transform: rotate(-8deg); }
.seal path { fill: var(--seal); stroke: none; }

/* ---------- đăng nhập ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-sheet { width: min(380px, 100%); background: var(--sheet); border-top: 3px double var(--blue); border-bottom: 1px solid var(--rule); padding: 28px 28px 30px; display: flex; flex-direction: column; }
.login-sheet .seal { width: 56px; height: 56px; margin-bottom: 14px; }
.login-lead { color: var(--ink-2); margin: 6px 0 20px; }
.login-sheet label { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.login-sheet input { margin-bottom: 14px; padding: 10px 2px 8px; border: 0; border-bottom: 1.5px solid var(--ink-2); background: transparent; border-radius: 0; }
.login-sheet input:focus-visible { outline: none; border-bottom-color: var(--blue); box-shadow: 0 1.5px 0 var(--blue); }
.login-sheet button { margin-top: 6px; padding: 11px 14px; background: var(--blue); color: var(--sheet); border: 0; border-radius: 3px; font-weight: 600; cursor: pointer; }
.login-sheet button:disabled { opacity: 0.55; cursor: default; }
.form-error { color: var(--seal); font-size: 14px; }
.form-error:empty { display: none; }

/* ---------- khung trang ---------- */
#app { max-width: 1360px; margin: 0 auto; padding: 22px 24px 60px; }
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px 24px; padding-bottom: 16px; border-bottom: 3px double var(--blue); }
.brand { display: flex; align-items: center; gap: 14px; }
.stamp { color: var(--ink-2); font-size: 13px; }
.tools { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; }
.seg { display: inline-flex; border: 1px solid var(--blue); border-radius: 3px; overflow: hidden; }
.seg button { border: 0; border-left: 1px solid var(--blue); background: transparent; padding: 7px 12px; cursor: pointer; color: var(--blue); font-weight: 500; }
.seg button:first-child { border-left: 0; }
.seg button[aria-checked="true"] { background: var(--blue); color: var(--sheet); font-weight: 600; }
.pick { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--ink-2); }
.pick select { padding: 7px 26px 7px 8px; border: 1px solid var(--rule); border-radius: 3px; background-color: var(--sheet); font-size: 14px; color: var(--ink); max-width: 260px; }
.quiet { background: transparent; border: 1px solid var(--rule); border-radius: 3px; padding: 7px 12px; cursor: pointer; color: var(--ink); }
.quiet:hover { border-color: var(--blue); color: var(--blue); }
.demo-note { margin-top: 12px; padding: 8px 12px; border-left: 3px solid var(--seal); background: var(--sheet); font-size: 14px; }
#loadError { margin-top: 12px; }

/* ---------- dòng tóm tắt ---------- */
.summary { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); margin: 18px 0; background: var(--sheet); border-bottom: 1px solid var(--rule); }
.summary div { padding: 14px 16px 12px; border-left: 1px solid var(--rule); }
.summary div:first-child { border-left: 0; }
.summary dt { font-size: 13px; color: var(--ink-2); }
.summary dd { font-size: 24px; white-space: nowrap; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; margin-top: 2px; }
.summary small { display: block; font-size: 12px; font-weight: 400; color: var(--ink-2); letter-spacing: 0; }
.live-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); margin-right: 7px; vertical-align: 2px; animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }

/* ---------- tờ ---------- */
.grid { display: grid; gap: 18px; margin-bottom: 18px; }
.grid.two { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.sheet { background: var(--sheet); padding: 18px 20px 20px; border-top: 2px solid var(--blue); border-bottom: 1px solid var(--rule); min-width: 0; }
.lead { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.footnote { color: var(--ink-2); font-size: 13px; margin-top: 14px; }
.empty { color: var(--ink-2); font-size: 14px; padding: 10px 0; }

/* ---------- phễu 5 bước ---------- */
.funnel { margin-top: 16px; }
.f-row { display: grid; grid-template-columns: 28px minmax(120px, 210px) minmax(0, 1fr) 132px; grid-template-areas: "no name track val" ". drop drop drop"; column-gap: 12px; align-items: center; }
.f-no { grid-area: no; } .f-name { grid-area: name; } .f-track { grid-area: track; } .f-val { grid-area: val; } .f-drop { grid-area: drop; }
.f-no { width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--blue); color: var(--blue); font-size: 13px; font-weight: 600; display: grid; place-items: center; }
.f-no.start { border-style: dashed; }
.f-name { font-weight: 500; }
.f-track { height: 26px; background: transparent; border-left: 1px solid var(--ink-2); }
.f-bar { height: 100%; min-width: 2px; background: var(--blue); border-radius: 0 4px 4px 0; }
.f-val { text-align: right; font-weight: 600; font-size: 17px; }
.f-val small { font-weight: 400; font-size: 13px; color: var(--ink-2); margin-left: 6px; }
.f-drop { font-size: 12.5px; color: var(--ink-2); padding: 3px 0 9px; }
.f-drop.big { color: var(--seal); font-weight: 500; }

/* ---------- đánh giá ---------- */
.stack { display: flex; height: 22px; margin: 16px 0 10px; gap: 2px; }
.stack i { display: block; height: 100%; min-width: 3px; }
.stack i:first-child { border-radius: 4px 0 0 4px; }
.stack i:last-child { border-radius: 0 4px 4px 0; }
.s-up { background: var(--ok); } .s-down { background: var(--seal); } .s-none { background: var(--mute); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; list-style: none; }
.legend li { display: flex; align-items: baseline; gap: 7px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; flex: none; align-self: center; }
.legend b { font-weight: 600; }
.comments { list-style: none; margin-top: 10px; max-height: 300px; overflow: auto; }
.comments li { padding: 10px 0 10px 12px; border-left: 3px solid var(--seal); margin-bottom: 10px; }
.comments q { quotes: none; display: block; white-space: pre-wrap; overflow-wrap: anywhere; }
.comments span { display: block; margin-top: 4px; font-size: 12.5px; color: var(--ink-2); }

/* ---------- danh sách thanh ngang ---------- */
.bars { margin-top: 12px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; align-items: baseline; }
.b-name { font-size: 14px; overflow-wrap: anywhere; }
.b-name.flag::before { content: "!"; display: inline-grid; place-items: center; width: 15px; height: 15px; margin-right: 6px; border-radius: 50%; background: var(--seal); color: var(--sheet); font-size: 11px; font-weight: 700; }
.b-val { font-weight: 600; text-align: right; }
.b-val small { font-weight: 400; color: var(--ink-2); font-size: 12.5px; margin-left: 5px; }
.b-track { grid-column: 1 / -1; height: 8px; margin-bottom: 9px; border-left: 1px solid var(--ink-2); }
.b-bar { height: 100%; min-width: 2px; background: var(--blue); border-radius: 0 4px 4px 0; }
.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
.trio dt { font-size: 12.5px; color: var(--ink-2); }
.trio dd { font-size: 22px; font-weight: 600; line-height: 1.2; }
.trio small { display: block; font-size: 12px; font-weight: 400; color: var(--ink-2); }

/* ---------- cột theo ngày ---------- */
.daily { margin-top: 14px; }
.d-plot { display: flex; align-items: flex-end; gap: 2px; height: 150px; border-bottom: 1px solid var(--ink-2); }
.d-col { flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; cursor: default; }
.d-col i { display: block; width: 100%; max-width: 26px; margin: 0 auto; background: var(--blue); border-radius: 4px 4px 0 0; }
.d-col:hover i, .d-col:focus-visible i { opacity: 0.7; }
.d-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.d-max { font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }

/* ---------- sổ phiên ---------- */
.ledger-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px 12px; }
.table-wrap { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--ink-2); padding: 8px 10px; border-bottom: 1.5px solid var(--ink); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
th.num, td.num { text-align: right; }
td:nth-child(1), td:nth-child(2) { white-space: nowrap; }
td small { display: block; color: var(--ink-2); font-size: 12.5px; }
tr.has-note { cursor: pointer; }
tr.note td { background: var(--paper); border-left: 3px solid var(--seal); white-space: pre-wrap; overflow-wrap: anywhere; }
.track { display: inline-flex; align-items: center; }
.track i { width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid var(--ink-2); background: transparent; }
.track i.on { background: var(--blue); border-color: var(--blue); }
.track b { width: 12px; height: 1.5px; background: var(--ink-2); }
.track b.on { background: var(--blue); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 12.5px; padding: 1px 7px; border: 1px solid var(--rule); border-radius: 3px; white-space: nowrap; }
.tag.live { border-color: var(--ok); color: var(--ok); font-weight: 600; }
.mark { font-weight: 600; white-space: nowrap; }
.mark.up { color: var(--ok); } .mark.down, .mark.err { color: var(--seal); } .mark.none { color: var(--ink-2); font-weight: 400; }
.more { display: block; margin: 16px auto 0; }

.tip { position: fixed; z-index: 10; pointer-events: none; background: var(--ink); color: var(--sheet); font-size: 13px; padding: 6px 9px; border-radius: 3px; max-width: 260px; }

@media (max-width: 1180px) { .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); } .summary { grid-template-columns: repeat(3, minmax(0, 1fr)); } .summary div:nth-child(4) { border-left: 0; } .summary div:nth-child(n+4) { border-top: 1px solid var(--rule); } }
@media (max-width: 860px) {
  #app { padding: 16px 14px 40px; }
  .grid.two, .grid.four { grid-template-columns: minmax(0, 1fr); }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary div { border-left: 0; border-top: 1px solid var(--rule); }
  .summary div:nth-child(even) { border-left: 1px solid var(--rule); }
  .f-row { grid-template-columns: 28px minmax(0, 1fr) 96px; grid-template-areas: "no name val" ". track track" ". drop drop"; }
  .f-track { height: 14px; margin: 4px 0; }
  /* sổ phiên: mỗi phiên thành một khối, mỗi ô tự mang nhãn cột */
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { padding: 10px 0; border-bottom: 1.5px solid var(--ink); }
  td { border: 0; padding: 3px 0; display: grid; grid-template-columns: 118px minmax(0, 1fr); gap: 10px; text-align: left !important; }
  td::before { content: attr(data-label); color: var(--ink-2); font-size: 12.5px; }
  tr.note td { display: block; padding: 8px 10px; }
  tr.note td::before { content: none; }
}
