:root {
  --ink: #2A221D;
  --soft: #6F6055;
  --paper: #FAF6EF;
  --card: #FFFDF9;
  --tint: #F1E9DC;
  --line: #E4D8C8;
  --ember: #B5471B;
  --ember-dark: #923814;
  --night: #231C18;
  --ok-bg: #D9E8D6;
  --ok-ink: #1F4D2B;
  --warn-bg: #F6DCCB;
  --warn-ink: #7A2E0E;
  --error: #A1260D;
  --focus: #1F6FEB;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 'Nunito Sans', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
h1, h2 { font-family: 'Domine', Georgia, serif; line-height: 1.2; margin: 0; }
h1 { font-size: 30px; }
h2 { font-size: 20px; margin-top: 28px; margin-bottom: 12px; }
.card h2 { margin-top: 0; margin-bottom: 0; }
p { margin: 0; }
a { color: var(--ember-dark); }
code { font: 14px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.muted { color: var(--soft); }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.narrow { max-width: 680px; display: flex; flex-direction: column; gap: 14px; }
.eyebrow, .label { font-size: 14px; font-weight: 700; letter-spacing: .04em; color: var(--ember-dark); }
.label { color: var(--soft); letter-spacing: 0; margin-bottom: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--card); padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip:focus { left: 8px; }

/* forms */
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 15px; }
input, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: #fff;
  border: 1px solid #BFB09E; border-radius: 10px; padding: 10px 12px; width: 100%;
}
textarea { resize: vertical; }
input[type='color'] { width: 48px; height: 44px; padding: 4px; flex: none; }
input[type='file'] { padding: 8px; }
.hint { font-weight: 400; font-size: 14px; color: var(--soft); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.color-row { display: flex; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; color: var(--ink); background: var(--card);
  border: 1px solid #BFB09E; border-radius: 10px; padding: 10px 16px; cursor: pointer; text-decoration: none;
  min-height: 44px;
}
.btn:hover { background: var(--tint); }
.btn-primary { background: var(--ember); border-color: var(--ember); color: #FFFDF9; }
.btn-primary:hover { background: var(--ember-dark); }
.btn-small { padding: 6px 12px; min-height: 36px; font-size: 14px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

.notice { border-radius: 10px; padding: 10px 14px; font-size: 15px; margin-bottom: 14px; }
.stack > .notice, .narrow > .notice { margin-bottom: 0; }
.notice-error { background: #FBE4DE; color: var(--error); }
.notice-ok { background: var(--ok-bg); color: var(--ok-ink); }
.notice-info { background: var(--tint); color: var(--ink); }

.pill { display: inline-block; font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 20px; white-space: nowrap; }
.pill-ok { background: var(--ok-bg); color: var(--ok-ink); }
.pill-warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill-quiet { background: #E7DBCA; color: var(--ink); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }

/* sign in */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.brand-mark { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; font-weight: 800; letter-spacing: .1em; white-space: nowrap; text-transform: uppercase; color: var(--ink); }
.brand-mark img { flex: none; }

/* layout */
.shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.shell > * { min-width: 0; }
.side { background: var(--card); color: var(--ink); border-right: 1px solid var(--line); padding: 22px 14px; display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh; }
.side .brand-mark { color: #161616; }
.side-org { font-size: 14px; color: var(--soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-link { color: var(--ink); text-decoration: none; padding: 10px 12px; border-radius: 10px; font-weight: 600; }
.nav-link:hover { background: var(--tint); }
.nav-link[aria-current='page'] { background: var(--ember); color: #FFFDF9; }
.side-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.side-foot .muted { color: var(--soft); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .btn { background: transparent; color: var(--ink); border-color: var(--line); }
.side-foot .btn:hover { background: var(--tint); }
.main { padding: 32px; max-width: 1040px; width: 100%; outline: none; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin-bottom: 4px; }

/* home */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 4px; color: var(--ink); text-decoration: none; }
.tile-link:hover { background: var(--tint); }
.tile-num { font: 700 36px/1.1 'Domine', Georgia, serif; color: var(--ember); }
.tile-label { font-size: 14px; color: var(--soft); }
.activity { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.activity li { display: flex; align-items: baseline; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.activity li:first-child { border-top: 0; }
.activity time { font-size: 14px; white-space: nowrap; }

/* setup */
.url-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.url-form label { min-width: 220px; }
.found-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.found-brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: #fff; border: 1px solid var(--line); }
.swatch { width: 32px; height: 32px; border-radius: 16px; border: 1px solid var(--line); }
.plain-list { margin: 0; padding-left: 20px; }

/* chat */
.chat-page { display: flex; flex-direction: column; min-height: calc(100vh - 64px); }
.chat-log { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 10px; min-height: 280px; margin-bottom: 14px; overflow-y: auto; }
.chat-empty { margin: auto; text-align: center; display: flex; flex-direction: column; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { font: inherit; font-size: 15px; background: var(--card); border: 1px solid #BFB09E; border-radius: 18px; padding: 8px 14px; cursor: pointer; color: var(--ink); }
.chip:hover { background: var(--tint); }
.bubble-wrap { display: flex; flex-direction: column; gap: 4px; max-width: 80%; }
.bubble-wrap.user { align-self: flex-end; align-items: flex-end; }
.bubble-wrap.assistant { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.user { background: var(--ember); color: #FFFDF9; border-bottom-right-radius: 4px; }
.bubble.assistant { background: var(--tint); border-bottom-left-radius: 4px; }
.sources { font-size: 13px; color: var(--soft); padding: 0 6px; }
.sources a { color: inherit; }
.chat-form { display: flex; gap: 10px; }

/* conversations */
.split { display: grid; grid-template-columns: 320px 1fr; gap: 18px; align-items: start; }
.conv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.conv-item { width: 100%; text-align: left; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.conv-item:hover, .conv-item.active { background: var(--tint); }
.conv-item.active { border-color: var(--ember); }
.conv-preview { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; flex-wrap: wrap; }
.conv-detail { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 10px; min-height: 200px; }
.back-btn { display: none; align-self: flex-start; }

/* requests */
.cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.cards .card { margin: 0; }
.request { display: flex; flex-direction: column; gap: 8px; }
.request.is-done { opacity: .75; }
.request-head, .request-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.request-contact { font-weight: 600; overflow-wrap: anywhere; }

/* knowledge + settings */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { text-align: left; padding: 10px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
thead th { border-top: 0; font-size: 13px; color: var(--soft); }
.num { text-align: right; white-space: nowrap; }
.snippet { margin: 0; background: var(--night); color: #FAF6EF; border-radius: 10px; padding: 14px; overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; padding: 12px 14px; gap: 10px; }
  .side-top { display: flex; align-items: baseline; gap: 10px; }
  .side nav { flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px; }
  .nav-link { white-space: nowrap; padding: 8px 12px; }
  .main { padding: 18px 16px 32px; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .split.has-detail .conv-list { display: none; }
  .split:not(.has-detail) .conv-detail { display: none; }
  .back-btn { display: inline-flex; }
  .bubble-wrap { max-width: 92%; }
  .chat-page { min-height: calc(100vh - 170px); }
  .activity li { flex-wrap: wrap; }
  h1 { font-size: 25px; }
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .nav-link, .chip, .tile, .conv-item { transition: background-color .12s ease; }
}

/* ---- added with stages 2 to 5 ---- */
.small { font-size: 14px; }
select {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid #BFB09E; border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px;
}
td select { min-width: 170px; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 8px; }
.quote { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--tint); border-radius: 10px; padding: 12px 14px; }
.plain-cards { list-style: none; margin: 0; padding: 0; }
.is-done { opacity: .8; }
.badge { display: inline-block; min-width: 22px; text-align: center; margin-left: 8px; padding: 0 6px; border-radius: 11px; font-size: 13px; line-height: 22px; background: #FFFDF9; color: var(--ember-dark); font-weight: 700; }
.nav-link { display: flex; align-items: center; justify-content: space-between; }
.side nav { overflow-y: auto; }
.notes { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.chips.left { justify-content: flex-start; margin-bottom: 14px; }
.chip-on { background: var(--ember); border-color: var(--ember); color: #FFFDF9; }
.chip-on:hover { background: var(--ember-dark); }
.meter { height: 14px; border-radius: 7px; background: #E7DBCA; overflow: hidden; margin-bottom: 6px; }
.meter span { display: block; height: 100%; background: var(--ok-ink); border-radius: 7px; }
.meter-high span { background: #B7791F; }
.meter-full span { background: var(--error); }
.plan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 14px; }
.plan-grid .card { margin: 0; }
.plan-current { border-color: var(--ember); border-width: 2px; }
.activity li .btn { flex: none; }

@media (max-width: 860px) {
  .plan-grid { grid-template-columns: 1fr; }
  .side nav { overflow-y: visible; }
  .nav-link { justify-content: flex-start; }
}
/* Visually hidden labels inside a scrolling table must stay inside it, or they widen the page on phones. */
.table-wrap { position: relative; }
code { overflow-wrap: anywhere; }

/* ---- files, charts and documents ---- */
.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 600; }
.check input { width: 20px; height: 20px; flex: none; }
label.btn { flex-direction: row; gap: 8px; font-weight: 700; }
label.btn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.is-disabled { opacity: .55; pointer-events: none; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--ember-dark); text-decoration: underline; cursor: pointer; }
.email-rule { border-top: 1px solid var(--line); padding-top: 14px; }
.filed { margin-left: 8px; }
.attach-chip { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--tint); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; overflow-wrap: anywhere; }
.bubble-wrap.wide { max-width: 100%; width: 100%; }
.bubble-wrap .btn-row { padding: 0 4px; }

.chart { margin: 0; width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.chart-title { font-weight: 700; font-size: 16px; }
.chart-data summary { font-size: 14px; }
.bars { display: flex; flex-direction: column; gap: 2px; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 30%) 1fr; align-items: center; gap: 12px; padding: 3px 0; border-radius: 6px; }
.bar-row.is-hover { background: var(--tint); }
.bar-label { font-size: 14px; color: var(--ink); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Bars are measured against the track without its right padding, so the value always has room and widths stay proportional. */
.bar-track { display: flex; align-items: center; gap: 8px; min-width: 0; padding-right: 96px; }
.bar-fill { display: block; height: 20px; border-radius: 0 4px 4px 0; flex: none; }
.bar-value { font-size: 14px; color: var(--soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.line-box { position: relative; width: 100%; }
.line-box svg { display: block; }
.chart-tip { position: absolute; pointer-events: none; background: var(--night); color: #FAF6EF; border-radius: 8px; padding: 6px 10px; font-size: 13px; display: flex; flex-direction: column; min-width: 140px; }
@media (max-width: 860px) {
  .bar-row { grid-template-columns: minmax(70px, 38%) 1fr; }
}
