/* =====================================================================
   GHN — Quy hoạch Bưu Cục · stylesheet
   Một hệ token duy nhất (design tokens ở :root, dùng var() xuyên suốt).
   Đã gộp khối "gốc" + khối "POLISH" cũ, khử khai báo trùng.
   ===================================================================== */

:root{
  /* nền & bề mặt */
  --bg:#eef2f7; --surface:#fff; --surface-2:#f8fafc;
  /* mực & chữ phụ (đã nâng tương phản đạt WCAG AA cho chữ nhỏ) */
  --ink:#0f172a; --ink2:#334155; --muted:#475569; --muted-2:#64748b;
  /* viền */
  --border:#e7edf4; --border-2:#e5e7eb;
  /* thương hiệu */
  --brand:#2563eb; --brand-d:#1d4ed8; --brand-soft:#eef4ff;
  /* trạng thái */
  --ok:#16a34a; --ok-d:#15803d; --danger:#dc2626; --warn:#b45309;
  --hot-bg:#fee2e2; --hot-ink:#991b1b; --cold-bg:#dbeafe; --cold-ink:#1e40af;
  /* topbar (nền tối) */
  --topbar-1:#0f1629; --topbar-2:#0b1220;
  /* bóng */
  --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);
  --sh-modal:0 20px 60px rgba(0,0,0,.4);
  /* bo góc & tầng z */
  --r-sm:6px; --r:8px; --r-lg:12px; --r-xl:14px;
  --z-map:0; --z-panel:6; --z-topbar:10; --z-float:41; --z-modal:70;
  /* chuyển động */
  --t:.15s;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family:"Be Vietnam Pro", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing:antialiased; text-rendering:optimizeLegibility;
}
button, input, select, textarea { font-family: inherit; }
#map { position: absolute; inset: 0; }

/* Accessibility: focus nhìn thấy rõ trên MỌI phần tử tương tác (bàn phím) */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
button:focus-visible, .tab:focus-visible { outline-offset: 3px; }
/* chỉ ẩn cho screen-reader */
.sr-only{ position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }

/* Icon SVG dùng chung */
.ic{ width:1em; height:1em; display:inline-block; vertical-align:-0.14em; fill:none;
     stroke:currentColor; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; flex:none; }
.tab .ic{ width:16px; height:16px; }

/* =========================== LOGIN =========================== */
#login {
  position: fixed; inset: 0; z-index: 100;
  background: radial-gradient(1100px 560px at 30% -10%, #1e2a44, #0a0f1c);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
#login.hidden { display: none; }
#login-card {
  background: var(--surface); padding: 28px 30px; border-radius: 16px; width: min(340px, 100%);
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 26px 70px rgba(0,0,0,.55);
}
#login-card h2 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -.3px; }
.lg-sub { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
#login-card input { padding: 9px 11px; border: 1px solid #d1d5db; border-radius: 7px; font-size: 14px; transition: border-color var(--t), box-shadow var(--t); }
#login-card button {
  padding: 10px; border: 0; border-radius: 7px; background: var(--brand); color: #fff;
  font-weight: 600; font-size: 14px; cursor: pointer; transition: background var(--t), transform .1s;
}
#login-card button:hover { background: var(--brand-d); }
#login-card button:active { transform: translateY(1px); }
#lg-err { color: var(--danger); font-size: 12px; min-height: 14px; }

/* =========================== TOPBAR =========================== */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: var(--z-topbar);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 12px; color: #e5e7eb; font-size: 13px;
  background: linear-gradient(180deg, var(--topbar-1), var(--topbar-2));
  border-bottom: 1px solid rgba(255,255,255,.06); box-shadow: 0 2px 12px rgba(0,0,0,.28);
}
#title { font-weight: 700; font-size: 14px; color: #fff; flex: 0 0 auto; letter-spacing: -.2px; }
.tabs { display: flex; gap: 6px; flex: 1 1 auto; flex-wrap: wrap; }
.tab {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-width: 150px; background: rgba(255,255,255,.06); color: #94a3b8; font-weight: 500;
  border: 0; padding: 6px 12px; border-radius: var(--r-sm); font-size: 13px; cursor: pointer;
  white-space: nowrap; transition: background var(--t), color var(--t);
}
.tab:hover { background: rgba(255,255,255,.13); color: #e2e8f0; }
.tab.active { background: var(--brand); color: #fff; font-weight: 600; box-shadow: 0 2px 12px rgba(37,99,235,.5); }
#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; transition: border-color var(--t), box-shadow var(--t); }
#meta, #diff { flex: 0 1 250px; min-width: 90px; text-align: center; padding: 5px 8px; border-radius: var(--r-sm);
  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; }

/* nút icon trên topbar */
#userbox { position: relative; flex: 0 0 auto; }
#userbtn, #clog-btn {
  background: rgba(255,255,255,.12); border: 0; color: #e5e7eb;
  width: 32px; height: 27px; border-radius: var(--r-sm); cursor: pointer; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; font-size: 15px;
}
#userbtn:hover, #clog-btn:hover { background: rgba(255,255,255,.2); }
#clog-btn.on { background: var(--brand); }
#usermenu { position: absolute; right: 0; top: 33px; background: var(--surface); color: var(--ink);
  border-radius: var(--r); 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: var(--muted); margin-bottom: 9px; white-space: nowrap; }
.um-info b { color: var(--ink); }
#usermenu a#logout { color: var(--danger); font-weight: 600; font-size: 13px; text-decoration: none; }

/* =========================== PANELS TOÀN TRANG =========================== */
#scorecard, #optimizer, #rezone, #chatlog {
  position: absolute; top: var(--topbar-h, 40px); left: 0; right: 0; bottom: 0; z-index: 4;
  background: var(--bg); overflow: auto; padding: 18px 24px;
}
#scorecard.hidden, #optimizer.hidden, #rezone.hidden, #chatlog.hidden { display: none; }
.sc-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.sc-head h2 { margin: 0 0 4px; font-size: 18px; letter-spacing: -.2px; color: var(--ink); }
.sc-note { color: var(--muted); font-size: 12px; margin-bottom: 14px; }

/* bảng scorecard */
table.sc { border-collapse: collapse; width: 100%; font-size: 13px; background: var(--surface); box-shadow: var(--sh1); }
table.sc th, table.sc td { padding: 7px 10px; border-bottom: 1px solid #f1f5f9; text-align: right; white-space: nowrap; }
table.sc th {
  background:#eef2f7; color:#52617a; font-weight:600; font-size:11px; letter-spacing:.04em;
  text-transform:uppercase; cursor: pointer; user-select:none; position: sticky; top:0; z-index:1;
}
table.sc th:first-child, table.sc td:first-child { text-align: left; font-weight: 600; }
table.sc td.l, table.sc th.l { text-align: left; }
table.sc tr.region-row:hover { background: var(--brand-soft); cursor:pointer; }
table.sc tr.total td { font-weight: 700; background: var(--surface-2); border-top: 2px solid #cbd5e1; }

/* ô nóng/lạnh — KÈM ký hiệu ▲▼ (kênh dự phòng ngoài màu cho người mù màu) */
.hot { background: var(--hot-bg); color: var(--hot-ink); }
.cold { background: var(--cold-bg); color: var(--cold-ink); }
td.hot .mk, td.cold .mk { font-size: 9px; margin-right: 3px; opacity: .85; }

.sc-sub { margin-top: 22px; }
#scorecard .sc-sub, #optimizer .sc-sub { border-top: 1px solid var(--border-2); padding-top: 16px; }
.sc-sub h3 { margin: 0 0 8px; font-size: 15px; letter-spacing: -.2px; color: var(--ink); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sc-sub h3 small { color: var(--muted); font-weight: 400; font-size: 12px; }
.chip { display:inline-block; background: var(--brand); color:#fff; padding:3px 10px; border-radius:14px; font-size:12px; cursor:pointer; margin-left:8px; transition: background var(--t); }
.chip:hover { background: var(--brand-d); }

/* =========================== TOOLTIP INFO (ⓘ) =========================== */
/* thay cho các đoạn giải thích công thức dài nhồi dưới tiêu đề */
.info{ position:relative; display:inline-flex; align-items:center; justify-content:center;
  width:16px; height:16px; border-radius:50%; background:var(--brand-soft); color:var(--brand-d);
  font-size:11px; font-weight:700; cursor:help; flex:none; border:0; }
.info:hover, .info:focus-visible{ background:#dbe6ff; }
/* .tip: CHỈ chứa nội dung (JS đọc textContent + screen-reader đọc); hiển thị qua popover cố định bên dưới */
.info .tip{ position:absolute; width:1px; height:1px; padding:0; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; }
/* popover thật: fixed -> thoát mọi stacking context & overflow của panel; nổi trên cả nút Hướng dẫn/Chat */
.info-pop{
  position:fixed; z-index:300; max-width:340px; white-space:normal; text-align:left;
  background:#0f172a; color:#e5e7eb; font-size:12px; font-weight:400; line-height:1.5;
  padding:9px 12px; border-radius:8px; box-shadow:var(--sh2); pointer-events:none; display:none;
}

/* =========================== NÚT NỔI TRÊN MAP =========================== */
#ctrl-toggle {
  position: absolute; top: calc(var(--topbar-h, 40px) + 8px); left: 10px; z-index: var(--z-panel); width: 34px; height: 34px;
  border: 1px solid var(--border); border-radius: var(--r); background: var(--surface);
  box-shadow: var(--sh2); font-size: 18px; padding: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink2);
  transition: background var(--t), transform .1s;
}
#ctrl-toggle:hover { background: var(--surface-2); transform: translateY(-1px); }

#help-btn {
  position: absolute; bottom: 16px; left: 12px; z-index: var(--z-float);
  border: 1px solid var(--border); border-radius: var(--r); padding: 6px 10px; font-size: 12px; font-weight: 600; cursor: pointer;
  background: var(--surface); color: #1f2937; box-shadow: var(--sh2);
  display: inline-flex; align-items: center; gap: 6px; transition: background var(--t), transform .1s;
}
#help-btn:hover { background: var(--brand-soft); transform: translateY(-1px); }

/* =========================== PANEL ĐIỀU KHIỂN (trái) =========================== */
#controls {
  position: absolute; top: calc(var(--topbar-h, 40px) + 48px); left: 10px; z-index: 5; width: 268px; max-width: calc(100vw - 20px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 12px;
  box-shadow: var(--sh2); font-size: 13px; max-height: calc(100% - 100px); overflow: auto;
}
#controls.collapsed { display: none; }
.grp { margin-bottom: 12px; }
.grp > label:first-child { display:block; font-weight: 600; margin-bottom: 6px; color: var(--ink2); 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: var(--r-sm); font-size: 13px;
  transition: border-color var(--t), box-shadow var(--t);
}
#planmode { width: 100%; padding: 8px; border: 0; border-radius: var(--r-sm); background: var(--brand); color:#fff; font-weight:600; cursor:pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background var(--t), transform .1s; }
#planmode:hover { background: var(--brand-d); }
#planmode:active { transform: translateY(1px); }
#planmode.on { background: var(--danger); }
.note { font-size: 11px; color: var(--muted); margin-top: 6px; }
.dq { font-size: 11px; color: var(--warn); margin-top: 8px; border-top: 1px dashed var(--border-2); 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: var(--brand-soft); }

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

/* =========================== PANEL CHI TIẾT (phải) =========================== */
#detail {
  position: absolute; top: calc(var(--topbar-h, 40px) + 8px); right: 10px; z-index: var(--z-panel); width: 330px; max-width: calc(100vw - 20px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 14px 16px;
  box-shadow: var(--sh2); 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;
  width: 26px; height: 26px; border-radius: var(--r-sm); display: inline-flex; align-items: center; justify-content: center; }
#detail-close:hover { background: var(--surface-2); color: var(--ink2); }
#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: var(--muted); }
.kv div:nth-child(even) { font-weight: 600; text-align: right; }
.kv .grp-top { border-top: 1px solid var(--border-2); padding-top: 6px; margin-top: 4px; }
.warn { color: var(--warn); 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: var(--danger); } .delta-pos { color: var(--ok); }
.maplibregl-popup-content { font-size: 12px; padding: 6px 9px; }

/* =========================== CHAT =========================== */
#chat-fab { position: absolute; right: 16px; bottom: 16px; z-index: 40; background: var(--brand); 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); display: inline-flex; align-items: center; gap: 7px;
  transition: background var(--t), transform .1s; }
#chat-fab:hover { background: var(--brand-d); transform: translateY(-1px); }
#chat { position: absolute; right: 16px; bottom: 16px; z-index: 41; width: min(400px, calc(100vw - 24px)); height: 560px; max-height: calc(100% - 70px);
  background: var(--surface); border-radius: var(--r-lg); 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: var(--surface-2); }
.msg { font-size: 13px; line-height: 1.45; padding: 8px 11px; border-radius: 10px; max-width: 90%; }
.msg.u { align-self: flex-end; background: var(--brand); color: #fff; white-space: pre-wrap; }
.msg.a { align-self: flex-start; background: var(--surface); border: 1px solid var(--border-2); color: var(--ink); }
.msg.a table { border-collapse: collapse; font-size: 12px; margin: 6px 0; }
.msg.a th, .msg.a td { border: 1px solid var(--border-2); 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: var(--r); padding: 8px 10px; font-size: 13px; font-family: inherit; transition: border-color var(--t), box-shadow var(--t); }
#chat-send { border: 0; background: var(--brand); color: #fff; border-radius: var(--r); padding: 0 16px; font-weight: 600; cursor: pointer; transition: background var(--t), transform .1s; }
#chat-send:hover { background: var(--brand-d); }
#chat-send:active { transform: translateY(1px); }

/* =========================== 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: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 10px 14px; box-shadow: var(--sh1); }
.stat-card .sv { font-size: 22px; font-weight: 700; color: var(--ink); }
.stat-card .st { font-size: 11px; color: var(--muted); 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: var(--ink2); }
.bar-row { display: flex; align-items: center; gap: 6px; font-size: 11px; margin: 2px 0; }
.bar-row .bd { width: 38px; color: var(--muted); 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: var(--brand); border-radius: 4px; }
.bar-row .bn { width: 30px; text-align: right; color: var(--ink2); 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: var(--ink2); }
ol.topq li b { color: var(--brand); white-space: nowrap; }
#cl-load { border:0; background: var(--brand); color:#fff; border-radius: var(--r-sm); padding:6px 14px; font-weight:600; font-size:13px; cursor:pointer; transition: background var(--t); }
#cl-load:hover { background: var(--brand-d); }
#cs-ai { font-size: 11px; border: 1px solid #c7d2fe; background: #eef2ff; color: #3730a3; border-radius: var(--r-sm); padding: 2px 8px; cursor: pointer; transition: background var(--t); }
#cs-ai:hover { background: #e0e7ff; }
#cs-ai:disabled { opacity: .6; cursor: default; }
.ai-summary { margin-top: 10px; background: var(--surface-2); border: 1px solid var(--border-2); border-left: 3px solid #6366f1; border-radius: var(--r); 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-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: var(--surface); border-radius: var(--r-xl); 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: var(--r);
  width: 30px; height: 30px; font-size: 15px; cursor: pointer; color: #334155;
  display: inline-flex; align-items: center; justify-content: center;
}
#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 var(--border-2); 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: var(--surface-2); }

/* =========================== BẢNG THU/XỔ =========================== */
.tbl-toggle {
  border: 0; background: #eef2ff; color: #3730a3; border-radius: var(--r-sm);
  padding: 5px 12px; font-size: 12px; font-weight: 600; cursor: pointer; margin: 2px 0; transition: background var(--t);
}
.tbl-toggle:hover { background: #e0e7ff; }
.tbl-body { max-height: 340px; overflow: auto; margin-top: 6px; border: 1px solid #eef2f7; border-radius: var(--r); }
.tbl-body.collapsed { display: none; }
.tbl-body.tall { max-height: 640px; }   /* ~20 dòng cho Re-zone */
.tbl-body > .sc-note { padding: 6px 8px 0; }
.tbl-body table { margin: 4px 0 0; }
/* sticky header chắc chắn khi cuộn trong hộp .tbl-body (đè mọi bg khác) */
.tbl-body thead th { position: sticky; top: 0; z-index: 2; background:#eef2f7; box-shadow: inset 0 -1px 0 #d8e0ea; }

/* =========================== DIALOG ĐỀ XUẤT =========================== */
#prop-modal { position:fixed; inset:0; z-index: var(--z-modal); background:rgba(15,23,42,.55);
  display:flex; align-items:center; justify-content:center; padding:24px; }
#prop-modal.hidden { display:none; }
#prop-box { background: var(--surface); border-radius: var(--r-xl); width:min(860px,100%); height:88vh;
  display:flex; flex-direction:column; overflow:hidden; box-shadow: var(--sh-modal); }
#prop-head { display:flex; align-items:center; gap:10px; padding:12px 16px; border-bottom:1px solid #eef2f7; font-size:15px; }
#prop-title-lbl { font-weight:600; color:#334155; }
#prop-close { margin-left:auto; border:0; background:#f1f5f9; border-radius:var(--r); width:30px; height:30px; font-size:15px; cursor:pointer; color:#334155;
  display:inline-flex; align-items:center; justify-content:center; }
#prop-close:hover { background:#e2e8f0; }
#prop-frame { flex:1; width:100%; border:0; background: var(--surface); }
#prop-foot { display:flex; align-items:center; gap:12px; padding:12px 16px; border-top:1px solid #eef2f7; flex-wrap: wrap; }
#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); }
#prop-status { font-size:12px; color:#334155; white-space:nowrap; max-width:230px; overflow:hidden; text-overflow:ellipsis; }
#prop-confirm { border:0; background: var(--ok); color:#fff; border-radius:var(--r); padding:9px 18px; font-weight:600; cursor:pointer; transition: background var(--t); }
#prop-confirm:hover { background: var(--ok-d); }
#prop-confirm:disabled { opacity:.6; cursor:default; }
#prop-review { border:0; background:#7c3aed; color:#fff; border-radius:var(--r); padding:9px 14px; font-weight:600; cursor:pointer; white-space:nowrap; transition: background var(--t); }
#prop-review:hover { background:#6d28d9; }
#prop-review:disabled { opacity:.6; cursor:default; }

/* autocomplete gán cụm */
#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: var(--surface); border:1px solid #d1d5db; border-radius:var(--r); 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; }

/* =========================== TOAST (thông báo) =========================== */
#toast-wrap{ position:fixed; right:16px; top:calc(var(--topbar-h, 40px) + 12px); z-index:200; display:flex; flex-direction:column; gap:8px;
  max-width:min(360px, calc(100vw - 32px)); pointer-events:none; }
.toast{ pointer-events:auto; display:flex; align-items:flex-start; gap:9px;
  background:#0f172a; color:#e5e7eb; border-radius:10px; padding:10px 12px; font-size:13px; line-height:1.4;
  box-shadow:var(--sh2); border-left:4px solid var(--brand);
  animation:toast-in .18s ease-out; }
.toast.hide{ animation:toast-out .18s ease-in forwards; }
.toast.ok{ border-left-color:var(--ok); }
.toast.err{ border-left-color:var(--danger); }
.toast.warn{ border-left-color:#f59e0b; }
.toast .ic{ width:16px; height:16px; margin-top:1px; }
.toast .tx{ flex:1; }
.toast .tx b{ display:block; font-weight:600; margin-bottom:1px; }
.toast .x{ background:none; border:0; color:#94a3b8; cursor:pointer; font-size:15px; line-height:1; padding:0 2px; }
.toast .x:hover{ color:#e5e7eb; }
@keyframes toast-in{ from{opacity:0; transform:translateX(16px);} to{opacity:1; transform:none;} }
@keyframes toast-out{ to{opacity:0; transform:translateX(16px);} }

/* =========================== RESPONSIVE =========================== */
@media (max-width: 1280px){
  .tab{ min-width:0; padding:6px 12px; }   /* nhãn vẫn hiện, chỉ bỏ min-width cố định */
  #meta, #diff{ flex-basis:180px; }
}
@media (max-width: 1080px){
  .tab .lbl{ display:none; }            /* thu về icon-only, giữ aria-label cho screen reader */
  .tab .ic{ width:18px; height:18px; }
  .tab{ padding:6px 10px; }
}
@media (max-width: 1100px) { .stat-grid { grid-template-columns: 1fr; } }
@media (max-width: 860px){
  #topbar{ gap:8px; padding:6px 10px; }
  #meta, #diff{ display:none !important; }  /* nhường chỗ; số liệu vẫn ở scorecard */
  #controls{ width:min(300px, calc(100vw - 20px)); }
  #detail{ width:min(340px, calc(100vw - 20px)); }
  #scorecard, #optimizer, #rezone, #chatlog{ padding:14px; }
}

/* ---------- Màn tải (#boot-ov) ---------- */
#boot-ov{ position:fixed; inset:0; z-index:var(--z-modal); display:flex; align-items:center; justify-content:center;
  background:var(--bg); }
#boot-ov.hidden{ display:none; }
#boot-ov .bo-card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--r-lg);
  box-shadow:var(--sh2); padding:28px 32px; max-width:460px; text-align:center; }
#boot-ov .bo-spin{ width:32px; height:32px; margin:0 auto 14px; border-radius:50%;
  border:3px solid var(--border-2); border-top-color:var(--brand); animation:bo-spin .8s linear infinite; }
#boot-ov.err .bo-spin{ display:none; }
@keyframes bo-spin{ to{ transform:rotate(360deg); } }
#boot-ov .bo-tx{ font-weight:600; color:var(--ink); }
#boot-ov .bo-sub{ margin-top:6px; font-size:13px; color:var(--muted); min-height:18px; }
#boot-ov .bo-err{ margin-top:16px; text-align:left; }
#boot-ov .bo-err.hidden{ display:none; }
#boot-ov .bo-err-hd{ display:flex; gap:8px; align-items:flex-start; color:var(--danger); }
#boot-ov .bo-err-hd .ic{ width:18px; height:18px; flex:0 0 18px; margin-top:1px;
  fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; }
#boot-ov .bo-err-hint{ margin-top:10px; font-size:12.5px; line-height:1.5; color:var(--muted);
  background:var(--surface-2); border:1px solid var(--border); border-radius:var(--r-sm); padding:8px 10px; }
#boot-ov #bo-retry{ margin-top:14px; width:100%; padding:9px 14px; border:0; border-radius:var(--r);
  background:var(--brand); color:#fff; font-weight:600; cursor:pointer; transition:background var(--t); }
#boot-ov #bo-retry:hover{ background:var(--brand-d); }

/* Tôn trọng người tắt hiệu ứng chuyển động */
@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{ animation-duration:.001ms !important; transition-duration:.001ms !important; }
}
