:root {
  --bg: #ffffff;
  --sidebar-bg: #f7f7f8;
  --sidebar-hover: #ececed;
  --text: #1a1a1a;
  --muted: #6f6f76;
  --border: #e5e5e5;
  --accent: #111111;
  --accent-text: #ffffff;
  --user-bg: #f4f4f4;
  --tool-bg: #f0f7ff;
  --tool-border: #c9def5;
  --danger: #b91c1c;
  --code-bg: #f4f4f4;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { overflow-x: clip; }
body {
  margin: 0; font-family: var(--font); color: var(--text); background: var(--bg);
  font-size: 15px; line-height: 1.55;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }

/* Gate (login / setup) */
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.gate-card { width: 100%; max-width: 380px; }
.gate-card h1 { font-size: 26px; margin: 0 0 6px; }
.gate-card p { color: var(--muted); margin: 0 0 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg);
}
.field textarea { resize: vertical; min-height: 70px; }
.primary {
  width: 100%; padding: 11px; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 8px 0 0; }
.note { color: var(--muted); font-size: 13px; margin-top: 14px; }

/* App shell */
.shell { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: 260px; flex: none; background: var(--sidebar-bg);
  display: flex; flex-direction: column; border-right: 1px solid var(--border);
}
.sidebar-top { padding: 12px; }
.new-chat {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); text-align: left; font-weight: 600;
}
.new-chat:hover { background: var(--sidebar-hover); }
.session-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.session-item {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 8px; background: transparent;
  text-align: left; font-size: 14px;
}
.session-item:hover { background: var(--sidebar-hover); }
.session-item.active { background: var(--sidebar-hover); font-weight: 600; }
.session-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .icon-btn { visibility: hidden; }
.session-item:hover .icon-btn, .session-item.active .icon-btn { visibility: visible; }
.icon-btn { border: 0; background: transparent; color: var(--muted); padding: 2px 5px; border-radius: 6px; font-size: 13px; }
.icon-btn:hover { background: var(--border); color: var(--text); }
.sidebar-foot { padding: 10px 12px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.sidebar-foot button { border: 0; background: transparent; text-align: left; padding: 4px 0; color: var(--muted); }
.sidebar-foot button:hover { color: var(--text); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; margin-right: 6px; vertical-align: middle; }
.status-dot.ok { background: #16a34a; }
.status-dot.bad { background: #dc2626; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.main-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 20px;
  border-bottom: 1px solid var(--border); font-weight: 600;
}
.main-head .model { font-weight: 400; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 6px 10px; }
.messages { flex: 1; overflow-y: auto; padding: 24px 0 12px; }
.thread { max-width: 760px; margin: 0 auto; padding: 0 20px; }
.empty { text-align: center; padding: 60px 20px 0; }
.empty h2 { font-size: 24px; margin: 0 0 8px; }
.empty p { color: var(--muted); margin: 0 0 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { border: 1px solid var(--border); background: var(--bg); border-radius: 999px; padding: 7px 13px; font-size: 13px; }
.chip:hover { background: var(--sidebar-bg); }

.msg { margin-bottom: 22px; }
.msg .role { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.msg.user .body { background: var(--user-bg); border-radius: var(--radius); padding: 10px 14px; white-space: pre-wrap; word-break: break-word; }
.msg.assistant .body { word-break: break-word; }
.msg .body p { margin: 0 0 10px; }
.msg .body p:last-child { margin-bottom: 0; }
.msg .body h1, .msg .body h2, .msg .body h3 { margin: 14px 0 8px; }
.msg .body ul, .msg .body ol { margin: 0 0 10px; padding-left: 22px; }
.msg .body code { font-family: var(--mono); font-size: 13px; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.msg .body pre { background: #111111; color: #f3f3f3; padding: 12px; border-radius: 8px; overflow-x: auto; }
.msg .body pre code { background: transparent; padding: 0; color: inherit; }
.msg .body blockquote { border-left: 3px solid var(--border); margin: 0 0 10px; padding-left: 12px; color: var(--muted); }
.msg .body table { border-collapse: collapse; margin-bottom: 10px; }
.msg .body th, .msg .body td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.msg .body a { color: var(--text); }
.msg-actions { margin-top: 6px; display: flex; gap: 4px; }
.think { margin: 0 0 10px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 13px; color: var(--muted); white-space: pre-wrap; }
.think summary { cursor: pointer; }
.tool-chip {
  display: inline-block; background: var(--tool-bg); border: 1px solid var(--tool-border);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; margin: 0 6px 8px 0;
}
.tool-chip.bad { background: #fef2f2; border-color: #fecaca; }
.waiting { color: var(--muted); font-size: 14px; }

/* Composer */
.composer-wrap { padding: 0 20px 18px; }
.composer { max-width: 760px; margin: 0 auto; }
.composer-box { border: 1px solid var(--border); border-radius: 16px; padding: 10px 12px; background: var(--bg); }
.composer-box textarea {
  width: 100%; border: 0; resize: none; outline: none; background: transparent;
  font-size: 15px; line-height: 1.5; max-height: 180px;
}
.composer-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.send {
  border: 0; border-radius: 50%; width: 34px; height: 34px;
  background: var(--accent); color: var(--accent-text); font-size: 16px; line-height: 1;
}
.send:disabled { opacity: 0.4; }
.stop-btn { border: 1px solid var(--border); background: var(--bg); border-radius: 999px; padding: 6px 14px; }
.composer-note { text-align: center; color: var(--muted); font-size: 12px; margin-top: 8px; }

/* Drawer (settings / files) */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%);
  background: var(--bg); border-left: 1px solid var(--border); padding: 20px;
  overflow-y: auto; z-index: 20;
}
.drawer h2 { margin: 0 0 4px; font-size: 19px; }
.drawer .sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.drawer .actions { display: flex; gap: 8px; margin-top: 16px; }
.drawer .actions .primary { width: auto; padding: 9px 18px; }
.drawer .ghost { border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 9px 14px; }
.file-row { display: flex; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.file-row span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 720px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 30; transform: translateX(-100%); transition: transform 0.2s ease; }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-block; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
