/* Bug-Buddy web chat — shares the editorial palette of the report pages. */

:root {
  --ink: #1a1916;
  --ink-soft: #3b3a36;
  --muted: #7a766b;
  --faint: #a8a396;
  --cream: #f4f0e8;
  --paper: #fbf9f3;
  --paper-2: #f7f3ea;
  --rule: #e2dcc9;
  --rule-strong: #cfc7ad;
  --accent: #c95f30;
  --accent-soft: #f3dfd3;
  --accent-ink: #8f3f1c;
  --sage: #3d5447;
  --sage-soft: #e3e9e2;
  --teal: #1f3a4b;
  --ochre: #b58b4a;
  --danger: #a14545;
  --danger-soft: #f4dcdc;
  --shadow: 0 1px 2px rgba(26, 25, 22, 0.06), 0 6px 20px -12px rgba(26, 25, 22, 0.25);
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 272px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration-thickness: 1px; text-underline-offset: 2px; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
code, pre, .mono { font-family: var(--mono); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------------------------------------------------------------- layout */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  background: var(--paper);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.brand {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 1rem 1rem 0.85rem;
  border-bottom: 1px solid var(--rule);
}
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.brand-wordmark { font-family: var(--serif); font-weight: 600; font-size: 1.1rem; letter-spacing: -0.005em; }
.brand-sub { display: block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); margin-top: 1px; }

.new-chat {
  margin: 0.85rem 0.85rem 0.35rem;
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  background: var(--paper);
  font-weight: 500;
  transition: background 0.12s, border-color 0.12s;
}
.new-chat:hover { background: var(--paper-2); border-color: var(--accent); }
.new-chat svg { width: 14px; height: 14px; }

.conv-heading {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted);
  padding: 0.85rem 1.1rem 0.35rem;
}
.conv-list { list-style: none; overflow-y: auto; flex: 1; padding: 0 0.5rem 0.5rem; }
.conv-item {
  display: flex; align-items: center; gap: 0.35rem;
  border-radius: 7px;
}
.conv-item a {
  flex: 1; display: block; padding: 0.5rem 0.6rem;
  color: var(--ink-soft); text-decoration: none; font-size: 0.9rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-radius: 7px;
}
.conv-item:hover { background: var(--paper-2); }
.conv-item.active { background: var(--accent-soft); }
.conv-item.active a { color: var(--accent-ink); font-weight: 500; }
.conv-del {
  opacity: 0; width: 26px; height: 26px; border-radius: 6px; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; margin-right: 0.25rem;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { background: var(--danger-soft); color: var(--danger); }
.conv-del svg { width: 13px; height: 13px; }
.conv-empty { color: var(--faint); font-size: 0.85rem; padding: 0.5rem 0.65rem; }

.user-box {
  border-top: 1px solid var(--rule);
  padding: 0.8rem 1rem;
  display: flex; align-items: center; gap: 0.6rem;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: var(--sage); color: #fff; font-weight: 600; font-size: 0.78rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 0.9rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-sub { font-size: 0.72rem; color: var(--muted); }
.signout { font-size: 0.78rem; color: var(--muted); padding: 0.3rem 0.5rem; border-radius: 6px; }
.signout:hover { color: var(--accent-ink); background: var(--paper-2); }

/* ------------------------------------------------------------------ main */

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.7rem 1.5rem;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.topbar-title { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; font-size: 0.78rem; color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600;
  padding: 0.22rem 0.55rem; border-radius: 999px;
  background: var(--sage-soft); color: var(--sage);
}
.menu-btn { display: none; }

.thread {
  flex: 1; overflow-y: auto;
  padding: 1.5rem 1.5rem 2rem;
  scroll-behavior: smooth;
}
.thread-inner { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.35rem; }

/* welcome */
.welcome {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 1.75rem 1.9rem;
  box-shadow: var(--shadow);
}
.welcome .eyebrow { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.16em; color: var(--accent); font-weight: 600; margin-bottom: 0.6rem; }
.welcome h1 { font-family: var(--serif); font-weight: 600; font-size: 1.75rem; letter-spacing: -0.015em; line-height: 1.2; margin-bottom: 0.65rem; }
.welcome p { color: var(--ink-soft); max-width: 62ch; }
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.15rem; }
.chip {
  padding: 0.45rem 0.8rem; border-radius: 999px;
  border: 1px solid var(--rule-strong); background: var(--paper);
  font-size: 0.85rem; color: var(--ink-soft);
  transition: border-color 0.12s, background 0.12s;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }

/* messages */
.msg { display: grid; grid-template-columns: 34px 1fr; gap: 0.85rem; align-items: start; }
.msg-avatar {
  width: 34px; height: 34px; border-radius: 50%; overflow: hidden; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--sage); color: #fff; font-weight: 600; font-size: 0.8rem;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg-body { min-width: 0; }
.msg-meta { display: flex; align-items: baseline; gap: 0.6rem; margin-bottom: 0.3rem; }
.msg-author { font-weight: 600; font-size: 0.88rem; }
.msg-time { font-size: 0.72rem; color: var(--faint); }
.msg-model { font-size: 0.7rem; color: var(--faint); font-family: var(--mono); }
.msg.user .bubble {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 0.7rem 0.95rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.assistant .bubble { padding: 0.1rem 0; }

/* markdown */
.md > * + * { margin-top: 0.7rem; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; margin-top: 1.1rem; }
.md h1 { font-size: 1.45rem; } .md h2 { font-size: 1.25rem; } .md h3 { font-size: 1.08rem; } .md h4 { font-size: 1rem; }
.md p { max-width: 78ch; }
.md ul, .md ol { padding-left: 1.4rem; }
.md li + li { margin-top: 0.25rem; }
.md code { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 4px; padding: 0.05rem 0.35rem; font-size: 0.88em; }
.md pre { background: #23221f; color: #f0ece2; padding: 0.85rem 1rem; border-radius: 8px; overflow-x: auto; font-size: 0.84rem; line-height: 1.5; }
.md pre code { background: none; border: 0; padding: 0; color: inherit; font-size: inherit; }
.md blockquote { border-left: 3px solid var(--accent); padding: 0.2rem 0 0.2rem 0.9rem; color: var(--ink-soft); }
.md hr { border: 0; border-top: 1px solid var(--rule); }
.md table { border-collapse: collapse; width: auto; max-width: 100%; font-size: 0.88rem; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--rule); padding: 0.4rem 0.65rem; text-align: left; vertical-align: top; }
.md th { background: var(--paper-2); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
.md td.num, .md th.num { text-align: right; font-variant-numeric: tabular-nums; }
.md img { max-width: 100%; border-radius: 6px; }

/* activity trail */
.activity {
  margin-top: 0.55rem;
  font-size: 0.78rem; color: var(--muted);
}
.activity summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 0.4rem; user-select: none; }
.activity summary::-webkit-details-marker { display: none; }
.activity summary::before { content: '▸'; font-size: 0.7rem; transition: transform 0.12s; }
.activity[open] summary::before { transform: rotate(90deg); }
.activity ol { list-style: none; margin: 0.4rem 0 0 0.2rem; padding-left: 0.6rem; border-left: 1px solid var(--rule); }
.activity li { padding: 0.15rem 0 0.15rem 0.6rem; display: flex; gap: 0.5rem; align-items: baseline; }
.activity li .dur { color: var(--faint); font-family: var(--mono); font-size: 0.7rem; margin-left: auto; }
.activity li.err { color: var(--danger); }
.activity li.narr { color: var(--ink-soft); font-style: italic; }

/* live status */
.status-line {
  display: inline-flex; align-items: center; gap: 0.55rem;
  color: var(--muted); font-size: 0.85rem; padding: 0.25rem 0;
}
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--rule-strong); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-trail { margin-top: 0.4rem; font-size: 0.78rem; color: var(--faint); display: flex; flex-direction: column; gap: 0.15rem; }
.status-trail .done::before { content: '✓ '; color: var(--sage); }
.status-trail .fail::before { content: '✕ '; color: var(--danger); }

/* artifacts */
.artifacts { display: flex; flex-direction: column; gap: 0.85rem; margin-top: 0.85rem; }
.card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper-2);
}
.card-title { font-family: var(--serif); font-weight: 600; font-size: 1rem; letter-spacing: -0.005em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-kind { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); font-weight: 600; margin-right: 0.5rem; }
.card-actions { display: flex; gap: 0.35rem; flex: none; }
.btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.76rem; font-weight: 500;
  padding: 0.32rem 0.6rem; border-radius: 6px;
  border: 1px solid var(--rule-strong); background: var(--paper); color: var(--ink-soft);
  text-decoration: none;
}
.btn:hover { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }
.btn svg { width: 12px; height: 12px; }
.card-body { padding: 0.9rem 1rem; }
.card-note { font-size: 0.76rem; color: var(--muted); padding: 0 1rem 0.75rem; }
.chart-wrap { position: relative; height: 320px; }
.chart-wrap.pie { height: 300px; }
.table-wrap { overflow: auto; max-height: 460px; }
.data-table { border-collapse: collapse; width: 100%; font-size: 0.86rem; }
.data-table th, .data-table td { border-bottom: 1px solid var(--rule); padding: 0.45rem 0.7rem; text-align: left; white-space: nowrap; }
.data-table th {
  position: sticky; top: 0; background: var(--paper-2);
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); font-weight: 600;
  cursor: pointer; user-select: none;
}
.data-table th:hover { color: var(--accent-ink); }
.data-table th.sorted-asc::after { content: ' ▲'; font-size: 0.6rem; }
.data-table th.sorted-desc::after { content: ' ▼'; font-size: 0.6rem; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover { background: var(--paper-2); }
.card-foot { font-size: 0.74rem; color: var(--muted); padding: 0.5rem 1rem; border-top: 1px solid var(--rule); }

.csv-card .card-body { display: flex; align-items: center; gap: 1rem; }
.file-icon {
  width: 42px; height: 50px; border-radius: 6px; flex: none;
  background: var(--sage-soft); color: var(--sage);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.08em;
  border: 1px solid #cfd8cf;
}
.file-meta { flex: 1; min-width: 0; }
.file-name { font-weight: 600; font-family: var(--mono); font-size: 0.86rem; word-break: break-all; }
.file-sub { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: #fff; }

.report-card .card-body { display: flex; align-items: center; gap: 1rem; }
.report-card .file-icon { background: var(--accent-soft); color: var(--accent-ink); border-color: #e6c6b6; }

/* composer */
.composer-wrap {
  border-top: 1px solid var(--rule);
  background: var(--paper);
  padding: 0.9rem 1.5rem 0.65rem;
}
.composer {
  max-width: 860px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 0.35rem;
  background: #fff;
  border: 1px solid var(--rule-strong);
  border-radius: 12px;
  padding: 0.5rem 0.5rem 0.5rem 0.5rem;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(201, 95, 48, 0.12); }
.composer-row { display: flex; align-items: flex-end; gap: 0.4rem; }
.attach {
  width: 36px; height: 36px; border-radius: 9px; flex: none;
  color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.12s, color 0.12s;
}
.attach:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent-ink); }
.attach svg { width: 17px; height: 17px; }

/* pending attachments in the composer */
.attachments { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0.2rem 0.25rem 0; }
.attachments[hidden] { display: none; }
.att-chip {
  display: inline-flex; align-items: center; gap: 0.45rem;
  max-width: 100%;
  border: 1px solid var(--rule); border-radius: 8px;
  background: var(--paper);
  padding: 0.3rem 0.45rem 0.3rem 0.35rem;
  font-size: 0.8rem; color: var(--ink-soft);
}
.att-chip.error { border-color: #c94a3a; color: #9b3a2e; }
.att-chip .thumb {
  width: 30px; height: 30px; border-radius: 5px; object-fit: cover; flex: none;
  background: var(--rule);
}
.att-chip .ext {
  width: 30px; height: 30px; border-radius: 5px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--sage); color: #fff;
  font-family: var(--mono, ui-monospace, monospace); font-size: 0.6rem; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase;
}
.att-chip .att-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-chip .att-size { color: var(--muted); font-size: 0.72rem; }
.att-chip .spinner { width: 12px; height: 12px; border-width: 2px; }
.att-chip .att-remove {
  width: 20px; height: 20px; border-radius: 50%; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.att-chip .att-remove:hover { background: var(--rule); color: var(--ink); }
.att-chip .att-remove svg { width: 10px; height: 10px; }

/* attachments shown on a sent message */
.msg-attachments { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.45rem; }
.msg-attachments a.att-chip { text-decoration: none; }
.msg-attachments a.att-chip:hover { border-color: var(--accent); }
.msg-attachments .att-image {
  display: block; max-width: 320px; max-height: 240px; border-radius: 8px;
  border: 1px solid var(--rule); background: var(--paper); object-fit: contain;
}

/* drag & drop */
.drop-overlay {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(250, 247, 242, 0.85);
  border: 2px dashed var(--accent);
  pointer-events: none;
}
.drop-overlay[hidden] { display: none; }
.drop-card {
  font-family: var(--serif); font-size: 1.3rem; color: var(--accent-ink);
  background: #fff; border: 1px solid var(--rule-strong); border-radius: 12px;
  padding: 1rem 1.6rem;
}
.composer textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent;
  font: inherit; color: var(--ink); line-height: 1.5;
  min-height: 24px; max-height: 200px; padding: 0.3rem 0;
}
.composer textarea::placeholder { color: var(--faint); }
.send {
  width: 36px; height: 36px; border-radius: 9px; flex: none;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.12s;
}
.send:hover:not(:disabled) { background: var(--accent-ink); }
.send svg { width: 16px; height: 16px; }
.footnote {
  max-width: 860px; margin: 0.55rem auto 0;
  font-size: 0.72rem; color: var(--muted); text-align: center; line-height: 1.45;
}
.footnote strong { color: var(--ink-soft); font-weight: 500; }

/* error toast */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 0.6rem 1rem; border-radius: 8px;
  font-size: 0.85rem; box-shadow: var(--shadow); z-index: 50;
}
.toast.error { background: var(--danger); }

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

.login-page {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  background:
    radial-gradient(1100px 600px at 10% -10%, #efe3d6 0, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #e2e8df 0, transparent 60%),
    var(--cream);
  padding: 1.5rem;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 2rem 2rem 1.5rem;
}
.login-brand { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.4rem; }
.login-brand img { width: 44px; height: 44px; border-radius: 11px; }
.login-brand .brand-wordmark { font-size: 1.35rem; }
.login-card h1 { font-family: var(--serif); font-weight: 600; font-size: 1.35rem; letter-spacing: -0.01em; margin-bottom: 0.3rem; }
.login-card .lede { color: var(--muted); font-size: 0.9rem; margin-bottom: 1.35rem; }
.field { margin-bottom: 0.95rem; }
.field label { display: block; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 600; margin-bottom: 0.35rem; }
.field input {
  width: 100%; padding: 0.65rem 0.8rem; font: inherit;
  border: 1px solid var(--rule-strong); border-radius: 8px; background: #fff; color: var(--ink);
  outline: 0; transition: border-color 0.12s, box-shadow 0.12s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(201, 95, 48, 0.12); }
.login-btn {
  width: 100%; padding: 0.7rem; border-radius: 8px; margin-top: 0.3rem;
  background: var(--accent); color: #fff; font-weight: 600;
  transition: background 0.12s;
}
.login-btn:hover:not(:disabled) { background: var(--accent-ink); }
.login-error { color: var(--danger); background: var(--danger-soft); border-radius: 7px; padding: 0.55rem 0.75rem; font-size: 0.85rem; margin-bottom: 0.9rem; }
.login-foot { font-size: 0.74rem; color: var(--muted); margin-top: 1.25rem; line-height: 1.5; }

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

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(85vw, 320px); z-index: 40;
    transform: translateX(-100%); transition: transform 0.18s ease;
    box-shadow: 0 0 0 100vmax rgba(26, 25, 22, 0); pointer-events: none;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 0 100vmax rgba(26, 25, 22, 0.35); pointer-events: auto; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--rule-strong); }
  .menu-btn svg { width: 16px; height: 16px; }
  .topbar { padding: 0.6rem 0.9rem; }
  .thread { padding: 1rem 0.9rem 1.5rem; }
  .composer-wrap { padding: 0.7rem 0.9rem 0.5rem; }
  .chart-wrap { height: 260px; }
}

@media print {
  .sidebar, .composer-wrap, .topbar-right, .card-actions { display: none !important; }
  .app { grid-template-columns: 1fr; height: auto; }
  .thread { overflow: visible; }
  body { background: #fff; }
}
