/* Dashboard KiemCoin — giao diện tối. CSP chỉ cho phép stylesheet này (không style inline). */

:root {
  color-scheme: dark;
  --bg: #0a0e14;
  --surface: #10161f;
  --surface-2: #151d28;
  --surface-3: #1c2634;
  --border: #253142;
  --border-strong: #34445b;
  --text: #e7edf4;
  --text-2: #bcc7d5;
  --muted: #9aa8ba;
  --focus: #9ccbff;
  --accent: #4c9aff;
  --link: #8fc2ff;
  --idle: #8593a8;
  --idle-stroke: #4b5a70;
  --edge-idle: #6b7a90;
  --running: #4c9aff;
  --waiting: #f5b83d;
  --done: #3fcf7f;
  --blocked: #ff6161;
  --demo: #e5c6ff;
  --demo-border: rgba(160, 100, 230, 0.55);
  --demo-bg: rgba(150, 90, 220, 0.14);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 12px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  overflow-x: hidden;
}
h1, h2, h3, h4 { line-height: 1.3; }
a { color: var(--link); text-underline-offset: 2px; }
p { margin: 6px 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
main:focus { outline: none; }

.skip-link { position: absolute; left: -9999px; top: 8px; }
.skip-link:focus { left: 8px; z-index: 100; background: var(--surface-3); color: var(--text); padding: 8px 12px; border-radius: 8px; }

/* ---------- Thanh trên ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px;
  background: rgba(10, 14, 20, 0.94);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { flex: none; border-radius: 8px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; }
.tabs [role="tab"] {
  background: none; border: 0; color: var(--text-2);
  padding: 8px 12px; border-radius: 8px;
  font: inherit; font-weight: 600; cursor: pointer;
}
.tabs [role="tab"]:hover { background: var(--surface-2); color: var(--text); }
.tabs [role="tab"][aria-selected="true"] { background: var(--surface-3); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.sync { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sync.offline { color: #ff8a8a; font-weight: 600; }

main { padding: 16px 20px 48px; max-width: 1760px; margin: 0 auto; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 7px 14px;
  border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface-3); color: var(--text);
  font: inherit; font-weight: 600; line-height: 1.2; cursor: pointer; text-align: center;
}
.btn:hover:not(:disabled) { border-color: #4a5f7c; background: #233043; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: #2569c7; border-color: #3b80dd; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #2d77dc; border-color: #5a96ea; }
.btn-success { background: #187a48; border-color: #23995b; color: #fff; }
.btn-success:hover:not(:disabled) { background: #1d8c53; border-color: #2fb26c; }
.btn-warn { background: rgba(245, 184, 61, 0.14); border-color: rgba(245, 184, 61, 0.65); color: #ffd27a; }
.btn-warn:hover:not(:disabled) { background: rgba(245, 184, 61, 0.22); border-color: #f5b83d; }
.btn-danger { background: #b83434; border-color: #d24a4a; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #c93d3d; }
.btn-danger-outline { background: transparent; border-color: rgba(255, 97, 97, 0.55); color: #ff8f8f; }
.btn-danger-outline:hover:not(:disabled) { background: rgba(255, 97, 97, 0.12); border-color: #ff6161; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border); }
.link-button {
  background: none; border: 0; padding: 0; color: var(--link);
  font: inherit; font-weight: 600; text-align: left; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}

/* ---------- Nhãn ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border-strong);
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.02em; line-height: 1.5;
  white-space: nowrap; background: var(--surface-3); color: var(--text-2);
}
.badge-demo { color: var(--demo); border-color: var(--demo-border); background: var(--demo-bg); }
.badge-warn, .badge-waiting { color: #ffd27a; border-color: rgba(245, 184, 61, 0.55); background: rgba(245, 184, 61, 0.12); }
.badge-done { color: #7fe3a8; border-color: rgba(63, 207, 127, 0.5); background: rgba(63, 207, 127, 0.1); }
.badge-blocked { color: #ff9a9a; border-color: rgba(255, 97, 97, 0.55); background: rgba(255, 97, 97, 0.12); }
.state-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.state-badge.state-idle { color: var(--text-2); }
.state-badge.state-running { color: #8cc0ff; border-color: rgba(76, 154, 255, 0.55); background: rgba(76, 154, 255, 0.12); }
.state-badge.state-waiting { color: #ffd27a; border-color: rgba(245, 184, 61, 0.55); background: rgba(245, 184, 61, 0.12); }
.state-badge.state-done { color: #7fe3a8; border-color: rgba(63, 207, 127, 0.5); background: rgba(63, 207, 127, 0.1); }
.state-badge.state-blocked { color: #ff9a9a; border-color: rgba(255, 97, 97, 0.55); background: rgba(255, 97, 97, 0.12); }

/* ---------- Thông báo ---------- */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px 14px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface-2);
}
.banner p { margin: 0; }
.banner-waiting { border-color: rgba(245, 184, 61, 0.6); background: rgba(245, 184, 61, 0.1); }
.banner-blocked { border-color: rgba(255, 97, 97, 0.6); background: rgba(255, 97, 97, 0.1); }
.banner-done { border-color: rgba(63, 207, 127, 0.5); background: rgba(63, 207, 127, 0.08); }
.conn-banner { margin: 10px 20px 0; }
.attention { display: flex; flex-direction: column; gap: 8px; }
.attention:empty { display: none; }
.notice { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface-3); margin: 8px 0; }
.notice p { margin: 0 0 6px; }
.notice-warn { border-color: rgba(245, 184, 61, 0.65); background: rgba(245, 184, 61, 0.1); }
.notice-error { border-color: rgba(255, 97, 97, 0.6); background: rgba(255, 97, 97, 0.1); }
.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px;
  width: min(420px, calc(100vw - 32px));
}
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border-radius: 10px;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.toast p { margin: 0; flex: 1; }
.toast-success { border-color: rgba(63, 207, 127, 0.65); }
.toast-error { border-color: rgba(255, 97, 97, 0.75); }
.toast-close { background: none; border: 0; color: var(--text-2); font-size: 20px; line-height: 1; cursor: pointer; padding: 0 2px; }

/* ---------- Bố cục tab Dự án ---------- */
.panel-projects { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 16px; align-items: start; }
.sidebar {
  position: sticky; top: 74px; max-height: calc(100vh - 90px); overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.sidebar-title { margin: 0; font-size: 15px; }
.list-toggle {
  display: none; background: none; border: 0; color: var(--text); padding: 4px 0;
  font: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
}
.project-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.list-state { color: var(--muted); padding: 8px 2px; }
.project-item {
  width: 100%; display: flex; flex-direction: column; gap: 5px; text-align: left;
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; cursor: pointer;
}
.project-item:hover { border-color: var(--border-strong); background: #1a2330; }
.project-item.active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); background: var(--surface-3); }
.pi-title { font-weight: 700; overflow-wrap: anywhere; }
.pi-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.pi-stage, .pi-spend { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.project-area { min-width: 0; display: flex; flex-direction: column; gap: 12px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card > h3, .card > h2 { margin: 0 0 10px; }
.card h3 { font-size: 14.5px; }
.card h4 { font-size: 13.5px; margin: 14px 0 6px; }
.empty-state { text-align: center; padding: 40px 20px; }
.empty-state h2 { margin-top: 0; }

.project-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 16px; }
.project-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; width: 100%; }
.project-title { margin: 0; font-size: 20px; overflow-wrap: anywhere; }
.project-facts { display: flex; flex-wrap: wrap; gap: 8px 26px; margin: 0; flex: 1 1 420px; }
.fact { min-width: 0; }
.fact dt { font-size: 12px; color: var(--muted); }
.fact dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.project-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 450px); gap: 12px; align-items: start; }
.workspace-flow { min-width: 0; }
.workspace-details { position: sticky; top: 74px; max-height: calc(100vh - 90px); overflow: auto; min-width: 0; overscroll-behavior: contain; }
.details { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Sơ đồ ---------- */
.flow-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.flow-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.flow-title { margin: 0; font-size: 14.5px; }
.zoom-controls { display: flex; align-items: center; gap: 4px; }
.zoom-label { min-width: 42px; text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.flow-frame { overflow: auto; max-height: calc(100vh - 270px); min-height: 380px; background: #0c1119; overscroll-behavior: contain; }
.flow-frame:focus { outline: none; }
.flow-svg { display: block; margin: 0 auto; font-family: var(--font); }

.node { cursor: pointer; outline: none; }
.node .node-body { fill: #131b26; stroke: var(--idle-stroke); stroke-width: 1.5; transition: stroke 0.25s, fill 0.25s; }
.node .node-rim { fill: none; stroke: var(--idle-stroke); stroke-width: 1.5; }
.node .node-ring { fill: none; stroke: transparent; stroke-width: 2.5; }
.node .node-label { fill: var(--text); font-size: 12.5px; font-weight: 600; }
.node .node-sub { fill: var(--muted); font-size: 11px; }
.node.state-idle .node-label { fill: var(--text-2); }
.node:hover .node-body { fill: #19222f; }
.node.state-running .node-body { fill: rgba(76, 154, 255, 0.13); stroke: var(--running); stroke-width: 2.6; }
.node.state-waiting .node-body { fill: rgba(245, 184, 61, 0.12); stroke: var(--waiting); stroke-width: 2.6; }
.node.state-done .node-body { fill: rgba(63, 207, 127, 0.08); stroke: var(--done); stroke-width: 2; }
.node.state-blocked .node-body { fill: rgba(255, 97, 97, 0.13); stroke: var(--blocked); stroke-width: 2.6; }
.node.state-running .node-rim { stroke: var(--running); }
.node.state-waiting .node-rim { stroke: var(--waiting); }
.node.state-done .node-rim { stroke: var(--done); }
.node.state-blocked .node-rim { stroke: var(--blocked); }
.node.selected .node-ring { stroke: var(--focus); }
.node:focus-visible .node-ring { stroke: #ffffff; stroke-dasharray: 5 3; }
.node-badge circle { fill: var(--surface); stroke: currentColor; stroke-width: 1.8; }
.node-badge .badge-icon { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.node.state-idle .node-badge { display: none; }
.node.state-running .node-badge { color: var(--running); }
.node.state-running .node-badge .badge-icon { fill: currentColor; stroke-width: 1; }
.node.state-waiting .node-badge { color: var(--waiting); }
.node.state-done .node-badge { color: var(--done); }
.node.state-blocked .node-badge { color: var(--blocked); }
.node.state-running .node-body { animation: mg-pulse 1.6s ease-in-out infinite; }

.edge { fill: none; stroke: var(--edge-idle); stroke-width: 1.6; transition: stroke 0.25s; }
.edge.kind-data { stroke-dasharray: 5 5; }
.edge.kind-halt { stroke-dasharray: 2 4; }
.edge.state-done { stroke: var(--done); stroke-width: 2.1; }
.edge.state-blocked { stroke: var(--blocked); stroke-width: 2.6; }
.edge.state-running { stroke: var(--running); stroke-width: 2.8; stroke-dasharray: 10 7; animation: mg-flow 0.85s linear infinite; }
.edge.state-waiting { stroke: var(--waiting); stroke-width: 2.6; stroke-dasharray: 4 6; animation: mg-flow-slow 1.8s linear infinite; }
.arrowhead.state-idle { fill: var(--edge-idle); }
.arrowhead.state-running { fill: var(--running); }
.arrowhead.state-waiting { fill: var(--waiting); }
.arrowhead.state-done { fill: var(--done); }
.arrowhead.state-blocked { fill: var(--blocked); }
.edge-label-bg { fill: #0c1119; stroke: var(--border); stroke-width: 1; }
.edge-label text { fill: var(--muted); font-size: 11px; font-weight: 500; }
.edge-label-holder.state-running text { fill: #8cc0ff; }
.edge-label-holder.state-waiting text { fill: #ffd27a; }
.edge-label-holder.state-done text { fill: #7fe3a8; }
.edge-label-holder.state-blocked text { fill: #ff9a9a; }
.edge-label-holder.state-running .edge-label-bg { stroke: var(--running); }
.edge-label-holder.state-blocked .edge-label-bg { stroke: var(--blocked); }

@keyframes mg-flow { to { stroke-dashoffset: -17; } }
@keyframes mg-flow-slow { to { stroke-dashoffset: -10; } }
@keyframes mg-pulse { 50% { stroke-opacity: 0.55; } }

@media (prefers-reduced-motion: reduce) {
  .edge, .node .node-body { animation: none !important; transition: none !important; }
}
.flow-panel.ended .edge, .flow-panel.ended .node .node-body { animation: none !important; }
.flow-note { margin: 0; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); font-size: 12.5px; }

.legend { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); }
.legend ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--text-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend-note { margin: 0; font-size: 12px; color: var(--muted); }
.legend-line { display: inline-block; width: 28px; border-top: 3px solid var(--edge-idle); }
.legend-line.state-running { border-top-color: var(--running); border-top-style: dashed; }
.legend-line.state-waiting { border-top-color: var(--waiting); border-top-style: dotted; }
.legend-line.state-done { border-top-color: var(--done); }
.legend-line.state-blocked { border-top-color: var(--blocked); }
.legend-shape { display: inline-block; width: 18px; height: 12px; border: 1.5px solid var(--text-2); }
.legend-shape.shape-stage { border-radius: 3px; }
.legend-shape.shape-gate { width: 11px; height: 11px; transform: rotate(45deg); margin: 0 3px; }
.legend-shape.shape-store { border-radius: 50% / 30%; }
.legend-shape.shape-data { height: 0; border: 0; border-top: 2px dashed var(--text-2); }
.legend-shape.shape-side { height: 12px; border-left: 0; border-radius: 0 10px 10px 0; }

/* ---------- Bảng chi tiết ---------- */
.detail-nav { margin: -4px 0 6px -6px; }
.detail-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.detail-title h2, .detail-head > h2 { margin: 0; font-size: 17px; }
.detail-title h2:focus { outline: none; }
.kv { display: grid; grid-template-columns: minmax(110px, 40%) minmax(0, 1fr); gap: 6px 12px; margin: 6px 0 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv dd > .hint { display: block; margin-top: 1px; }
.field-block { margin-top: 8px; }
.field-label { margin: 10px 0 4px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.list { margin: 0; padding-left: 18px; }
.list li { margin: 2px 0; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; }
.pre { white-space: pre-wrap; }
.mono, code { font-family: var(--mono); font-size: 0.92em; overflow-wrap: anywhere; word-break: break-word; }
code.mono { background: var(--surface-3); border: 1px solid var(--border); padding: 0 5px; border-radius: 4px; }
.text-waiting { color: #ffd27a; }
.text-blocked { color: #ff9a9a; }
.error-card { border-color: rgba(255, 97, 97, 0.6); }
.error-card.soft { border-color: rgba(245, 184, 61, 0.55); }
.error-message { font-weight: 600; }
.approval-card.pending { border-color: rgba(245, 184, 61, 0.65); }
.approval-card.approved { border-color: rgba(63, 207, 127, 0.5); }
.subject-hash { font-size: 12.5px; color: var(--text-2); }
.review-item { border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin: 10px 0; background: var(--surface-2); }
.review-item-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 6px; }
.review-target { border: 1px solid rgba(245, 184, 61, 0.5); background: rgba(245, 184, 61, 0.08); border-radius: 10px; padding: 8px 10px; margin: 8px 0; }
.review-target.missing { border-color: rgba(255, 97, 97, 0.55); background: rgba(255, 97, 97, 0.08); }
.review-target .field-label { margin-top: 0; }
.target-line { margin: 2px 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.decision-grid { display: grid; grid-template-columns: 1fr; gap: 0; }
.demo-note {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 10px; margin: 0 0 10px; border-radius: 8px;
  border: 1px solid var(--demo-border); background: var(--demo-bg); color: var(--demo); font-size: 13px;
}
.media { display: block; height: min(60vh, 520px); max-width: 100%; aspect-ratio: 9 / 16; margin: 0 auto 10px; background: #000; border-radius: 10px; }
.media-placeholder {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; text-align: center;
  min-height: 130px; padding: 12px; margin-bottom: 10px; border-radius: 10px;
  border: 1px dashed var(--demo-border); color: var(--demo); font-weight: 600;
  background: repeating-linear-gradient(45deg, rgba(150, 90, 220, 0.07) 0 10px, transparent 10px 20px);
}
.qa-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 2px; font-weight: 600; }
.meter { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; margin: 4px 0 10px; }
.meter-fill { display: block; height: 100%; width: 0; background: var(--done); }
.meter-fill.high { background: var(--waiting); }
.meter-fill.over { background: var(--blocked); }
.reconcile { display: flex; flex-direction: column; }

.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item { position: relative; margin-left: 6px; padding: 0 0 12px 18px; border-left: 2px solid var(--border); }
.tl-item:last-child { padding-bottom: 2px; }
.tl-item::before { content: ""; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--idle); }
.tl-item.tone-running::before { background: var(--running); }
.tl-item.tone-waiting::before { background: var(--waiting); }
.tl-item.tone-done::before { background: var(--done); }
.tl-item.tone-blocked::before { background: var(--blocked); }
.tl-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 10px; }
.tl-head time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.tl-detail { margin: 2px 0; color: var(--text-2); overflow-wrap: anywhere; }
.tl-meta { margin: 0; color: var(--muted); font-size: 12px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table th { color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table td .hint { display: block; }

details.collapsible { margin-top: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
details.collapsible > summary { cursor: pointer; padding: 7px 10px; font-size: 13px; font-weight: 600; color: var(--text-2); }
details.collapsible[open] > summary { border-bottom: 1px solid var(--border); }
details.collapsible > :not(summary) { margin: 10px; }
pre.json {
  margin: 0; padding: 10px; max-height: 360px; overflow: auto;
  background: var(--bg); border-radius: 6px; color: #cfe3ff;
  font: 12px/1.45 var(--mono); white-space: pre;
}

/* ---------- Biểu mẫu ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; min-width: 0; }
label { font-size: 13px; color: var(--text-2); font-weight: 600; }
input, textarea, select {
  width: 100%; min-width: 0; padding: 8px 10px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 8px;
  font: inherit;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input[type="checkbox"] { width: 18px; height: 18px; flex: none; margin: 2px 0 0; accent-color: var(--accent); }
.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 500; color: var(--text); margin: 8px 0; }
.field-check { justify-content: flex-end; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 0 12px; }
.form-error { color: #ff9a9a; font-weight: 600; margin: 4px 0; }
.form-error:empty { display: none; }
.action-form { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-top: 10px; background: var(--surface-2); }
.action-form h4 { margin: 0 0 4px; font-size: 13.5px; }
.action-form > .hint { margin: 0 0 8px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
.field.inline select { width: auto; min-width: 220px; max-width: 100%; }

/* ---------- Các tab khác ---------- */
.panel-stack { display: flex; flex-direction: column; gap: 12px; max-width: 1240px; margin: 0 auto; }
.tab-head-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.tab-head-row h2 { margin: 0; font-size: 19px; }
.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.button-row select { width: auto; max-width: 100%; }
.perf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: 12px; }
.perf-project { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface-2); min-width: 0; }
.perf-project.selected { border-color: var(--accent); }
.perf-project-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.perf-project-head h4 { margin: 0; overflow-wrap: anywhere; }
.kpi-window { margin-bottom: 12px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); gap: 10px; }
.kpi { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface-2); min-width: 0; }
.kpi-missing { border-style: dashed; border-color: rgba(245, 184, 61, 0.55); }
.kpi-label { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-2); }
.kpi-value { margin: 4px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-missing .kpi-value { color: #ffd27a; font-size: 16px; }
.kpi-reason { margin: 0 0 6px; font-size: 13px; color: var(--text-2); }
.kpi-formula { margin: 4px 0; font-size: 12.5px; color: var(--muted); }
.kpi-components { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
.kpi-components li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.caveats { margin-top: 12px; color: var(--text-2); font-size: 13px; }
.report-text {
  margin: 0; padding: 14px; max-height: 70vh; overflow: auto;
  white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  font: 13.5px/1.6 var(--mono); color: var(--text);
}
.checklist { list-style: none; margin: 8px 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.checklist li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.meta-slot:empty { display: none; }

/* ---------- Hộp thoại ---------- */
dialog.dialog {
  width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow: auto;
  padding: 0; border: 1px solid var(--border-strong); border-radius: 14px;
  background: var(--surface); color: var(--text);
}
dialog.dialog-small { width: min(460px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(3, 6, 10, 0.72); }
.dialog-body { padding: 18px 20px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.dialog-head h2, .dialog-body > h2 { margin: 0; font-size: 18px; }
fieldset { border: 1px solid var(--border); border-radius: 10px; margin: 0 0 12px; padding: 10px 12px 2px; min-width: 0; }
legend { padding: 0 6px; font-size: 13px; font-weight: 700; color: var(--text-2); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* ---------- Đăng nhập ---------- */
body.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); padding: 26px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; }
.brand-lg .brand-text strong { font-size: 18px; }
.brand-lg .brand-text span { font-size: 13px; }
.login-card h1 { margin: 20px 0 12px; font-size: 20px; }
.login-note { margin: 14px 0 0; font-size: 12.5px; color: var(--muted); }

/* ---------- Màn hình hẹp ---------- */
@media (max-width: 1099px) {
  .panel-projects { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; max-height: none; overflow: visible; }
  .list-toggle { display: inline-flex; }
  .sidebar-title { display: none; }
  .sidebar-head { margin-bottom: 0; }
  .sidebar.list-open .sidebar-head { margin-bottom: 10px; }
  .sidebar:not(.list-open) .project-list { display: none; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .workspace-details { position: static; max-height: none; overflow: visible; }
  .flow-frame { max-height: 70vh; min-height: 320px; }
}

@media (max-width: 720px) {
  main { padding: 12px 14px 40px; }
  .topbar { padding: 8px 14px; gap: 8px 10px; }
  .brand-text span { display: none; }
  .tabs { order: 3; width: 100%; }
  .tabs [role="tab"] { flex: 1 1 0; padding: 8px 4px; font-size: 13.5px; }
  .sync { display: none; }
  .project-title { font-size: 18px; }
  .project-facts { gap: 8px 18px; flex-basis: 100%; }
  .project-actions { margin-left: 0; width: 100%; }
  .project-actions .btn { flex: 1 1 0; }
  .card { padding: 12px; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .kv dt { margin-top: 8px; }
  .kv dt:first-child { margin-top: 0; }
  .conn-banner { margin: 8px 14px 0; }
  .toasts { left: 12px; right: 12px; bottom: 12px; width: auto; }
  .field.inline { flex-direction: column; align-items: stretch; width: 100%; }
  .field.inline select { min-width: 0; width: 100%; }
  .dialog-body { padding: 14px; }
}

/* Kết nối Meta (public/meta.js) */
.meta-card h4 { margin: 18px 0 6px; font-size: 13px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.meta-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
.probe-list, .page-list { list-style: none; margin: 6px 0; padding: 0; display: grid; gap: 6px; }
.page-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.page-list li .btn { margin-left: auto; }
.meta-pages { margin-top: 14px; padding: 12px; border: 1px solid var(--border-strong); border-radius: 12px; }
.abandon-form { display: grid; gap: 6px; min-width: 220px; }
.abandon-form input[type="text"] { width: 100%; }
.abandon-form label { font-size: 12px; color: var(--text-2); }
