/* ═══════════════════════════════════════════════════════════
   AutoAI — Web SPA (P3) · css/app.css
   Thiết kế lại từ đầu (không copy Tkinter): hiện đại, 2 cột,
   chat là màn hình chính, chức năng phụ = modal.
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg: #f3f5f9;
  --bg-soft: #f8fafc;
  --surface: #ffffff;
  --border: #e3e8ef;
  --border-soft: #edf1f6;
  --text: #1c2333;
  --muted: #64748b;
  --primary: #4f6bf5;
  --primary-dark: #3b53d6;
  --primary-soft: #eef1fe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .10);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

/* ─────────── DARK MODE (doc 02 §6.5) — override TẤT CẢ variables của :root ─────────── */
:root[data-theme="dark"] {
  --bg: #0f1420;
  --bg-soft: #151b2b;
  --surface: #1a2233;
  --border: #2a3550;
  --border-soft: #222c44;
  --text: #e6ebf4;
  --muted: #8b97ad;
  --primary: #4f6bf5;          /* giữ accent */
  --primary-dark: #3b53d6;
  --primary-soft: rgba(79, 107, 245, .18);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, .16);
  --ok: #16a34a;
  --ok-soft: rgba(22, 163, 74, .16);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, .18);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .40), 0 1px 3px rgba(0, 0, 0, .50);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

/* Rules hardcode ảnh hưởng nền chính — override riêng cho dark */
[data-theme="dark"] .toast {
  background: #26314d;
  border: 1px solid var(--border);
}
[data-theme="dark"] .badge.Pending        { background: rgba(99, 102, 241, .18); color: #c7d2fe; }
[data-theme="dark"] .badge[class~='"In Progress"'] { background: rgba(59, 130, 246, .18); color: #bfdbfe; }
[data-theme="dark"] .badge[class~='"Waiting User"']{ background: rgba(217, 119, 6, .18); color: #fde68a; }
[data-theme="dark"] .badge.WaitTools      { background: rgba(234, 88, 12, .18); color: #fed7aa; }
[data-theme="dark"] .badge[class~='"Error Analysis"'] { background: rgba(190, 24, 93, .18); color: #fbcfe8; }
[data-theme="dark"] .badge.Completed      { background: rgba(22, 163, 74, .18); color: #bbf7d0; }
[data-theme="dark"] .badge.Failed         { background: rgba(220, 38, 38, .18); color: #fecaca; }
[data-theme="dark"] .badge.unknown        { background: rgba(100, 116, 139, .18); color: #cbd5e1; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}
#app { display: flex; flex-direction: column; height: 100vh; }
/* [MR-WEBLOGIN2] CHỐNG LỆCH (điểm b): rule author display (vd label.field{display:block})
   ghi đè UA default của thuộc tính [hidden] → ô Base URL login HIỆN mặc định.
   Rule này buộc [hidden] luôn che — áp toàn app (login + topbar + modal + tab-pane). */
[hidden] { display: none !important; }

/* ─────────── LOGIN SCREEN (login-gate API key — doc 02 §9.9) ───────────
   Chưa xác thực: CHE #app, chỉ hiện màn này. Verify OK → vào UI chính. */
.login-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(79,107,245,.16), transparent 60%),
    radial-gradient(900px 500px at 100% 110%, rgba(79,107,245,.12), transparent 55%),
    var(--bg);
  padding: 16px;
  overflow-y: auto;
}
.login-screen[hidden] { display: none; }
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 28px 26px 22px;
  margin: auto;
  animation: modalIn .18s ease-out;
}
.login-logo { font-size: 34px; text-align: center; line-height: 1; }
.login-title { margin: 8px 0 2px; text-align: center; font-size: 22px; letter-spacing: .3px; }
.login-sub { margin: 0 0 18px; text-align: center; font-size: 13px; }
.login-card .field { margin-bottom: 12px; }
.login-error {
  margin: 0 0 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px; font-weight: 600;
  white-space: pre-wrap; word-break: break-word;
}
.login-actions { display: flex; gap: 8px; margin-top: 4px; }
.login-actions .btn-primary { flex: 1; }
.login-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border-soft);
  flex-wrap: wrap;
}
.login-foot .btn-ghost { color: var(--muted); }
.login-foot .btn-ghost:hover { background: var(--bg-soft); color: var(--text); }

/* ─────────── HEADER ─────────── */

/* ─────────── HEADER ─────────── */
.topbar {
  background: linear-gradient(135deg, #171e34 0%, #232c52 100%);
  color: #fff;
  flex: 0 0 auto;
  z-index: 20;
}
.topbar-main {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
}
.logo { font-weight: 800; font-size: 16px; letter-spacing: .2px; }
.project-name {
  background: rgba(255,255,255,.12);
  padding: 3px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conn {
  display: flex; align-items: center; gap: 7px;
  background: rgba(255,255,255,.08);
  padding: 4px 12px; border-radius: 999px; font-size: 12px;
}
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: #94a3b8; flex: 0 0 auto; }
.conn-dot.open { background: #34d399; box-shadow: 0 0 8px rgba(52,211,153,.8); }
.conn-dot.reconnecting { background: #fbbf24; animation: pulse 1s infinite; }
.conn-dot.paused { background: #f87171; }
.conn-dot.closed { background: #94a3b8; }
@keyframes pulse { 50% { opacity: .35; } }
.spacer { flex: 1; }
.topbar-actions {
  display: flex; align-items: center; gap: 4px;
  padding: 0 12px 10px;
  flex-wrap: wrap;
}

/* ─────────── BANNER OFFLINE (WS — doc 02 §6.4) ─────────── */
.banner-offline {
  flex: 0 0 auto;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: #92400e;
  background: var(--warn-soft);
  border-bottom: 1px solid #fde68a;
  z-index: 30; /* trên topbar (20) · dưới sidebar-mobile (40) và modal (50) */
}
.banner-offline[hidden] { display: none; }
[data-theme="dark"] .banner-offline { color: #fde68a; border-bottom-color: rgba(217, 119, 6, .35); }

/* ─────────── LAYOUT 2 CỘT ─────────── */
.main-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 0;
}

/* ─────────── SIDEBAR (danh sách chat) ─────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0;
}
.sidebar-head { padding: 12px; border-bottom: 1px solid var(--border-soft); }
.sidebar-head .btn { width: 100%; }
.sidebar-tools {
  display: flex; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.sidebar-tools input { flex: 1; min-width: 0; }
.chat-list { flex: 1; overflow-y: auto; padding: 6px; }
.chat-item {
  display: block; width: 100%; text-align: left;
  padding: 10px 12px; margin-bottom: 4px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; cursor: pointer; font: inherit; color: inherit;
}
.chat-item:hover { background: var(--bg-soft); }
.chat-item.active { background: var(--primary-soft); border-color: #c7d2fe; }
.chat-item-top { display: flex; align-items: center; gap: 8px; }
.chat-item-name {
  flex: 1; min-width: 0;
  font-weight: 600; font-size: 13.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item-meta {
  display: flex; align-items: center; gap: 8px;
  margin-top: 5px;
  font-size: 11.5px; color: var(--muted);
}
.chat-item-time { margin-left: auto; }
.empty-hint { padding: 24px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* ─────────── CHAT VIEW ─────────── */
.chat-view {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--bg);
}
.chat-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  color: var(--muted); padding: 24px; text-align: center;
}
.chat-empty .big { font-size: 44px; }
.chat-empty h2 { margin: 0; color: var(--text); font-size: 20px; }
.chat-empty .composer { width: min(680px, 92%); }

.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.chat-title { font-weight: 700; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { font-size: 12px; color: var(--muted); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.chat-head .spacer { flex: 1; }

.chat-tools-bar {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--warn-soft);
  border-bottom: 1px solid #fde68a;
}
.tool-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid #fcd34d;
  padding: 3px 10px; border-radius: 999px; font-size: 12px;
}
.tool-chip .spin {
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid #f59e0b; border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chat-msgs { flex: 1; overflow-y: auto; padding: 18px 20px; scroll-behavior: smooth; }
.load-more-row { text-align: center; margin-bottom: 12px; }

/* bubbles */
.msg { display: flex; margin-bottom: 14px; }
.msg.user { justify-content: flex-end; }
.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow);
}
.msg.user .bubble {
  background: linear-gradient(135deg, #4f6bf5, #6d86ff);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.msg.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}
.msg.thinking { justify-content: flex-start; }
.msg.thinking .bubble {
  background: var(--bg-soft);
  border: 1px dashed #cbd5e1;
  font-size: 12.5px; color: var(--muted);
  max-width: 82%;
}
.msg.tool { justify-content: flex-start; }
.msg.tool .bubble {
  background: #0f172a; color: #e2e8f0;
  font-family: var(--mono); font-size: 12px;
  max-width: 82%;
}
.msg.system { justify-content: center; }
.msg.system .bubble {
  background: transparent; box-shadow: none;
  color: var(--muted); font-size: 12px;
  border: 1px dashed var(--border);
}
.bubble-head {
  display: flex; gap: 8px; align-items: center;
  font-size: 11px; color: var(--muted);
  margin-bottom: 6px; font-weight: 600;
}
.msg.user .bubble-head { color: rgba(255,255,255,.75); justify-content: flex-end; }
.bubble-content { font-size: 14px; }
.bubble-content pre {
  background: rgba(15,23,42,.06);
  border-radius: 8px; padding: 8px 10px;
  overflow-x: auto; font-family: var(--mono); font-size: 12px;
}
.msg.tool .bubble-content pre { background: rgba(255,255,255,.08); }
.tool-calls { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.file-chips { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(15,23,42,.05);
  border: 1px solid var(--border);
  padding: 2px 9px; border-radius: 999px; font-size: 11.5px;
}
.msg.user .file-chip { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.35); color: #fff; }
.thinking-block {
  margin-bottom: 8px;
  border-left: 3px solid #c7d2fe;
  background: var(--bg-soft);
  padding: 6px 10px; border-radius: 6px;
  font-size: 12.5px; color: var(--muted);
}
.thinking-block summary { cursor: pointer; font-weight: 600; }
.thinking-block pre {
  margin: 6px 0 0; white-space: pre-wrap; word-break: break-word;
  font-family: var(--font); font-size: 12.5px; color: var(--muted);
  max-height: 180px; overflow-y: auto;
}
/* [R3] Table (GFM) + Mermaid trong bubble assistant/system */
.md table { border-collapse: collapse; width: 100%; margin: 8px 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border, #444); padding: 6px 10px; text-align: left; }
.md th { background: rgba(127,127,127,.15); }
.mermaid { text-align: center; margin: 8px 0; overflow-x: auto; }
.bubble.failed { border-color: var(--danger); }
.bubble.failed .bubble-head { color: var(--danger); }
.stream-cursor {
  display: inline-block; width: 8px; height: 15px;
  background: var(--primary); vertical-align: -2px;
  margin-left: 2px; border-radius: 2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
/* [FIX-4] Entry state hiển thị (load history) */
.msg .bubble.streaming { border-color: var(--primary); }
.streaming-label { font-size: 11px; color: var(--muted); font-style: italic; }

/* [WEB-CHAT-01] Markdown trong bubble assistant/system */
.md { line-height: 1.55; }
.md .md-p { margin: 0 0 8px; }
.md .md-p:last-child { margin-bottom: 0; }
.md .md-h { margin: 10px 0 6px; line-height: 1.3; }
.md h1.md-h { font-size: 1.25em; }
.md h2.md-h { font-size: 1.15em; }
.md h3.md-h, .md h4.md-h, .md h5.md-h, .md h6.md-h { font-size: 1.05em; }
.md .md-list { margin: 0 0 8px; padding-left: 22px; }
.md .md-list:last-child { margin-bottom: 0; }
.md .md-list li { margin: 2px 0; }
.md a { color: var(--primary); text-decoration: underline; word-break: break-word; }
.md code {
  background: rgba(15,23,42,.07);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: 0.9em;
}
.msg.user .md code { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.3); }
.md pre {
  background: rgba(15,23,42,.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  margin: 0 0 8px;
}
.md pre:last-child { margin-bottom: 0; }
.md pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}
.md del { color: var(--muted); }

.waiting-badge {
  display: inline-block; margin-left: 8px;
  background: var(--warn-soft);
  color: var(--warn);
  padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}

/* composer */
.composer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 10px 16px 12px;
  flex: 0 0 auto;
}
.attach-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.attach-row:empty { display: none; }
.attach-item {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 6px; font-size: 12px;
}
.attach-item img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.attach-item button { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 13px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer-row textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 160px;
  padding: 11px 14px; font: inherit; line-height: 1.4;
}
.composer-hint { font-size: 11px; color: var(--muted); margin-top: 6px; }
.token-counter {
  font-size: 11.5px; color: var(--muted);
  margin-bottom: 6px; font-variant-numeric: tabular-nums;
}

/* ─────────── NÚT ─────────── */
.btn {
  font: inherit; font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 14px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-warn { background: #b45309; border-color: #b45309; color: #fff; }
.btn-warn:hover { background: #92400e; }
.btn-ghost { background: transparent; border-color: transparent; color: #cbd5e1; }
.btn-ghost:hover { background: rgba(255,255,255,.12); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }

/* ─────────── FORM ─────────── */
input[type=text], input[type=search], input[type=password], input[type=number], select, textarea {
  font: inherit; color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  background: var(--surface);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,107,245,.15);
}
label.field { display: block; margin-bottom: 10px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
label.field span { display: block; margin-bottom: 4px; }
label.field input, label.field select, label.field textarea { margin-top: 2px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.check input { width: auto; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 0 0 auto; }
.row input[type=text] { flex: 1 1 160px; min-width: 120px; }
.muted { color: var(--muted); font-size: 12.5px; }
.small { font-size: 11.5px; }

/* ─────────── BADGE / TABLE / CARD ─────────── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
.badge.Pending        { background: #e0e7ff; color: #3730a3; }
.badge[class~='"In Progress"'] { background: #dbeafe; color: #1d4ed8; }
.badge[class~='"Waiting User"']{ background: #fef3c7; color: #92400e; }
.badge.WaitTools      { background: #ffedd5; color: #9a3412; }
.badge[class~='"Error Analysis"'] { background: #fce7f3; color: #9d174d; }
.badge.Completed      { background: #dcfce7; color: #166534; }
.badge.Failed         { background: #fee2e2; color: #991b1b; }
.badge.unknown        { background: #e2e8f0; color: #475569; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td {
  text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
.table th { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover { background: var(--bg-soft); }
.table tr.selected { background: var(--primary-soft); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-top: 12px;
  box-shadow: var(--shadow);
}
.card-title { font-weight: 700; font-size: 13px; margin-bottom: 8px; }

.pre {
  background: #0f172a; color: #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 10px 12px; font-family: var(--mono); font-size: 12px;
  white-space: pre-wrap; word-break: break-word;
  max-height: 320px; overflow-y: auto;
  margin: 8px 0 0;
}
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar input[type=text] { flex: 1; min-width: 140px; }

/* ─────────── MODAL ─────────── */
.modal { position: fixed; inset: 0; z-index: 50; }
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(2px);
}
.modal-panel {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(980px, calc(100vw - 32px));
  height: min(680px, calc(100vh - 48px));
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: modalIn .18s ease-out;
}
@keyframes modalIn { from { opacity: 0; transform: translate(-50%, -47%) scale(.98); } }
.modal-head {
  display: flex; align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16px; flex: 1; }
.modal-close {
  border: none; background: none; font-size: 16px;
  cursor: pointer; color: var(--muted);
  padding: 4px 8px; border-radius: 8px;
}
.modal-close:hover { background: var(--bg-soft); color: var(--text); }
.modal-body { flex: 1; overflow-y: auto; padding: 16px 18px; min-height: 0; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
}

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab-btn {
  border: none; background: none; font: inherit; font-weight: 600;
  padding: 8px 14px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane[hidden] { display: none; }

/* split 2 cột trong modal */
.split { display: grid; grid-template-columns: minmax(220px, 340px) minmax(0, 1fr); gap: 14px; align-items: start; }
.split-main { min-width: 0; }
.split-side { min-width: 0; }
.split-side .card { margin-top: 0; }
.list-row {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; margin-bottom: 4px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer; font-size: 13px;
}
.list-row:hover { background: var(--bg-soft); }
.list-row.selected { border-color: var(--primary); background: var(--primary-soft); }
.list-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* task tree */
.task-node { margin-left: 0; }
.task-node .task-node { margin-left: 22px; border-left: 2px solid var(--border-soft); padding-left: 8px; }
.task-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  font-size: 13px;
}
.task-row:hover { background: var(--bg-soft); }
.task-caret {
  border: none; background: none; cursor: pointer;
  width: 18px; font-size: 10px; color: var(--muted);
}
.task-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.task-actions { display: flex; gap: 4px; }

/* ─────────── TOAST ─────────── */
#toasts {
  position: fixed; top: 14px; right: 14px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 380px;
}
.toast {
  background: #0f172a; color: #f1f5f9;
  padding: 10px 14px; border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-size: 13px; line-height: 1.45;
  animation: toastIn .2s ease-out;
  word-break: break-word;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(24px); } }
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--ok); color: #fff; }
.toast.warn { background: var(--warn); color: #fff; }

/* ─────────── RESPONSIVE ─────────── */
@media (max-width: 900px) {
  .main-grid { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(320px, 85vw);
    transform: translateX(-102%);
    transition: transform .2s ease;
    z-index: 40;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .bubble { max-width: 88%; }
}
