/* MSO Dashboard. Base styles, dashboard charts and the table standard are taken from FLG Comp (public/styles.css)
   so every FLG app looks and works the same. Additions for this app are at the end. */
:root {
  --ink: #1c2430; --ink-2: #4a5568; --ink-3: #6f7b8f;
  --paper: #f6f7f5; --panel: #ffffff; --rule: #d9dde3; --rule-2: #eceef1;
  --sum: #d5e4f7;
  --ok: #1f7a4d; --ok-bg: #dff3e6;
  --warn: #9a6512; --warn-bg: #fff2d6;
  --err: #b42318; --err-bg: #fde3e1;
  --accent: #1f4e9c;
  --grid: #c4cad3;
  --blue: #2a78d6; --orange: #eb6834; --purple: #4a3aa7; --green: #008300;
  --sans: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font: 15px/1.45 var(--sans); color: var(--ink); background: var(--paper); display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 26px; font-weight: 700; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 18px; font-weight: 700; margin: 28px 0 10px; }
h3 { font-size: 15px; font-weight: 700; margin: 16px 0 6px; }
.muted { color: var(--ink-3); } .sub { color: var(--ink-2); margin: 0 0 18px; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hint { font-size: 13px; color: var(--ink-3); margin: 4px 0 0; }

/* rail */
.rail { background: #172033; color: #c9d2e3; padding: 22px 0; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.rail a { color: #c9d2e3; padding: 9px 22px; display: block; border-left: 3px solid transparent; }
.rail a:hover { background: #202b45; text-decoration: none; }
.rail a.active { color: #fff; border-left-color: #f2c14e; background: #202b45; }
.rail .brand { font-size: 22px; font-weight: 700; line-height: 1.05; color: #fff; margin-bottom: 20px; padding-bottom: 14px; border-bottom: 1px solid #2a3652; }
.rail .brand span { font-weight: 400; color: #f2c14e; }
.rail-foot { margin-top: auto; padding: 14px 22px; font-size: 12px; color: #8a94ab; }
/* "Open an app" on the Dashboard */
.apps-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 18px; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 8px; background: #fff; }
.apps-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); margin-right: 6px; }
.apps-bar .app-btn { padding: 6px 12px; font-size: 14px; }
.apps-bar .app-btn small { font-weight: 400; color: var(--ink-3); }
.apps-bar .app-btn.off { opacity: .45; cursor: default; }
@media print { .apps-bar { display: none; } }
/* Who is signed in, at the bottom of the menu (as in the other FLG apps), with Sign out just above it */
#whoami { margin-bottom: 10px; color: #c9d2e3; font-size: 13px; }
#whoami .who-mail { color: #8e9ab3; font-size: 11px; word-break: break-all; }
.rail a.rail-signout { margin-top: auto; border-top: 1px solid #2a3652; }
.rail a.rail-signout + .rail-foot { margin-top: 0; }
@media (max-width: 760px) { .rail a.rail-signout { margin-top: 0; border-top: 0; } }

main { padding: 30px 36px 60px; max-width: 1500px; min-width: 0; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* controls */
button, .btn { font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--rule); background: #fff; color: var(--ink); cursor: pointer; display: inline-block; }
button:hover, .btn:hover { border-color: var(--ink-3); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #17407f; }
button.ghost { background: transparent; border-color: transparent; color: var(--accent); padding: 6px 8px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--rule); border-radius: 5px; background: #fff; color: var(--ink); min-width: 0; max-width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid #f2c14e; outline-offset: 1px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
label.f > input, label.f > select { font-size: 15px; color: var(--ink); }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 16px; }

/* panels & tables */
.panel { background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 16px 18px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 13px; padding: 7px 8px; border-bottom: 2px solid var(--rule); background: #fafbfc; vertical-align: bottom; }
td { padding: 6px 8px; border-bottom: 1px solid var(--rule-2); vertical-align: top; }
tr.total td { font-weight: 700; background: var(--sum); border-top: 2px solid var(--rule); }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: #f3f5f8; }
.tight td, .tight th { padding: 4px 6px; }
.scroll { overflow-x: auto; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); } .badge.neutral { background: var(--rule-2); color: var(--ink-2); }
.badge.info { background: #e2ebfa; color: #1f4e9c; } .badge.plan { background: #ece9f8; color: var(--purple); }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #172033; color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 80; }
#toast.show { opacity: 1; }
.empty { padding: 40px; text-align: center; color: var(--ink-2); background: var(--panel); border: 1px dashed var(--rule); border-radius: 8px; }

@media print {
  body { display: block; background: #fff; font-size: 12px; } .rail, .actions, .noprint, #toast, .previewbar button { display: none !important; }
  main { padding: 0; max-width: none; } .panel { border: none; padding: 0; }
  @page { margin: 12mm; }
  .print-head { display: block !important; }
}
.print-head { display: none; font-size: 11px; color: var(--ink-2); border-bottom: 1px solid var(--rule); margin-bottom: 10px; padding-bottom: 4px; }

/* table tools: sort, filter, rearrange, hide/show (the FLG table standard) */
.tabletools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.tabletools input[type=search] { width: 260px; }
.colmenu { margin-bottom: 10px; max-width: 720px; }
.colmenu-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.colmenu-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 16px; }
.colmenu-list label { display: flex; gap: 6px; align-items: center; font-size: 14px; cursor: pointer; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th.dropto { box-shadow: inset 3px 0 0 var(--accent); }
@media print { .tabletools, .colmenu { display: none; } }

/* choice dialog (print scope) */
dialog.choice { box-sizing: border-box; overflow: visible; border: 1px solid var(--rule); border-radius: 10px; padding: 20px 22px; width: min(460px, calc(100vw - 32px)); color: var(--ink); background: var(--panel); }
dialog.choice::backdrop { background: rgba(28, 36, 48, .35); }
dialog.choice h3 { margin: 0 0 14px; font-size: 18px; }
.choice-opts { display: grid; gap: 10px; }
.choice-opts button { box-sizing: border-box; width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 12px 14px; }
.choice-opts button span { font-weight: 400; font-size: 13px; opacity: .85; }
.choice-foot { display: flex; justify-content: flex-end; margin-top: 12px; }
.print-only { display: none; }
@media print { .print-only { display: block; font-weight: 600; } }

/* dashboard: KPI tiles and plain HTML/CSS charts */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 12px 14px; min-width: 0; }
.kpi .l { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .v small { font-size: 14px; font-weight: 600; color: var(--ink-3); }
.kpi .d { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.kpi.hero { grid-column: span 2; }
.kpi.hero .v { font-size: 40px; line-height: 1.1; }
.kpi.warn { border-left: 4px solid var(--orange); } .kpi.err { border-left: 4px solid var(--err); } .kpi.ok { border-left: 4px solid var(--green); }
.kpi.empty-v .v { color: var(--ink-3); font-size: 20px; }
a.kpi, .kpi.clickable { color: inherit; text-decoration: none; display: block; cursor: pointer; } a.kpi:hover, .kpi.clickable:hover { border-color: var(--accent); }
.viz-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.viz-card { background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 16px 18px; min-width: 0; }
.viz-card.wide { grid-column: 1 / -1; }
.viz-card h3 { margin: 0 0 2px; font-size: 16px; }
.viz-card > .hint { margin-bottom: 12px; }
.viz-empty { padding: 28px 12px; text-align: center; color: var(--ink-3); font-size: 14px; border: 1px dashed var(--rule); border-radius: 6px; }
.viz-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-bottom: 10px; }
.viz-legend span { display: inline-flex; align-items: center; gap: 6px; }
.viz-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.hbars { display: grid; gap: 6px; }
.hbar-row { display: grid; grid-template-columns: minmax(90px, 38%) minmax(0, 1fr); align-items: center; gap: 10px; font-size: 13px; padding: 2px 0; border-radius: 4px; }
.hbar-row:hover { background: var(--rule-2); }
.clickable { cursor: pointer; }
.hbar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.hbar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hbar { height: 16px; border-radius: 0 4px 4px 0; flex: none; min-width: 2px; }
.hbar-val { font-size: 12px; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.vcols { position: relative; height: 240px; margin: 4px 0 26px 52px; }
.vcols-grid { position: absolute; inset: 0; }
.vcols-grid .tick { position: absolute; left: 0; right: 0; border-top: 1px solid var(--rule-2); }
.vcols-grid .tick span { position: absolute; right: calc(100% + 8px); top: -8px; font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.vcols-plot { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: space-around; border-bottom: 1px solid var(--rule); }
.vcol { position: relative; height: 100%; flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; cursor: default; }
.vcol:hover { background: rgba(28, 36, 48, .04); }
.vstack { width: min(28px, 60%); display: flex; flex-direction: column-reverse; gap: 2px; min-height: 0; }
.vstack .seg { width: 100%; min-height: 1px; }
.vstack .seg:last-child { border-radius: 4px 4px 0 0; }
.vcol-label { position: absolute; top: calc(100% + 6px); font-size: 11px; color: var(--ink-3); white-space: nowrap; }
.viz-table { margin-top: 12px; font-size: 13px; overflow-x: auto; }
.viz-table summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.viz-table table { margin-top: 8px; }
.viz-tip { position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; line-height: 1.45; padding: 7px 10px; border-radius: 6px; white-space: pre-line; max-width: 320px; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
@media (max-width: 700px) { .viz-grid { grid-template-columns: minmax(0, 1fr); } .kpi.hero { grid-column: auto; } .kpi.hero .v { font-size: 32px; } }
@media print { .viz-card, .mod-card, .kpi { break-inside: avoid; } .viz-table[open] summary { display: none; } .viz-tip { display: none; } }

/* resizable columns (every table) */
th.rz-th { position: relative; }
.rz-handle { position: absolute; top: 0; right: -4px; width: 8px; height: 100%; cursor: col-resize; z-index: 2; }
.rz-handle::after { content: ""; position: absolute; top: 20%; bottom: 20%; left: 3px; width: 2px; border-radius: 1px; background: transparent; }
th:hover > .rz-handle::after, .rz-handle:hover::after { background: var(--ink-3); }
body.resizing, body.resizing * { cursor: col-resize !important; user-select: none !important; }
@media print { .rz-handle { display: none; } }

/* table standard: boxed, shaded column headings and a thin vertical line between every column, full height */
th { border: 1px solid var(--grid); border-bottom-width: 2px; background-color: #eef1f5; }
td { border-left: 1px solid var(--grid); border-right: 1px solid var(--grid); }
td { white-space: normal; overflow-wrap: anywhere; }

/* Excel-style column filters */
th .th-in { display: inline-flex; align-items: flex-end; gap: 4px; }
th.num .th-in { justify-content: flex-end; }
.fbtn { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; padding: 0; margin-left: 2px; border: 1px solid transparent; border-radius: 4px; background: transparent; color: var(--ink-3); cursor: pointer; }
.fbtn:hover { border-color: var(--grid); background: #fff; color: var(--ink); }
.fbtn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.fpop { position: fixed; z-index: 60; width: min(280px, calc(100vw - 16px)); background: var(--panel); border: 1px solid var(--grid); border-radius: 8px; box-shadow: 0 8px 28px rgba(28,36,48,.18); padding: 10px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; font-weight: 400; color: var(--ink); }
.fpop-head { font-weight: 700; font-size: 14px; }
.fpop-cond { display: grid; gap: 6px; padding-bottom: 8px; border-bottom: 1px solid var(--rule-2); }
.fpop-ab { display: flex; align-items: center; gap: 6px; }
.fpop-ab input { flex: 1; min-width: 0; }
.fpop-ab[hidden], .fpop-ab [hidden] { display: none; }
.fpop-all { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.fpop-list { max-height: 240px; overflow: auto; border: 1px solid var(--rule-2); border-radius: 6px; padding: 4px 6px; }
.fpop-list label { display: flex; align-items: center; gap: 8px; padding: 3px 2px; border-radius: 4px; cursor: pointer; }
.fpop-list label:hover { background: var(--rule-2); }
.fpop-list label[hidden] { display: none; }
.fpop-list .fv { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.fpop-list .fn { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.fpop-foot { display: flex; justify-content: space-between; align-items: center; }
.fpop-foot button { padding: 6px 12px; }
@media print { .fbtn, .fpop { display: none; } }

/* ---------- MSO Dashboard additions ---------- */
.status { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; border: 1px solid transparent; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.live { background: var(--ok-bg); color: var(--ok); }
.status.saved { background: #e2ebfa; color: #1f4e9c; }
.status.placeholder { background: var(--rule-2); color: var(--ink-2); }
.status.planned { background: #fff; color: var(--purple); border-color: #cfc8ef; }
.status.offline { background: var(--err-bg); color: var(--err); }
.entity { display: inline-block; font-size: 12px; font-weight: 600; color: var(--ink-2); background: #f1f3f6; border: 1px solid var(--rule); border-radius: 4px; padding: 0 6px; margin-right: 4px; white-space: nowrap; }

.meter { display: flex; height: 6px; border-radius: 3px; background: var(--rule-2); overflow: hidden; margin-top: 6px; }
.meter span { height: 100%; }

.progress { display: grid; gap: 10px; }
.prow { display: grid; grid-template-columns: minmax(90px, 38%) minmax(0, 1fr); gap: 10px; align-items: center; font-size: 13px; border-radius: 4px; }
.prow:hover { background: var(--rule-2); }
.prow .ptrack { display: flex; align-items: center; gap: 8px; min-width: 0; }
.prow .pbar { flex: 1; min-width: 0; height: 14px; border-radius: 4px; background: var(--rule-2); overflow: hidden; }
.prow .pbar span { display: block; height: 100%; background: var(--blue); }
.prow.here .plabel { font-weight: 700; } .prow.here .pbar span { background: var(--orange); }
.prow .pval { font-size: 12px; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 72px; text-align: right; }
.plabel { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mod-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 16px; }
.mod-card { background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.mod-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.mod-head h3 { margin: 0; font-size: 17px; }
.mod-purpose { margin: 0; color: var(--ink-2); font-size: 14px; }
.draft-tag { font-size: 11px; font-weight: 700; color: var(--warn); background: var(--warn-bg); border-radius: 3px; padding: 0 5px; margin-left: 4px; white-space: nowrap; }
.mini { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.mini .m { border: 1px solid var(--rule-2); border-radius: 6px; padding: 7px 9px; min-width: 0; }
.mini .m .l { font-size: 12px; color: var(--ink-2); } .mini .m .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.mini .m .v.none { color: var(--ink-3); font-size: 15px; font-weight: 600; } .mini .m .t { font-size: 11px; color: var(--purple); }
.mod-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--ink-3); margin-top: auto; padding-top: 8px; border-top: 1px solid var(--rule-2); }
.mod-foot .btns { display: flex; gap: 6px; } .mod-foot .btn, .mod-foot button { padding: 5px 10px; font-size: 13px; }
.changes { margin: 0; padding-left: 18px; font-size: 13px; color: var(--ink-2); } .changes li { margin: 2px 0; }
.up { color: var(--ok); font-weight: 700; } .down { color: var(--err); font-weight: 700; }
.notes { margin: 0; padding-left: 18px; font-size: 13px; color: var(--ink-2); }

.next { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.next li { display: grid; grid-template-columns: 12px minmax(0, 1fr); gap: 8px; align-items: baseline; font-size: 14px; padding: 6px 6px; border-radius: 6px; }
.next li.clickable:hover { background: var(--rule-2); }
.next .pri { width: 10px; height: 10px; border-radius: 50%; background: var(--blue); display: inline-block; }
.next li.high .pri { background: var(--orange); }
.next .meta { font-size: 12px; color: var(--ink-3); }

.previewbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: #fff6e6; border: 1px solid #f0c9a3; border-radius: 8px; padding: 8px 12px; margin: 0 0 14px; font-size: 14px; }
.warnbox { background: var(--err-bg); color: var(--err); border-radius: 8px; padding: 10px 14px; margin: 0 0 14px; }
.infobox { background: #eef4ff; border: 1px solid #b9d3f5; border-radius: 8px; padding: 10px 14px; margin: 0 0 14px; font-size: 14px; }
.okbox { background: #eef8f1; border: 1px solid #b9e0c6; border-radius: 8px; padding: 10px 14px; margin: 0 0 14px; font-size: 14px; }
.ent-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.ent { background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 12px 14px; }
.ent b { display: block; margin-bottom: 4px; }
.list-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.list-rows li { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; }
.list-rows .when { font-weight: 700; color: var(--purple); font-variant-numeric: tabular-nums; }
.section-sub { color: var(--ink-3); font-size: 13px; margin: -6px 0 12px; }

@media (max-width: 760px) {
  body { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px 8px; gap: 2px; }
  .rail .brand { width: 100%; margin: 0 0 6px; padding: 0 8px 8px; font-size: 18px; }
  .rail .flg-rel { flex-basis: 100%; }   /* the release number (release.js) on its own line under the name */
  .rail a { padding: 6px 10px; border-left: 0; border-bottom: 3px solid transparent; font-size: 14px; }
  .rail a.active { border-bottom-color: #f2c14e; }
  .rail-foot { display: none; }
  main { padding: 16px; }
  h1 { font-size: 22px; }
  .mod-grid { grid-template-columns: minmax(0, 1fr); }
  .tabletools input[type=search] { width: 100%; }
  .vcols { margin-left: 44px; margin-bottom: 38px; }
  .vcol-label { font-size: 10px; white-space: normal; text-align: center; width: 100%; line-height: 1.1; }
}

/* ---------- Chat (same look as Deal GPS and FLG Comp): a drawer on every page, a full Chat page, answers with tables,
   charts and a button to the right app's own chat for deep questions ---------- */
.chat-log { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; min-height: 0; }
.chat-msg { max-width: 88%; padding: 10px 14px; border-radius: 12px; line-height: 1.45; overflow-wrap: anywhere; }
.chat-msg p { margin: 0 0 8px; } .chat-msg p:last-child { margin-bottom: 0; } .chat-msg ul, .chat-msg ol { margin: 4px 0 8px; padding-left: 20px; }
.chat-msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.assistant { align-self: flex-start; background: #f1f3f6; border-bottom-left-radius: 4px; }
.chat-msg.error { align-self: flex-start; background: var(--err-bg); color: var(--err); }
.chat-att { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; font-size: 13px; opacity: .9; }
.chat-display { margin-top: 10px; }
.chat-card { background: #fff; border: 1px solid var(--rule); border-radius: 8px; padding: 12px; }
.chat-card h4 { margin: 0 0 8px; font-size: 14px; }
.chat-card .handoff { margin-top: 8px; }
.chat-viz { padding: 12px 14px; } .chat-viz .vcols { height: 200px; }
.chat-from { margin: 0 0 2px; font-size: 11px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.chat-md { background: #fff; margin: 6px 0 8px; } .chat-md th, .chat-md td { font-size: 13px; }
.typing { display: inline-flex; gap: 4px; padding: 14px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.chat-suggest { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--grid); background: #fff; border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; font-weight: 400; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip button { border: 0; background: none; padding: 0 2px; cursor: pointer; font-size: 14px; }
.chip.about { background: #f2f7ff; border-color: #b9d3f5; max-width: 100%; } .chip.about button { color: var(--accent); }
.chat-compose { border-top: 1px solid var(--rule); padding: 10px 12px; display: grid; gap: 8px; }
.chat-compose textarea { width: 100%; resize: vertical; min-height: 48px; font: inherit; }
.chat-files { display: flex; flex-wrap: wrap; gap: 6px; } .chat-files:empty { display: none; }
.chat-bar { display: flex; align-items: center; gap: 10px; } .chat-bar .hint { flex: 1; margin: 0; }
.chat-fab { position: fixed; right: 22px; bottom: 22px; z-index: 40; display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px; border-radius: 999px;
  background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 6px 20px rgba(23, 32, 51, .28); }
.chat-fab:hover { background: #17407f; border-color: #17407f; }
body.chat-open .chat-fab { display: none; }
.chat-drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 45; width: min(540px, 100vw); display: flex; flex-direction: column; background: var(--paper);
  border-left: 1px solid var(--rule); box-shadow: -10px 0 30px rgba(23, 32, 51, .16); transform: translateX(105%); transition: transform .18s ease; visibility: hidden; }
.chat-drawer.open { transform: none; visibility: visible; }
.chat-drawer.wide { width: min(900px, 100vw); }
.cd-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 12px 14px 10px; background: var(--panel); border-bottom: 1px solid var(--rule); }
.cd-title { display: flex; flex-direction: column; min-width: 0; } .cd-title b { font-size: 17px; }
.cd-ctx { font-size: 12.5px; color: var(--ink-2); overflow-wrap: anywhere; }
.cd-actions { display: flex; flex-wrap: wrap; gap: 2px; justify-content: flex-end; }
.cd-actions button { padding: 5px 8px; font-size: 13px; }
.chat-drawer .chat-log { background: var(--panel); }
.chat-drawer .chat-msg { max-width: 96%; }
.chat-drawer .chat-msg.assistant { max-width: 100%; width: 100%; }
.chat-drawer .chat-suggest { background: var(--panel); padding-top: 4px; }
.chat-drawer .chat-compose { background: var(--panel); }
.chat-drawer .chat-compose[hidden], .cd-nokey[hidden], .cd-history[hidden] { display: none; }
.chat-drawer .chat-card { overflow: hidden; }
.chat-drawer .chat-card .panel.scroll { max-height: 360px; overflow: auto; padding: 0; }
.chat-drawer .chat-card .tabletools input[type=search] { width: 150px; }
.chat-drawer .chat-card .tabletools { flex-wrap: wrap; gap: 6px; } .chat-drawer .chat-card .tabletools button { padding: 5px 9px; font-size: 13px; }
.chat-steps { margin-top: 8px; font-size: 12.5px; color: var(--ink-2); } .chat-steps summary { cursor: pointer; } .chat-steps ol { margin: 4px 0 0; padding-left: 20px; }
.chat-msg.typing { align-items: center; } .chat-msg.typing em { font-style: normal; margin-left: 6px; }
.cd-nokey { margin: 14px; padding: 12px 14px; background: #fff8ef; border: 1px solid #f0c9a3; border-radius: 8px; }
.cd-nokey p { margin: 6px 0 10px; } .cd-nokey code { font-size: 12.5px; overflow-wrap: anywhere; }
.cd-history { max-height: 45vh; overflow: auto; background: var(--panel); border-bottom: 1px solid var(--rule); padding: 8px 14px 10px; }
.cd-hist-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.cd-history ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.cd-hist-item { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 1px; padding: 7px 10px; font-weight: 400; }
.cd-hist-item b { font-weight: 600; } .cd-hist-item span { font-size: 12px; color: var(--ink-3); } .cd-hist-item.on { border-color: var(--accent); }
/* A deep question: the prominent button to the right app's own chat */
.handoff-card { border: 2px solid #b9d3f5; background: #f5f9ff; }
.handoff-card.off { border: 1px solid var(--rule); background: #fafbfc; }
.handoff-card h4 { font-size: 15px; }
.handoff-why { margin: 0 0 10px; font-size: 14px; }
a.handoff-go { display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 700; font-size: 15px; text-decoration: none; }
a.handoff-go:hover { background: #17407f; text-decoration: none; }
.handoff-q { margin-top: 10px; overflow-wrap: anywhere; }
@media (min-width: 1500px) { body.chat-open main { padding-right: calc(540px + 24px); } body.chat-open.chat-wide main { padding-right: calc(900px + 24px); } }
@media print { .chat-fab, .chat-drawer, .chatbtn, .ask-inline { display: none !important; } body.chat-open main { padding-right: 0; } }
/* "Ask Claude" buttons */
.chatbtn { border-color: var(--accent); color: var(--accent); }
button.ask-inline { margin-left: 6px; padding: 0 8px; font-size: 12px; line-height: 18px; border-radius: 999px; border-color: #b9d3f5; color: var(--accent); vertical-align: 1px; font-weight: 600; }
button.ask-inline:hover { border-color: var(--accent); }
.staging-tag { display: inline-block; margin-top: 6px; padding: 1px 6px; border-radius: 4px; background: #fff2d6; color: #7a4d00; font-weight: 700; font-size: 12px; }
/* The Chat page (#/chat): the same drawer, filling the screen beside the rail, with the conversation centred */
body.chat-page .chat-drawer { left: 220px; width: auto; transform: none; visibility: visible; transition: none; box-shadow: none; border-left: 0; }
body.chat-page .chat-fab, body.chat-page .cd-actions [data-cd=wide], body.chat-page .cd-actions [data-cd=close] { display: none; }
body.chat-page .cd-head, body.chat-page .chat-drawer .chat-log, body.chat-page .chat-drawer .chat-suggest, body.chat-page .chat-drawer .chat-compose,
body.chat-page .cd-history, body.chat-page .cd-nokey { padding-left: max(16px, calc((100% - 1000px) / 2)); padding-right: max(16px, calc((100% - 1000px) / 2)); }
body.chat-page .cd-nokey { margin: 14px 0; border-left: 0; border-right: 0; border-radius: 0; }
body.chat-page.chat-open main { padding-right: 36px; }
@media (max-width: 760px) {
  body.chat-page .chat-drawer { position: static; height: 85vh; width: 100%; border-top: 1px solid var(--rule); }
  body.chat-page main { padding: 0; }
  .chat-fab { right: 14px; bottom: 14px; padding: 9px 14px; }
  .chat-drawer .chat-card .tabletools input[type=search] { width: 100%; }
}
