/* ============ Theme tokens ============ */
:root {
  --bg: #EFE6D4;
  --bg-elev: #F7F1E3;
  --bg-panel: #FBF6EA;
  --ink: #0E2440;
  --ink-muted: #5B6A7E;
  --ink-faint: #8E9AA8;
  --rule: #D9CEB6;
  --rule-soft: #E6DCC6;
  --accent: #B55330;
  --accent-ink: #FBF6EA;
  --accent-soft: #EBDACD;
  --ok: #3E6B4A;
  --warn: #B07B1E;
  --danger: #A83A2A;
  --chip-bg: #E6DCC6;
  --shadow: 0 1px 0 rgba(14,36,64,0.04), 0 8px 24px -12px rgba(14,36,64,0.12);
  --focus: 0 0 0 3px rgba(181,83,48,0.25);
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4 { margin: 0; font-weight: 500; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; font-size: inherit; cursor: pointer; border: 0; background: transparent; color: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--ink); text-decoration: none; }

/* ============ App shell ============ */
.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  border-right: 1px solid var(--rule);
  background: var(--bg-elev);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center;
  padding: 4px 8px 18px;
  border-bottom: 1px solid var(--rule-soft);
  margin-bottom: 14px;
  text-decoration: none;
}
.brand-logo { width: 100%; max-width: 180px; height: auto; display: block; }

.nav-section { font-size: 10.5px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.14em; margin: 14px 8px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 5px;
  color: var(--ink-muted); font-size: 13.5px;
  cursor: pointer; user-select: none;
}
.nav-item:hover { background: var(--rule-soft); color: var(--ink); }
.nav-item.active { background: var(--ink); color: var(--bg-elev); }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; stroke-width: 1.6; }
.sidebar-footer {
  margin-top: auto;
  padding: 14px 8px 4px;
  border-top: 1px solid var(--rule-soft);
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 500; flex-shrink: 0;
}
.avatar-img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar-role { font-size: 11px; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Main ---- */
.main { overflow-y: auto; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.topbar-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elev); border: 1px solid var(--rule);
  border-radius: 5px; padding: 6px 10px;
  min-width: 280px; color: var(--ink-faint); font-size: 12.5px;
}
.kbd {
  font-family: 'JetBrains Mono', monospace; font-size: 10.5px;
  padding: 1px 5px; border: 1px solid var(--rule);
  border-radius: 3px; background: var(--bg); color: var(--ink-muted);
}
.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 5px; color: var(--ink-muted);
}
.icon-btn:hover { background: var(--bg-elev); color: var(--ink); }
.content { flex: 1; }
.page { padding: 28px 32px 48px; max-width: 1400px; width: 100%; margin: 0 auto; }
.page-header { margin-bottom: 24px; }
.page-title { font-family: 'Libre Caslon Text', serif; font-size: 30px; line-height: 1.1; letter-spacing: -0.015em; }
.page-sub { font-size: 13.5px; color: var(--ink-muted); margin-top: 6px; max-width: 640px; }

/* ============ Primitives ============ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: 5px;
  border: 1px solid var(--rule); background: var(--bg-elev); color: var(--ink);
  font-size: 13px; transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--bg-panel); border-color: var(--ink-faint); }
.btn.primary { background: var(--ink); color: var(--bg-elev); border-color: var(--ink); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(168,58,42,0.08); border-color: var(--danger); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.google {
  width: 100%; justify-content: center;
  padding: 11px 12px; font-size: 14px;
  background: var(--bg-elev); border-color: var(--rule);
  gap: 10px;
}
.btn.google:hover { background: var(--bg-panel); border-color: var(--ink-faint); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 99px;
  background: var(--chip-bg); font-size: 11.5px; color: var(--ink-muted);
}
.chip.dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.ok { color: var(--ok); background: rgba(62,107,74,0.12); }
.chip.warn { color: var(--warn); background: rgba(176,123,30,0.12); }
.chip.err { color: var(--danger); background: rgba(168,58,42,0.12); }
.chip.accent { color: var(--accent); background: rgba(181,83,48,0.12); }
.chip-spinner {
  width: 9px; height: 9px;
  border: 1.5px solid var(--rule);
  border-top-color: var(--ink-muted);
  border-radius: 50%;
  animation: chip-spin 0.85s linear infinite;
}
@keyframes chip-spin { to { transform: rotate(360deg); } }

/* Attio-link state on form inputs. When the input is linked to an existing
   Attio record, its background gets a subtle teal tint and a "✓ Linked to
   Attio: …" chip renders just below. Free-text inputs render plain. */
.input.attio-linked {
  background: rgba(31, 130, 89, 0.06);
  border-color: rgba(31, 130, 89, 0.35);
}
.attio-link-chip {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 5px;
  padding: 2px 4px 2px 9px;
  background: rgba(31, 130, 89, 0.10);
  color: #1F8259;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 500;
}
.attio-link-chip button {
  background: transparent; border: 0; color: #1F8259;
  cursor: pointer; padding: 0 6px; line-height: 1; font-size: 14px;
  border-radius: 99px;
}
.attio-link-chip button:hover { background: rgba(31, 130, 89, 0.18); }

.card { background: var(--bg-panel); border: 1px solid var(--rule); border-radius: 8px; box-shadow: var(--shadow); }
.card-hd {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--rule-soft);
}
.card-hd h3 { font-size: 13px; font-weight: 500; letter-spacing: 0.02em; text-transform: uppercase; color: var(--ink-muted); }
.card-body { padding: 16px 18px; }
.card-body.nopad { padding: 0; }

/* Collapsible card — used on /meeting.php for the pre-meeting brief once notes have arrived. */
.card.collapsible .card-hd { cursor: pointer; user-select: none; }
.card.collapsible .collapse-toggle {
  background: transparent; border: 0; padding: 4px;
  display: inline-flex; align-items: center;
  color: var(--ink-muted); cursor: pointer; border-radius: 4px;
}
.card.collapsible .collapse-toggle:hover { color: var(--ink); background: var(--rule-soft); }
.card.collapsible .chev { transition: transform 0.15s ease; }
.card.collapsible.collapsed .chev { transform: rotate(-90deg); }
.card.collapsible.collapsed .card-hd { border-bottom: 0; }
.card.collapsible.collapsed .collapsible-body { display: none; }

.input {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--rule); border-radius: 5px;
  background: var(--bg-elev); font-size: 13.5px;
  line-height: 1.4;
  box-sizing: border-box;
  /* min-height keeps <select> elements visually aligned with <input> boxes —
     browsers render single-line <select>s shorter than <input>s by default
     because they ignore CSS line-height for the selected-value box. The
     explicit floor pins everything to the same height regardless of element
     type. Multi-row selects (size>1) naturally exceed this and aren't
     affected. */
  min-height: 36px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input:focus { outline: 0; border-color: var(--accent); box-shadow: var(--focus); }
.input::placeholder { color: var(--ink-faint); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 11.5px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 500; }
.field-hint { font-size: 11.5px; color: var(--ink-faint); }

/* ============ Tables ============ */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-weight: 500; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-faint);
  padding: 10px 18px; border-bottom: 1px solid var(--rule); background: var(--bg-elev);
}
.table td { padding: 12px 18px; border-bottom: 1px solid var(--rule-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable:hover td { background: var(--bg-elev); cursor: pointer; }
.table td.num { font-variant-numeric: tabular-nums; text-align: right; }
.table td.mono { font-family: 'JetBrains Mono', monospace; font-size: 12px; }

/* ============ Login ============ */
.login {
  min-height: 100vh; display: grid; place-items: center;
  background: var(--bg); padding: 32px; position: relative; overflow: hidden;
}
.login-bg {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(181,83,48,0.1), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(14,36,64,0.08), transparent 45%);
  pointer-events: none;
}
.login-card {
  width: 100%; max-width: 420px;
  background: var(--bg-panel); border: 1px solid var(--rule);
  border-radius: 10px; padding: 36px 36px 28px;
  box-shadow: var(--shadow); position: relative; z-index: 1;
}
.login-brand { display: flex; align-items: center; justify-content: center; margin-bottom: 32px; }
.login-logo { width: 100%; max-width: 240px; height: auto; display: block; }
.login-title { font-family: 'Libre Caslon Text', serif; font-size: 26px; line-height: 1.15; margin-bottom: 6px; }
.login-sub { font-size: 13px; color: var(--ink-muted); margin-bottom: 28px; }
.login-divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: var(--ink-faint); font-size: 12px; }
.login-divider::before, .login-divider::after { content: ''; flex: 1; height: 1px; background: var(--rule-soft); }
.login-footer { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--rule-soft); font-size: 11.5px; color: var(--ink-faint); text-align: center; }
.login-error { background: rgba(168,58,42,0.1); border: 1px solid rgba(168,58,42,0.25); color: var(--danger); border-radius: 5px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; }

/* Google logo */
.g-logo { width: 18px; height: 18px; flex-shrink: 0; }

/* ============ Dashboard grids ============ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

.stat {
  background: var(--bg-panel); border: 1px solid var(--rule);
  border-radius: 8px; padding: 16px 18px;
}
.stat-label { font-size: 10.5px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.12em; font-weight: 500; }
.stat-value { font-family: 'Libre Caslon Text', serif; font-size: 30px; line-height: 1.1; margin-top: 6px; letter-spacing: -0.01em; }
.stat-delta { font-size: 11.5px; color: var(--ink-faint); margin-top: 4px; }
.stat-delta.up { color: var(--ok); }
.stat-delta.down { color: var(--danger); }

/* Activity feed */
.activity-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); margin-top: 7px; flex-shrink: 0;
}
.activity-dot.alert { background: var(--warn); }

/* ============ Settings ============ */
.settings-layout { display: grid; grid-template-columns: 200px 1fr; gap: 28px; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; }
/* Switch */
.switch {
  width: 30px; height: 17px; background: var(--rule);
  border-radius: 99px; position: relative; cursor: pointer; flex-shrink: 0;
}
.switch::after {
  content: ''; position: absolute;
  width: 13px; height: 13px; background: white;
  border-radius: 50%; top: 2px; left: 2px;
  transition: transform 0.15s;
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(13px); }

/* ============ Admin ============ */
.admin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.log-row { display: flex; gap: 14px; padding: 12px 18px; border-bottom: 1px solid var(--rule-soft); font-size: 12.5px; align-items: flex-start; }
.log-row:last-child { border-bottom: 0; }
.log-time { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--ink-faint); white-space: nowrap; padding-top: 2px; min-width: 140px; }
.log-body { flex: 1; min-width: 0; }
.log-action { font-weight: 500; color: var(--ink); }
.log-detail { color: var(--ink-muted); font-size: 12px; margin-top: 2px; }

/* ============ Spinner (used by intake + day-nav loading state) ============ */
.upload-spinner {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    border: 2.5px solid var(--rule);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: upload-spin 0.9s linear infinite;
}
@keyframes upload-spin { to { transform: rotate(360deg); } }

/* ============ Segmented toggle ============ */
.seg-toggle {
    display: inline-flex;
    border: 1px solid var(--rule);
    border-radius: 99px;
    background: var(--bg-elev);
    padding: 2px;
    gap: 2px;
}
.seg-toggle-item {
    padding: 4px 12px;
    border-radius: 99px;
    font-size: 11.5px;
    color: var(--ink-muted);
    text-decoration: none;
    line-height: 1.3;
    transition: background 0.12s, color 0.12s;
}
.seg-toggle-item:hover:not(.active) { color: var(--ink); }
.seg-toggle-item.active {
    background: var(--ink);
    color: var(--bg-elev);
}

/* ============ Day navigator ============ */
.day-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--rule-soft);
}
.day-nav-arrow {
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: 4px;
    color: var(--ink-muted);
    font-size: 18px;
    line-height: 1;
    text-decoration: none;
    user-select: none;
    transition: background 0.12s, color 0.12s;
}
.day-nav-arrow:hover { background: var(--bg-elev); color: var(--ink); }
.day-nav-arrow.disabled { color: var(--rule); pointer-events: none; }
.day-nav-label {
    flex: 1;
    text-align: center;
    font-size: 13px;
    color: var(--ink);
}
.day-nav-today {
    height: 26px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    border-radius: 4px;
    color: var(--ink-muted);
    font-size: 11.5px;
    text-decoration: none;
    margin-right: 4px;
    transition: background 0.12s, color 0.12s;
}
.day-nav-today:hover { background: var(--bg-elev); color: var(--ink); }

/* Loading overlay — keeps prior content visible but dimmed, centers an
   in-flight spinner on top. Used by the meeting list and the brief view. */
.loading-region { position: relative; min-height: 60px; }
.loading-region.loading > :not(.loading-spinner) {
    opacity: 0.4;
    pointer-events: none;
    transition: opacity 0.12s;
}
.loading-spinner {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    z-index: 1;
    pointer-events: none;
}
.loading-region.loading .loading-spinner { display: flex; }

/* Past meetings (end_time has passed) read as muted on the home meeting list. */
.log-row.past { opacity: 0.65; }
.log-row.past .log-action { color: var(--ink-muted); font-weight: 400; }

/* ============ Misc ============ */
.divider { height: 1px; background: var(--rule-soft); margin: 16px 0; }
.link { color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }
.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }
.tabular { font-variant-numeric: tabular-nums; }
.placeholder-section {
  border: 2px dashed var(--rule);
  border-radius: 8px; padding: 40px;
  text-align: center; color: var(--ink-faint);
  background: var(--bg-elev);
}
.placeholder-section strong { display: block; font-size: 15px; color: var(--ink-muted); margin-bottom: 6px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }

/* ============ Keys ============ */
.key-row { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--rule-soft); }
.key-row:last-child { border-bottom: 0; }
.key-logo { width: 32px; height: 32px; border-radius: 6px; background: var(--bg-elev); border: 1px solid var(--rule); display: grid; place-items: center; font-family: 'Libre Caslon Text', serif; font-size: 14px; flex-shrink: 0; }
.key-name { font-weight: 500; font-size: 13.5px; }
.key-masked { font-family: 'JetBrains Mono', monospace; font-size: 12.5px; letter-spacing: 0.06em; }

/* ============ Models ============ */
.model-card {
  background: var(--bg-panel);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
  transition: border-color 0.12s;
}
.model-card:hover { border-color: var(--ink-faint); }
.model-card.default { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.model-card-hd { display: flex; align-items: flex-start; gap: 12px; }
.model-icon { width: 34px; height: 34px; border-radius: 6px; display: grid; place-items: center; font-family: 'Libre Caslon Text', serif; font-size: 15px; flex-shrink: 0; background: var(--bg-elev); border: 1px solid var(--rule); }
.model-name { font-weight: 500; font-size: 14px; }
.model-vendor { font-size: 11.5px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.1em; }
.model-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: 12px; border-top: 1px solid var(--rule-soft); padding-top: 12px; }
.model-meta .lbl { color: var(--ink-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; }
.model-meta .val { font-variant-numeric: tabular-nums; }

/* ============ Prompts ============ */
.split { display: grid; grid-template-columns: 280px 1fr; gap: 0; height: calc(100vh - 200px); border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; background: var(--bg-panel); }
.prompt-list { border-right: 1px solid var(--rule); overflow-y: auto; min-height: 0; }
.prompt-list-hd { padding: 12px 16px; border-bottom: 1px solid var(--rule-soft); display: flex; align-items: center; gap: 8px; background: var(--bg-elev); }
.prompt-list-item { padding: 12px 16px; border-bottom: 1px solid var(--rule-soft); cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.prompt-list-item:hover { background: var(--bg-elev); }
.prompt-list-item.active { background: var(--bg-elev); border-left: 2px solid var(--accent); padding-left: 14px; }
.prompt-list-item .pl-name { font-size: 13.5px; font-weight: 500; }
.prompt-list-item .pl-meta { font-size: 11px; color: var(--ink-faint); }
.prompt-editor { display: flex; flex-direction: column; min-width: 0; min-height: 0; max-height: 100%; }
.prompt-hd { padding: 16px 20px; border-bottom: 1px solid var(--rule-soft); display: flex; align-items: center; gap: 12px; }
.prompt-title { font-family: 'Libre Caslon Text', serif; font-size: 20px; border: 0; background: transparent; width: 100%; padding: 2px 0; color: var(--ink); }
.prompt-title:focus { outline: 0; }
.prompt-body { flex: 1 1 0; display: grid; grid-template-columns: 1fr 280px; min-height: 0; overflow: hidden; }
.prompt-textarea { padding: 20px 24px; border: 0; background: transparent; resize: none; font-family: 'JetBrains Mono', monospace; font-size: 13px; line-height: 1.7; color: var(--ink); overflow-y: auto; min-height: 0; }
.prompt-textarea:focus { outline: 0; }
.version-panel { border-left: 1px solid var(--rule-soft); background: var(--bg-elev); overflow-y: auto; padding: 14px 0; min-height: 0; }
.version-panel-title { padding: 0 16px 10px; font-size: 10.5px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.14em; font-weight: 500; }
.version-item { padding: 10px 16px 10px 38px; border-left: 2px solid transparent; cursor: pointer; display: flex; flex-direction: column; gap: 2px; position: relative; }
.version-item::before { content: ''; position: absolute; left: 18px; top: 14px; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint); border: 2px solid var(--bg-elev); z-index: 1; }
.version-item::after { content: ''; position: absolute; left: 21px; top: 22px; bottom: -2px; width: 2px; background: var(--rule); }
.version-item:last-child::after { display: none; }
.version-item.active::before { background: var(--accent); }
.version-item.current::before { background: var(--ok); }
.version-item:hover { background: var(--bg-panel); }
.version-item.active { background: var(--bg-panel); border-left-color: var(--accent); }
.version-label { font-size: 12.5px; font-weight: 500; }
.version-meta { font-size: 11px; color: var(--ink-faint); }
.version-note { font-size: 11.5px; color: var(--ink-muted); font-style: italic; }

/* ============ Settings ============ */
.settings-layout { display: grid; grid-template-columns: 200px 1fr; gap: 28px; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; }
.settings-nav-item { padding: 8px 12px; border-radius: 5px; cursor: pointer; font-size: 13px; color: var(--ink-muted); text-decoration: none; display: block; }
.settings-nav-item:hover { background: var(--bg-elev); color: var(--ink); }
.settings-nav-item.active { background: var(--bg-elev); color: var(--ink); font-weight: 500; }

/* ============ Prompts diff modal ============ */
.diff-modal { position: fixed; inset: 0; background: rgba(14,36,64,0.5); display: grid; place-items: center; z-index: 100; padding: 40px; }
.diff-panel { width: 100%; max-width: 1100px; max-height: 85vh; background: var(--bg-panel); border-radius: 10px; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--rule); box-shadow: var(--shadow); }
.diff-hd { padding: 16px 22px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--rule-soft); }
.diff-body { flex: 1; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.diff-col { padding: 16px 20px; overflow-y: auto; font-family: 'JetBrains Mono', monospace; font-size: 12.5px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; min-height: 0; }
.diff-col.before { border-right: 1px solid var(--rule-soft); }
.diff-col .hd { font-family: 'IBM Plex Sans', sans-serif; font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-faint); margin-bottom: 10px; font-weight: 500; }
.diff-line { display: block; padding: 0 6px; border-radius: 2px; }
.diff-line.add { background: color-mix(in oklab, var(--ok) 14%, transparent); }
.diff-line.del { background: color-mix(in oklab, var(--danger) 14%, transparent); }

/* ============ Chat panel ============ */
.chat-toggle {
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: 5px;
    color: var(--ink-muted);
    background: transparent;
    border: 0;
    cursor: pointer;
}
.chat-toggle:hover { background: var(--bg-elev); color: var(--ink); }
.chat-toggle.open { background: var(--ink); color: var(--bg-elev); }
.chat-toggle.open:hover { background: var(--accent); color: var(--accent-ink); }

.chat-panel {
    position: fixed;
    top: 0; right: 0;
    width: 420px;
    max-width: 90vw;
    height: 100vh;
    background: var(--bg-panel);
    border-left: 1px solid var(--rule);
    box-shadow: -8px 0 24px -12px rgba(14,36,64,0.18);
    transform: translateX(100%);
    transition: transform 0.2s ease;
    display: flex;
    flex-direction: column;
    z-index: 50;
}
.chat-panel.open { transform: translateX(0); }

.chat-header {
    display: flex; align-items: center; gap: 6px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--rule);
    background: var(--bg-elev);
    flex-shrink: 0;
}
.chat-header .title {
    flex: 1;
    font-family: 'Libre Caslon Text', serif;
    font-size: 16px;
    line-height: 1.2;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-header .icon-btn { width: 28px; height: 28px; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
}

.chat-message { display: flex; flex-direction: column; gap: 4px; }
.chat-message .role-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--ink-faint);
    font-weight: 500;
}
.chat-message .body {
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--ink);
    word-wrap: break-word;
}
.chat-message.user .body {
    background: var(--bg-elev);
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--rule-soft);
    white-space: pre-wrap;
}
.chat-message.assistant .body { padding: 2px 0; line-height: 1.45; }

.chat-input-wrap {
    padding: 12px 16px 14px;
    border-top: 1px solid var(--rule);
    background: var(--bg-panel);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}
.chat-input {
    flex: 1;
    border: 1px solid var(--rule);
    background: var(--bg-elev);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--ink);
    resize: none;
    min-height: 38px;
    max-height: 140px;
    overflow-y: auto;
    line-height: 1.4;
}
.chat-input:focus { outline: 0; border-color: var(--accent); box-shadow: var(--focus); }
.chat-input::placeholder { color: var(--ink-faint); }
.chat-send {
    background: var(--ink);
    color: var(--bg-elev);
    border: 0;
    border-radius: 6px;
    padding: 0 14px;
    height: 38px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
}
.chat-send:hover { background: var(--accent); color: var(--accent-ink); }
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

.chat-empty {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    color: var(--ink-faint);
    padding: 24px;
}
.chat-empty .lead {
    font-family: 'Libre Caslon Text', serif;
    font-size: 19px;
    color: var(--ink);
    margin-bottom: 4px;
}
.chat-empty .hint {
    font-size: 12.5px;
    max-width: 300px;
    line-height: 1.55;
}

.chat-pending {
    display: inline-flex;
    align-items: center;
    color: var(--ink-faint);
    font-size: 13px;
    font-style: italic;
}
.chat-pending::after {
    content: '';
    display: inline-block;
    width: 1ch;
    text-align: left;
    animation: chat-dots 1.2s steps(4, end) infinite;
}
@keyframes chat-dots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
    100% { content: ''; }
}

.chat-error {
    padding: 10px 12px;
    background: color-mix(in oklab, var(--danger) 12%, transparent);
    border: 1px solid color-mix(in oklab, var(--danger) 30%, transparent);
    border-radius: 6px;
    font-size: 12.5px;
    color: var(--danger);
}

/* History sub-panel — overlays the messages region when toggled */
.chat-history {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-panel);
    display: none;
    flex-direction: column;
    z-index: 1;
}
.chat-history.open { display: flex; }
.chat-history-hd {
    padding: 12px 16px;
    border-bottom: 1px solid var(--rule);
    background: var(--bg-elev);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.chat-history-hd .title {
    flex: 1;
    font-family: 'Libre Caslon Text', serif;
    font-size: 16px;
    color: var(--ink);
}
.chat-history-list { flex: 1; overflow-y: auto; }
.chat-history-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--rule-soft);
    cursor: pointer;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    transition: opacity 250ms ease, background 100ms ease;
}
.chat-history-item-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.chat-history-item:hover { background: var(--bg-elev); }
.chat-history-item.active { background: var(--bg-elev); border-left: 2px solid var(--accent); padding-left: 14px; }
.chat-history-item.is-removing { opacity: 0; pointer-events: none; }
.chat-history-item.is-confirming-delete .chat-history-item-actions { opacity: 1; }
.chat-history-item.is-renaming { background: var(--bg-elev); cursor: default; }
.chat-history-item .title {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-history-item .meta {
    font-size: 11px;
    color: var(--ink-faint);
}

/* Per-row actions — pencil + archive buttons, hover-revealed on desktop,
   always visible on narrow viewports so a tap on mobile doesn't require
   first hovering. */
.chat-history-item-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 120ms ease;
}
.chat-history-item:hover .chat-history-item-actions,
.chat-history-item:focus-within .chat-history-item-actions {
    opacity: 1;
}
.chat-history-action {
    background: transparent;
    border: 0;
    padding: 5px;
    color: var(--ink-muted);
    cursor: pointer;
    border-radius: 4px;
    line-height: 0;
}
.chat-history-action:hover {
    background: var(--rule-soft);
    color: var(--ink);
}
.chat-history-action svg {
    width: 14px;
    height: 14px;
    display: block;
}

/* Inline-rename input replaces the title span while editing. */
.chat-history-rename-input {
    width: 100%;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--ink);
    padding: 2px 6px;
    margin: -2px -6px;  /* keep the row baseline aligned with non-editing rows */
    border: 1px solid var(--rule);
    border-radius: 4px;
    background: var(--bg-panel);
    box-sizing: border-box;
}
.chat-history-rename-input:focus {
    outline: 0;
    border-color: var(--accent);
    box-shadow: var(--focus);
}

/* Delete-confirm strip: replaces the rename+delete buttons inline while
   the user is confirming a single-row delete. */
.chat-history-confirm-label {
    font-size: 11.5px;
    color: var(--ink-muted);
    align-self: center;
    margin-right: 2px;
}
.chat-history-confirm {
    font-family: inherit;
    font-size: 11.5px;
    font-weight: 500;
    padding: 3px 8px;
    border: 1px solid var(--rule);
    border-radius: 4px;
    background: var(--bg-panel);
    cursor: pointer;
    line-height: 1.2;
}
.chat-history-confirm-yes {
    color: var(--danger);
    border-color: color-mix(in oklab, var(--danger) 35%, var(--rule));
}
.chat-history-confirm-yes:hover {
    background: color-mix(in oklab, var(--danger) 12%, var(--bg-panel));
}
.chat-history-confirm-no { color: var(--ink-muted); }
.chat-history-confirm-no:hover { background: var(--bg-elev); color: var(--ink); }

/* Hover tint on the trash icon — signals destructive vs the neutral
   rename icon next to it. */
.chat-history-action.chat-history-delete:hover {
    background: color-mix(in oklab, var(--danger) 14%, transparent);
    color: var(--danger);
}

/* Top-of-list "Delete all" bar — replaces the old archived-toggle slot. */
.chat-history-delete-all-bar {
    padding: 8px 16px 6px;
    border-bottom: 1px solid var(--rule-soft);
    display: flex;
    justify-content: flex-end;
}
.chat-history-delete-all-btn {
    background: transparent;
    border: 0;
    padding: 4px 8px;
    color: var(--ink-muted);
    font-family: inherit;
    font-size: 11.5px;
    cursor: pointer;
    border-radius: 4px;
}
.chat-history-delete-all-btn:hover {
    background: color-mix(in oklab, var(--danger) 14%, transparent);
    color: var(--danger);
}

/* Delete-all modal — overlays the history view only (parented to
   chat-history-overlay), so it shares the panel's stacking context and
   doesn't escape into the rest of the page. */
.chat-delete-modal {
    position: absolute;
    inset: 0;
    background: color-mix(in oklab, var(--ink) 35%, transparent);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.chat-delete-modal-box {
    background: var(--bg-panel);
    border: 1px solid var(--rule);
    border-radius: 8px;
    padding: 18px 20px 16px;
    max-width: 320px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.18);
}
.chat-delete-modal-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--ink);
    margin-bottom: 8px;
}
.chat-delete-modal-body {
    font-size: 12.5px;
    color: var(--ink-muted);
    line-height: 1.45;
    margin-bottom: 16px;
}
.chat-delete-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
.chat-delete-modal-cancel,
.chat-delete-modal-confirm {
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 5px;
    cursor: pointer;
    border: 1px solid var(--rule);
}
.chat-delete-modal-cancel { background: var(--bg-panel); color: var(--ink-muted); }
.chat-delete-modal-cancel:hover { background: var(--bg-elev); color: var(--ink); }
.chat-delete-modal-confirm {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}
.chat-delete-modal-confirm:hover { filter: brightness(0.92); }
.chat-delete-modal-confirm:disabled,
.chat-delete-modal-cancel:disabled { opacity: 0.55; cursor: default; }
.chat-delete-modal-error {
    margin-top: 10px;
    font-size: 12px;
    color: var(--danger);
}

/* Narrow viewports: surface action buttons by default rather than
   requiring hover (no hover on touch). */
@media (max-width: 480px) {
    .chat-history-item-actions { opacity: 1; }
}
.chat-history-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-faint);
    font-size: 13px;
    padding: 24px;
    text-align: center;
}

/* Markdown rendering inside assistant bubbles */
.chat-message.assistant p { margin: 0 0 0.3em; }
.chat-message.assistant p:last-child { margin-bottom: 0; }
.chat-message.assistant ul, .chat-message.assistant ol { margin: 0.1em 0 0.3em; padding-left: 1.25em; }
.chat-message.assistant li { margin-bottom: 0.15em; }
.chat-message.assistant strong { font-weight: 600; }
.chat-message.assistant code { background: rgba(0,0,0,0.06); padding: 0.05em 0.3em; border-radius: 3px; font-size: 0.9em; }
.chat-message.assistant pre { background: rgba(0,0,0,0.06); padding: 0.5em; border-radius: 4px; overflow-x: auto; }
.chat-message.assistant h1, .chat-message.assistant h2, .chat-message.assistant h3 { font-size: 1em; font-weight: 600; margin: 0.3em 0 0.15em; }

/* Inline tool-use indicators inside an assistant bubble. Active = pulsing
   magnifier while a tool is running; complete = subdued check that stays as
   a record of which tools were used. Sits above the markdown body so the
   per-delta re-render of body.innerHTML doesn't wipe them. */
.chat-tool-indicator {
    display: flex;
    align-items: center;
    gap: 0.4em;
    font-size: 0.82em;
    color: var(--ink-muted);
    font-style: italic;
    padding: 0.15em 0;
    line-height: 1.4;
}
.chat-tool-indicator-icon {
    display: inline-block;
    width: 1em;
    flex-shrink: 0;
    text-align: center;
}
.chat-tool-indicator.is-active {
    color: var(--accent);
}
.chat-tool-indicator.is-active .chat-tool-indicator-icon {
    animation: chat-tool-pulse 1.2s ease-in-out infinite;
}
.chat-tool-indicator.is-active .chat-tool-indicator-ellipsis {
    opacity: 0.6;
}
.chat-tool-indicator.is-complete {
    color: var(--ink-muted);
    opacity: 0.72;
    font-style: normal;
}
.chat-tool-indicator.is-complete .chat-tool-indicator-icon {
    color: var(--accent);
}
@keyframes chat-tool-pulse {
    0%,  100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

/* Send → Stop transformation. Same button element, danger palette + label
   swap while a turn is streaming. Class is toggled from chat.js. */
.chat-send.is-stop-mode {
    background: var(--danger);
    color: #fff;
}
.chat-send.is-stop-mode:hover {
    background: #8a2e21; /* darker shade of --danger */
    color: #fff;
}

/* Reload banner — shows above the messages list when a previously-started
   turn is still generating server-side after a page reload. Sits between
   the chat-header and chat-messages, outside the scroll container. */
.chat-reload-banner {
    display: flex;
    align-items: center;
    gap: 0.6em;
    margin: 10px 14px 0;
    padding: 8px 12px;
    background: var(--rule-soft);
    border: 1px solid var(--rule);
    border-radius: 6px;
    font-size: 12.5px;
    color: var(--ink);
    flex-shrink: 0;
}
.chat-reload-banner-icon {
    display: inline-block;
    color: var(--accent);
    font-size: 14px;
    line-height: 1;
    animation: chat-reload-spin 1.4s linear infinite;
}
.chat-reload-banner-label {
    flex: 1;
}
.chat-reload-banner-btn {
    background: var(--ink);
    color: var(--bg-elev);
    border: 0;
    border-radius: 5px;
    padding: 4px 10px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
}
.chat-reload-banner-btn:hover {
    background: var(--accent);
    color: var(--accent-ink);
}
.chat-reload-banner.is-ready {
    background: color-mix(in oklab, var(--accent) 12%, var(--rule-soft));
    border-color: color-mix(in oklab, var(--accent) 30%, var(--rule));
}
.chat-reload-banner.is-ready .chat-reload-banner-icon {
    animation: none;
    color: var(--accent);
}
@keyframes chat-reload-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* Source badge for deal listings (email-sourced deals; upload is default and unbadged) */
.deal-source-badge {
  display: inline-block;
  margin-left: 0.5em;
  padding: 0.1em 0.55em;
  border-radius: 999px;
  font-size: 0.75em;
  font-weight: 500;
  line-height: 1.4;
  vertical-align: middle;
  white-space: nowrap;
}
/* Per-tag pill colors so the recent list scans visually instead of reading.
   "via email" stays neutral cream. +deck stays neutral (same as deck-via-web).
   Non-deck tags each get a distinct subtle hue. */
.deal-tag-note    { background: rgba(63, 119, 181, 0.14); color: #3a6ea8;  border: 1px solid rgba(63, 119, 181, 0.30); }
.deal-tag-founder { background: rgba(46, 125,  77, 0.14); color: #2c6a4a;  border: 1px solid rgba(46, 125,  77, 0.30); }
.deal-tag-vc      { background: rgba(118, 80, 158, 0.14); color: #6a4a8c;  border: 1px solid rgba(118, 80, 158, 0.30); }
.deal-tag-exec    { background: rgba(176, 123, 30, 0.16); color: #8a5e10;  border: 1px solid rgba(176, 123, 30, 0.34); }
.deal-tag-deck    { background: var(--rule-soft);         color: var(--ink-muted); border: 1px solid var(--rule); }
.deal-source-email {
  background: var(--rule-soft);
  color: var(--ink-muted);
  border: 1px solid var(--rule);
}

/* Intelligence brief rendering — applies to all in-portal brief renders */
.brief-body h1 { font-family: 'Libre Caslon Text', serif; font-size: 22px; color: var(--ink); margin: 20px 0 10px; }
.brief-body h2 { font-family: 'Libre Caslon Text', serif; font-size: 17px; color: var(--accent); margin: 18px 0 10px; padding-bottom: 4px; border-bottom: 1px solid var(--rule-soft); }
.brief-body h3 { font-size: 14.5px; color: var(--ink); margin: 14px 0 6px; }
.brief-body p  { margin: 0 0 10px; line-height: 1.55; }
.brief-body ul, .brief-body ol { margin: 0 0 12px; padding-left: 22px; }
.brief-body li { margin-bottom: 5px; line-height: 1.5; }
.brief-body a  { color: var(--accent); text-decoration: underline; }
.brief-body strong { color: var(--ink); font-weight: 500; }
.brief-body em { color: var(--ink-muted); }
.brief-body hr { border: 0; border-top: 1px solid var(--rule-soft); margin: 18px 0; }
.brief-body > h1:first-child,
.brief-body > h2:first-child { margin-top: 0; }

/* Drag-and-drop wrapper around a native <input type="file">.
   Activated per-input by assets/js/upload-dropzone.js. Keeps the existing
   Choose-file picker visible — drop is additive, not a replacement. */
.dropzone {
    display: block;
    border: 2px dashed var(--rule);
    border-radius: 6px;
    padding: 16px 14px;
    background: rgba(0, 0, 0, 0.012);
    transition: border-color 0.15s, background 0.15s, border-style 0.15s;
    cursor: copy;
}
.dropzone:hover { border-color: var(--ink-muted); }
.dropzone.dropzone-hover {
    border-color: var(--accent);
    border-style: solid;
    background: color-mix(in oklab, var(--accent) 6%, transparent);
}
.dropzone-prompt {
    font-size: 12.5px;
    color: var(--ink-muted);
    margin-bottom: 8px;
}
.dropzone-prompt strong { color: var(--ink); font-weight: 500; }
.dropzone input[type="file"] {
    display: block;
    font-size: 13px;
    cursor: pointer;
}
.dropzone-status {
    margin-top: 8px;
    font-size: 11.5px;
    color: var(--ink-muted);
    transition: opacity 0.35s ease;
    min-height: 1.1em;
}
.dropzone-status.ok     { color: var(--ok); }
.dropzone-status.warn   { color: var(--warn); }
.dropzone-status.reject { color: var(--danger); }

/* === Search palette (cmdk-style) === */
.search-palette {
    position: relative;
    max-width: 720px;
    margin: 0 auto;
}
.search-palette-input-wrap {
    display: flex;
    align-items: center;
    gap: 0.6em;
    background: var(--bg-elev);
    border: 1px solid var(--rule);
    border-radius: 14px;
    padding: 0.7em 1em;
    box-shadow: 0 4px 24px rgba(14, 36, 64, 0.06);
}
.search-palette-icon {
    width: 1.1em; height: 1.1em;
    color: var(--ink-muted);
    flex-shrink: 0;
}
.search-palette-input {
    flex: 1;
    border: 0;
    outline: 0;
    background: transparent;
    font-size: 1.05em;
    color: var(--ink);
    font-family: inherit;
}
.search-palette-input::placeholder { color: var(--ink-muted); }
.search-palette-shortcut {
    font-size: 0.75em;
    background: var(--rule-soft);
    color: var(--ink-muted);
    padding: 0.15em 0.45em;
    border-radius: 4px;
    font-family: inherit;
    font-weight: 500;
}
.search-palette-dropdown {
    position: absolute;
    top: calc(100% + 0.5em);
    left: 0; right: 0;
    background: var(--bg-elev);
    border: 1px solid var(--rule);
    border-radius: 14px;
    box-shadow: 0 12px 48px rgba(14, 36, 64, 0.12);
    max-height: 60vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 50;
}
.search-palette-results {
    flex: 1;
    overflow-y: auto;
    padding: 0.4em 0;
}
.search-palette-section-header {
    display: flex;
    justify-content: space-between;
    padding: 0.7em 1.2em 0.4em;
    font-size: 0.7em;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--ink-muted);
    text-transform: uppercase;
}
.search-palette-section-subtitle { font-weight: 400; }
.search-palette-row {
    display: flex;
    align-items: center;
    gap: 0.9em;
    padding: 0.65em 1.2em;
    cursor: pointer;
    user-select: none;
    transition: background 80ms ease;
}
.search-palette-row.is-selected,
.search-palette-row:hover {
    background: var(--rule-soft);
}
.search-palette-avatar {
    width: 2.2em; height: 2.2em;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8em;
    font-weight: 600;
    color: #FFF;
    flex-shrink: 0;
}
.search-palette-avatar-company { background: var(--ink); }
.search-palette-avatar-person  { background: var(--accent); }
.search-palette-row-text { flex: 1; min-width: 0; }
.search-palette-row-name {
    display: flex; align-items: center; gap: 0.6em;
    font-weight: 600;
    color: var(--ink);
}
.search-palette-row-subtitle {
    font-size: 0.85em;
    color: var(--ink-muted);
    margin-top: 0.1em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.search-palette-row-type {
    font-size: 0.7em;
    color: var(--ink-muted);
    letter-spacing: 0.08em;
    font-weight: 500;
    flex-shrink: 0;
}
.search-palette-badge {
    font-size: 0.65em;
    padding: 0.1em 0.5em;
    border-radius: 999px;
    font-weight: 600;
    letter-spacing: 0.05em;
}
.search-palette-badge-portfolio {
    background: rgba(89, 143, 89, 0.15);
    color: #3D7A3D;
    border: 1px solid rgba(89, 143, 89, 0.25);
}
.search-palette-empty {
    padding: 1.5em 1.2em;
    color: var(--ink-muted);
    text-align: center;
}
.search-palette-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5em 1.2em;
    border-top: 1px solid var(--rule);
    background: var(--bg-panel);
    font-size: 0.75em;
    color: var(--ink-muted);
}
.search-palette-footer kbd {
    background: var(--bg-elev);
    border: 1px solid var(--rule);
    border-radius: 3px;
    padding: 0.05em 0.35em;
    font-size: 0.85em;
    font-family: inherit;
}
.search-palette-hints kbd { margin-right: 0.2em; }
.search-palette-sync { display: inline-flex; align-items: center; gap: 0.4em; }
.search-palette-sync-dot {
    width: 6px; height: 6px;
    background: var(--accent);
    border-radius: 50%;
    display: inline-block;
}

/* === Entity detail card overlay === */
.entity-card-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(14, 36, 64, 0.32);
    backdrop-filter: blur(2px);
    z-index: 100;
}
.entity-card {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 580px);
    max-height: 88vh;
    overflow-y: auto;
    background: var(--bg-elev);
    border: 1px solid var(--rule);
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(14, 36, 64, 0.25);
    z-index: 101;
    padding: 1.6em 1.6em 1.2em;
}
.entity-card-header {
    display: flex;
    align-items: flex-start;
    gap: 0.9em;
    margin-bottom: 1.3em;
}
.entity-card-avatar {
    width: 2.4em; height: 2.4em;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.9em;
    font-weight: 600;
    color: #FFF;
    flex-shrink: 0;
}
.entity-card-avatar-company { background: var(--ink); }
.entity-card-avatar-person  { background: var(--accent); }
.entity-card-header-text { flex: 1; min-width: 0; }
.entity-card-name-row {
    display: flex; align-items: center; gap: 0.7em;
    margin-bottom: 0.15em;
}
.entity-card-name {
    font-size: 1.35em;
    font-weight: 600;
    color: var(--ink);
}
.entity-card-badge {
    font-size: 0.6em;
    padding: 0.15em 0.55em;
    border-radius: 999px;
    font-weight: 600;
    letter-spacing: 0.06em;
    background: rgba(89, 143, 89, 0.15);
    color: #3D7A3D;
    border: 1px solid rgba(89, 143, 89, 0.25);
}
.entity-card-subtitle {
    font-size: 0.95em;
    color: var(--ink-muted);
}
.entity-card-close {
    background: transparent;
    border: 0;
    cursor: pointer;
    padding: 0.3em;
    color: var(--ink-muted);
    border-radius: 6px;
    margin-left: auto;
}
.entity-card-close:hover { background: var(--rule-soft); }
.entity-card-close svg { width: 1em; height: 1em; }
.entity-card-section {
    padding: 1em 0;
    border-top: 1px solid var(--rule);
}
.entity-card-section:first-of-type {
    padding-top: 0;
    border-top: 0;
}
.entity-card-section-label {
    font-size: 0.72em;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--ink-muted);
    text-transform: uppercase;
    margin-bottom: 0.6em;
}
.entity-card-section-label-row {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 0.6em;
}
.entity-card-section-subtitle {
    font-size: 0.75em;
    color: var(--ink-muted);
}
.entity-card-about {
    font-style: italic;
    color: var(--ink);
    font-size: 0.95em;
    line-height: 1.5;
}
.entity-card-key-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.9em 1.5em;
}
.entity-card-detail-label {
    font-size: 0.7em;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--ink-muted);
    text-transform: uppercase;
    margin-bottom: 0.1em;
}
.entity-card-detail-value {
    color: var(--ink);
    font-size: 0.95em;
}
.entity-card-detail-empty {
    color: var(--ink-muted);
    font-style: italic;
}
.entity-card-activity-placeholder-text {
    color: var(--ink-muted);
    font-style: italic;
    font-size: 0.9em;
}
.entity-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5em;
    padding-top: 1em;
    border-top: 1px solid var(--rule);
    margin-top: 0.5em;
}
.entity-card-footer-left {
    display: flex;
    gap: 0.5em;
}
.entity-card-button {
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
    padding: 0.5em 0.9em;
    border-radius: 8px;
    border: 1px solid var(--rule);
    background: var(--bg-panel);
    color: var(--ink);
    font-size: 0.88em;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
}
.entity-card-button:disabled,
.entity-card-button[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
}
.entity-card-button:not(:disabled):not([aria-disabled="true"]):hover {
    background: var(--rule-soft);
}
.entity-card-button svg { width: 0.95em; height: 0.95em; }
.entity-card-button-primary {
    background: var(--ink);
    color: #FFF;
    border-color: var(--ink);
}
.entity-card-button-primary:hover { background: #1B375B; }

/* === Entity card — Recent Activity rows === */
.entity-card-activity-status {
    font-size: 0.75em;
    color: var(--ink-muted);
}
.entity-card-activity-list {
    display: flex;
    flex-direction: column;
    gap: 0.5em;
}
.entity-card-activity-item {
    display: flex;
    align-items: flex-start;
    gap: 0.6em;
    padding: 0.4em 0;
    font-size: 0.9em;
}
.entity-card-activity-icon {
    color: var(--ink-muted);
    margin-top: 0.15em;
    flex-shrink: 0;
}
.entity-card-activity-icon svg { width: 0.95em; height: 0.95em; }
.entity-card-activity-content {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: 0.4em;
    flex-wrap: wrap;
    color: var(--ink);
}
.entity-card-activity-type {
    font-size: 0.7em;
    letter-spacing: 0.07em;
    font-weight: 600;
    color: var(--ink-muted);
    background: var(--rule-soft);
    padding: 0.05em 0.4em;
    border-radius: 4px;
}
.entity-card-activity-actor {
    font-weight: 500;
}
.entity-card-activity-preview {
    color: var(--ink);
    word-break: break-word;
}
.entity-card-activity-time {
    color: var(--ink-muted);
    font-size: 0.8em;
    flex-shrink: 0;
    margin-left: auto;
}
.entity-card-activity-empty {
    padding: 0.6em 0;
    color: var(--ink-muted);
    font-style: italic;
    font-size: 0.9em;
}

/* Honor the `hidden` attribute against the explicit `display: flex` / `display: block`
   set on these overlays above. Without these rules the user-agent
   [hidden] { display: none } gets out-specificity'd and the elements stay visible. */
.search-palette-dropdown[hidden] { display: none; }
.entity-card[hidden]             { display: none; }
.entity-card-backdrop[hidden]    { display: none; }

/* ============================================================
   Extended markdown styling for chat assistant messages.
   marked + DOMPurify support tables / blockquotes / hr / task
   lists / heading levels — but the existing rules only styled
   p, ul, ol, li, strong, code, pre, h1-h3 (see :728-735). Fill
   in the rest so the model's richer output renders cleanly.
   ============================================================ */
.chat-message.assistant table {
    border-collapse: collapse;
    margin: 0.5em 0;
    font-size: 0.9em;
    width: 100%;
}
.chat-message.assistant th,
.chat-message.assistant td {
    border: 1px solid var(--rule);
    padding: 0.3em 0.5em;
    text-align: left;
    vertical-align: top;
}
.chat-message.assistant th {
    background: var(--rule-soft);
    font-weight: 600;
}
.chat-message.assistant blockquote {
    margin: 0.5em 0;
    padding: 0.1em 0 0.1em 0.8em;
    border-left: 3px solid var(--rule);
    color: var(--ink-muted);
    font-style: italic;
}
.chat-message.assistant hr {
    border: 0;
    border-top: 1px solid var(--rule);
    margin: 0.8em 0;
}
/* GFM task lists render as <ul class="contains-task-list"> with
   <li class="task-list-item"><input type="checkbox">…. */
.chat-message.assistant ul.contains-task-list {
    list-style: none;
    padding-left: 0.5em;
}
.chat-message.assistant li.task-list-item { list-style: none; }
.chat-message.assistant li.task-list-item input[type="checkbox"] {
    margin-right: 0.4em;
    vertical-align: middle;
}
.chat-message.assistant h4,
.chat-message.assistant h5,
.chat-message.assistant h6 {
    font-size: 1em;
    font-weight: 600;
    margin: 0.5em 0 0.25em;
    color: var(--ink);
}
.chat-message.assistant a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}
.chat-message.assistant a:hover { text-decoration-thickness: 2px; }

/* ============================================================
   Narrow-viewport adjustments (audit identified zero @media
   rules in this stylesheet). 480px is the tablet/phone break.
   Selectors are the *actual* class names used by chat.js +
   layout.php + search-palette + entity-card, not the prompt's
   sketches. font-size: 16px on the textarea prevents iOS
   Safari from auto-zooming when it gains focus.
   ============================================================ */
@media (max-width: 480px) {
    /* Chat panel: full-screen so the textarea + Send button get
       room. Existing rule is width:420px;max-width:90vw — the
       90vw fallback works but leaves a ~10vw gutter that wastes
       space at phone widths. */
    .chat-panel {
        width: 100vw;
        max-width: 100vw;
        border-left: 0;
    }
    .chat-messages       { padding: 12px 14px; }
    .chat-input-wrap     { padding: 10px 12px 12px; }
    .chat-input          { font-size: 16px; min-height: 44px; }
    .chat-send           { padding: 0 18px; height: 44px; font-size: 14px; }

    /* Topbar chat-open icon: existing 32×32px sits below the iOS
       44px tap-target guideline. Bump on narrow viewports only. */
    .chat-toggle {
        width: 44px;
        height: 44px;
    }

    /* Entity-card overlay: existing rule is width:min(92vw,580px)
       which still leaves a small gutter on phones; full-screen is
       easier to interact with. */
    .entity-card {
        width: 100vw;
        max-width: 100vw;
        max-height: 100vh;
        height: 100vh;
        top: 0;
        left: 0;
        transform: none;
        border-radius: 0;
        padding: 1.1em;
    }
    /* Key-details grid stacks to one column on phones. */
    .entity-card-key-details { grid-template-columns: 1fr; }

    /* Search palette + its dropdown: existing max-width:720px is
       already responsive, but explicitly cap dropdown height so
       it doesn't push the input off-screen on small viewports. */
    .search-palette          { max-width: 100vw; }
    .search-palette-dropdown { max-height: 70vh; }

    /* History panel rename input — already has its own responsive
       rule via .chat-history-item flex layout (Prompt 6), no
       override needed here. */
}

/* ============================================================ */
/* Docs (/docs.php) — rendered markdown + Quickstart/Manual toggle */
/* ============================================================ */
.docs-toggle {
  display: inline-flex;
  gap: 0;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 20px;
  background: var(--bg-elev);
}
.docs-toggle-item {
  padding: 7px 14px;
  font-size: 13px;
  color: var(--ink-muted);
  border-right: 1px solid var(--rule);
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}
.docs-toggle-item:last-child { border-right: none; }
.docs-toggle-item:hover      { background: var(--rule-soft); color: var(--ink); }
.docs-toggle-item.active     { background: var(--ink); color: var(--bg-elev); }

.docs-body {
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink);
}
.docs-body h1,
.docs-body h2,
.docs-body h3,
.docs-body h4 {
  font-family: 'Libre Caslon Text', serif;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 1.6em 0 0.55em;
  line-height: 1.2;
}
.docs-body h1 { font-size: 28px; margin-top: 0.4em; }
.docs-body h2 { font-size: 22px; padding-bottom: 6px; border-bottom: 1px solid var(--rule-soft); }
.docs-body h3 { font-size: 17px; }
.docs-body h4 { font-size: 14.5px; color: var(--ink-muted); }
.docs-body p,
.docs-body ul,
.docs-body ol { margin: 0.6em 0 0.9em; }
.docs-body ul, .docs-body ol { padding-left: 1.4em; }
.docs-body li { margin: 0.22em 0; }
.docs-body a  { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.docs-body a:hover { text-decoration: none; }
.docs-body strong { font-weight: 500; color: var(--ink); }
.docs-body em { font-style: italic; color: var(--ink-muted); }
.docs-body code {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: var(--rule-soft);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--ink);
}
.docs-body pre {
  background: var(--bg-panel);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.55;
  margin: 0.9em 0 1.1em;
}
.docs-body pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}
.docs-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 0.9em 0;
  padding: 4px 0 4px 14px;
  color: var(--ink-muted);
  background: rgba(181, 83, 48, 0.04);
}
.docs-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.9em 0 1.1em;
  font-size: 13px;
}
.docs-body th,
.docs-body td {
  text-align: left;
  vertical-align: top;
  padding: 8px 10px;
  border-bottom: 1px solid var(--rule-soft);
}
.docs-body th {
  font-weight: 500;
  color: var(--ink);
  background: var(--bg-elev);
  border-bottom-color: var(--rule);
}
.docs-body hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 1.6em 0;
}
.docs-error { color: var(--danger); }

/* Print stylesheet — strips nav/sidebar, formats for paper.
   Triggered by Print/Save-as-PDF button on /docs.php (window.print). */
@media print {
  @page { margin: 0.6in 0.7in; }

  body {
    background: #fff !important;
    color: #000 !important;
    font-size: 10.5pt;
    line-height: 1.45;
  }
  .sidebar,
  .topbar,
  .docs-no-print,
  .chat-panel,
  .chat-toggle      { display: none !important; }

  .app              { display: block !important; }
  .main             { overflow: visible !important; display: block !important; }
  .content          { padding: 0 !important; }
  .page             { padding: 0 !important; max-width: 100% !important; margin: 0 !important; }

  .docs-body            { font-size: 10.5pt; color: #000; }
  .docs-body a          { color: #000; text-decoration: none; }
  .docs-body h1,
  .docs-body h2,
  .docs-body h3,
  .docs-body h4         { color: #000; page-break-after: avoid; }
  .docs-body h2         { page-break-before: auto; margin-top: 1.4em; }
  .docs-body pre,
  .docs-body table,
  .docs-body blockquote { page-break-inside: avoid; }
  .docs-body table th   { background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .docs-body code,
  .docs-body pre        { background: #f5f5f5 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
