:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #5d6677;
  --line: #dde1e8;
  --accent: #2f5fb3;
  --accent-text: #ffffff;
  --mark: #fff1a8;
  --error: #b42318;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2027;
    --text: #e4e7ec;
    --muted: #98a1b2;
    --line: #2e343e;
    --accent: #6f9be8;
    --accent-text: #0d1117;
    --mark: #5c4d00;
    --error: #f97066;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* Elements with their own display rule (the preview panel, toolbars) must still honor the hidden attribute. */
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; color: inherit; }

.bar {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2;
}
.brand { font-weight: 700; letter-spacing: 0.02em; }
.spacer { flex: 1; }
.tab {
  border: 0; background: none; padding: 0.35rem 0.75rem; border-radius: 6px; cursor: pointer; color: var(--muted);
}
.tab.active { background: var(--bg); color: var(--text); font-weight: 600; }

main { max-width: 64rem; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 1.5rem; }
.narrow { max-width: 24rem; margin: 3rem auto; }
h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.5em; }

label { display: block; margin: 0.75rem 0; font-weight: 600; }
label input { display: block; width: 100%; margin-top: 0.25rem; font-weight: 400; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 0.45rem 0.6rem;
}
button {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 6px; padding: 0.45rem 1rem; cursor: pointer;
}
button.secondary { background: none; color: var(--text); border: 1px solid var(--line); }
button.link { background: none; color: var(--accent); padding: 0.25rem 0.5rem; }
button:disabled { opacity: 0.6; cursor: default; }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.toolbar input[name="query"] { flex: 1 1 14rem; min-width: 0; }

.results { list-style: none; padding: 0; margin: 0.5rem 0; }
.results li {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.6rem 0.8rem; margin-bottom: 0.5rem;
}
.results .path { font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: 0.9em; word-break: break-all; }
.results .server { color: var(--muted); font-size: 0.85em; margin-right: 0.5rem; }
.results .fragment { color: var(--muted); font-size: 0.9em; margin-top: 0.3rem; }
mark { background: var(--mark); color: inherit; padding: 0 0.1em; border-radius: 2px; }
a.file { color: var(--accent); text-decoration: none; cursor: pointer; }
a.file:hover { text-decoration: underline; }

.crumbs { margin: 0.75rem 0 0.25rem; font-family: ui-monospace, Menlo, monospace; font-size: 0.9em; word-break: break-all; }
.crumbs a { color: var(--accent); cursor: pointer; }
.listing { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.listing th, .listing td { text-align: left; padding: 0.4rem 0.7rem; border-bottom: 1px solid var(--line); }
.listing th { font-size: 0.85em; color: var(--muted); font-weight: 600; }
.listing .num { text-align: right; font-variant-numeric: tabular-nums; }
.listing tr:last-child td { border-bottom: 0; }

.transcript { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }
.msg { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0.75rem 1rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; max-width: 80%; background: var(--bg); }
.msg.error { color: var(--error); }
.tools { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.4rem; }
.chip { font-size: 0.8em; border: 1px solid var(--line); border-radius: 999px; padding: 0.05rem 0.55rem; color: var(--muted); }
.chip.failed { color: var(--error); }
.ask textarea { width: 100%; resize: vertical; }
.ask-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

.preview {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(40rem, 100vw);
  background: var(--surface); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; z-index: 3; box-shadow: -8px 0 24px rgb(0 0 0 / 0.12);
}
.preview header { display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1rem; border-bottom: 1px solid var(--line); }
.preview header span { flex: 1; font-family: ui-monospace, Menlo, monospace; font-size: 0.9em; word-break: break-all; }
.preview p { margin: 0.5rem 1rem; }
.preview pre { flex: 1; overflow: auto; margin: 0; padding: 0.75rem 1rem; font-size: 0.85em; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---- banners, cards, small text ---- */
.banner { margin: 0; padding: 0.5rem 1rem; text-align: center; border-bottom: 1px solid var(--line); }
.banner.ok { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.banner.error { color: var(--error); background: color-mix(in srgb, var(--error) 10%, var(--surface)); }
.small { font-size: 0.85em; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; }
h3 { font-size: 1rem; margin: 0 0 0.5rem; }
.card { margin: 1rem 0; }
.danger { color: var(--error); }
button.danger { background: var(--error); color: #fff; }
button.link.danger { background: none; color: var(--error); }
.confirm { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; padding: 0.5rem 0; }
label.check { display: inline-flex; align-items: center; gap: 0.3rem; margin: 0.4rem 0.8rem 0.4rem 0; font-weight: 400; }
label.check input { width: auto; margin: 0; }
label.inline { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; font-weight: 400; }
label.inline input { width: 4.5rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 0 1rem; }
.inline-form { display: inline-flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
code { font-family: ui-monospace, Menlo, monospace; font-size: 0.9em; }

/* ---- sessions ---- */
main:has(#ask-view:not([hidden])) { max-width: 80rem; }
.split { display: grid; grid-template-columns: 16rem 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 52rem) { .split { grid-template-columns: 1fr; } }
.sessions { position: sticky; top: 4rem; }
.sessions #new-session { width: 100%; margin-bottom: 0.75rem; }
.session-list { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow: auto; }
.session-list li { padding: 0.45rem 0.6rem; border-radius: 6px; display: flex; flex-direction: column; }
.session-list li a { cursor: pointer; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-list li.active { background: var(--surface); border: 1px solid var(--line); }
.conversation-head { display: flex; align-items: center; gap: 0.5rem; }
.conversation-head h2 { margin: 0 0 0.75rem; }
.conversation-head input.rename { font-size: 1.1rem; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .chips:empty, .msg .tools:empty { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.chip.attachment { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.2rem 0.6rem; }
.chip.attachment a { color: var(--accent); }
.chip.attachment.agent { border-color: var(--accent); }
.chip button.link { padding: 0 0.2rem; }
img.thumb { max-height: 3rem; max-width: 6rem; border-radius: 4px; }
.ask.dragging { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 8px; }
.ask-actions { align-items: center; }
.attach-button { border: 1px solid var(--line); border-radius: 6px; padding: 0.45rem 1rem; cursor: pointer; margin: 0; font-weight: 400; }
#pending-uploads:empty { display: none; }

/* ---- mail and admin ---- */
.suggestion p { margin: 0 0 0.5rem; }
.oauth { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0.25rem 1rem 0.25rem 0; }
details.link-account summary { cursor: pointer; font-weight: 600; }
details.link-account[open] summary { margin-bottom: 0.75rem; }
#mail-accounts, #admin-servers { margin-bottom: 0.5rem; }
.preview-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 1rem 0.5rem; }
.preview-actions:empty { display: none; }
.preview-actions a.chip { color: var(--accent); text-decoration: none; }
