/* Kíp — giao diện trò chuyện với kíp agent
   Giấy xám ngả lá, mực xanh đen. Màu nhóm: teal (thực thi), mận (chuyên gia), hổ phách (huấn luyện).
   Bút dạ quang chỉ dùng cho thứ đang diễn ra. */
:root {
  --paper: #E9ECE6;
  --sheet: #F7F8F4;
  --sheet-2: #F0F2EC;
  --ink: #1B2A33;
  --ink-2: #4A5960;
  --ink-3: #75828A;
  --line: #C8CFC9;
  --line-2: #DDE2DC;
  --teal: #0E6B5E;
  --teal-2: #0A5248;
  --plum: #7B3F6E;
  --amber: #A86F0C;
  --hl: #F3DD5A;
  --danger: #A9362B;
  --ok: #2E6B3A;

  --f-body: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --f-display: 'Bricolage Grotesque', 'Be Vietnam Pro', system-ui, sans-serif;
  --f-code: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;

  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-3: 2.25rem;
  --step-4: 3.25rem;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--step-0)/1.6 var(--f-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--hl); color: var(--ink); }
a { color: var(--teal-2); text-underline-offset: 3px; }
a:hover { color: var(--ink); }
h1, h2, h3 { margin: 0; font-family: var(--f-display); letter-spacing: -0.015em; line-height: 1.15; }
p { margin: 0; }
code { font-family: var(--f-code); font-size: 0.88em; background: var(--sheet-2); padding: 0.08em 0.35em; border-radius: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--teal); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 50; background: var(--hl); color: var(--ink); padding: 8px 12px; }
.skip:focus { left: 8px; }
.muted { color: var(--ink-3); }
.booting { padding: 48px; color: var(--ink-3); }

/* ---------- khung ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); height: 100vh; }
.rail {
  background: var(--ink);
  color: #C9D3CF;
  padding: 26px 18px 18px;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.wordmark {
  font: 800 2.75rem/0.9 var(--f-display);
  letter-spacing: -0.045em;
  color: #F4F6F1;
  text-decoration: none;
  padding-left: 8px;
  width: max-content;
}
.wordmark:hover { color: var(--hl); }
.rail-tag { font-size: var(--step--1); color: #8E9C9A; padding: 8px 8px 0; line-height: 1.4; }
.rail nav { margin-top: 30px; display: flex; flex-direction: column; gap: 26px; }
.rail-section { display: flex; flex-direction: column; gap: 1px; }
.rail-head { display: flex; justify-content: space-between; align-items: center; padding: 0 8px 6px; font-size: var(--step--1); color: #8E9C9A; }
.rail-add {
  color: #F4F6F1; text-decoration: none; font-size: 1.25rem; line-height: 1;
  width: 26px; height: 26px; display: grid; place-items: center; border-radius: 5px;
}
.rail-add:hover { background: #2B3C46; color: var(--hl); }
.rail-link {
  display: flex; align-items: center; gap: 8px;
  color: #D6DFDB; text-decoration: none;
  padding: 7px 8px; border-radius: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rail-link:hover { background: #24343E; color: #fff; }
.rail-link.is-on { background: #2D3F4A; color: #fff; box-shadow: inset 3px 0 0 var(--hl); }
.rail-empty { padding: 4px 8px; color: #6F7E7D; font-size: var(--step--1); }
.rail-foot { margin-top: auto; padding: 18px 8px 0; font-size: 0.75rem; color: #6F7E7D; line-height: 1.45; }
.live-dot, .warn-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; margin-left: auto; }
.live-dot { background: var(--hl); animation: pulse 1.4s ease-in-out infinite; }
.warn-dot { background: #E0795B; }
@keyframes pulse { 50% { opacity: 0.25; } }

.main { min-width: 0; overflow-y: auto; padding: 44px clamp(20px, 5vw, 64px) 96px; outline: none; }
.main > * { max-width: 1180px; }

/* ---------- chữ ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 28px; flex-wrap: wrap; }
.page-head h1 { font-size: var(--step-3); font-weight: 700; }
.lede { font-size: var(--step-1); line-height: 1.55; color: var(--ink-2); max-width: 64ch; margin-bottom: 28px; }
.back { display: inline-block; font-size: var(--step--1); margin-bottom: 6px; color: var(--ink-3); }
.hint { font-size: var(--step--1); color: var(--ink-3); margin: -2px 0 8px; max-width: 70ch; }
.notice { background: #F6EBC0; border-left: 3px solid var(--amber); padding: 12px 16px; border-radius: 0 6px 6px 0; margin-bottom: 24px; max-width: 75ch; font-size: var(--step--1); }

/* ---------- nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 6px;
  padding: 8px 15px; font-weight: 600; font-size: var(--step--1);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .12s, border-color .12s, color .12s;
}
.btn-lg { padding: 12px 22px; font-size: var(--step-0); border-radius: 7px; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-2); color: #fff; }
.btn-primary:disabled { background: #9AA8A3; cursor: not-allowed; }
.btn-quiet { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-quiet:hover { background: var(--sheet); border-color: var(--ink-3); color: var(--ink); }
.btn-danger-text { color: var(--danger); }
.btn-stop { background: var(--ink); color: #fff; }
.btn-stop:hover { background: var(--danger); }
.link-btn {
  background: none; border: 0; padding: 4px 0; cursor: pointer;
  color: var(--teal-2); font-size: var(--step--1); font-weight: 500;
  text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px;
}
.link-btn:hover { text-decoration-color: currentColor; }
.link-btn:disabled { color: var(--ink-3); cursor: not-allowed; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- form ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 22px; border: 0; padding: 0; min-width: 0; }
.field > label, .field > legend, .block-label { font-weight: 600; font-size: var(--step--1); color: var(--ink); padding: 0; }
input[type=text], input:not([type]), input[type=password], input[type=number], select, textarea {
  width: 100%; background: var(--sheet); border: 1px solid var(--line); border-radius: 5px;
  padding: 9px 11px; line-height: 1.45;
}
input:hover, select:hover, textarea:hover { border-color: var(--ink-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14, 107, 94, .16); background: #fff; }
textarea { resize: vertical; }
textarea.code { font-family: var(--f-code); font-size: 0.8125rem; line-height: 1.6; }
select { appearance: none; padding-right: 30px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%); background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 16px; align-items: end; }
.field.is-narrow { max-width: 110px; }
.form-error { color: var(--danger); font-size: var(--step--1); }

/* ---------- trang chủ ---------- */
.empty-home { padding-top: 9vh; max-width: 760px; }
.empty-home h1 { font-size: var(--step-4); font-weight: 800; letter-spacing: -0.035em; line-height: 1.02; max-width: 12ch; margin-bottom: 22px; }
.empty-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.import-link { display: inline-block; margin-top: 26px; font-size: var(--step--1); color: var(--ink-3); text-decoration: underline; cursor: pointer; }
.proj-list { border-top: 1.5px solid var(--ink); }
.proj-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 130px 110px; gap: 20px; align-items: center;
  padding: 16px 4px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none;
}
.proj-row:hover { background: var(--sheet); }
.proj-name { font: 600 var(--step-1)/1.3 var(--f-display); min-width: 0; }
.proj-name small { display: block; font: 400 var(--step--1)/1.4 var(--f-body); color: var(--ink-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-time { text-align: right; font-size: var(--step--1); }

/* ---------- ký hiệu agent ---------- */
.mono {
  --c: var(--teal);
  flex: none; display: inline-grid; place-items: center;
  width: 48px; height: 48px; border-radius: 9px;
  font: 700 1.125rem/1 var(--f-display); letter-spacing: -0.02em;
  color: var(--c); border: 1.5px solid var(--c); background: transparent;
}
.g-delivery { --c: var(--teal); }
.g-expert { --c: var(--plum); }
.g-meta { --c: var(--amber); }
.mono.is-sm { width: 30px; height: 30px; border-radius: 6px; font-size: 0.75rem; border-width: 1.25px; }
.mono.is-xs { width: 26px; height: 26px; border-radius: 5px; font-size: 0.6875rem; border-width: 1.25px; background: var(--paper); }
.stack { display: inline-flex; align-items: center; }
.stack .mono + .mono { margin-left: -6px; }
.stack-more { font-size: 0.75rem; color: var(--ink-3); margin-left: 6px; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; background: var(--line-2); color: var(--ink-2); }
.pill.is-running { background: var(--hl); color: var(--ink); }
.pill.is-running::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--ink); animation: pulse 1.2s infinite; }
.pill.is-done { background: #D6E7DE; color: var(--teal-2); }
.pill.is-partial { background: #F2E2C2; color: #7A520A; }
.pill.is-error { background: #F3D5CF; color: var(--danger); }
.pill.is-stopped { background: var(--line-2); color: var(--ink-2); }
.tag { font: 500 0.6875rem/1 var(--f-body); color: var(--ink-2); background: var(--line-2); padding: 3px 6px; border-radius: 3px; margin-left: 8px; vertical-align: 2px; }

/* ---------- dự án mới ---------- */
.new-form { max-width: 820px; }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.preset { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 14px 16px 14px 44px; border: 1px solid var(--line); border-radius: 8px; background: var(--sheet); cursor: pointer; }
.preset:hover { border-color: var(--ink-3); }
.preset input { position: absolute; left: 16px; top: 17px; accent-color: var(--teal); width: 16px; height: 16px; margin: 0; }
.preset:has(input:checked) { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); background: #fff; }
.preset-name { font-weight: 600; }
.preset-note { font-size: var(--step--1); color: var(--ink-3); line-height: 1.4; margin-bottom: 8px; }

/* ---------- đầu trang dự án ---------- */
.proj-head { display: flex; align-items: flex-end; gap: 6px 32px; flex-wrap: wrap; border-bottom: 1.5px solid var(--ink); margin: -8px 0 28px; }
.proj-title { flex: 1 1 260px; min-width: 0; padding-bottom: 10px; }
.proj-head .head-actions { padding-bottom: 10px; }
.title-input, .summary-input { border: 0 !important; background: transparent !important; padding: 2px 0 !important; box-shadow: none !important; width: 100%; border-radius: 0; }
.title-input { font: 700 var(--step-2)/1.2 var(--f-display); letter-spacing: -0.02em; }
.summary-input { font-size: var(--step-0); color: var(--ink-2); margin-top: 4px; }
.title-input:focus, .summary-input:focus { box-shadow: 0 2px 0 var(--teal) !important; }
.tabs { display: flex; gap: 26px; overflow-x: auto; margin-bottom: -1.5px; }
.tab { padding: 10px 0 11px; color: var(--ink-2); text-decoration: none; font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab.is-on { color: var(--ink); border-bottom-color: var(--ink); }
.count { font-size: 0.6875rem; background: var(--line-2); padding: 1px 7px; border-radius: 999px; color: var(--ink-2); }

/* ---------- thiết lập ---------- */
.brief-block { margin-bottom: 40px; }
.brief { margin-top: 8px; font-size: var(--step-1); line-height: 1.6; padding: 16px 18px; min-height: 160px; border-radius: 8px; }
.more-ctx { margin-top: 14px; }
.more-ctx summary { cursor: pointer; font-size: var(--step--1); color: var(--ink-2); font-weight: 500; width: max-content; }
.more-ctx summary:hover { color: var(--ink); }
.ctx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; margin-top: 14px; }

.plan-block { background: var(--sheet); border: 1px solid var(--line); border-radius: 12px; padding: 22px 24px; margin-bottom: 48px; }
.block-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.block-row .block-label { font-family: var(--f-body); letter-spacing: 0; font-size: var(--step--1); }
.block-row .muted { font-size: var(--step--1); }
.plan { list-style: none; margin: 0; padding: 0 0 6px; display: flex; overflow-x: auto; }
.plan-stage {
  position: relative; flex: none; min-width: 92px;
  display: flex; flex-direction: column; gap: 8px;
  padding: 0 16px 0 0; margin-right: 16px;
}
.plan-stage:not(:last-child)::after {
  content: ''; position: absolute; top: 11px; right: -8px; width: 16px; height: 1.5px; background: var(--ink-3);
}
.plan-no {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font: 700 0.6875rem/1 var(--f-display); background: var(--ink); color: #fff;
}
.plan-label { font-size: 0.75rem; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.plan-agents { display: flex; flex-direction: column; gap: 5px; }
.plan-par { font-size: 0.6875rem; color: var(--ink-3); }
.plan-stage.is-live .plan-no { background: var(--hl); color: var(--ink); box-shadow: 0 0 0 4px rgba(243, 221, 90, .45); }
.plan-stage.is-live .plan-label { color: var(--ink); }
.plan-empty { color: var(--ink-3); font-size: var(--step--1); padding: 6px 0 12px; }
.run-bar { display: flex; align-items: center; gap: 18px; padding-top: 18px; margin-top: 16px; border-top: 1px dashed var(--line); flex-wrap: wrap; }
.run-note { font-size: var(--step--1); color: var(--ink-2); max-width: 60ch; }

.band { margin-bottom: 44px; }
.band-head { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 16px; align-items: baseline; padding-bottom: 12px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.band-head h2 { font-size: var(--step-2); font-weight: 700; }
.band-head p { color: var(--ink-3); font-size: var(--step--1); }
.band-delivery .band-head h2 { color: var(--teal-2); }
.band-expert .band-head h2 { color: var(--plum); }
.band-meta .band-head h2 { color: var(--amber); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.tile {
  --c: var(--teal);
  position: relative; display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: start;
  padding: 14px; border-radius: 10px; border: 1px solid var(--line-2); background: transparent;
  cursor: pointer; user-select: none;
  transition: background-color .12s, border-color .12s;
}
.tile:hover { border-color: var(--line); background: var(--sheet); }
.tile.is-on { background: var(--sheet); border-color: var(--c); box-shadow: inset 0 0 0 0.5px var(--c); }
.tile.is-on .mono { background: var(--c); color: #fff; }
.tile-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; padding-top: 2px; }
.tile-title { font-weight: 600; line-height: 1.3; }
.tile-blurb { font-size: var(--step--1); color: var(--ink-3); line-height: 1.45; }
.tile-check { width: 18px; height: 18px; border-radius: 4px; border: 1.5px solid var(--line); margin-top: 3px; }
.tile.is-on .tile-check { border-color: var(--c); background: var(--c) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' stroke='white' stroke-width='2.2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/14px no-repeat; }
.tile-model { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 6px; cursor: default; }
.tile-model select, .tile-model input { font-size: 0.8125rem; padding: 6px 9px; background-color: #fff; }
.tile-model input { font-family: var(--f-code); font-size: 0.75rem; }
.link-btn[data-act="toggle-group"] { justify-self: end; }

/* ---------- phiên chạy ---------- */
.run-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px 20px; margin-bottom: 28px; }
.run-pick { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-width: 0; }
.run-pick select { width: auto; max-width: 480px; font-weight: 600; }
.run-pick .muted { font-size: var(--step--1); }
.run-plan { flex-basis: 100%; background: var(--sheet); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px 10px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.t-stage { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 0 18px; position: relative; padding-bottom: 26px; }
.t-stage::before { content: ''; position: absolute; left: 13px; top: 44px; bottom: 0; width: 1.5px; background: var(--line); }
.t-stage:last-child::before { display: none; }
.t-mark { display: flex; align-items: center; gap: 10px; padding-top: 12px; align-self: start; }
.t-no { width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font: 700 0.75rem/1 var(--f-display); position: relative; z-index: 1; }
.t-label { font-size: var(--step--1); font-weight: 600; color: var(--ink-2); line-height: 1.25; }
.t-steps { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.t-steps.is-par { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }

.step { background: var(--sheet); border: 1px solid var(--line); border-radius: 10px; min-width: 0; }
.step.is-running { border-color: #D9C24A; box-shadow: 0 0 0 3px rgba(243, 221, 90, .35); }
.step.is-error { border-color: #D9A39A; }
.step.is-queued { background: transparent; border-style: dashed; }
.step-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; flex-wrap: wrap; }
.step-head .mono { width: 38px; height: 38px; font-size: 0.875rem; border-radius: 8px; }
.step.is-done .step-head .mono, .step.is-running .step-head .mono { background: var(--c); color: #fff; }
.step-id { flex: 1 1 160px; min-width: 0; }
.step-id h3 { font-size: var(--step-1); font-weight: 700; }
.step-model { font-size: 0.75rem; color: var(--ink-3); font-family: var(--f-code); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-model .tag { font-family: var(--f-body); }
.step-time { font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.step-wait { padding: 0 16px 14px; font-size: var(--step--1); color: var(--ink-3); }
.step-error { margin: 0 16px 12px; padding: 10px 12px; background: #F8E3DE; color: #7F2219; border-radius: 6px; font-size: var(--step--1); overflow-wrap: anywhere; }
.step-body { padding: 4px 20px 16px; border-top: 1px solid var(--line-2); max-height: 360px; overflow: hidden; position: relative; }
.step.is-running .step-body { overflow-y: auto; max-height: 420px; }
.step.is-done:not(.is-open) .step-body::after, .step.is-stopped:not(.is-open) .step-body::after, .step.is-error:not(.is-open) .step-body::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 80px;
  background: linear-gradient(to bottom, rgba(247, 248, 244, 0), var(--sheet));
}
.step.is-open .step-body { max-height: none; }
.step-foot { display: flex; gap: 18px; flex-wrap: wrap; padding: 8px 16px 12px; border-top: 1px solid var(--line-2); }
.feedback { padding: 14px 16px 16px; border-top: 1px solid var(--line-2); background: #fff; border-radius: 0 0 10px 10px; display: flex; flex-direction: column; gap: 8px; }
.feedback label { font-weight: 600; font-size: var(--step--1); }

.empty-tab { padding: 40px 0; max-width: 520px; }
.empty-tab h2 { font-size: var(--step-2); margin-bottom: 10px; }
.empty-tab p { color: var(--ink-2); margin-bottom: 20px; }

/* ---------- tài liệu ---------- */
.docs { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 32px; align-items: start; }
.docs-index { position: sticky; top: 0; display: flex; flex-direction: column; gap: 2px; }
.doc-link { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 7px; border: 0; background: none; text-align: left; cursor: pointer; }
.doc-link:hover { background: var(--sheet); }
.doc-link.is-on { background: var(--sheet); box-shadow: inset 3px 0 0 var(--ink); }
.doc-link > span:not(.mono) { display: flex; flex-direction: column; font-weight: 600; font-size: var(--step--1); line-height: 1.3; }
.doc-link small { font-weight: 400; color: var(--ink-3); font-size: 0.75rem; }
.docs-actions { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.doc { background: var(--sheet); border: 1px solid var(--line); border-radius: 12px; padding: 28px clamp(18px, 4vw, 44px) 40px; }
.doc-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; padding-bottom: 18px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.doc-head h2 { font-size: var(--step-2); }
.doc-head .muted { font-size: var(--step--1); margin-top: 4px; }
.doc-body { max-width: 74ch; }

/* ---------- markdown ---------- */
.md { overflow-wrap: anywhere; }
.md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1.5em 0 0.5em; font-family: var(--f-display); }
.md h2 { font-size: 1.375rem; }
.md h3 { font-size: 1.125rem; }
.md h4, .md h5, .md h6 { font-size: 1rem; font-family: var(--f-body); font-weight: 600; letter-spacing: 0; }
.md > :first-child { margin-top: 0.9em; }
.md p, .md ul, .md ol, .md pre, .md blockquote, .md .md-table { margin: 0 0 0.85em; }
.md ul, .md ol { padding-left: 1.3em; }
.md li { margin: 0.2em 0; }
.md li.d1 { margin-left: 1.2em; } .md li.d2 { margin-left: 2.4em; } .md li.d3 { margin-left: 3.6em; }
.md li:has(> .task) { list-style: none; margin-left: -1.2em; }
.md .task { display: inline-block; width: 12px; height: 12px; border: 1.5px solid var(--ink-3); border-radius: 3px; margin-right: 7px; vertical-align: -1px; }
.md .task.is-done { background: var(--teal); border-color: var(--teal); }
.md pre { background: var(--ink); color: #E3EAE6; padding: 14px 16px; border-radius: 8px; overflow-x: auto; font-size: 0.8125rem; line-height: 1.55; position: relative; }
.md pre[data-lang]::before { content: attr(data-lang); position: absolute; top: 6px; right: 10px; font: 500 0.6875rem var(--f-body); color: #8E9C9A; }
.md pre code { background: none; padding: 0; font-size: inherit; color: inherit; }
.md blockquote { border-left: 3px solid var(--line); padding-left: 14px; color: var(--ink-2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.6em 0; }
.md .md-table { overflow-x: auto; }
.md table { border-collapse: collapse; font-size: var(--step--1); min-width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--sheet-2); font-weight: 600; }

/* ---------- thư viện ---------- */
.lib { display: flex; flex-direction: column; }
.lib-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 12px 6px; border-bottom: 1px solid var(--line-2); color: inherit; text-decoration: none; border-radius: 6px; }
.lib-row:hover { background: var(--sheet); }
.lib-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lib-meta { font-size: 0.75rem; text-align: right; }
.agent-form { max-width: 900px; }

/* ---------- kết nối ---------- */
.providers { display: flex; flex-direction: column; gap: 14px; margin-bottom: 48px; }
.provider { background: var(--sheet); border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px 14px; }
.provider.is-off { background: transparent; }
.provider.is-off .provider-grid, .provider.is-off .provider-foot { display: none; }
.provider-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.provider-head .muted { font-size: 0.75rem; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font: 700 var(--step-1)/1.2 var(--f-display); }
.switch input { appearance: none; width: 34px; height: 20px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; margin: 0; transition: background-color .15s; flex: none; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--teal); }
.switch input:checked::after { transform: translateX(14px); }
.key-state { font-size: 0.75rem; font-weight: 600; color: #A65B2B; }
.key-state.is-ok { color: var(--ok); }
.default-pick { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: var(--step--1); cursor: pointer; }
.default-pick input { accent-color: var(--teal); margin: 0; }
.provider-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 14px; margin-top: 16px; }
.provider-grid .field { margin-bottom: 14px; }
.provider-grid .field.is-wide { grid-column: span 2; }
.provider-grid input, .provider-grid select { font-size: 0.8125rem; }
.provider-grid input[name=baseUrl], .provider-grid input[name^=model] { font-family: var(--f-code); font-size: 0.75rem; }
.provider-foot { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.test-result { font-size: var(--step--1); color: var(--ink-3); overflow-wrap: anywhere; }
.test-result.is-ok { color: var(--ok); }
.test-result.is-bad { color: var(--danger); }

/* ---------- đăng nhập & thông báo ---------- */
.login { max-width: 380px; padding-top: 14vh; }
.login h1 { font-size: var(--step-3); margin-bottom: 10px; }
.login > p { color: var(--ink-2); margin-bottom: 24px; }
.login form { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.login label { font-weight: 600; font-size: var(--step--1); }
.toasts { position: fixed; right: 24px; bottom: 20px; align-items: flex-end; display: flex; flex-direction: column; gap: 8px; z-index: 40; pointer-events: none; }
.toast { background: var(--ink); color: #F1F4EF; padding: 11px 16px; border-radius: 7px; font-size: var(--step--1); max-width: 420px; box-shadow: 0 8px 24px rgba(27, 42, 51, .22); transition: opacity .3s, transform .3s; }
.toast.is-out { opacity: 0; transform: translateY(6px); }

/* ---------- màn hình nhỏ ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .rail { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 12px 16px; position: sticky; top: 0; z-index: 20; }
  .wordmark { font-size: 1.75rem; padding: 0; }
  .rail-tag, .rail-foot, .rail-head { display: none; }
  .rail-new { margin: 0; padding: 6px 10px; white-space: nowrap; }
  .rail nav { margin: 0; flex-direction: row; gap: 4px; overflow-x: auto; flex: 1; }
  .rail-section { flex-direction: row; gap: 2px; }
  .rail-head { padding: 0; }
  .rail-link { padding: 6px 9px; }
  .main { overflow: visible; padding: 28px 18px 80px; }
  .ctx-grid, .docs { grid-template-columns: 1fr; }
  .docs-index { position: static; flex-direction: row; flex-wrap: wrap; }
  .t-stage { grid-template-columns: 1fr; }
  .t-stage::before { display: none; }
  .t-mark { padding-top: 0; margin-bottom: 10px; }
  .proj-row { grid-template-columns: minmax(0, 1fr) auto; }
  .proj-row .stack, .proj-time { display: none; }
  .provider-grid { grid-template-columns: 1fr 1fr; }
  .band-head { grid-template-columns: 1fr; }
  .link-btn[data-act="toggle-group"] { justify-self: start; }
  .toasts { left: 16px; right: 16px; }
  .empty-home h1 { font-size: var(--step-3); }
  .title-input { font-size: 1.75rem; }
  .proj-head .head-actions { order: -1; margin-left: auto; }
}
@media (max-width: 520px) {
  .tiles { grid-template-columns: 1fr; }
  .tile-model { grid-template-columns: 1fr; }
  .provider-grid { grid-template-columns: 1fr; }
  .provider-grid .field.is-wide { grid-column: auto; }
  .t-steps.is-par { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}


/* =================== v2: trò chuyện =================== */
.btn-sm { padding: 6px 11px; font-size: 0.8125rem; border-radius: 5px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--step--1); cursor: pointer; }
.check input { accent-color: var(--teal); width: 16px; height: 16px; margin: 0; }
.g-lead { --c: var(--ink); }
.mono.g-lead { background: var(--ink); color: var(--hl); border-color: var(--ink); }
.at { font-weight: 600; color: var(--plum); background: #F1E6EE; padding: 0 4px; border-radius: 3px; }
.at-code { font-size: 0.75rem; color: var(--ink-3); background: transparent; padding: 0; margin-left: 6px; }

.rail-new {
  display: block; margin: 0 0 4px; padding: 9px 12px; border-radius: 6px;
  border: 1px solid #3A4B55; color: #F4F6F1; text-decoration: none; font-weight: 600; font-size: var(--step--1);
}
.rail-new:hover, .rail-new.is-on { background: var(--hl); color: var(--ink); border-color: var(--hl); }
.rail-head { padding: 0 8px 6px; }
.rail-text { overflow: hidden; text-overflow: ellipsis; }

/* ---------- trang đầu ---------- */
.home { max-width: 860px; padding-top: 6vh; }
.home h1 { font-size: var(--step-4); font-weight: 800; letter-spacing: -0.035em; line-height: 1.02; margin-bottom: 18px; }
.home .lede { margin-bottom: 26px; }
.home-sub { font-size: var(--step-1); margin: 56px 0 10px; }
.starters, .suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.starter {
  border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 13px;
  font-size: 0.8125rem; color: var(--ink-2); cursor: pointer; text-align: left;
}
.starter:hover { border-color: var(--ink-2); color: var(--ink); background: var(--sheet); }
.suggest .starter { border-style: dashed; }
.proj-row { grid-template-columns: minmax(0, 1fr) auto 120px 100px; }
.proj-src { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- ô soạn tin ---------- */
.composer {
  position: relative; background: #fff; border: 1.5px solid var(--ink); border-radius: 12px;
  padding: 10px 12px 10px; box-shadow: 0 1px 0 var(--ink);
}
.composer:focus-within { box-shadow: 0 0 0 4px rgba(14, 107, 94, .14), 0 1px 0 var(--ink); border-color: var(--teal-2); }
.composer textarea { border: 0 !important; box-shadow: none !important; background: transparent !important; padding: 6px 4px; resize: none; font-size: var(--step-0); line-height: 1.55; max-height: 320px; }
.composer.is-hero textarea { font-size: var(--step-1); }
.cmp-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 2px 6px; }
.cmp-bar { display: flex; align-items: center; gap: 12px; padding-top: 8px; border-top: 1px solid var(--line-2); flex-wrap: wrap; }
.cmp-hint { margin-left: auto; font-size: 0.75rem; color: var(--ink-3); }
.attach { position: relative; }
.attach-menu {
  position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 30; min-width: 210px;
  background: var(--ink); border-radius: 8px; padding: 6px; display: flex; flex-direction: column;
  box-shadow: 0 12px 32px rgba(27, 42, 51, .28);
}
.attach-menu > * { color: #E8EEEA; background: none; border: 0; text-align: left; padding: 8px 10px; border-radius: 5px; cursor: pointer; font-size: var(--step--1); }
.attach-menu > *:hover, .attach-menu > *:focus-visible { background: #2D3F4A; color: #fff; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 5px 11px; font-size: 0.8125rem; color: var(--ink-2); }
.seg input:checked + span { background: var(--ink); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: -2px; }
.mention-pop {
  position: absolute; left: 10px; bottom: calc(100% - 4px); z-index: 30; width: min(360px, 90%);
  background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 5px; box-shadow: 0 14px 34px rgba(27, 42, 51, .18);
}
.mp-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 6px 8px; border-radius: 6px; cursor: pointer; text-align: left; font-size: var(--step--1); }
.mp-item span { flex: 1; }
.mp-item code { background: none; color: var(--ink-3); }
.mp-item.is-on, .mp-item:hover { background: var(--sheet-2); }

.chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; font-size: 0.8125rem; padding: 3px 4px 3px 4px; border-radius: 6px; background: var(--sheet-2); border: 1px solid var(--line); }
.chip.is-sm { font-size: 0.75rem; padding: 1px 6px; }
.chip.is-off { opacity: .5; }
.chip-kind { font-size: 0.6875rem; font-weight: 600; padding: 1px 5px; border-radius: 4px; background: var(--ink); color: #fff; }
.chip-github .chip-kind { background: var(--ink); }
.chip-file .chip-kind { background: var(--teal); }
.chip-text .chip-kind { background: var(--amber); }
.chip-x { border: 0; background: none; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 4px; color: var(--ink-3); border-radius: 4px; }
.chip-x:hover { color: var(--danger); background: #F3D5CF; }

/* ---------- bố cục trao đổi ---------- */
.main[data-view="project-chat"] { padding-bottom: 0; }
.chat { display: grid; grid-template-columns: minmax(0, 1fr) 292px; gap: 44px; align-items: start; }
.thread { min-width: 0; display: flex; flex-direction: column; min-height: calc(100vh - 150px); }
.thread-empty { padding: 4vh 0 30px; max-width: 60ch; }
.thread-empty h2 { font-size: var(--step-2); margin-bottom: 10px; }
.thread-empty p { color: var(--ink-2); }
.composer-dock { position: sticky; bottom: 0; margin-top: auto; padding: 18px 0 22px; background: linear-gradient(to top, var(--paper) 78%, rgba(233, 236, 230, 0)); z-index: 5; }

.turn { padding: 0 0 34px; }
.turn + .turn { border-top: 1px solid var(--line); padding-top: 30px; }
.ask { border-left: 3px solid var(--ink); padding: 2px 0 2px 16px; margin-bottom: 18px; max-width: 72ch; }
.ask-meta { display: flex; gap: 10px; align-items: baseline; font-size: 0.75rem; color: var(--ink-3); margin-bottom: 2px; }
.who { font-weight: 700; color: var(--ink); font-size: var(--step--1); }
.ask-text { font-size: var(--step-1); line-height: 1.55; }
.ask-text > :first-child { margin-top: 0; }
.ask-text p:last-child { margin-bottom: 0; }
.ask-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.plan-card { display: flex; gap: 12px; align-items: flex-start; margin: 0 0 16px; max-width: 72ch; }
.plan-card b { font-size: var(--step--1); }
.plan-card p { color: var(--ink-2); }
.plan-card.is-live p::after { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--amber); margin-left: 8px; vertical-align: middle; animation: pulse 1.1s infinite; }

.run .timeline { margin-top: 4px; }
.run .t-stage { grid-template-columns: 30px minmax(0, 1fr); gap: 0 14px; padding-bottom: 14px; }
.run .t-stage::before { left: 13px; top: 32px; }
.run .t-no { margin-top: 12px; }
.step-task { padding: 0 16px 12px 66px; margin-top: -6px; font-size: var(--step--1); color: var(--ink-2); line-height: 1.5; }
.step-foot .muted { font-size: 0.75rem; align-self: center; }

.synth { margin: 10px 0 0 44px; background: #fff; border: 1.5px solid var(--ink); border-radius: 10px; padding: 14px 20px 16px; }
.synth-head { display: flex; align-items: center; gap: 10px; }
.synth-head b { font-family: var(--f-display); font-size: var(--step-1); }
.synth-body > :first-child { margin-top: 0.6em; }
.run-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 14px 0 0 44px; font-size: 0.8125rem; }
.run-acts { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }

/* ---------- cột bối cảnh ---------- */
.ctx { position: sticky; top: 0; max-height: calc(100vh - 60px); overflow-y: auto; padding: 4px 2px 24px; display: flex; flex-direction: column; gap: 26px; }
.ctx-sec textarea { font-size: 0.8125rem; }
.ctx-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.ctx-head h2 { font: 600 var(--step--1)/1.3 var(--f-body); letter-spacing: 0; }
.ctx-empty { font-size: 0.8125rem; color: var(--ink-3); line-height: 1.5; }
.src-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.src { background: var(--sheet); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; display: flex; flex-direction: column; gap: 3px; }
.src.is-off { background: transparent; opacity: .7; }
.src-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.src-toggle input { accent-color: var(--teal); margin: 0; }
.src-name { font-weight: 600; font-size: var(--step--1); overflow-wrap: anywhere; }
.src-detail { font-size: 0.75rem; color: var(--ink-3); padding-left: 21px; }
.src-acts { display: flex; gap: 12px; padding-left: 21px; }
.src-acts .link-btn { font-size: 0.75rem; padding: 0; }
.link-btn.danger { color: var(--danger); }
.ctx-crew { display: flex; flex-wrap: wrap; gap: 6px; }
.crew-mono { border: 0; background: none; padding: 0; cursor: pointer; border-radius: 7px; }
.crew-mono:hover .mono { background: var(--c); color: #fff; }
.ctx-note { font-size: 0.75rem; color: var(--ink-3); margin-top: 8px; }
.ctx-toggle { display: none; }
.crew-chip { display: flex; align-items: center; gap: 9px; border: 0; background: none; padding: 4px 6px; border-radius: 6px; cursor: pointer; font-size: 0.8125rem; text-align: left; color: var(--ink); }
.crew-chip:hover { background: var(--sheet); }
.preset-row { display: flex; flex-wrap: wrap; gap: 8px; margin: -12px 0 24px; }
.plan-block .block-label { font-family: var(--f-body); letter-spacing: 0; font-size: var(--step--1); margin-bottom: 14px; display: block; }

/* ---------- hộp thoại ---------- */
.modal { border: 0; padding: 0; border-radius: 14px; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); background: var(--sheet); color: var(--ink); box-shadow: 0 24px 64px rgba(27, 42, 51, .35); }
.modal::backdrop { background: rgba(27, 42, 51, .45); }
.modal-in { padding: 24px 26px 22px; }
.modal h2 { font-size: var(--step-2); margin-bottom: 12px; }
.modal .notice { margin: 0 0 16px; }
.file-pick { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px 8px; margin: 14px 0; max-height: 230px; overflow-y: auto; }
.file-pick legend { font-size: var(--step--1); font-weight: 600; padding: 0 4px; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; font-size: 0.8125rem; cursor: pointer; }
.file-row input { accent-color: var(--teal); margin: 0; }
.file-row code { background: none; padding: 0; flex: 1; overflow-wrap: anywhere; }
.file-row .muted { font-size: 0.75rem; white-space: nowrap; }
.push-form .field.is-wide { grid-column: 1 / -1; }
.push-result { font-size: var(--step--1); margin: 0 0 12px; overflow-wrap: anywhere; }
.push-result.is-ok { color: var(--ok); }
.push-result.is-bad { color: var(--danger); }
.source-pre { background: var(--ink); color: #E3EAE6; padding: 14px; border-radius: 8px; font: 0.75rem/1.55 var(--f-code); max-height: 60vh; overflow: auto; white-space: pre-wrap; margin: 0 0 16px; }
.switch-label { font: 700 var(--step-1)/1.2 var(--f-display); }
.provider .hint a { color: var(--teal-2); }

@media (max-width: 1100px) {
  .chat { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .ctx { position: static; max-height: none; order: -1; padding: 0 0 16px; gap: 18px; }
  .ctx-toggle { display: inline-flex; align-self: flex-start; }
  .ctx:not(.is-open) .ctx-sec { display: none; }
  .ctx.is-open { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); border-bottom: 1px solid var(--line); margin-bottom: 18px; }
  .ctx.is-open .ctx-toggle { grid-column: 1 / -1; }
  .thread { min-height: 0; }
}
@media (max-width: 900px) {
  .home h1 { font-size: var(--step-3); }
  .cmp-hint { display: none; }
  .synth, .run-foot { margin-left: 0; }
  .step-task { padding-left: 16px; }
  .proj-head { margin-top: 0; }
  .title-input { font-size: 1.375rem; }
}
