/* ============================================================================
   Construction Planner - design tokens and base components
   Two themes: "dark" (Obsidian, default) and "light" (Daylight), set as
   <html data-theme="..."> by the theme toggle in the title bar.
   ========================================================================== */
:root, :root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8fafc; --panel: #ffffff; --panel-2: #f1f5f9; --panel-3: #f8fafc; --chrome: rgba(255, 255, 255, .95);
  --ribbon: rgba(243, 246, 250, .96); --input-bg: #ffffff; --hover: rgba(226, 232, 240, .7); --hover-row: rgba(241, 245, 249, .9);
  --line: #e2e8f0; --line2: #eef2f6; --line-strong: #cbd5e1;
  --text: #0f172a; --text-2: #334155; --muted: #64748b; --faint: #94a3b8;
  --brand: #2e7d32; --brand-dark: #1f5a23;
  --accent: #059669; --accent-strong: #059669; --accent-text: #047857; --accent-weak: rgba(16, 185, 129, .12); --accent-line: rgba(5, 150, 105, .45);
  --crit: #dc2626; --ok: #059669; --warn: #b45309; --info: #0284c7;
  --sel: #d3e8d2; --sel-text: #0f172a; --sel-gantt: #fdf4dc; --multi: #e7f3e6; --hl-row: #fef3c7;
  --wbs-row: #edf2f8; --weekend: #f4f6f9; --tl-bg: #f1f5f9;
  --t-emerald: #059669; --t-sky: #0284c7; --t-amber: #d97706; --t-rose: #e11d48; --t-violet: #7c3aed; --t-slate: #64748b;
  --shadow: 0 10px 30px rgba(15, 23, 42, .12); --shadow-lg: 0 24px 60px rgba(15, 23, 42, .22);
  --dots: rgba(15, 23, 42, .045);
  --rowh: 26px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090d16; --panel: #0f1624; --panel-2: #131c2e; --panel-3: #0b111e; --chrome: rgba(11, 16, 28, .96);
  --ribbon: rgba(17, 25, 42, .96); --input-bg: #0b1220; --hover: rgba(30, 41, 59, .7); --hover-row: rgba(30, 41, 59, .45);
  --line: #1e293b; --line2: #172133; --line-strong: #334155;
  --text: #e2e8f0; --text-2: #cbd5e1; --muted: #94a3b8; --faint: #64748b;
  --brand: #2e7d32; --brand-dark: #236127;
  --accent: #10b981; --accent-strong: #059669; --accent-text: #34d399; --accent-weak: rgba(16, 185, 129, .14); --accent-line: rgba(16, 185, 129, .4);
  --crit: #f43f5e; --ok: #34d399; --warn: #fbbf24; --info: #38bdf8;
  --sel: rgba(16, 185, 129, .17); --sel-text: #ecfdf5; --sel-gantt: rgba(245, 158, 11, .12); --multi: rgba(16, 185, 129, .1); --hl-row: rgba(250, 204, 21, .13);
  --wbs-row: #111a2b; --weekend: rgba(148, 163, 184, .045); --tl-bg: #0f1726;
  --t-emerald: #34d399; --t-sky: #38bdf8; --t-amber: #fbbf24; --t-rose: #fb7185; --t-violet: #a78bfa; --t-slate: #94a3b8;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45); --shadow-lg: 0 24px 70px rgba(0, 0, 0, .6);
  --dots: rgba(16, 185, 129, .045);
}
:root {
  --bar: #3b82f6; --done: #1e3a8a; --bl: #94a3b8;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, "SF Mono", ui-monospace, monospace;
  font-family: var(--font); font-size: 13px; color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { transition: background-color .2s ease; }
::selection { background: var(--accent); color: #fff; }
.mono { font-family: var(--mono); font-size: .92em; letter-spacing: -.01em; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- controls ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--accent-strong); color: #fff; border: 1px solid var(--accent-strong); border-radius: 8px; padding: 5px 12px; cursor: pointer; white-space: nowrap; font-weight: 500; transition: background-color .15s, border-color .15s, filter .15s; }
button:hover { filter: brightness(1.1); }
button:disabled { opacity: .45; cursor: default; filter: none; }
button.ghost { background: transparent; color: var(--text); border-color: var(--line-strong); }
button.ghost:hover { background: var(--hover); border-color: var(--accent-line); filter: none; }
button.danger { background: #e11d48; border-color: #e11d48; }
button.small { padding: 2px 9px; font-size: 12px; border-radius: 6px; }
button.on { background: var(--accent-weak); border-color: var(--accent); color: var(--accent-text); }
input, select, textarea { border: 1px solid var(--line-strong); border-radius: 7px; padding: 5px 8px; background: var(--input-bg); color: var(--text); transition: border-color .15s, box-shadow .15s; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
input[type=range] { accent-color: var(--accent); }
input[type=color] { padding: 1px; height: 28px; }
label { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: 3px; color: var(--text); font-weight: 400; }
a { color: var(--accent-text); }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 14px; margin: 18px 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.page { padding: 18px 22px; overflow: auto; height: 100%; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--line2); font-size: 11px; color: var(--muted); border: 1px solid var(--line); }
.pill.crit { background: rgba(244, 63, 94, .14); color: var(--crit); border-color: rgba(244, 63, 94, .3); }
.pill.ok { background: rgba(16, 185, 129, .14); color: var(--ok); border-color: rgba(16, 185, 129, .3); }
.pill.warn { background: rgba(245, 158, 11, .14); color: var(--warn); border-color: rgba(245, 158, 11, .3); }

#layout { display: flex; height: calc(100% - 46px); }
#main { flex: 1; min-width: 0; height: 100%; overflow: hidden; display: flex; flex-direction: column; background: var(--bg); background-image: radial-gradient(var(--dots) 1px, transparent 1px); background-size: 20px 20px; }
#chat { width: 400px; border-left: 1px solid var(--accent-line); background: var(--panel); display: flex; flex-direction: column; min-width: 300px; box-shadow: -12px 0 40px rgba(0, 0, 0, .18); }
#chat[hidden] { display: none; }
#layout { position: relative; }
#chat { position: relative; max-width: 85vw; }
#chat-rz { position: absolute; left: -3px; top: 0; bottom: 0; width: 7px; cursor: ew-resize; z-index: 5; }
#chat-rz:hover, #chat.resizing #chat-rz { background: var(--accent-line); }
#chat.resizing { user-select: none; }
/* maximized: the assistant covers the whole work area (the schedule stays underneath, unchanged) */
#chat.max { position: absolute; inset: 0; width: auto !important; max-width: none; z-index: 30; border-left: 0; }
#chat.max #chat-rz { display: none; }
#chat.max #chat-log, #chat.max #chat-form, #chat.max #chat-quick { padding-left: max(14px, calc((100% - 900px) / 2)); padding-right: max(14px, calc((100% - 900px) / 2)); }
#chat.max #chat-log { padding-top: 16px; padding-bottom: 16px; }
/* floating: a window the user moves (title bar) and resizes (edges and corners) */
#chat.float { position: fixed; z-index: 35; max-width: none; min-width: 320px; border: 1px solid var(--accent-line); border-radius: 12px; overflow: hidden; box-shadow: 0 20px 60px rgba(0, 0, 0, .38); }
#chat.float .chat-head { cursor: move; user-select: none; }
#chat.float #chat-rz { display: none; }
.chat-h { position: absolute; z-index: 6; display: none; }
#chat.float .chat-h { display: block; }
#chat:not(.float):not(.min):not(.max) .chat-h[data-d="n"], #chat:not(.float):not(.min):not(.max) .chat-h[data-d="s"] { display: block; }
.chat-h[data-d="s"]:hover, .chat-h[data-d="n"]:hover, .chat-h[data-d="e"]:hover, .chat-h[data-d="w"]:hover { background: var(--accent-line); }
.chat-h[data-d="n"] { top: 0; left: 10px; right: 10px; height: 5px; cursor: ns-resize; }
.chat-h[data-d="s"] { bottom: 0; left: 10px; right: 10px; height: 6px; cursor: ns-resize; }
.chat-h[data-d="e"] { right: 0; top: 10px; bottom: 10px; width: 6px; cursor: ew-resize; }
.chat-h[data-d="w"] { left: 0; top: 10px; bottom: 10px; width: 6px; cursor: ew-resize; }
.chat-h[data-d="ne"], .chat-h[data-d="sw"] { width: 12px; height: 12px; cursor: nesw-resize; }
.chat-h[data-d="nw"], .chat-h[data-d="se"] { width: 12px; height: 12px; cursor: nwse-resize; }
.chat-h[data-d="ne"] { top: 0; right: 0; } .chat-h[data-d="sw"] { bottom: 0; left: 0; }
.chat-h[data-d="nw"] { top: 0; left: 0; } .chat-h[data-d="se"] { bottom: 0; right: 0; }
.chat-h[data-d="se"]::after { content: ""; position: absolute; right: 3px; bottom: 3px; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); opacity: .6; }
/* docked panel: a visible grip on the left edge */
#chat-rz::after { content: ""; position: absolute; left: 2px; top: 50%; width: 3px; height: 36px; margin-top: -18px; border-radius: 2px; background: var(--line-strong); }
#chat-quick[hidden] { display: none; }
#chat-wf { padding: 6px 9px; border-radius: 10px; font-size: 14px; line-height: 1; align-self: flex-end; }
#update-bar { position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%); z-index: 60; display: flex; align-items: center; gap: 14px;
  padding: 10px 14px 10px 18px; border-radius: 12px; background: var(--brand); color: #fff; box-shadow: var(--shadow); font-size: 13px; }
#update-bar button { background: #fff; color: var(--brand); border: 0; font-weight: 600; }
.msg hr { border: 0; border-top: 1px solid var(--line-strong); margin: 10px 0; }
.msg table { border-collapse: collapse; margin: 6px 0; font-size: 12px; display: block; overflow-x: auto; max-width: 100%; }
.msg th, .msg td { border: 1px solid var(--line-strong); padding: 4px 8px; text-align: left; vertical-align: top; }
.msg th { background: var(--panel-3); color: var(--text); font-weight: 600; }
.msg-export { display: flex; align-items: center; gap: 6px; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line-strong); flex-wrap: wrap; }
.msg-export .muted { font-size: 11px; margin-right: 2px; }
.msg-export button { font-size: 11.5px; padding: 3px 10px; border-radius: 8px; }
/* minimized: a slim strip on the right edge; click it to restore */
#chat.min { width: 46px !important; min-width: 46px; cursor: pointer; }
#chat.min > :not(.chat-head), #chat.min .chat-title, #chat.min .spacer, #chat.min #chat-clear { display: none; }
#chat.min .chat-head { flex-direction: column; padding: 10px 0; gap: 8px; border-bottom: 0; height: 100%; background: var(--panel); }
#chat.min .chat-head::after { content: "AI assistant"; writing-mode: vertical-rl; font-size: 11.5px; font-weight: 600; color: var(--accent-text); letter-spacing: .04em; margin-top: 6px; }

/* ---------- tables ---------- */
table.tbl { border-collapse: collapse; width: 100%; background: var(--panel); }
table.tbl th { text-align: left; font-weight: 600; background: var(--panel-2); color: var(--text-2); border-bottom: 1px solid var(--line); padding: 7px 8px; position: sticky; top: 0; z-index: 1; font-size: 11.5px; }
table.tbl td { border-bottom: 1px solid var(--line2); padding: 6px 8px; vertical-align: top; }
table.tbl tr:hover td { background: var(--hover-row); }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl td.num { font-family: var(--mono); font-size: 12px; }
table.tbl tr.wbsrow td { background: var(--wbs-row); font-weight: 600; }
.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }

/* ---------- schedule ---------- */
.toolbar { display: flex; gap: 6px; align-items: center; padding: 7px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 3px; }
.toolbar input[type=search] { width: 170px; }
.summarybar { display: flex; gap: 18px; padding: 5px 12px; font-size: 12px; color: var(--muted); background: var(--panel-3); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.summarybar b { color: var(--text); font-weight: 600; }
.summarybar .bad { color: var(--crit); }
#sched-wrap { flex: 1; min-height: 120px; overflow: auto; position: relative; background: var(--panel); }
#sched-inner { display: flex; flex-direction: column; width: max-content; min-width: 100%; }
.s-head { display: flex; position: sticky; top: 0; z-index: 4; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.s-body { display: flex; }
.s-left { position: sticky; left: 0; z-index: 3; background: var(--panel); border-right: 1px solid var(--line-strong); flex: none; }
.s-head .s-left { background: var(--panel-2); z-index: 5; }
.s-cols { display: flex; height: 44px; align-items: flex-end; }
.s-cols .hcol { padding: 0 6px 5px; font-weight: 600; font-size: 11px; line-height: 13px; color: var(--text-2); overflow: hidden; white-space: normal; border-right: 1px solid var(--line2); position: relative; height: 100%; display: flex; align-items: flex-end; box-sizing: border-box; }
.s-row { display: flex; height: var(--rowh); align-items: center; border-bottom: 1px solid var(--line2); cursor: default; transition: background-color .08s; }
.s-row:hover { background: var(--hover-row); }
.s-row > div { padding: 0 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; height: 100%; line-height: var(--rowh); border-right: 1px solid var(--line2); }
.s-row.wbs { background: var(--wbs-row); font-weight: 650; color: var(--text); }
.s-row.sel, .s-row.sel.wbs { background: var(--sel); color: var(--sel-text); box-shadow: inset 2px 0 0 var(--accent); }
.s-row.multi { background: var(--multi); }
.s-row .crit { color: var(--crit); font-weight: 500; }
.s-row .done { color: var(--muted); }
.s-row .n { text-align: right; font-variant-numeric: tabular-nums; }
.s-row .mono { font-size: 11.5px; }
.s-row .neg { color: var(--crit); font-weight: 600; }
.s-row .tw { cursor: pointer; display: inline-block; width: 14px; color: var(--muted); }
.s-row .tw:hover { color: var(--accent-text); }
.s-row input.cell { width: 100%; height: 22px; padding: 1px 4px; }
.c-code { width: 92px; } .c-name { width: 260px; } .c-dur { width: 52px; } .c-start, .c-finish { width: 86px; }
.c-tf { width: 50px; } .c-pc { width: 48px; } .c-pred { width: 130px; } .c-res { width: 120px; }

/* resource chips in the grid (CARP[30] STEEL[15] ...) */
.chip { display: inline-block; font-family: var(--mono); font-size: 10.5px; line-height: 16px; padding: 0 5px; margin-right: 3px; border-radius: 5px; border: 1px solid; vertical-align: 1px; }
.chip.c0 { color: var(--t-amber); background: color-mix(in srgb, var(--t-amber) 13%, transparent); border-color: color-mix(in srgb, var(--t-amber) 35%, transparent); }
.chip.c1 { color: var(--t-sky); background: color-mix(in srgb, var(--t-sky) 13%, transparent); border-color: color-mix(in srgb, var(--t-sky) 35%, transparent); }
.chip.c2 { color: var(--t-emerald); background: color-mix(in srgb, var(--t-emerald) 13%, transparent); border-color: color-mix(in srgb, var(--t-emerald) 35%, transparent); }
.chip.c3 { color: var(--t-violet); background: color-mix(in srgb, var(--t-violet) 13%, transparent); border-color: color-mix(in srgb, var(--t-violet) 35%, transparent); }
.chip.c4 { color: var(--t-rose); background: color-mix(in srgb, var(--t-rose) 13%, transparent); border-color: color-mix(in srgb, var(--t-rose) 35%, transparent); }
.chip.c5 { color: var(--t-slate); background: color-mix(in srgb, var(--t-slate) 13%, transparent); border-color: color-mix(in srgb, var(--t-slate) 35%, transparent); }

/* ---------- Gantt chart (SVG) ---------- */
svg.gantt text { font-size: 10.5px; fill: var(--text-2); font-family: var(--font); }
svg.gantt .scale-line { stroke: var(--line); }
svg.gantt .weekend { fill: var(--weekend); }
svg.gantt .hl { fill: var(--sel-gantt); }
svg.gantt .hlband { fill: var(--hl-row); }
svg.gantt .bar { fill: var(--bar); }
svg.gantt .bar.crit { fill: var(--crit); }
svg.gantt .prog { fill: var(--done); opacity: .75; }
svg.gantt .bl { fill: var(--bl); }
svg.gantt .float { stroke: var(--muted); stroke-width: 1.5; }
svg.gantt .link { fill: none; stroke: var(--faint); stroke-width: 1; }
svg.gantt .link.crit { stroke: var(--crit); opacity: .75; }
svg.gantt .dd { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 3; }
svg.gantt .today { stroke: #f59e0b; stroke-width: 1.2; stroke-dasharray: 2 3; }
svg.gantt .lbl { font-size: 10.5px; fill: var(--text-2); }
svg.gantt .gbar { transition: filter .12s; }
svg.gantt .gbar:hover { filter: brightness(1.15) drop-shadow(0 0 3px rgba(16, 185, 129, .45)); }
#detail { height: 300px; border-top: 1px solid var(--line-strong); background: var(--panel-3); overflow: auto; flex: none; resize: vertical; }
#detail.closed { height: 0; border: 0; overflow: hidden; }
.detail-inner { padding: 10px 16px; }
.detail-inner .grid4 label { margin: 0; }
.detail-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.detail-head h3 { margin: 0; }
.assign-list td { padding: 3px 6px; }

/* light-coloured SVG fills written by charts: follow the theme */
svg text:not([fill]) { fill: var(--text-2); }
svg [fill="#fff"], svg [fill="#ffffff"] { fill: var(--panel); }
svg [fill="#eef2f6"], svg [fill="#d7dee8"] { fill: var(--line); }
svg [stroke="#eee"], svg [stroke="#ccc"], svg [stroke="#c9d3df"] { stroke: var(--line); }
svg [fill="#666"], svg [fill="#555"], svg [fill="#888"] { fill: var(--muted); }
[style*="background:#fff"], [style*="background:#fbfcfd"] { background: var(--panel) !important; }
[style*="color:#555"], [style*="color:#999"] { color: var(--muted) !important; }
[style*="background:#e2f3e8"] { background: var(--accent-weak) !important; }
:root[data-theme="dark"] svg [fill="#22874a"] { fill: #34d399; }
:root[data-theme="dark"] svg [stroke="#22874a"] { stroke: #34d399; }
:root[data-theme="dark"] svg [stroke="#2a8a4c"] { stroke: #34d399; }

/* ---------- misc pages ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi .v { font-size: 19px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; font-family: var(--mono); letter-spacing: -.02em; }
.kpi .k { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.kpi .s { font-size: 11px; color: var(--muted); }
.kpi.bad .v { color: var(--crit); } .kpi.good .v { color: var(--ok); }
.split { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 16px; height: 100%; }
.side-list { display: flex; flex-direction: column; gap: 2px; }
.side-list a { padding: 7px 10px; border-radius: 8px; text-decoration: none; color: var(--text); cursor: pointer; }
.side-list a.active, .side-list a:hover { background: var(--accent-weak); color: var(--accent-text); }
.drop { border: 2px dashed var(--line-strong); border-radius: 12px; padding: 18px; text-align: center; color: var(--muted); background: var(--panel-3); }
.drop.over { border-color: var(--accent); background: var(--accent-weak); }
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.proj-card { cursor: pointer; }
.proj-card:hover { border-color: var(--accent-line); }
.proj-card h3 { margin: 0 0 6px; }
.md h1, .md h2, .md h3 { margin: 12px 0 6px; } .md p { margin: 6px 0; } .md table { border-collapse: collapse; margin: 6px 0; font-size: 12px; }
.md th, .md td { border: 1px solid var(--line); padding: 3px 6px; text-align: left; } .md th { background: var(--panel-2); }
.md code { background: var(--line2); padding: 0 4px; border-radius: 4px; font-family: var(--mono); font-size: .92em; } .md pre { background: var(--panel-3); border: 1px solid var(--line); padding: 8px; overflow: auto; border-radius: 8px; }
.md ul, .md ol { margin: 4px 0; padding-left: 20px; }
.md strong { color: var(--text); }

/* ---------- AI assistant drawer ---------- */
.chat-head { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(6, 78, 59, .45), var(--panel) 55%, rgba(49, 46, 129, .3)); }
:root[data-theme="light"] .chat-head { background: linear-gradient(90deg, #ecfdf5, #fff 55%, #eef2ff); }
.chat-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700; font-size: 12px; display: flex; align-items: center; justify-content: center; flex: none; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
.chat-title strong { display: block; font-size: 12.5px; }
.chat-title span { display: block; font-size: 10.5px; color: var(--accent-text); font-family: var(--mono); max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chat-log { flex: 1; overflow: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 9px 12px; border-radius: 12px; line-height: 1.5; overflow-wrap: anywhere; font-size: 12.5px; border: 1px solid var(--line); }
.msg.user { background: var(--accent-weak); border-color: var(--accent-line); align-self: flex-end; max-width: 90%; white-space: pre-wrap; margin-left: 24px; }
.msg.assistant { background: var(--panel-2); color: var(--text-2); }
.msg p:first-child { margin-top: 0; } .msg p:last-child { margin-bottom: 0; }
.msg.error { background: rgba(244, 63, 94, .12); border-color: rgba(244, 63, 94, .35); color: var(--crit); }
.tool { font-size: 11.5px; color: var(--muted); padding: 1px 0; font-family: var(--mono); }
.tool.ok::before { content: "\2713  "; color: var(--ok); } .tool.fail::before { content: "\2717  "; color: var(--crit); }
.tool.run::before { content: "\2026  "; color: var(--warn); }
.actions { font-size: 11px; color: var(--muted); margin-top: 6px; border-top: 1px dashed var(--line-strong); padding-top: 5px; font-family: var(--mono); }
/* suggested workflows: small chips, shown only before the first prompt (afterwards in the lightning menu) */
#chat-quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel-3); }
#chat-quick::before { content: "Try:"; font-size: 11.5px; color: var(--muted); align-self: center; }
#chat-quick:empty { display: none; }
#chat-quick button { display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 500; padding: 4px 11px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--text); }
#chat-quick button:hover { border-color: var(--accent-line); filter: none; }
#chat-form { display: flex; gap: 8px; padding: 10px 14px; align-items: flex-end; border-top: 1px solid var(--line); background: var(--panel-3); }
#chat-form textarea { flex: 1; resize: vertical; min-height: 54px; border-radius: 10px; }
#chat-send { border-radius: 10px; }

/* ---------- modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(2, 6, 15, .62); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 50; animation: fadein .14s ease-out; }
.modal { background: var(--panel); border: 1px solid var(--line-strong); border-radius: 16px; padding: 18px 20px; width: min(640px, 94vw); max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg); animation: popin .16s ease-out; }
.modal h2 { display: flex; align-items: center; gap: 10px; }
.modal h2::before { content: "CP"; flex: none; width: 26px; height: 26px; border-radius: 7px; background: var(--accent-strong); color: #fff; font-size: 10.5px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.modal.wide { width: min(980px, 96vw); }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
#toast { position: fixed; bottom: 40px; right: 24px; z-index: 60; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
#toast div { background: var(--accent-strong); color: #fff; padding: 9px 14px 9px 34px; border-radius: 12px; max-width: min(520px, 80vw); box-shadow: var(--shadow-lg); border: 1px solid rgba(52, 211, 153, .4); font-size: 12.5px; font-weight: 500; position: relative; animation: popin .16s ease-out; }
#toast div::before { content: "\2713"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; border: 1.5px solid #fff; border-radius: 50%; font-size: 9px; line-height: 13px; text-align: center; }
#toast div.err { background: #be123c; border-color: rgba(251, 113, 133, .5); }
#toast div.err::before { content: "!"; font-weight: 700; }
.menu { position: absolute; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 11px; box-shadow: var(--shadow); z-index: 40; padding: 5px; min-width: 210px; }
.menu a { display: block; padding: 6px 10px; color: var(--text); text-decoration: none; border-radius: 7px; cursor: pointer; font-size: 12.5px; }
.menu a:hover { background: var(--accent-weak); color: var(--accent-text); }
.menu a .muted { font-size: 11px; }
.menu a { display: flex; align-items: center; gap: 18px; }
.menu a kbd { margin-left: auto; font-family: var(--mono); font-size: 10.5px; color: var(--muted); background: none; border: 0; padding: 0; }
.menu a.dis { color: var(--muted); opacity: .5; cursor: default; }
.menu a.dis:hover { background: none; color: var(--muted); }
.menu a.danger { color: var(--crit); }
.menu a.danger:hover { background: rgba(244, 63, 94, .12); color: var(--crit); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: sp 0.8s linear infinite; vertical-align: -2px; }
@keyframes sp { to { transform: rotate(360deg); } }
@keyframes fadein { from { opacity: 0; } }
@keyframes popin { from { opacity: 0; transform: translateY(6px) scale(.985); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media print {
  #topbar, #chat, .toolbar, .noprint { display: none !important; }
  #layout, #main, .page { height: auto; overflow: visible; }
}

.s-row.drop-before { box-shadow: inset 0 3px 0 var(--accent); }
.s-row.drop-after { box-shadow: inset 0 -3px 0 var(--accent); }
.s-row.drop-into { background: var(--accent-weak) !important; outline: 2px dashed var(--accent); outline-offset: -2px; }
.s-row[draggable="true"] { cursor: grab; }

.s-cols .rz { position: absolute; right: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 2; }
.s-cols .rz:hover { background: var(--accent); opacity: .4; }
.s-row > div { box-sizing: border-box; }
.dtabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 4px 0 10px; }
.dtabs a { padding: 6px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; text-decoration: none; }
.dtabs a.active { color: var(--accent-text); border-bottom-color: var(--accent); font-weight: 600; }
.dtabs a:hover { color: var(--text); }
.rel-tbl td { vertical-align: middle; }
.s-row select.cell { width: 100%; height: 22px; padding: 0 2px; }
