:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --border: #e2e2dc;
  --accent: #c2603a;
  --accent-text: #ffffff;
  --user-bg: #f1e6dc;
  --tool: #7a7a72;
  --error: #b3261e;
  --ok: #2e7d32;
  --warn: #b26a00;
  --code-bg: #efefea;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1a;
    --panel: #242422;
    --text: #ecebe6;
    --muted: #9a9991;
    --border: #3a3a36;
    --accent: #d97757;
    --user-bg: #3a2f28;
    --tool: #8f8e86;
    --error: #ff8a80;
    --ok: #81c784;
    --warn: #ffb74d;
    --code-bg: #2f2f2c;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

button, .button {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:disabled { opacity: .5; cursor: default; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.icon, .button.icon { padding: 6px 10px; }
.wide { width: 100%; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

/* sidebar */
#sidebar {
  width: 290px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
}
.side-head { display: flex; flex-direction: column; }
#session-list { display: flex; flex-direction: column; gap: 2px; }
.session-item { display: flex; align-items: flex-start; border-radius: 8px; }
.session-item:hover { background: var(--bg); }
.session-item.active { background: var(--user-bg); }
.session-item a { flex: 1; min-width: 0; padding: 8px 10px; color: inherit; text-decoration: none; }
.session-item .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Delete cross: only on your own dialogs, on hover; touch screens have no hover, so it stays visible there. */
.session-item .del { visibility: hidden; border: none; background: none; color: var(--muted); padding: 6px 10px; font-size: 16px; line-height: 1; }
.session-item:hover .del, .session-item .del:focus-visible { visibility: visible; }
.session-item .del:hover { color: var(--error); }
@media (hover: none) { .session-item .del { visibility: visible; } }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--border); }
.dot.working { background: var(--accent); animation: pulse 1.2s infinite; }
.dot.waiting { background: var(--warn); }
@keyframes pulse { 50% { opacity: .3; } }

/* main column */
main { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100%; }
#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
#menu { display: none; }
.title-block { flex: 1; min-width: 0; }
#title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#new-form { padding: 16px; display: flex; flex-direction: column; gap: 10px; max-width: 520px; }
#new-form label { display: flex; flex-direction: column; gap: 4px; }

#log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 860px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user-bg); padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; }
.msg.user .author { font-size: 12px; color: var(--muted); }
.msg.text { white-space: pre-wrap; }
.msg.text pre { white-space: pre; overflow-x: auto; background: var(--code-bg); padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.msg.text code { background: var(--code-bg); padding: 0 4px; border-radius: 4px; font-size: 13px; }
.msg.text pre code { background: none; padding: 0; }
.msg.text .h { display: block; font-size: 16px; margin-top: 4px; }
.msg.tools { color: var(--tool); font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.msg.tools summary { cursor: pointer; list-style: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg.tools summary::-webkit-details-marker { display: none; }
.msg.tools summary::before { content: '▸ '; }
.msg.tools[open] summary::before { content: '▾ '; }
.msg.tools .line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 1.2em; }
.msg.tool_error { color: var(--error); font: 12.5px/1.4 ui-monospace, monospace; white-space: pre-wrap; }
.msg.error { color: var(--error); border: 1px solid var(--error); border-radius: 8px; padding: 8px 12px; white-space: pre-wrap; }
.msg.result { color: var(--muted); font-size: 12px; border-top: 1px dashed var(--border); padding-top: 4px; }
.msg.result.fail { color: var(--error); }
.msg img { max-width: 100%; max-height: 480px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.msg figcaption { color: var(--muted); font-size: 13px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.thumbs img { max-height: 140px; max-width: 220px; }

.question { border: 1px solid var(--warn); border-radius: 12px; padding: 12px; background: var(--panel); display: flex; flex-direction: column; gap: 12px; }
.question.closed { border-color: var(--border); }
.question .q-head { font-size: 12px; color: var(--warn); text-transform: uppercase; letter-spacing: .04em; }
.question .q-text { font-weight: 600; }
.question .options { display: flex; flex-direction: column; gap: 6px; }
.question .option { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.question .option input { margin-top: 4px; }
.question .option .d { color: var(--muted); font-size: 13px; }
.question .option pre { font-size: 12px; background: var(--code-bg); padding: 6px; border-radius: 6px; overflow-x: auto; }
.question .chosen { color: var(--ok); }

#composer { border-top: 1px solid var(--border); background: var(--panel); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
#text { flex: 1; resize: vertical; min-height: 44px; max-height: 40vh; }
#attachments { display: flex; gap: 6px; flex-wrap: wrap; }
#attachments:not(:empty) { margin-bottom: 8px; }
.att { position: relative; }
.att img { height: 64px; border-radius: 6px; border: 1px solid var(--border); display: block; }
.att button { position: absolute; top: -6px; right: -6px; padding: 0 6px; border-radius: 50%; font-size: 12px; }
body.dragging #composer { outline: 2px dashed var(--accent); outline-offset: -4px; }

@media (max-width: 760px) {
  #sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 24px rgba(0,0,0,.3); }
  body.menu-open #sidebar { transform: none; }
  #menu { display: inline-block; }
  #topbar { padding: 8px 12px; gap: 6px; flex-wrap: wrap; }
  #log { padding: 12px; }
  #composer { padding-left: 12px; padding-right: 12px; }
  #send { padding: 6px 10px; }
}

/* login */
body.login-page { align-items: center; justify-content: center; padding: 16px; }
.login-box { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 340px; padding: 24px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; }
.login-error { color: var(--error); font-size: 14px; min-height: 1.4em; }
#logout { align-self: flex-start; padding: 2px 8px; font-size: 12px; }

