* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #111214;
  --panel: #1a1c1f;
  --panel2: #222528;
  --text: #e8e8e6;
  --muted: #9a9a94;
  --accent: #c96442;
  --border: #2e3134;
  --ok: #4caf50;
  --warn: #ffb300;
  --err: #ef5350;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.title { display: flex; align-items: center; gap: 8px; flex: 1; font-weight: 600; min-width: 0; }
.title .model { color: var(--muted); font-size: 12px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--err); }

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 8px;
}
.icon-btn:active { background: var(--panel2); }

#drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(320px, 85vw);
  background: var(--panel);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  z-index: 20;
  overflow-y: auto;
  padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
  padding-top: calc(16px + env(safe-area-inset-top));
}
#drawer.open { transform: translateX(0); }

#scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 15;
}
#scrim.show { opacity: 1; pointer-events: auto; }

.drawer-section { margin-bottom: 22px; }
.drawer-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 8px; }
.drawer-section ul { list-style: none; }
.drawer-section li {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.drawer-section li.active, .drawer-section li:active { background: var(--panel2); }
.drawer-section li .li-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.drawer-section li .li-sub { color: var(--muted); font-size: 11px; }
.drawer-section li button { background: none; border: none; color: var(--muted); font-size: 14px; cursor: pointer; padding: 4px; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
select, input, textarea {
  width: 100%;
  margin-top: 4px;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
}

.wide-btn {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  margin-top: 4px;
}
.wide-btn.subtle { background: var(--panel2); color: var(--text); }

main {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg { max-width: 92%; word-wrap: break-word; }
.msg.user {
  align-self: flex-end;
  background: rgba(201, 100, 66, 0.18);
  padding: 8px 12px;
  border-radius: 14px 14px 4px 14px;
  white-space: pre-wrap;
}
.msg.assistant { align-self: flex-start; width: 100%; }
.msg.assistant .md { white-space: pre-wrap; }
.msg.error { color: var(--warn); font-size: 14px; }
.msg img { max-width: 200px; border-radius: 8px; display: block; margin-top: 6px; }
img.generated { max-width: 100%; border-radius: 10px; display: block; margin: 8px 0; }

.md pre {
  background: #0c0d0e;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  overflow-x: auto;
  font-size: 13px;
  margin: 8px 0;
  white-space: pre;
}
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }

details.tool {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  align-self: flex-start;
  max-width: 100%;
}
details.tool summary { cursor: pointer; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 85vw; }
details.tool pre { margin-top: 6px; white-space: pre-wrap; word-break: break-word; max-height: 40vh; overflow-y: auto; font-size: 12px; font-family: ui-monospace, Menlo, monospace; }

.approval {
  background: rgba(255, 179, 0, 0.08);
  border: 1px solid rgba(255, 179, 0, 0.4);
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
}
.approval pre { white-space: pre-wrap; word-break: break-word; font-size: 12px; margin: 8px 0; font-family: ui-monospace, Menlo, monospace; max-height: 30vh; overflow-y: auto; }
.approval .row { display: flex; gap: 8px; }
.approval button {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  background: var(--panel2);
  color: var(--text);
}
.approval button.allow { background: var(--accent); color: #fff; }

.working { color: var(--muted); font-size: 13px; }

footer {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
footer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  margin-top: 0;
}
.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn.stop { background: var(--err); }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-card h3 { margin-bottom: 10px; }
.modal-card p { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.modal-actions { display: flex; gap: 8px; margin-top: 8px; }

/* Login */
.login-error { color: #c0392b; font-size: 14px; margin: 0 0 8px; }
#loginModal input { width: 100%; margin-bottom: 8px; }

.switch-line { text-align: center; margin-top: 10px; font-size: 13px; }
.switch-line a { color: var(--accent); text-decoration: none; }
