/* ==========================================================================
   Quote Hub - "blackprint" stylesheet
   Lifted from the approved mockup's final theme layer: near-black blueprint
   ground with a drafting grid, bolted panels with corner screws, condensed
   engineering type, navy controls, copper money.
   One committed dark look in every theme. No frameworks, no webfonts.
   ========================================================================== */

:root {
  /* ground (the blueprint sheet) */
  --bp-mid: #0B1520;
  --bp-deep: #05090F;
  --bp-glow: rgba(80, 140, 210, .12);
  --bp-grid: rgba(150, 195, 240, .09);
  --bp-grid-major: rgba(150, 195, 240, .20);
  --bp-line: rgba(160, 205, 250, .34);
  --bp-line-strong: rgba(180, 215, 255, .62);

  /* panels + ink */
  --surface: #121B26;
  --surface-2: #17222E;
  --ink: #E9EFF5;
  --ink-2: #A6B5C4;
  --ink-3: #7E90A3;   /* >= 4.5:1 on --surface-2 (WCAG AA for the 9px labels) */
  --line: #263442;
  --panel-border: rgba(190, 215, 240, .30);
  --panel-border-strong: rgba(190, 215, 240, .45);

  /* accents */
  --navy: #24567F;
  --navy-deep: #1C4568;
  --navy-wash: #1A2C3E;
  --accent-ink: #85B5E0;
  --copper: #D2905A;
  --good: #57B385;
  --good-wash: rgba(35, 72, 54, .5);
  --bad: #E08084;
  --bad-wash: rgba(90, 35, 38, .5);
  --amber: #E4B75E;
  --amber-wash: rgba(84, 66, 24, .45);
  --bar: #4F7FAE;
  --bar-hot: #85B5E0;
  --focus: #D2905A;

  /* nameplates + screws */
  --plate-hi: #212D3B;
  --plate-lo: #151E29;
  --screw-hi: #8395A6;
  --screw-mid: #4A5C6E;
  --screw-lo: #10161E;
  --slot: rgba(0, 0, 0, .7);
  --engrave-shadow: rgba(0, 0, 0, .6);

  --shadow: 0 2px 6px rgba(0, 0, 0, .5), 0 16px 40px rgba(0, 0, 0, .55);

  --font-display: Bahnschrift, "Franklin Gothic Medium", "Arial Narrow", "Segoe UI", sans-serif;
  --font-body: Bahnschrift, "Franklin Gothic Medium", "Arial Narrow", "Segoe UI", sans-serif;
  --font-plain: "Segoe UI", -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-mono: Consolas, "Cascadia Mono", "Courier New", monospace;
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  font: 15px/1.55 var(--font-body);
  letter-spacing: .015em;
  -webkit-font-smoothing: antialiased;
  background-color: var(--bp-mid);
  background-image:
    repeating-linear-gradient(0deg, var(--bp-grid-major) 0 1px, transparent 1px 80px),
    repeating-linear-gradient(90deg, var(--bp-grid-major) 0 1px, transparent 1px 80px),
    repeating-linear-gradient(0deg, var(--bp-grid) 0 1px, transparent 1px 16px),
    repeating-linear-gradient(90deg, var(--bp-grid) 0 1px, transparent 1px 16px),
    radial-gradient(ellipse 90% 60% at 50% 28%, var(--bp-glow), transparent 65%),
    radial-gradient(ellipse 130% 110% at 50% 50%, var(--bp-mid) 45%, var(--bp-deep) 100%);
  background-attachment: fixed;
}

a { color: var(--accent-ink); }
a:focus-visible, button:focus-visible, select:focus-visible,
input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.frame { max-width: 1080px; margin: 0 auto; padding: 0 20px 56px; position: relative; z-index: 1; }

/* faint one-line diagram printed on the sheet behind everything */
.bp-art { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
.bp-art rect, .bp-art line, .bp-art path,
.bp-art circle, .bp-art polyline, .bp-art ellipse { fill: none; stroke: var(--bp-line); stroke-width: 1.3; }
.bp-art text { fill: var(--bp-line); stroke: none; letter-spacing: .12em; font-family: var(--font-display); }
.bp-art .node { fill: var(--bp-line); stroke: none; }   /* solid terminal / screw dots */
.bp-art .dim { stroke-width: .7; }                       /* dimension & guide lines */
.bp-art .heavy { stroke-width: 1.8; }   /* cabinet outlines - same brightness as everything else, just slightly thicker */
.bp-art .title { fill: var(--bp-line-strong); letter-spacing: .16em; }  /* NAV-TECH nameplates */

/* ---------- nameplates (plate + engraved + screws) ---------- */

.plate {
  background: linear-gradient(180deg, var(--plate-hi), var(--plate-lo));
  position: relative;
}
.plate::before, .plate::after {
  content: ""; position: absolute; top: 50%; transform: translateY(-50%);
  width: 8px; height: 8px; border-radius: 50%;
  box-shadow: inset 0 0 1px rgba(0, 0, 0, .5);
}
.plate::before {
  left: 9px;
  background:
    linear-gradient(50deg, transparent 42%, var(--slot) 45% 55%, transparent 58%),
    radial-gradient(circle at 35% 30%, var(--screw-hi), var(--screw-mid) 55%, var(--screw-lo));
}
.plate::after {
  right: 9px;
  background:
    linear-gradient(-35deg, transparent 42%, var(--slot) 45% 55%, transparent 58%),
    radial-gradient(circle at 35% 30%, var(--screw-hi), var(--screw-mid) 55%, var(--screw-lo));
}

.engraved {
  font-family: var(--font-display);
  text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-2); text-shadow: 0 1px 0 var(--engrave-shadow);
}

/* four corner screws - panels read as bolted to the board */
.screws {
  background-image:
    radial-gradient(circle at 11px 11px, var(--screw-hi) 0 1px, var(--screw-mid) 2.4px, var(--screw-lo) 3.4px, transparent 4px),
    radial-gradient(circle at calc(100% - 11px) 11px, var(--screw-hi) 0 1px, var(--screw-mid) 2.4px, var(--screw-lo) 3.4px, transparent 4px),
    radial-gradient(circle at 11px calc(100% - 11px), var(--screw-hi) 0 1px, var(--screw-mid) 2.4px, var(--screw-lo) 3.4px, transparent 4px),
    radial-gradient(circle at calc(100% - 11px) calc(100% - 11px), var(--screw-hi) 0 1px, var(--screw-mid) 2.4px, var(--screw-lo) 3.4px, transparent 4px);
}

/* ---------- app bar ---------- */

.appbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  border: 1.5px solid rgba(255, 255, 255, .42);
  padding: 16px 26px; margin-top: 18px;
  box-shadow: var(--shadow);
}
.brandplate {
  width: 148px; max-width: 34vw; height: auto; display: block; flex: none;
  box-shadow: 0 1px 3px rgba(15, 25, 40, .25);
  background: #fff; /* the logo art is navy-on-white */
}
.wordmark {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 700; letter-spacing: .08em; color: var(--ink);
  line-height: 1.15;
}
.appbar .sub { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.appbar .session { margin-left: auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.whoami {
  font-size: 10px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink-3);
}
.whoami b { color: var(--ink-2); font-weight: 700; }

/* ---------- nav tabs ---------- */

.tabs {
  display: flex; margin: 20px 0 24px; width: max-content; max-width: 100%;
  background: linear-gradient(180deg, var(--plate-hi), var(--plate-lo));
  border: 1px solid rgba(255, 255, 255, .35);
  overflow-x: auto;
}
.tab {
  display: inline-block; text-decoration: none; white-space: nowrap;
  color: var(--ink-2); background: transparent;
  font-family: var(--font-display);
  font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  padding: 11px 20px; cursor: pointer;
}
.tab + .tab { border-left: 1px solid var(--line); }
.tab:hover { color: var(--ink); }
.tab[aria-current="page"] {
  background: var(--navy); color: #fff;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .28);
}

/* ---------- panels ---------- */

.card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, .35);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 22px; }
.card-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 11px 28px; border-bottom: 1px solid var(--line);
}
.card-head h1, .card-head h2 {
  font-family: var(--font-display);
  font-size: 14px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink-2); text-shadow: 0 1px 0 var(--engrave-shadow);
  margin: 0;
}
.card-head .spacer { margin-left: auto; }
.card-body { padding: 18px 20px; }
.card-body .sub { font-size: 13.5px; color: var(--ink-2); margin: 0 0 12px; max-width: 52ch; }
.card-foot {
  display: flex; gap: 10px; align-items: center; padding: 13px 18px; flex-wrap: wrap;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.card-foot .hint { font-size: 13px; color: var(--ink-2); }

/* ---------- banners (scan status, errors, warnings, success) ---------- */

.banner {
  display: flex; gap: 12px; align-items: flex-start;
  background-color: var(--surface);
  border: 1px solid var(--panel-border);
  padding: 13px 16px; margin-bottom: 20px;
  font-size: 14px;
}
.banner .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: none; }
.banner strong { color: var(--ink); }
.banner .when { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.banner-good { background-image: linear-gradient(var(--good-wash), var(--good-wash)); }
.banner-good .dot { background: var(--good); box-shadow: 0 0 6px var(--good); }
.banner-bad { background-image: linear-gradient(var(--bad-wash), var(--bad-wash)); border-color: rgba(224, 128, 132, .4); }
.banner-bad .dot { background: var(--bad); }
.banner-warn { background-image: linear-gradient(var(--amber-wash), var(--amber-wash)); border-color: rgba(228, 183, 94, .4); }
.banner-warn .dot { background: var(--amber); }
.banner-idle .dot { background: var(--ink-3); }
.banner ul { margin: 6px 0 0; padding-left: 18px; }
.banner li { margin: 2px 0; }

/* ---------- stat tiles: one bolted strip of cells ---------- */

.tiles {
  display: flex; flex-wrap: wrap; gap: 0; margin-bottom: 22px;
  border: 1.5px solid rgba(255, 255, 255, .35);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.tile {
  flex: 1 1 200px; min-height: 112px;
  padding: 16px 18px 14px;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.tile:last-child { border-right: 0; }
.tile .label {
  font-size: 9px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink-3);
}
.tile .big {
  font-family: var(--font-display);
  font-size: 34px; font-weight: 700; line-height: 1.1; margin-top: 8px;
  font-variant-numeric: tabular-nums; color: var(--ink);
}
.tile .big .unit { font-size: 18px; color: var(--ink-2); font-weight: 600; }
.tile .note { font-size: 12.5px; color: var(--ink-2); margin-top: auto; padding-top: 6px; }
.money { color: var(--copper); }

/* the last-7-days bar chart inside a tile */
.weekbar { display: flex; align-items: flex-end; gap: 6px; height: 52px; margin-top: 10px; }
.weekbar .b {
  flex: 1; background: var(--bar); opacity: .45;
  position: relative; min-height: 3px; cursor: default;
}
.weekbar .b.hot { opacity: 1; background: var(--bar-hot); }
.weekbar .b .tip {
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #0C1218; font-size: 11.5px; padding: 3px 8px;
  white-space: nowrap; display: none; z-index: 3;
  font-variant-numeric: tabular-nums; font-family: var(--font-plain);
}
.weekbar .b:hover .tip, .weekbar .b:focus-visible .tip { display: block; }
.weekbar .b.hot::after {
  content: attr(data-n); position: absolute; top: -20px; left: 50%; transform: translateX(-50%);
  font-size: 12px; font-weight: 700; color: var(--ink);
}
.weekdays { display: flex; gap: 6px; margin-top: 5px; }
.weekdays span { flex: 1; text-align: center; font-size: 10.5px; color: var(--ink-3); }

/* ---------- tables ---------- */

.tablewrap { overflow-x: auto; }
table.log { border-collapse: collapse; width: 100%; min-width: 720px; }
table.log th {
  text-align: left;
  font-size: 9px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink-3);
  padding: 8px 14px; border-bottom: 1px solid var(--line);
  background: var(--surface-2); white-space: nowrap;
}
table.log td {
  padding: 11px 14px; border-bottom: 1px solid var(--line);
  vertical-align: top; font-size: 14px;
  font-variant-numeric: tabular-nums;
}
table.log tbody tr:hover td { background: var(--surface-2); }
table.log tr:last-child td { border-bottom: 0; }
table.log th.num, table.log td.num { text-align: right; white-space: nowrap; }
td.subject { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.qno { font-family: var(--font-mono); font-size: 13px; color: var(--accent-ink); font-weight: 600; white-space: nowrap; }
.muted { color: var(--ink-3); }
.empty-note { padding: 34px 20px; text-align: center; color: var(--ink-3); font-size: 14px; }

/* Quote-log search toolbar */
.log-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.search-field { max-width: 380px; }
@media (max-width: 560px) { .search-field { max-width: 100%; } }

/* ---------- status pills ---------- */

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  font-family: var(--font-display);
  border-radius: 2px; padding: 3px 9px; white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-new { color: var(--accent-ink); background: var(--navy-wash); }
.pill-follow-up { color: var(--amber); background: var(--amber-wash); }
.pill-won { color: var(--good); background: var(--good-wash); }
.pill-lost { color: var(--bad); background: var(--bad-wash); }

/* status form inside a table row: pill + select (+ Set button when no JS) */
.status-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status-select {
  appearance: none;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); padding: 5px 26px 5px 9px;
  font: 600 12px/1.3 var(--font-display); letter-spacing: .05em;
  cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 14px) 55%, calc(100% - 9px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.status-select:hover { border-color: var(--ink-3); }
.js .status-form .btn-set { display: none; }   /* fetch takes over when JS runs */

/* ---------- buttons: panel controls ---------- */

.btn {
  appearance: none; display: inline-block; border: 0; cursor: pointer;
  text-decoration: none; text-align: center;
  font-family: var(--font-display);
  text-transform: uppercase; letter-spacing: .08em;
  font-size: 12px; font-weight: 600; line-height: 1;
  padding: 10px 16px;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-deep); }
.btn-ghost { background: transparent; color: var(--accent-ink); border: 1px solid var(--ink-3); }
.btn-ghost:hover { border-color: var(--accent-ink); }
.btn-big { font-size: 13px; padding: 12px 20px; }
.btn-mini { font-size: 11px; padding: 6px 10px; }
.btn[disabled] { opacity: .55; cursor: default; }

/* ---------- forms ---------- */

.field-label {
  display: block;
  font-size: 9px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink-3); margin: 0 0 6px;
}
input.field {
  width: 100%; background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); padding: 10px 12px;
  font: 15px/1.4 var(--font-plain);
}
textarea.paste {
  width: 100%; min-height: 260px; resize: vertical;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); padding: 12px 14px;
  font: 13px/1.5 var(--font-mono);
}
textarea.paste:focus-visible, input.field:focus-visible { outline-offset: 1px; }
/* the UA default placeholder gray is too dim on --surface-2 */
textarea::placeholder, input::placeholder { color: var(--ink-3); opacity: 1; }
.gen-row { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.promise {
  font-size: 12.5px; color: var(--ink-3); margin: 12px 0 0;
  padding-left: 10px; border-left: 2px solid var(--good); max-width: 52ch;
}
.form-row { margin-bottom: 14px; }

/* ---------- login ---------- */

.login-wrap { max-width: 420px; margin: 48px auto 0; }
.login-wrap .card-body { padding: 22px 24px 24px; }
.login-wrap .btn { width: 100%; margin-top: 4px; }

/* ---------- quote result ---------- */

.result-summary {
  display: flex; gap: 24px; flex-wrap: wrap; align-items: baseline;
  padding: 4px 0 14px;
}
.result-summary .item .label {
  font-size: 9px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink-3); display: block; margin-bottom: 2px;
}
.result-summary .item .value { font-size: 17px; color: var(--ink); font-family: var(--font-display); }
.doc-actions { display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; align-items: center; }
.doc-actions .synergy { font-size: 12.5px; color: var(--ink-2); flex-basis: 100%; }
.doc-actions .synergy b { color: var(--good); }
textarea.jsonedit {
  width: 100%; min-height: 320px; resize: vertical;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); padding: 12px 14px;
  font: 12.5px/1.5 var(--font-mono);
  white-space: pre; overflow-x: auto;
}

/* ---------- status line (scan info) ---------- */

.status-line { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-2); }
.status-line.dim { color: var(--ink-3); }
.sdot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); flex: none; box-shadow: 0 0 6px var(--good); }
.sdot-idle { background: var(--ink-3); box-shadow: none; }

/* ---------- error page ---------- */

.error-wrap { max-width: 560px; margin: 48px auto 0; }
.error-wrap .card-body { padding: 24px; }
.error-msg { font-size: 15px; color: var(--ink); margin: 0 0 18px; font-family: var(--font-plain); }

/* ---------- engineering title block (footer) ---------- */

.titleblock {
  margin: 28px auto 0; width: max-content; max-width: 100%;
  display: flex; flex-wrap: wrap; align-items: stretch;
  background: var(--surface); border: 1.5px solid rgba(255, 255, 255, .5);
  box-shadow: var(--shadow); font-variant-numeric: tabular-nums;
}
.tb-cell {
  padding: 7px 14px 6px; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; justify-content: center;
  font-size: 11.5px; color: var(--ink); white-space: nowrap;
  font-family: var(--font-display); letter-spacing: .04em;
}
.tb-cell:last-child { border-right: 0; }
.tb-cell .lbl {
  font-size: 8.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 1px;
}
.tb-co { background: linear-gradient(180deg, var(--plate-hi), var(--plate-lo)); }
.tb-co .engraved { font-size: 12px; font-weight: 700; }
.tb-co .tb-sub { font-size: 9px; color: var(--ink-3); letter-spacing: .05em; }
.tb-title { min-width: 200px; }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: #0C1218; font-size: 13.5px; padding: 10px 16px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  max-width: min(92vw, 480px); text-align: center; box-shadow: var(--shadow); z-index: 50;
  font-family: var(--font-plain);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

/* ---------- mobile ---------- */

@media (max-width: 700px) {
  .frame { padding: 0 12px 40px; }
  .appbar { padding: 13px 16px; }
  .wordmark { font-size: 19px; }
  .tabs { width: 100%; }
  .tab { flex: 1 1 auto; text-align: center; padding: 11px 12px; }
  .tile { flex-basis: 100%; border-right: 0; }
  .tile + .tile { border-top: 1px solid var(--line); }
  .card-head { padding: 11px 28px; }
  .card-body { padding: 14px 14px; }
  .tb-cell { flex: 1 1 30%; white-space: normal; }
  .tb-co, .tb-title { flex-basis: 100%; border-top: 1px solid var(--line); }
  /* 16px inputs stop iOS zoom-on-focus */
  textarea.paste, textarea.jsonedit, input.field, .status-select { font-size: 16px; }
}

/* narrow phones: keep all three tabs on one line (no clipped QUOTE LOG) */
@media (max-width: 420px) {
  .tab { padding: 11px 6px; letter-spacing: .04em; font-size: 12px; }
}

/* ==========================================================================
   AI Help chat widget - bolted-plate FAB + blackprint chat panel.
   Robot mascot on the button, in the header, and beside every reply.
   ========================================================================== */

/* floating help button: a steel plate bolted to the board, bottom-right */
.chat-fab {
  position: fixed; right: 18px; bottom: 18px; z-index: 55;
  display: inline-flex; align-items: center; gap: 9px;
  appearance: none; cursor: pointer;
  border: 1px solid var(--panel-border-strong);
  color: var(--ink); padding: 12px 22px;
  font-family: var(--font-display);
  font-size: 13px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  box-shadow: var(--shadow);
  background-color: var(--plate-lo);
  background-image:
    radial-gradient(circle at 8px 8px, var(--screw-hi) 0 1px, var(--screw-mid) 2px, var(--screw-lo) 2.8px, transparent 3.3px),
    radial-gradient(circle at calc(100% - 8px) 8px, var(--screw-hi) 0 1px, var(--screw-mid) 2px, var(--screw-lo) 2.8px, transparent 3.3px),
    radial-gradient(circle at 8px calc(100% - 8px), var(--screw-hi) 0 1px, var(--screw-mid) 2px, var(--screw-lo) 2.8px, transparent 3.3px),
    radial-gradient(circle at calc(100% - 8px) calc(100% - 8px), var(--screw-hi) 0 1px, var(--screw-mid) 2px, var(--screw-lo) 2.8px, transparent 3.3px),
    linear-gradient(180deg, var(--plate-hi), var(--plate-lo));
  transition: filter .15s;
}
.chat-fab:hover,
.chat-fab[aria-expanded="true"] { filter: brightness(1.18); }
.chat-fab:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.fab-ico { width: 20px; height: 20px; color: var(--accent-ink); flex: none; }

/* chat panel */
.chat-panel {
  position: fixed; right: 18px; bottom: 74px; z-index: 60;
  width: min(390px, calc(100vw - 36px)); height: min(560px, 74vh);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--panel-border-strong);
  box-shadow: var(--shadow);
  background-image:
    radial-gradient(circle at 11px calc(100% - 11px), var(--screw-hi) 0 1px, var(--screw-mid) 2.4px, var(--screw-lo) 3.4px, transparent 4px),
    radial-gradient(circle at calc(100% - 11px) calc(100% - 11px), var(--screw-hi) 0 1px, var(--screw-mid) 2.4px, var(--screw-lo) 3.4px, transparent 4px);
}
.chat-panel[hidden] { display: none; }
.chat-head {
  display: flex; align-items: center; flex: none;
  padding: 11px 30px; font-size: 12.5px;
  border-bottom: 1px solid var(--line);
}
.head-ico { width: 18px; height: 18px; color: var(--accent-ink); flex: none; margin-right: 9px; }
.chat-head .engraved { font-size: 12.5px; }
.chat-close {
  appearance: none; border: 0; background: transparent; color: var(--ink-2);
  font-size: 22px; line-height: 1; cursor: pointer; margin-left: auto; padding: 0 4px;
}
.chat-close:hover { color: var(--ink); }
.chat-close:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* scrollable message area, faint drafting grid behind it */
.chat-msgs {
  flex: 1; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 9px;
  background-image:
    repeating-linear-gradient(0deg, var(--bp-grid) 0 1px, transparent 1px 18px),
    repeating-linear-gradient(90deg, var(--bp-grid) 0 1px, transparent 1px 18px);
}
.msg {
  max-width: 88%; padding: 9px 12px; font-size: 13.5px; line-height: 1.5;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.bot {
  position: relative; padding-left: 40px;
  background: var(--surface-2); border: 1px solid var(--line);
  align-self: flex-start; color: var(--ink);
}
.msg.user { background: var(--navy); color: #fff; align-self: flex-end; }
/* robot avatar beside every assistant message */
.msg.bot::before {
  content: ""; position: absolute; left: 10px; top: 9px; width: 21px; height: 21px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='none' stroke='%2385B5E0' stroke-width='1.6' stroke-linecap='round'%3E%3Ccircle cx='12' cy='3.2' r='1.2' fill='%2385B5E0' stroke='none'/%3E%3Cline x1='12' y1='4.6' x2='12' y2='7'/%3E%3Crect x='4.5' y='7' width='15' height='11' rx='2.5'/%3E%3Ccircle cx='9' cy='12' r='1.4' fill='%2385B5E0' stroke='none'/%3E%3Ccircle cx='15' cy='12' r='1.4' fill='%2385B5E0' stroke='none'/%3E%3Cline x1='9.5' y1='15.2' x2='14.5' y2='15.2'/%3E%3Cline x1='2.5' y1='11' x2='2.5' y2='14'/%3E%3Cline x1='21.5' y1='11' x2='21.5' y2='14'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
}
/* typing indicator: the robot "thinking" */
.msg.typing { display: inline-flex; gap: 5px; align-items: center; min-height: 21px; }
.msg.typing .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent-ink);
  opacity: .4; animation: chatdot 1.1s infinite ease-in-out both;
}
.msg.typing .dot:nth-child(2) { animation-delay: .18s; }
.msg.typing .dot:nth-child(3) { animation-delay: .36s; }
@keyframes chatdot {
  0%, 80%, 100% { opacity: .3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}
/* reload link offered on a session-expired reply */
.chat-reload {
  appearance: none; cursor: pointer; margin-top: 7px; display: inline-block;
  background: transparent; border: 1px solid var(--accent-ink); color: var(--accent-ink);
  font: 700 12px/1 var(--font-display); letter-spacing: .05em; text-transform: uppercase;
  padding: 7px 12px;
}
.chat-reload:hover { background: var(--navy-wash); }
.chat-reload:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* starter suggestion chips */
.chat-chips { display: flex; flex-wrap: wrap; gap: 7px; align-self: flex-start; }
.chat-chip {
  appearance: none; cursor: pointer; background: transparent;
  border: 1px solid var(--accent-ink); color: var(--accent-ink);
  font: 600 12px/1.3 var(--font-display); letter-spacing: .04em;
  padding: 7px 11px; text-align: left;
}
.chat-chip:hover { background: var(--navy-wash); }
.chat-chip:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* input row */
.chat-inrow {
  display: flex; gap: 8px; align-items: flex-end; flex: none; margin: 0;
  padding: 11px; border-top: 1px solid var(--line);
}
.chat-inrow textarea {
  /* overflow-y starts hidden so a resting single line never shows a
     scrollbar; the autoGrow JS flips it to auto once content exceeds
     max-height. */
  flex: 1; min-width: 0; resize: none; overflow-y: hidden;
  max-height: 96px; height: 44px;
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line);
  padding: 9px 12px; font: 13.5px/1.4 var(--font-plain);
}
.chat-inrow textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.chat-inrow .btn { flex: none; }

@media (prefers-reduced-motion: reduce) {
  .chat-fab { transition: none; }
  .msg.typing .dot { animation: none; }
}

/* mobile: near full-width panel */
@media (max-width: 560px) {
  .chat-panel {
    right: 8px; left: 8px; width: auto;
    /* dvh tracks the *visible* viewport, so when the iOS soft keyboard
       opens the panel shrinks with it and the input row stays reachable
       (plain vh keeps counting the covered area). */
    bottom: 70px; height: min(70vh, calc(100vh - 90px));
    height: min(70dvh, calc(100dvh - 90px));
  }
  .chat-fab { right: 12px; bottom: 12px; padding: 11px 18px; }
  /* lift the toast clear of the bottom-right FAB so a long status message
     is not tucked behind it */
  .toast { bottom: 78px; }
  /* 16px input stops iOS zoom-on-focus */
  .chat-inrow textarea { font-size: 16px; }
}
