/* FEOL — Báo cáo vận hành. Dashboard nội bộ, chạy offline: system font, không CDN.
 * Token màu: nền trung tính, 1 accent xanh; đỏ/cam/lục chỉ dùng theo NGHĨA trạng thái
 * (quá hạn / sắp hết hạn / tiền), không dùng trang trí. Light + dark theo hệ điều hành. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef0f3;
  --text: #1a212b;
  --text-2: #57616f;
  --text-3: #8b94a1;
  --border: #e2e5ea;
  --border-strong: #c9cfd8;

  --accent: #2155c4;
  --accent-strong: #1a46a3;
  --accent-weak: #e8eefb;
  --accent-text: #1c4bb0;

  --red: #bb3028;
  --red-weak: #fbeae8;
  --red-border: #ecc5c1;
  --amber: #995407;
  --amber-weak: #fcf1e0;
  --amber-border: #ecd3ab;
  --green: #177245;
  --green-weak: #e6f4eb;
  --green-border: #bfe0cc;
  --gray-weak: #eef0f3;

  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgb(23 32 43 / 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181e;
    --surface: #1c222b;
    --surface-2: #212833;
    --surface-3: #2a323e;
    --text: #e6eaef;
    --text-2: #a5afbc;
    --text-3: #717c8b;
    --border: #2d3540;
    --border-strong: #3c4654;

    --accent: #6a96e8;
    --accent-strong: #85aaec;
    --accent-weak: #22304a;
    --accent-text: #8fb1ee;

    --red: #e2766e;
    --red-weak: #3a2320;
    --red-border: #5c322d;
    --amber: #dfa050;
    --amber-weak: #392c17;
    --amber-border: #5c4824;
    --green: #5bbd8a;
    --green-weak: #1d3327;
    --green-border: #2d4f3b;
    --gray-weak: #2a323e;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ============ Topbar ============ */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: #fff;
  background: var(--accent);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
}
@media (prefers-color-scheme: dark) {
  .brand-mark { color: #14181e; }
}
.brand-text h1 { font-size: 16px; margin: 0; line-height: 1.25; font-weight: 650; }
.brand-sub { font-size: 12px; color: var(--text-3); }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.asof { font-size: 12.5px; color: var(--text-2); font-family: var(--mono); }

/* ============ Layout ============ */

.container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 18px 20px 48px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 16px;
}

.sec-title {
  font-size: 15px;
  font-weight: 650;
  margin: 22px 0 10px;
}
.sec-title:first-child { margin-top: 0; }
.count-note { font-size: 12px; font-weight: 400; color: var(--text-3); }

.hint { color: var(--text-2); font-size: 12.5px; margin: 6px 0; }

.foot {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 20px 28px;
  color: var(--text-3);
  font-size: 12px;
}

/* ============ Buttons & form controls ============ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
@media (prefers-color-scheme: dark) {
  .btn.primary { color: #14181e; }
}
.btn.ghost-light {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-2);
}
.btn input[type="file"] { display: none; }

.btn-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0 4px; }

input[type="text"], input[type="url"], input[type="number"], select {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input::placeholder { color: var(--text-3); }

/* ============ Setup / upload ============ */

.setup h2 { margin: 0 0 4px; font-size: 16px; }

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 26px 18px;
  text-align: center;
  margin-top: 12px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone.dragover { border-color: var(--accent); background: var(--accent-weak); }
.dz-title { font-size: 15px; font-weight: 600; margin: 0; }
.dz-sub { color: var(--text-3); font-size: 12.5px; margin: 4px 0 14px; }
.dz-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

.file-status { margin-top: 10px; font-size: 12.5px; font-family: var(--mono); }
.file-status .ok { color: var(--green); }
.file-status .bad { color: var(--red); }
.file-status div { padding: 2px 0; }

.setup.compact { padding: 10px 18px; }
.setup.compact .dropzone, .setup.compact > .hint, .setup.compact .file-status { display: none; }
.setup.compact h2 { font-size: 13.5px; color: var(--text-2); font-weight: 500; }

/* ============ Warnings ============ */

.warnings {
  background: var(--amber-weak);
  border: 1px solid var(--amber-border);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 16px;
  font-size: 12.5px;
}
.warnings h4 { margin: 2px 0 6px; font-size: 13px; color: var(--amber); }
.warnings ul { margin: 0; padding-left: 18px; }
.warnings li { margin: 2px 0; }

/* ============ Tabs ============ */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}
.tab-btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--text-2);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 13px;
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent-text); border-bottom-color: var(--accent); }
.tab-badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  background: var(--red);
  color: #fff;
  border-radius: 999px;
  padding: 0 6px;
  margin-left: 5px;
  vertical-align: 1px;
}

/* ============ Storytelling ============ */

.story-banner {
  background: var(--accent-weak);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 14px;
  line-height: 1.65;
}
.story-banner .story-label,
.story-note .story-label {
  display: block;
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 3px;
}
.story-note {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  margin: 10px 0 2px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-2);
}
.t-red { color: var(--red); }
.t-amber { color: var(--amber); }
.t-green { color: var(--green); }

/* ============ Hôm nay: nhóm hành động ============ */

.todo-group { margin-bottom: 16px; }
.todo-group-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}
.todo-group-head h2 { font-size: 14.5px; font-weight: 650; margin: 0; }
.todo-group-head .n {
  font-family: var(--mono);
  font-size: 12.5px;
  border-radius: 999px;
  padding: 1px 9px;
  background: var(--gray-weak);
  color: var(--text-2);
}
.todo-group.g-red .todo-group-head h2 { color: var(--red); }
.todo-group.g-red .todo-group-head .n { background: var(--red); color: #fff; }
.todo-group.g-amber .todo-group-head h2 { color: var(--amber); }
.todo-group.g-amber .todo-group-head .n { background: var(--amber); color: #fff; }
.todo-group.g-green .todo-group-head h2 { color: var(--green); }
.todo-group.g-green .todo-group-head .n { background: var(--green); color: #fff; }
.todo-group-head .gd { font-size: 12px; color: var(--text-3); }

.lead-list { display: flex; flex-direction: column; gap: 6px; }

.lead-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 14px;
}
.lead-row.red { border-left-color: var(--red); background: var(--red-weak); }
.lead-row.amber { border-left-color: var(--amber); background: var(--amber-weak); }
.lead-row.green { border-left-color: var(--green); }

.lead-main { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; min-width: 0; }
.lead-id { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.lead-person { font-weight: 600; }
.lead-phone { font-family: var(--mono); font-size: 12.5px; color: var(--text-2); }
.lead-action { grid-column: 1 / -1; font-size: 13px; color: var(--text-2); }
.lead-action b { color: var(--text); }
.lead-meta {
  grid-row: 1;
  grid-column: 2;
  font-size: 12px;
  color: var(--text-3);
  text-align: right;
  white-space: nowrap;
}

.status-chip {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 999px;
  padding: 1px 9px;
  background: var(--gray-weak);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.status-chip.Pending { background: var(--accent-weak); color: var(--accent-text); border-color: transparent; }
.status-chip.Approved { background: var(--green-weak); color: var(--green); border-color: transparent; }
.status-chip.Rejected { background: var(--red-weak); color: var(--red); border-color: transparent; }
.status-chip.Cancel { background: var(--gray-weak); color: var(--text-2); border-color: transparent; }

.days-chip { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.days-chip.neg { color: var(--red); }
.days-chip.near { color: var(--amber); }

.empty-note {
  color: var(--text-3);
  font-size: 13px;
  padding: 14px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}

/* ============ Stat tiles (Tổng quan) ============ */

.stat-section { margin-bottom: 14px; }
.stat-section h2 { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 0 0 7px; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
}
.stat-tile .v { font-family: var(--mono); font-size: 19px; font-weight: 650; line-height: 1.2; }
.stat-tile .l { font-size: 11.5px; color: var(--text-2); margin-top: 2px; line-height: 1.35; }
.stat-tile.red .v { color: var(--red); }
.stat-tile.amber .v { color: var(--amber); }
.stat-tile.green .v { color: var(--green); }

/* ============ Funnel bars ============ */

.funnel-row {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr) 54px 90px 90px;
  align-items: center;
  gap: 10px;
  padding: 3px 0;
  font-size: 12.5px;
}
.funnel-row .fr-name { color: var(--text); font-weight: 550; }
.funnel-row .fr-bar { background: var(--surface-3); border-radius: 4px; height: 16px; overflow: hidden; }
.funnel-row .fr-fill { background: var(--accent); height: 100%; border-radius: 4px; min-width: 2px; }
.funnel-row.money .fr-fill { background: var(--green); }
.funnel-row .fr-n { font-family: var(--mono); font-weight: 650; text-align: right; }
.funnel-row .fr-pct { font-family: var(--mono); color: var(--text-3); text-align: right; font-size: 11.5px; }
.funnel-head { font-size: 11px; color: var(--text-3); font-weight: 400; }

/* Thanh phân bổ trạng thái cuối */
.dist-bar-cell { min-width: 140px; }
.dist-bar { background: var(--surface-3); border-radius: 4px; height: 12px; overflow: hidden; }
.dist-fill { height: 100%; border-radius: 4px; min-width: 2px; background: var(--accent); }
.dist-fill.Rejected { background: var(--red); }
.dist-fill.Approved { background: var(--green); }
.dist-fill.Cancel { background: var(--text-3); }

/* ============ Pub cards ============ */

.pub-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
.pub-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 15px;
}
.pub-card.warn { border-left-color: var(--red); }
.pub-card.good { border-left-color: var(--green); }
.pub-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.pub-name { font-family: var(--mono); font-weight: 650; font-size: 13.5px; }
.pub-pic { font-size: 12px; color: var(--text-2); }
.pub-pic.missing { color: var(--amber); font-weight: 600; }
.pub-nums {
  display: flex;
  gap: 16px;
  margin: 8px 0 6px;
  font-family: var(--mono);
  font-size: 12.5px;
}
.pub-nums b { font-size: 15px; display: block; font-weight: 650; }
.pub-nums span { color: var(--text-3); font-size: 11px; font-family: inherit; }
.pub-story { font-size: 12.5px; color: var(--text-2); line-height: 1.55; }
.pub-story.warn { color: var(--red); }
.pub-story.good { color: var(--green); }

.callout {
  background: var(--amber-weak);
  border: 1px solid var(--amber-border);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 14px;
  font-size: 13px;
}
.callout b { color: var(--amber); }
.callout .pub-chip {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--amber-border);
  border-radius: 999px;
  padding: 1px 9px;
  margin: 2px 3px 0 0;
}

/* ============ Tables ============ */

.table-scroll { overflow-x: auto; }
.table-scroll.tall { max-height: 70vh; overflow-y: auto; }

table.data {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
  white-space: nowrap;
}
table.data th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-2);
  font-weight: 600;
  font-size: 11.5px;
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-strong);
  z-index: 1;
}
table.data td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data tbody tr:hover td { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-family: var(--mono); }
table.data td.mono { font-family: var(--mono); font-size: 12px; }
table.data td.wrap { white-space: normal; min-width: 220px; max-width: 420px; }

tr.row-overdue td { background: var(--red-weak); }
tr.row-near td { background: var(--amber-weak); }
tr.row-overdue:hover td, tr.row-near:hover td { filter: brightness(0.97); }

.cell-remaining-neg { color: var(--red); font-weight: 700; font-family: var(--mono); }
.cell-remaining-near { color: var(--amber); font-weight: 700; font-family: var(--mono); }

.unknown-flag {
  display: inline-block;
  font-size: 11px;
  background: var(--amber-weak);
  border: 1px solid var(--amber-border);
  color: var(--amber);
  border-radius: 999px;
  padding: 0 8px;
}

.editable-cell { background: var(--surface-2); cursor: text; min-width: 160px; }
.editable-cell:focus { outline: 2px solid var(--accent); background: var(--surface); }

/* ============ Collapse (details) ============ */

details.collapse > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-2);
  user-select: none;
}
details.collapse[open] > summary { margin-bottom: 8px; color: var(--text); }

/* ============ Google Sheet panel ============ */

.sheet-url-row { margin: 14px 0 6px; }
.sheet-url-row label { font-size: 12.5px; font-weight: 600; color: var(--text-2); display: block; margin-bottom: 5px; }
.sheet-url-controls { display: flex; gap: 8px; }
.sheet-url-controls input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 12px; }

.privacy-note {
  background: var(--amber-weak);
  border: 1px solid var(--amber-border);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  font-size: 12.5px;
  margin: 10px 0;
}

.sync-log {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  max-height: 220px;
  overflow-y: auto;
}
.sync-line { padding: 1.5px 0; }
.sync-line.ok { color: var(--green); }
.sync-line.bad { color: var(--red); }
.sync-line.muted { color: var(--text-3); }

/* ============ Filters ============ */

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.filters input[type="text"] { min-width: 220px; }
.range-label { font-size: 12.5px; color: var(--text-2); display: inline-flex; align-items: center; gap: 5px; }
.range-label input { width: 64px; }

/* ============ Responsive ============ */

@media (max-width: 760px) {
  .container { padding: 12px 12px 40px; }
  .topbar-inner { padding: 8px 12px; }
  .lead-row { grid-template-columns: 1fr; }
  .lead-meta { grid-row: auto; grid-column: 1; text-align: left; white-space: normal; }
  .funnel-row { grid-template-columns: 110px minmax(0, 1fr) 44px 64px; }
  .funnel-row .fr-pct:last-child { display: none; }
  .pub-cards { grid-template-columns: 1fr; }
  .sheet-url-controls { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
