:root {
  --ink: #393e42;
  --red: #aa1f24;
  --panel: #f4f4f5;
  --line: #dfe2e6;
  --muted: #6b7178;
  --radius: 3px;
  --green: #2e9c5a;
  --amber: #d8973a;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
}

button { font-family: inherit; }

/* ---- buttons ---- */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  line-height: 1.2;
}
.btn:hover { background: var(--panel); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #8f1a1e; }
.btn-primary:disabled { background: var(--red); }
.btn-small { padding: 4px 9px; font-size: 12px; }
.btn-icon { padding: 4px 9px; font-size: 15px; line-height: 1; }

.error { color: var(--red); }

/* ---- login ---- */
.login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel);
}
.login-card {
  display: flex; flex-direction: column; gap: 10px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px 32px; width: 320px;
}
.login-card h1 { margin: 0 0 8px; font-size: 18px; }
.login-card label { font-size: 12px; color: var(--muted); }
.login-card input {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; font-size: 14px;
}

/* ---- app shell ---- */
.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; border-bottom: 1px solid var(--line);
  background: #fff;
}
.brand { font-weight: 600; font-size: 15px; white-space: nowrap; }
.model-select {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 5px 8px; font-size: 13px; max-width: 260px;
}
.staging-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #b9bfc5; display: inline-block; }
.dot.ready { background: var(--green); }
.dot.starting { background: var(--amber); }
.dot.error { background: var(--red); }
.dot.stopped { background: #b9bfc5; }
.spacer { flex: 1; }

.layout { flex: 1; display: flex; min-height: 0; }

/* ---- left column ---- */
.left {
  width: var(--left-width, 420px); flex: 0 0 var(--left-width, 420px);
  display: flex; flex-direction: column; min-height: 0;
  border-right: 1px solid var(--line);
}

/* ---- splitter ---- */
.splitter {
  flex: 0 0 6px; margin-left: -3px; margin-right: -3px; z-index: 5;
  cursor: col-resize; background: transparent; transition: background .15s; touch-action: none;
}
.splitter:hover, .splitter.dragging, .splitter:focus-visible { background: var(--red); outline: none; }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing .preview-iframe { pointer-events: none; }
.conversations { border-bottom: 1px solid var(--line); background: var(--panel); }
.conversations-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.conv-toggle {
  border: none; background: transparent; cursor: pointer;
  font-weight: 600; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; flex: 1; text-align: left;
}
.conv-list { list-style: none; margin: 0; padding: 0 6px 6px; max-height: 200px; overflow: auto; }
.conversations.collapsed .conv-list { display: none; }
.conv-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-radius: var(--radius); cursor: pointer; font-size: 13px;
}
.conv-item:hover { background: #fff; }
.conv-item.active { background: #fff; border: 1px solid var(--line); }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-del { visibility: hidden; border: none; background: transparent; cursor: pointer; color: var(--muted); }
.conv-item:hover .conv-del { visibility: visible; }
.conv-del:hover { color: var(--red); }

.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.transcript { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }

/* ---- bubbles ---- */
.bubble { display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
.bubble.user { align-items: flex-end; }
.bubble-body {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 11px; background: #fff; max-width: 90%;
}
.bubble.user .bubble-body { background: var(--panel); }
.bubble.assistant.streaming .bubble-body { border-color: #cfd4d9; }
.bubble-text p { margin: 0 0 8px; }
.bubble-text p:last-child { margin-bottom: 0; }
.bubble-text ul { margin: 4px 0; padding-left: 20px; }
.bubble-text code {
  background: var(--panel); border: 1px solid var(--line); border-radius: 2px;
  padding: 0 3px; font-size: 12px;
}
.bubble-text a { color: var(--red); }
.bubble-text.error { color: var(--red); }
.time-note { font-size: 11px; color: var(--muted); }

.attach-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.thinking { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.thinking summary { cursor: pointer; padding: 5px 9px; font-size: 12px; color: var(--muted); }
.thinking-body { padding: 6px 9px; font-size: 12px; white-space: pre-wrap; color: var(--muted); border-top: 1px solid var(--line); }

/* ---- tool rows ---- */
.tool-row {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); font-size: 12px;
}
.tool-head { display: flex; align-items: center; gap: 8px; padding: 5px 9px; cursor: pointer; }
.tool-glyph { width: 14px; text-align: center; }
.tool-name { font-weight: 600; }
.tool-summary { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tool-row.spin .tool-glyph { animation: spin 1.1s linear infinite; }
.tool-row.error .tool-name { color: var(--red); }
.tool-result { display: none; padding: 6px 9px; border-top: 1px solid var(--line); }
.tool-row.open .tool-result { display: block; }
.tool-result pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 11px; max-height: 360px; overflow: auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- composer ---- */
.composer { border-top: 1px solid var(--line); padding: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:not(:empty) { margin-bottom: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 3px 6px; font-size: 12px;
}
.chip button { border: none; background: transparent; cursor: pointer; color: var(--muted); }
.chip button:hover { color: var(--red); }
.composer-row { display: flex; align-items: flex-end; gap: 8px; min-width: 0; }
.composer-input {
  flex: 1 1 0; min-width: 0; resize: none; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; font-size: 14px; font-family: inherit; max-height: 200px; line-height: 1.4;
}
.btn-send { flex: none; min-width: 64px; }
.composer-hint { margin-top: 6px; font-size: 11px; color: var(--muted); }

/* drop target: the whole chat column */
.left { position: relative; }
.drop-overlay {
  display: none; position: absolute; inset: 8px; z-index: 6; align-items: center; justify-content: center;
  border: 2px dashed var(--red); border-radius: var(--radius); background: rgba(255,255,255,.92);
  color: var(--red); font-size: 16px; font-weight: 600; pointer-events: none;
}
.left.dropping .drop-overlay { display: flex; }
.btn-send.stop { background: var(--red); border-color: var(--red); color: #fff; }

/* ---- preview ---- */
.preview { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
.urlbar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fff; }
.path-input { flex: 1; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; font-size: 13px; }
.width-toggle { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.wbtn { border: none; background: #fff; padding: 5px 10px; font-size: 12px; cursor: pointer; border-left: 1px solid var(--line); }
.wbtn:first-child { border-left: none; }
.wbtn.active { background: var(--ink); color: #fff; }
.preview-stage { flex: 1; overflow: auto; display: flex; justify-content: center; align-items: stretch; padding: 0; }
.preview-stage[data-w="tablet"], .preview-stage[data-w="mobile"] { padding: 16px; align-items: flex-start; }
.preview-frame { flex: 1; display: flex; background: #fff; }
.preview-stage[data-w="tablet"] .preview-frame,
.preview-stage[data-w="mobile"] .preview-frame {
  flex: 0 0 auto; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,.08); overflow: hidden; background: #fff;
}
.preview-stage[data-w="tablet"] .preview-frame { width: 820px; }
.preview-stage[data-w="mobile"] .preview-frame { width: 390px; }
.preview-iframe { flex: 1; width: 100%; border: none; background: #fff; }
.preview-stage[data-w="tablet"] .preview-iframe { height: 1100px; }
.preview-stage[data-w="mobile"] .preview-iframe { height: 780px; }

/* ---- drawers ---- */
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer::before { content: ""; position: absolute; inset: 0; background: rgba(57,62,66,.28); }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 460px; max-width: 90vw;
  background: #fff; border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 16px; }
.drawer-body { overflow: auto; padding: 12px 16px; }
.drawer-body h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }
.drawer-body h3:first-child { margin-top: 0; }

.record-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.record {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 11px;
  display: flex; flex-direction: column; gap: 6px;
}
.record.active { border-color: var(--ink); }
.record-line { font-size: 13px; }
.record-sub { font-size: 12px; color: var(--muted); }
.record-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); }
.badge.on { border-color: var(--green); color: var(--green); }

/* ---- settings ---- */
.settings-model { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.settings-model label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.settings-model select { border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; font-size: 13px; }
.providers-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.providers-table td { border-bottom: 1px solid var(--line); padding: 8px 6px; vertical-align: top; }
.provider-methods { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0; }
.provider-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.auth-area { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-top: 10px; background: var(--panel); }
.auth-area .row { margin-bottom: 8px; font-size: 13px; }
.auth-area input { border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; font-size: 13px; width: 100%; }
.auth-area a { color: var(--red); }

/* ---- toasts ---- */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: var(--radius);
  font-size: 13px; box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.toast.error { background: var(--red); }

/* ---- responsive ---- */
@media (max-width: 1200px) {
  .left { width: var(--left-width, 360px); flex-basis: var(--left-width, 360px); }
}
