/* NEXUS UI - Aggregate Intelligence brand (navy #21315E, blue #0C6CAD). No external fonts or CDNs. */
:root {
  --navy: #21315e; --navy-900: #0e1b3a; --navy-800: #15244a; --blue: #0c6cad; --blue-500: #1a7fc4; --sky: #5eb0ef;
  --bg: #f4f6fa; --panel: #ffffff; --panel-2: #f8fafc; --text: #16213e; --muted: #64708a; --border: #e2e7ef;
  --accent: var(--blue); --accent-soft: #e6f1fa; --accent-text: #fff;
  --ok: #157f4c; --ok-bg: #e5f5ec; --warn: #9a5b00; --warn-bg: #fff3dc; --bad: #b42318; --bad-bg: #fde9e7;
  --info: #0c6cad; --info-bg: #e6f1fa; --neutral-bg: #eef1f6;
  --user: var(--navy); --user-text: #fff; --bot: #f6f8fb; --code: #eef2f7;
  --shadow: 0 1px 2px rgba(16, 27, 58, .06), 0 4px 16px rgba(16, 27, 58, .06);
  --radius: 12px;
  --font: "Segoe UI Variable", "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}
[data-theme="dark"] {
  --bg: #0b1222; --panel: #121b30; --panel-2: #0f172a; --text: #e5ebf5; --muted: #93a0b8; --border: #23304d;
  --accent: #3d9be0; --accent-soft: #14304d; --accent-text: #fff;
  --ok: #4ccf8a; --ok-bg: #11301f; --warn: #f0b44c; --warn-bg: #33270f; --bad: #ff7b6e; --bad-bg: #3a1714;
  --info: #69b6f0; --info-bg: #13304a; --neutral-bg: #1b2640;
  --user: #2b5ea8; --bot: #17223a; --code: #1b2640;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.55 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.01em; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--code); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); font-size: 12.5px; }
[hidden] { display: none !important; }
.dark-only { display: none !important; }
[data-theme="dark"] .dark-only { display: block !important; }
[data-theme="dark"] .light-only { display: none !important; }

/* ---- icons (inline SVG injected by app.js) ---- */
.ico { display: inline-flex; width: 18px; height: 18px; flex: none; }
.ico svg { width: 100%; height: 100%; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border);
       background: var(--panel); border-radius: 9px; padding: 8px 14px; font-weight: 600; font-size: 13px; transition: .15s; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--blue-500); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); background: var(--bad-bg); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border);
            background: var(--panel); color: var(--muted); }
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ---- chat-first shell ---- */
.shell { display: grid; grid-template-columns: 272px 1fr; height: 100vh; transition: grid-template-columns .2s; }
.shell.rail-hidden { grid-template-columns: 0 1fr; }
.shell.rail-hidden .rail { visibility: hidden; }
.rail { background: linear-gradient(180deg, var(--navy-900) 0%, var(--navy-800) 100%); color: #cfd8ea; display: flex; flex-direction: column;
        padding: 16px 12px 12px; min-height: 0; overflow: hidden; }
.rail-head { display: flex; align-items: center; gap: 8px; padding: 2px 4px 0 8px; }
.rail-logo { width: 176px; height: auto; display: block; }
.rail-head .icon-btn { margin-left: auto; }
.icon-btn.on-dark { background: transparent; border-color: transparent; color: #8fa6cc; }
.icon-btn.on-dark:hover { background: rgba(255, 255, 255, .08); color: #fff; border-color: transparent; }
.rail-app { display: flex; align-items: center; gap: 8px; margin: 12px 8px 16px; }
.brand-name { font-weight: 800; letter-spacing: .12em; color: #fff; font-size: 14px; }
.brand-tag { font-size: 11px; color: #9fb4d8; background: rgba(94, 176, 239, .14); border: 1px solid rgba(94, 176, 239, .25); padding: 1px 8px; border-radius: 99px; }
.rail-new { justify-content: flex-start; background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .12); color: #fff; padding: 10px 12px; }
.rail-new:hover { background: rgba(94, 176, 239, .18); border-color: rgba(94, 176, 239, .4); color: #fff; }
.rail-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: #7083a8; margin: 18px 10px 6px; font-weight: 700; }
.conv-list { overflow-y: auto; flex: 1; min-height: 0; margin: 0 -4px; padding: 0 4px; }
.conv { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; color: #c3cee3; }
.conv:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.conv.active { background: rgba(94, 176, 239, .16); color: #fff; box-shadow: inset 3px 0 0 var(--sky); }
.conv-empty { color: #7083a8; font-size: 12.5px; padding: 6px 10px; }
.rail-foot { border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 12px; margin-top: 8px; display: flex; flex-direction: column; gap: 10px; }
.rail-ws { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; border-radius: 9px; padding: 9px 10px; background: transparent; color: #dfe7f5; font-weight: 600; }
.rail-ws:hover { background: rgba(255, 255, 255, .07); }
.rail-ws .ico { color: var(--sky); }
.count { margin-left: auto; font-size: 11px; font-weight: 700; padding: 0 7px; border-radius: 99px; background: rgba(127, 140, 170, .2); }
.count:empty { display: none; }
.count.warn { background: #f0b44c; color: #2a1d00; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { font-size: 11px; padding: 3px 8px; border-radius: 99px; background: rgba(255, 255, 255, .06); color: #b5c2da; display: inline-flex; align-items: center; gap: 6px; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #7083a8; }
.pill.ok::before { background: #4ccf8a; } .pill.warn::before { background: #f0b44c; } .pill.off::before { background: #ff7b6e; }
.powered { font-size: 11px; color: #6f81a5; padding: 0 4px; }
.scrim { display: none; }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg);
        background-image: radial-gradient(900px 420px at 50% -120px, color-mix(in srgb, var(--accent) 10%, transparent), transparent 70%); }
.chat-top { display: flex; align-items: center; gap: 10px; padding: 12px 18px; }
.chat-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-title b { display: block; font-size: 14px; letter-spacing: .08em; }
.chat-title div span { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.chat-mark { width: 44px; height: auto; display: none; }
.chat-mark img, .bot-ava img { width: 100%; height: auto; }
.shell.rail-hidden .chat-mark { display: block; }
#railOpen { display: none; }
.shell.rail-hidden #railOpen { display: inline-grid; }
.chat-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.sample-flag { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; color: var(--warn); background: var(--warn-bg); padding: 4px 9px; border-radius: 99px; }
.ws-btn { position: relative; }
.ws-btn .dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: #f0b44c; border: 2px solid var(--panel); }
.user-menu { position: relative; }
.avatar-btn { border: 0; background: transparent; padding: 0; border-radius: 50%; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--navy), var(--blue)); color: #fff;
          display: grid; place-items: center; font-weight: 700; font-size: 12.5px; }
.menu { position: absolute; right: 0; top: 42px; z-index: 30; min-width: 200px; background: var(--panel); border: 1px solid var(--border);
        border-radius: 12px; box-shadow: var(--shadow); padding: 6px; }
.menu-who { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; font-size: 13px; }
.menu-who small { display: block; color: var(--muted); text-transform: capitalize; }
.menu button { display: flex; gap: 8px; align-items: center; width: 100%; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; text-align: left; }
.menu button:hover { background: var(--bad-bg); color: var(--bad); }

.messages { flex: 1; overflow-y: auto; min-height: 0; padding: 8px 20px 24px; scroll-behavior: smooth; }
.empty { max-width: 760px; margin: 7vh auto 0; text-align: center; }
.empty-mark { width: 150px; height: auto; margin-bottom: 10px; }
.empty h1 { font-size: 27px; font-weight: 750; letter-spacing: -.02em; margin-bottom: 6px; }
.empty p { color: var(--muted); margin: 0; }
.suggestions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 28px; text-align: left; }
.chip { text-align: left; display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center; border: 1px solid var(--border); background: var(--panel);
        border-radius: 14px; padding: 12px 14px; transition: .15s; box-shadow: 0 1px 2px rgba(16, 27, 58, .04); }
.chip .ico { grid-row: span 2; color: var(--accent); width: 20px; height: 20px; }
.chip b { font-size: 13px; font-weight: 650; }
.chip small { font-size: 11.5px; color: var(--muted); }
.chip:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }

.msg { max-width: 820px; margin: 0 auto 22px; display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg .meta { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.bot-ava { width: 26px; height: 26px; border-radius: 8px; background: var(--panel); border: 1px solid var(--border); display: grid; place-items: center; }
.bot-ava img { width: 20px !important; }
.agent-badge { background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 99px; font-weight: 650; text-transform: capitalize; }
.bubble { padding: 12px 16px; border-radius: 16px; max-width: 100%; overflow-x: auto; }
.msg.user .bubble { background: var(--user); color: var(--user-text); border-bottom-right-radius: 5px; white-space: pre-wrap; max-width: 85%; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--border); border-top-left-radius: 5px; box-shadow: 0 1px 2px rgba(16, 27, 58, .04); }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble h4 { margin: 10px 0 6px; font-size: 14px; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.bubble pre { background: var(--code); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; }
.bubble table { border-collapse: collapse; margin: 8px 0; font-size: 12.5px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.bubble th { background: var(--panel-2); }
.bubble.typing { color: var(--muted); }
.typing-dots { display: inline-flex; gap: 4px; }
.typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: .2s; } .typing-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.notice { background: var(--warn-bg); color: var(--warn); padding: 7px 10px; border-radius: 8px; margin-bottom: 8px; font-size: 12px; }

/* inline cards under a reply (live data from the existing API) */
.cards { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.icard { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.icard-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--panel-2); }
.icard-head .ico { color: var(--accent); }
.icard-head b { font-size: 13px; }
.icard-head .live { margin-left: auto; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; color: var(--ok); display: inline-flex; align-items: center; gap: 5px; }
.icard-head .live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.icard-row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.icard-row:last-child { border-bottom: 0; }
.icard-row.click { cursor: pointer; } .icard-row.click:hover { background: color-mix(in srgb, var(--accent-soft) 50%, transparent); }
.icard-main { flex: 1; min-width: 0; }
.icard-title { font-weight: 650; font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.icard-title.mono { font-family: var(--mono); font-size: 12.5px; }
.icard-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.icard-sub.err { color: var(--bad); }
.icard-side { display: flex; align-items: center; gap: 6px; flex: none; }
.icard-foot { padding: 9px 14px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-top: 1px solid var(--border); }
.icard-foot a { margin-left: auto; font-weight: 600; cursor: pointer; }
.icard .rule-grid { padding: 12px 14px; }
.icard .progress { min-width: 110px; }

.composer-wrap { padding: 0 20px 14px; }
.composer { max-width: 820px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; background: var(--panel); border: 1px solid var(--border);
            border-radius: 20px; padding: 10px 10px 10px 18px; box-shadow: 0 6px 28px rgba(16, 27, 58, .10); transition: .15s; }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent), 0 6px 28px rgba(16, 27, 58, .10); }
.composer textarea { flex: 1; resize: none; border: 0; background: transparent; outline: none; padding: 9px 0; max-height: 200px; font-size: 14.5px; box-shadow: none !important; }
.send-btn { width: 42px; height: 42px; border-radius: 13px; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.send-btn:hover { background: var(--blue-500); } .send-btn:disabled { opacity: .5; }
.footnote { font-size: 11px; color: var(--muted); text-align: center; padding: 8px 0 0; }

/* ---- workspace slide-over ---- */
.sheet { position: fixed; inset: 0; z-index: 35; background: rgba(10, 18, 38, .4); display: flex; justify-content: flex-end; }
.sheet-panel { width: min(760px, 100%); height: 100%; background: var(--bg); box-shadow: -10px 0 40px rgba(0, 0, 0, .25); display: flex; flex-direction: column;
               animation: slidein .18s ease-out; }
@keyframes slidein { from { transform: translateX(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px 10px; }
.sheet-head b { font-size: 17px; margin-right: 8px; }
.sheet-head .icon-btn { margin-left: auto; }
.tabs { display: flex; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 10px 12px; font-weight: 600; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent;
               display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .count { margin-left: 0; color: inherit; }
.sheet-body { overflow-y: auto; padding: 16px 20px 32px; flex: 1; }
.ws { display: flex; flex-direction: column; gap: 14px; }
.ws .kpis { grid-template-columns: repeat(3, 1fr); }

/* ---- cards / KPIs ---- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.card-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-head h2 { font-size: 15px; font-weight: 700; }
.card-head .link, .card-head .muted { margin-left: auto; font-size: 12.5px; font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
       position: relative; overflow: hidden; }
.kpi::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--kc, var(--accent)); }
.kpi .k-label { font-size: 12px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi .k-value { font-size: 28px; font-weight: 750; margin-top: 4px; letter-spacing: -.02em; }
.kpi .k-sub { font-size: 12px; color: var(--muted); }
.kpi.ok { --kc: var(--ok); } .kpi.warn { --kc: #e09a1f; } .kpi.bad { --kc: var(--bad); } .kpi.navy { --kc: var(--navy); }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.callout { margin-top: 14px; padding: 11px 14px; border-radius: 10px; background: var(--info-bg); color: var(--text); font-size: 12.5px;
           display: flex; gap: 10px; align-items: flex-start; border: 1px solid color-mix(in srgb, var(--info) 25%, transparent); }
.callout .ico { color: var(--info); margin-top: 1px; }
.callout.warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); margin-top: 0; }
.callout.warn .ico { color: var(--warn); }
.empty-state { padding: 26px 10px; text-align: center; color: var(--muted); font-size: 13px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); }
.list-item .li-main { min-width: 0; flex: 1; }
.list-item .li-title { font-weight: 600; font-family: var(--mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-sub { font-size: 12px; color: var(--muted); }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.data th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700;
                padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--panel-2); }
table.data th:first-child { border-top-left-radius: 8px; } table.data th:last-child { border-top-right-radius: 8px; }
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
table.data tr.clickable { cursor: pointer; }
td.nowrap { white-space: nowrap; }
td.num, th.num { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
td.mono { font-family: var(--mono); font-size: 12px; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn + .btn { margin-left: 6px; }
.err-text { color: var(--bad); font-size: 12px; }

/* ---- badges / progress ---- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 650; padding: 3px 9px; border-radius: 99px;
         background: var(--neutral-bg); color: var(--muted); white-space: nowrap; text-transform: capitalize; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); } .badge.info { background: var(--info-bg); color: var(--info); }
.badge.plain::before { display: none; }
.tag { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; padding: 2px 7px; border-radius: 6px; background: var(--warn-bg); color: var(--warn); }
.progress { display: flex; align-items: center; gap: 8px; min-width: 130px; }
.bar { flex: 1; height: 6px; border-radius: 99px; background: var(--neutral-bg); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--navy), var(--blue)); }
[data-theme="dark"] .bar > i { background: linear-gradient(90deg, var(--blue), var(--sky)); }
.progress span { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }

/* ---- toolbar / segmented ---- */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar .btn { margin-left: auto; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.inline-form { display: flex; gap: 8px; margin-bottom: 12px; }
.inline-form input { width: 140px; text-transform: uppercase; }
input:not([type]), input[type=text], input[type=password], textarea {
  border: 1px solid var(--border); background: var(--panel); border-radius: 9px; padding: 9px 12px; outline: none; transition: .15s; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

/* ---- approvals / rule sets ---- */
.appr { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: start; }
.appr-ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.appr h3 { font-size: 14.5px; }
.appr .meta-row { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.appr .reason { margin-top: 8px; font-size: 12.5px; padding: 8px 10px; background: var(--panel-2); border-radius: 8px; border: 1px solid var(--border); }
.appr-actions { display: flex; gap: 6px; }
.rs-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rs-head h3 { font-size: 15px; }
.rs-scope { font-size: 12px; color: var(--muted); }
.rs-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12px; color: var(--muted); margin: 8px 0 12px; }
.rs-meta code { font-size: 11px; }
.rule-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.rule-box { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--panel-2); }
.rule-box h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-family: var(--mono); font-size: 12px; word-break: break-word; }
details.raw { margin-top: 12px; } details.raw summary { cursor: pointer; font-size: 12.5px; color: var(--muted); font-weight: 600; }
pre.json { background: var(--code); border-radius: 10px; padding: 12px; overflow: auto; font: 12px/1.5 var(--mono); max-height: 420px; }

/* ---- drawer (run detail) ---- */
.drawer { position: fixed; inset: 0; z-index: 40; background: rgba(10, 18, 38, .45); display: flex; justify-content: flex-end; }
.drawer-panel { width: min(560px, 100%); height: 100%; background: var(--panel); box-shadow: -10px 0 40px rgba(0, 0, 0, .2); display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 17px; } .drawer-head .icon-btn { margin-left: auto; }
.drawer-body { padding: 18px 22px; overflow-y: auto; }
.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
.fact { border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; background: var(--panel-2); }
.fact small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.fact b { font-size: 13.5px; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 6px; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--border); }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--panel);
                       border: 2px solid var(--accent); }
.timeline li.warning::before { border-color: #e09a1f; } .timeline li.error::before { border-color: var(--bad); }
.timeline .t-stage { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.timeline .t-at { font-size: 11px; color: var(--muted); margin-left: 6px; }
.timeline .t-msg { font-size: 13px; margin-top: 2px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60; background: var(--navy-900); color: #fff;
         padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; max-width: 90vw; }
.toast.bad { background: var(--bad); }

/* ---- login ---- */
.login-body { background: var(--bg); }
.login-split { display: grid; grid-template-columns: 1.05fr 1fr; min-height: 100vh; }
.login-hero { position: relative; overflow: hidden; color: #dbe5f5; padding: 48px 56px; display: flex; flex-direction: column;
              background: radial-gradient(1200px 600px at -10% 110%, rgba(12, 108, 173, .55), transparent 60%),
                          linear-gradient(160deg, var(--navy-900) 0%, var(--navy) 100%); }
.hero-logo { width: 260px; max-width: 70%; height: auto; }
.hero-copy { margin: auto 0; max-width: 460px; position: relative; z-index: 1; }
.hero-app { display: inline-block; font-size: 12px; font-weight: 800; letter-spacing: .18em; color: var(--sky); border: 1px solid rgba(94, 176, 239, .35);
            padding: 3px 10px; border-radius: 99px; margin-bottom: 16px; }
.hero-copy h2 { font-size: 34px; line-height: 1.15; color: #fff; font-weight: 750; letter-spacing: -.02em; }
.hero-copy p { font-size: 15px; color: #b9c7de; margin: 14px 0 22px; }
.hero-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.hero-points li { padding-left: 26px; position: relative; font-size: 14px; }
.hero-points li::before { content: ""; position: absolute; left: 0; top: 4px; width: 14px; height: 14px; border-radius: 50%;
                          background: rgba(94, 176, 239, .2); border: 2px solid var(--sky); }
.hero-wave { position: absolute; left: 0; right: 0; bottom: 40px; width: 100%; height: 160px; color: rgba(94, 176, 239, .35); }
.login-panel { display: grid; place-items: center; padding: 32px; }
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-logo { display: none; width: 200px; height: auto; margin-bottom: 8px; }
.login-card h1 { font-size: 24px; font-weight: 750; }
.login-sub { color: var(--muted); margin: -6px 0 6px; font-size: 13.5px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 650; color: var(--muted); }
.login-card input { font-size: 14px; padding: 11px 13px; color: var(--text); }
.login-card .btn { padding: 11px; font-size: 14px; margin-top: 4px; }
.login-error { color: var(--bad); font-size: 13px; min-height: 18px; }
.login-foot { font-size: 11.5px; color: var(--muted); text-align: center; margin-top: 10px; }

.scrim { display: none; }

/* ---- responsive / docked ---- */
@media (max-width: 1000px) { .suggestions { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px) {
  .shell, .shell.rail-hidden { grid-template-columns: 1fr; }
  .rail { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 30; transform: translateX(-100%); transition: transform .2s; visibility: visible !important; }
  .shell.rail-open .rail { transform: none; }
  .shell.rail-open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(10, 18, 38, .45); }
  #railOpen { display: inline-grid !important; }
  .chat-mark { display: block !important; width: 38px; }
}
@media (max-width: 560px) {
  .chat-top { padding: 10px 12px; gap: 8px; }
  .chat-title div span, .sample-flag, #newChatTop { display: none; }
  .messages { padding: 4px 12px 16px; }
  .empty { margin-top: 3vh; } .empty-mark { width: 110px; } .empty h1 { font-size: 21px; }
  .suggestions { grid-template-columns: 1fr; gap: 8px; margin-top: 18px; }
  .chip { padding: 10px 12px; }
  .composer-wrap { padding: 0 10px 10px; }
  .msg.user .bubble { max-width: 92%; }
  .ws .kpis { grid-template-columns: repeat(2, 1fr); }
  .sheet-body { padding: 12px 12px 24px; }
  .icard-row { flex-wrap: wrap; } .icard-side { width: 100%; justify-content: flex-end; }
  .login-split { grid-template-columns: 1fr; } .login-hero { display: none; } .login-logo { display: block; }
  .appr { grid-template-columns: 1fr; } .appr-ico { display: none; }
  .facts { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) { .login-split { grid-template-columns: 1fr; } .login-hero { display: none; } .login-logo { display: block; } }

/* ?compact=1 : docked chat widget (a small window on the desktop) */
body.compact { background: #dfe5ef; }
[data-theme="dark"] body.compact { background: #070c18; }
body.compact .shell { grid-template-columns: 1fr !important; max-width: 440px; height: min(100vh, 860px); margin: 0 auto; }
body.compact .rail { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 30; transform: translateX(-100%); transition: transform .2s; visibility: visible !important; }
body.compact .shell.rail-open .rail { transform: none; }
body.compact .shell.rail-open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(10, 18, 38, .45); }
body.compact #railOpen { display: inline-grid !important; }
body.compact .chat-mark { display: block !important; width: 38px; }
body.compact .chat { border-left: 1px solid var(--border); border-right: 1px solid var(--border); box-shadow: 0 0 40px rgba(16, 27, 58, .12); }
body.compact .chat-title div span, body.compact .sample-flag, body.compact #newChatTop { display: none; }
body.compact .suggestions { grid-template-columns: 1fr; gap: 8px; }
body.compact .empty { margin-top: 3vh; } body.compact .empty-mark { width: 110px; } body.compact .empty h1 { font-size: 21px; }
body.compact .messages { padding: 4px 12px 16px; } body.compact .composer-wrap { padding: 0 10px 10px; }
@media (min-height: 900px) { body.compact .shell { margin-top: calc((100vh - 860px) / 2); border-radius: 16px; overflow: hidden; } }
