* { box-sizing: border-box; }
#login { position: fixed; inset: 0; z-index: 100; background: #0f172a;
  display: flex; align-items: center; justify-content: center; }
#login.hidden { display: none; }
#login-card { background: #fff; padding: 28px 30px; border-radius: 12px; width: 310px;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 44px rgba(0,0,0,.45); }
#login-card h2 { margin: 0; font-size: 17px; }
.lg-sub { color: #6b7280; font-size: 12px; margin-bottom: 6px; }
#login-card input { padding: 9px 11px; border: 1px solid #d1d5db; border-radius: 7px; font-size: 14px; }
#login-card button { padding: 10px; border: 0; border-radius: 7px; background: #2563eb; color: #fff; font-weight: 600; font-size: 14px; cursor: pointer; }
#lg-err { color: #dc2626; font-size: 12px; min-height: 14px; }
#userbox { position: relative; flex: 0 0 auto; }
#userbtn, #clog-btn { background: rgba(255,255,255,.12); border: 0; color: #e5e7eb; font-size: 15px;
  width: 32px; height: 27px; border-radius: 6px; cursor: pointer; flex: 0 0 auto; }
#clog-btn.on { background: #2563eb; }
#usermenu { position: absolute; right: 0; top: 33px; background: #fff; color: #111827;
  border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.28); padding: 10px 13px; min-width: 160px; z-index: 30; }
#usermenu.hidden { display: none; }
.um-info { font-size: 12px; color: #6b7280; margin-bottom: 9px; white-space: nowrap; }
.um-info b { color: #111827; }
#usermenu a#logout { color: #dc2626; font-weight: 600; font-size: 13px; text-decoration: none; }
html, body { margin: 0; height: 100%; font-family: system-ui, "Segoe UI", Roboto, sans-serif; }
#map { position: absolute; inset: 0; }

#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px; background: rgba(17,24,39,.92); color: #e5e7eb;
  font-size: 13px; backdrop-filter: blur(4px);
}
#title { font-weight: 700; font-size: 14px; color: #fff; flex: 0 0 auto; }
.tabs { display: flex; gap: 6px; flex: 1 1 auto; }
.tab { flex: 0 0 150px; text-align: center; background: rgba(255,255,255,.08); color: #cbd5e1;
  border: 0; padding: 6px 8px; border-radius: 6px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.tab.active { background: #2563eb; color: #fff; font-weight: 600; }
#rf-wrap { flex: 0 0 auto; color: #cbd5e1; font-size: 12px; }
#regionfilter { padding: 3px 6px; border-radius: 5px; border: 1px solid #475569; background:#1e293b; color:#e5e7eb; font-size:12px; }
#meta, #diff { flex: 0 1 250px; min-width: 90px; text-align: center; padding: 5px 8px; border-radius: 6px;
  background: rgba(255,255,255,.06); font-size: 12px; line-height: 1.35;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#meta { color: #cbd5e1; }
#diff { color: #fcd34d; }

#scorecard, #optimizer, #rezone, #chatlog { position: absolute; top: 40px; left: 0; right: 0; bottom: 0; z-index: 4;
  background: #f8fafc; overflow: auto; padding: 18px 24px; }
#scorecard.hidden, #optimizer.hidden, #rezone.hidden, #chatlog.hidden { display: none; }
.sc-head h2 { margin: 0 0 4px; font-size: 18px; }
.sc-note { color: #6b7280; font-size: 12px; margin-bottom: 14px; }
table.sc { border-collapse: collapse; width: 100%; font-size: 13px; background:#fff; box-shadow:0 1px 4px rgba(0,0,0,.08); }
table.sc th, table.sc td { padding: 7px 10px; border-bottom: 1px solid #eef2f7; text-align: right; white-space: nowrap; }
table.sc th { background:#f1f5f9; cursor: pointer; user-select:none; position: sticky; top:0; }
table.sc th:first-child, table.sc td:first-child { text-align: left; font-weight: 600; }
table.sc tr.region-row:hover { background:#eff6ff; cursor:pointer; }
table.sc tr.total td { font-weight: 700; background:#f8fafc; border-top: 2px solid #cbd5e1; }
.hot { background:#fee2e2; } .cold { background:#dbeafe; }
.sc-sub { margin-top: 22px; }
/* gạch phân cách đầu mỗi nhóm ở Scorecard & Network Optimizer */
#scorecard .sc-sub, #optimizer .sc-sub { border-top: 1px solid #e5e7eb; padding-top: 16px; }
.sc-sub h3 { margin: 0 0 8px; font-size: 15px; }
.sc-sub h3 small { color:#6b7280; font-weight: 400; font-size: 12px; }
table.sc td.l, table.sc th.l { text-align: left; }
.chip { display:inline-block; background:#2563eb; color:#fff; padding:3px 10px; border-radius:14px; font-size:12px; cursor:pointer; margin-left:8px; }

#ctrl-toggle {
  position: absolute; top: 48px; left: 10px; z-index: 6; width: 34px; height: 34px;
  border: 0; border-radius: 8px; background: rgba(255,255,255,.97);
  box-shadow: 0 4px 18px rgba(0,0,0,.18); font-size: 18px; line-height: 34px; padding: 0; cursor: pointer;
}
#ctrl-toggle:hover { background: #f1f5f9; }
#controls.collapsed { display: none; }
#controls {
  position: absolute; top: 88px; left: 10px; z-index: 5; width: 268px;
  background: rgba(255,255,255,.97); border-radius: 10px; padding: 12px;
  box-shadow: 0 4px 18px rgba(0,0,0,.18); font-size: 13px; max-height: calc(100% - 100px); overflow:auto;
}
.grp { margin-bottom: 12px; }
.grp > label:first-child { display:block; font-weight: 600; margin-bottom: 6px; color:#374151; font-size:12px; }
.ck { display: flex; align-items: center; gap: 6px; font-weight: 400 !important; margin: 3px 0; cursor: pointer; }
#controls select, #controls input[type=text], #search {
  width: 100%; padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px;
}
#planmode { width: 100%; padding: 8px; border: 0; border-radius: 6px; background: #2563eb; color:#fff; font-weight:600; cursor:pointer; }
#planmode.on { background: #dc2626; }
.note { font-size: 11px; color: #6b7280; margin-top: 6px; }
.dq { font-size: 11px; color: #b45309; margin-top: 8px; border-top: 1px dashed #e5e7eb; padding-top: 8px; }

#legend { border-top: 1px solid #eee; padding-top: 8px; margin-top: 4px; }
.lg { display: flex; align-items: center; gap: 7px; margin: 3px 0; font-size: 12px; }
.sw { width: 13px; height: 13px; border-radius: 3px; flex: none; }
.sw.circle { border-radius: 50%; }

#search-results { max-height: 160px; overflow: auto; }
.sr { padding: 5px 6px; border-bottom: 1px solid #f3f4f6; cursor: pointer; font-size: 12px; }
.sr:hover { background: #eff6ff; }

#detail {
  position: absolute; top: 48px; right: 10px; z-index: 6; width: 330px;
  background: #fff; border-radius: 10px; padding: 14px 16px; box-shadow: 0 4px 18px rgba(0,0,0,.22);
  font-size: 13px; max-height: calc(100% - 60px); overflow: auto;
}
#detail.hidden { display: none; }
#detail-close { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 16px; cursor: pointer; color:#9ca3af; }
#detail h3 { margin: 0 8px 4px 0; font-size: 15px; }
.tag { display:inline-block; padding:1px 7px; border-radius: 10px; font-size:11px; font-weight:600; color:#fff; margin-right:4px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 2px 8px; margin: 8px 0; }
.kv div:nth-child(odd) { color: #6b7280; }
.kv div:nth-child(even) { font-weight: 600; text-align: right; }
.kv .grp-top { border-top: 1px solid #e5e7eb; padding-top: 6px; margin-top: 4px; }
.warn { color: #b45309; font-weight: 600; }
table.bal { width:100%; border-collapse: collapse; margin-top: 8px; font-size: 12px; }
table.bal th, table.bal td { border-bottom: 1px solid #eee; padding: 4px 5px; text-align: right; }
table.bal th:first-child, table.bal td:first-child { text-align: left; }
.delta-neg { color: #dc2626; } .delta-pos { color: #16a34a; }
.maplibregl-popup-content { font-size: 12px; padding: 6px 9px; }

#chat-fab { position: absolute; right: 16px; bottom: 16px; z-index: 40; background: #2563eb; color: #fff;
  border: 0; border-radius: 22px; padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 14px rgba(37,99,235,.45); }
#chat { position: absolute; right: 16px; bottom: 16px; z-index: 41; width: 400px; height: 560px; max-height: calc(100% - 70px);
  background: #fff; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.3); display: flex; flex-direction: column; overflow: hidden; }
#chat.hidden, #chat-fab.hidden { display: none; }
#chat-head { background: #1e293b; color: #fff; padding: 10px 14px; font-weight: 600; font-size: 14px; display: flex; align-items: center; }
#chat-scope { color: #93c5fd; font-weight: 400; font-size: 12px; margin-left: 6px; }
#chat-close { margin-left: auto; background: none; border: 0; color: #cbd5e1; font-size: 16px; cursor: pointer; }
#chat-msgs { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: #f8fafc; }
.msg { font-size: 13px; line-height: 1.45; padding: 8px 11px; border-radius: 10px; max-width: 90%; }
.msg.u { align-self: flex-end; background: #2563eb; color: #fff; white-space: pre-wrap; }
.msg.a { align-self: flex-start; background: #fff; border: 1px solid #e5e7eb; color: #111827; }
.msg.a table { border-collapse: collapse; font-size: 12px; margin: 6px 0; }
.msg.a th, .msg.a td { border: 1px solid #e5e7eb; padding: 3px 6px; }
.msg.a p { margin: 4px 0; } .msg.a ul { margin: 4px 0; padding-left: 18px; }
#chat-input { display: flex; gap: 6px; padding: 9px; border-top: 1px solid #eef2f7; }
#chat-q { flex: 1; resize: none; border: 1px solid #d1d5db; border-radius: 8px; padding: 8px 10px; font-size: 13px; font-family: inherit; }
#chat-send { border: 0; background: #2563eb; color: #fff; border-radius: 8px; padding: 0 16px; font-weight: 600; cursor: pointer; }

/* ---- Thống kê lịch sử chat ---- */
.stat-cards { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 16px; }
.stat-card { flex: 1 1 120px; background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 10px; padding: 10px 14px; }
.stat-card .sv { font-size: 22px; font-weight: 700; color: #111827; }
.stat-card .st { font-size: 11px; color: #6b7280; margin-top: 2px; }
.stat-grid { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 18px; align-items: start; }
.stat-col h4 { margin: 0 0 6px; font-size: 12px; color: #374151; }
.bar-row { display: flex; align-items: center; gap: 6px; font-size: 11px; margin: 2px 0; }
.bar-row .bd { width: 38px; color: #6b7280; font-variant-numeric: tabular-nums; }
.bar-row .bb { flex: 1; background: #eef2f7; border-radius: 4px; height: 12px; overflow: hidden; }
.bar-row .bb i { display: block; height: 100%; background: #2563eb; border-radius: 4px; }
.bar-row .bn { width: 30px; text-align: right; color: #374151; font-variant-numeric: tabular-nums; }
ol.topq { margin: 4px 0; padding-left: 22px; font-size: 12px; }
ol.topq li { margin: 3px 0; display: flex; justify-content: space-between; gap: 10px; }
ol.topq li span { color: #374151; }
ol.topq li b { color: #2563eb; white-space: nowrap; }
@media (max-width: 1100px) { .stat-grid { grid-template-columns: 1fr; } }
#cs-ai { font-size: 11px; border: 1px solid #c7d2fe; background: #eef2ff; color: #3730a3; border-radius: 6px; padding: 2px 8px; cursor: pointer; }
#cs-ai:disabled { opacity: .6; cursor: default; }
.ai-summary { margin-top: 10px; background: #f8fafc; border: 1px solid #e5e7eb; border-left: 3px solid #6366f1; border-radius: 8px; padding: 10px 14px; font-size: 12.5px; }
.ai-summary h1, .ai-summary h2, .ai-summary h3 { font-size: 13px; margin: 8px 0 4px; }
.ai-summary ul, .ai-summary ol { margin: 4px 0; padding-left: 20px; }
.ai-summary li { margin: 3px 0; }
.ai-summary p { margin: 5px 0; }

/* ---- Nút Hướng dẫn + popup ---- */
#help-btn {
  position: absolute; bottom: 16px; left: 12px; z-index: 41;
  border: 0; border-radius: 8px; padding: 6px 10px; font-size: 12px; font-weight: 600; cursor: pointer;
  background: rgba(255,255,255,.97); color: #1f2937; box-shadow: 0 4px 18px rgba(0,0,0,.18);
}
#help-btn:hover { background: #eef2ff; }
#help-modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
#help-modal.hidden { display: none; }
#help-box {
  position: relative; background: #fff; border-radius: 14px; width: min(820px, 100%);
  max-height: 88vh; overflow: auto; padding: 24px 30px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
#help-close {
  position: absolute; top: 12px; right: 14px; border: 0; background: #f1f5f9; border-radius: 8px;
  width: 30px; height: 30px; font-size: 15px; cursor: pointer; color: #334155;
}
#help-close:hover { background: #e2e8f0; }
#help-content { font-size: 13.5px; line-height: 1.55; color: #1f2937; }
#help-content h1 { font-size: 20px; margin: 0 0 4px; }
#help-content h2 { font-size: 16px; margin: 20px 0 6px; padding-top: 10px; border-top: 1px solid #eef2f7; }
#help-content h3 { font-size: 14px; margin: 12px 0 4px; }
#help-content table { border-collapse: collapse; margin: 8px 0; font-size: 12.5px; }
#help-content th, #help-content td { border: 1px solid #e5e7eb; padding: 4px 8px; text-align: left; }
#help-content code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
#help-content ul, #help-content ol { padding-left: 20px; margin: 6px 0; }
#help-content li { margin: 3px 0; }
#help-content blockquote { border-left: 3px solid #c7d2fe; margin: 8px 0; padding: 4px 12px; color: #475569; background: #f8fafc; }

/* ---- Bảng thu/xổ + hộp cuộn ~10 dòng ---- */
.tbl-toggle {
  border: 0; background: #eef2ff; color: #3730a3; border-radius: 6px;
  padding: 5px 12px; font-size: 12px; font-weight: 600; cursor: pointer; margin: 2px 0;
}
.tbl-toggle:hover { background: #e0e7ff; }
.tbl-body { max-height: 340px; overflow: auto; margin-top: 6px; border: 1px solid #eef2f7; border-radius: 8px; }
.tbl-body.collapsed { display: none; }
.tbl-body > .sc-note { padding: 6px 8px 0; }
.tbl-body table { margin: 4px 0 0; }
.tbl-body thead th { position: sticky; top: 0; background: #f8fafc; z-index: 1; }

/* ============ POLISH — nguyên tắc frontend-design, tinh chỉnh cho dashboard dữ liệu ============ */
:root{
  --bg:#eef2f7; --surface:#fff; --ink:#0f172a; --ink2:#334155; --muted:#64748b;
  --border:#e7edf4; --brand:#2563eb; --brand-d:#1d4ed8; --brand-soft:#eef4ff;
  --sh1:0 1px 2px rgba(15,23,42,.05), 0 2px 10px rgba(15,23,42,.06);
  --sh2:0 8px 28px rgba(15,23,42,.16);
}
html, body { font-family:"Be Vietnam Pro", system-ui, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing:antialiased; text-rendering:optimizeLegibility; }

/* Topbar: nền sâu, gradient nhẹ, viền dưới tinh tế */
#topbar { background:linear-gradient(180deg,#0f1629,#0b1220); border-bottom:1px solid rgba(255,255,255,.06); box-shadow:0 2px 12px rgba(0,0,0,.28); }
#title { letter-spacing:-.2px; }
.tab { background:rgba(255,255,255,.06); color:#94a3b8; font-weight:500; transition:background .15s,color .15s; }
.tab:hover { background:rgba(255,255,255,.13); color:#e2e8f0; }
.tab.active { background:var(--brand); color:#fff; box-shadow:0 2px 12px rgba(37,99,235,.5); }
#regionfilter { transition:border-color .15s,box-shadow .15s; }

/* Cards nổi: bóng mềm 2 lớp + viền nhạt + bo mượt */
#controls, #detail { border:1px solid var(--border); box-shadow:var(--sh2); border-radius:12px; }
#ctrl-toggle, #help-btn { border:1px solid var(--border); box-shadow:var(--sh2); transition:background .15s,transform .1s; }
#ctrl-toggle:hover, #help-btn:hover { transform:translateY(-1px); }

/* Nút chính: hover/active có phản hồi */
#planmode, #chat-send, #login-card button, #cl-load, #chat-fab { transition:background .15s,transform .1s,box-shadow .15s; }
#planmode:hover, #chat-send:hover, #login-card button:hover { background:var(--brand-d); }
#login-card button:active, #planmode:active, #chat-send:active { transform:translateY(1px); }
#chat-fab:hover { background:var(--brand-d); transform:translateY(-1px); }

/* Inputs: focus ring rõ ràng, đồng nhất */
#controls select, #controls input, #search, #login-card input, #chat-q, #regionfilter { transition:border-color .15s, box-shadow .15s; }
#controls select:focus, #controls input:focus, #search:focus, #login-card input:focus, #chat-q:focus {
  outline:none; border-color:var(--brand); box-shadow:0 0 0 3px var(--brand-soft);
}

/* Panels nội dung: nền dịu + tiêu đề nét */
#scorecard, #optimizer, #rezone, #chatlog { background:var(--bg); }
.sc-head h2, .sc-sub h3 { letter-spacing:-.2px; color:var(--ink); }

/* Bảng: header nhỏ-in hoa-xám, hover xanh nhạt.
   KHÔNG overflow:hidden trên table.sc — nó phá sticky header khi cuộn (.tbl-body lo bo góc). */
table.sc { box-shadow:var(--sh1); }
table.sc th { background:#eef2f7; color:#52617a; font-weight:600; font-size:11px; letter-spacing:.04em; text-transform:uppercase; }
table.sc td { border-bottom:1px solid #f1f5f9; }
table.sc tr.region-row:hover { background:var(--brand-soft); }
/* sticky header chắc chắn (đè mọi bg khác), giữ khi cuộn trong hộp .tbl-body */
.tbl-body thead th { position:sticky; top:0; z-index:2; background:#eef2f7; box-shadow:inset 0 -1px 0 #d8e0ea; }
.tbl-body.tall { max-height:640px; }   /* ~20 dòng cho Re-zone */

/* Login: nền có chiều sâu, card sang */
#login { background:radial-gradient(1100px 560px at 30% -10%, #1e2a44, #0a0f1c); }
#login-card { border-radius:16px; box-shadow:0 26px 70px rgba(0,0,0,.55); }
#login-card h2 { font-size:18px; font-weight:800; letter-spacing:-.3px; }

/* Thẻ thống kê + chip + nút nhỏ: bo & bóng đồng bộ */
.stat-card { box-shadow:var(--sh1); border-color:var(--border); }
.chip, .tbl-toggle, #cs-ai { transition:background .15s; }

/* Form controls không tự kế thừa font -> ép dùng chung Be Vietnam Pro (hết lệch font) */
button, input, select, textarea { font-family: inherit; }

/* ---- Dialog Đề xuất quy hoạch ---- */
#prop-modal { position:fixed; inset:0; z-index:70; background:rgba(15,23,42,.55);
  display:flex; align-items:center; justify-content:center; padding:24px; }
#prop-modal.hidden { display:none; }
#prop-box { background:#fff; border-radius:14px; width:min(860px,100%); height:88vh;
  display:flex; flex-direction:column; overflow:hidden; box-shadow:0 20px 60px rgba(0,0,0,.4); }
#prop-head { display:flex; align-items:center; padding:12px 16px; border-bottom:1px solid #eef2f7; font-size:15px; }
#prop-close { margin-left:auto; border:0; background:#f1f5f9; border-radius:8px; width:30px; height:30px; font-size:15px; cursor:pointer; color:#334155; }
#prop-frame { flex:1; width:100%; border:0; background:#fff; }
#prop-foot { display:flex; align-items:center; gap:12px; padding:12px 16px; border-top:1px solid #eef2f7; }
#prop-status { font-size:12px; color:#334155; white-space:nowrap; max-width:230px; overflow:hidden; text-overflow:ellipsis; }
#prop-confirm { border:0; background:#16a34a; color:#fff; border-radius:8px; padding:9px 18px; font-weight:600; cursor:pointer; }
#prop-confirm:hover { background:#15803d; }
#prop-confirm:disabled { opacity:.6; cursor:default; }
#prop-review { border:0; background:#7c3aed; color:#fff; border-radius:8px; padding:9px 14px; font-weight:600; cursor:pointer; white-space:nowrap; }
#prop-review:hover { background:#6d28d9; }
#prop-review:disabled { opacity:.6; cursor:default; }
#pt-box { position:relative; }
#pt-input { width:100%; box-sizing:border-box; padding:7px 10px; border:1px solid #d1d5db; border-radius:7px; font-size:13px; }
#pt-input:focus { outline:none; border-color:var(--brand); box-shadow:0 0 0 3px var(--brand-soft); }
#pt-list { display:none; position:absolute; left:0; right:0; top:100%; margin-top:3px; max-height:260px; overflow:auto;
  background:#fff; border:1px solid #d1d5db; border-radius:8px; box-shadow:0 8px 24px rgba(15,23,42,.18); z-index:50; }
.pt-item { padding:7px 10px; font-size:13px; cursor:pointer; border-bottom:1px solid #f1f5f9; }
.pt-item:hover { background:var(--brand-soft); }
.pt-code { color:#94a3b8; font-size:11px; float:right; }
.pt-more { padding:6px 10px; font-size:11px; color:#94a3b8; font-style:italic; }

/* ô tên + comment trong dialog đề xuất */
#prop-head { gap:10px; }
#prop-title-lbl { font-weight:600; color:#334155; }
#prop-name { flex:1; min-width:200px; padding:8px 11px; border:1px solid #d1d5db; border-radius:7px; font-size:14px; font-weight:600; }
#prop-name:focus { outline:none; border-color:var(--brand); box-shadow:0 0 0 3px var(--brand-soft); }
