* { box-sizing: border-box; }
:root {
  --bg: #0f172a;
  --panel: #111827;
  --muted: #94a3b8;
  --text: #e2e8f0;
  --accent: #7c3aed;
  --accent-2: #3b82f6;
  --danger: #ef4444;
  --border: #1f2937;
}
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  /* Prevent page-level scrolling. We'll scroll inside the messages pane only. */
  overflow: hidden;
}
/* Root app container just serves as a wrapper now */
#app { height: 100vh; }
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 300px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* Keep sidebar fixed without its own scroll so only chat pane scrolls */
  overflow: hidden;
  z-index: 20;
}
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(1px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.mobile-only { display: none; }
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}
.model-picker, .tokens-limit, .system-prompt, .cost-panel { display: grid; gap: 8px; }
.model-picker select, .tokens-limit input, .system-prompt textarea {
  width: 100%;
  background: #0b1220;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}
.cost-panel { border-top: 1px solid var(--border); padding-top: 12px; }
.cost-panel h3 { margin: 0 0 8px 0; font-size: 14px; }
.cost-line { display: flex; justify-content: space-between; padding: 2px 0; }
.cost-line.total { font-weight: bold; }
.muted { color: var(--muted); }

.chat {
  /* Occupy remaining viewport beside fixed sidebar */
  margin-left: 300px;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.messages {
  padding: 16px;
  overflow-y: auto;
}
.message {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: #0b1220; border: 1px solid var(--border); }
.avatar.user { background: rgba(59,130,246,.2); color: #93c5fd; }
.avatar.assistant { background: rgba(124,58,237,.2); color: #c4b5fd; }
.bubble {
  background: #0b1220;
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 12px;
  white-space: pre-wrap;
}
.bubble code { background: #020617; padding: 2px 4px; border-radius: 4px; }
.bubble pre { background: #020617; padding: 8px; border-radius: 8px; overflow: auto; }

.composer { border-top: 1px solid var(--border); padding: 12px; display: grid; gap: 8px; }
.composer .row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
#message-input {
  resize: none; max-height: 200px; min-height: 44px;
  background: #0b1220; color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.btn { border: 1px solid var(--border); background: #0b1220; color: var(--text); border-radius: 10px; padding: 8px 12px; cursor: pointer; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; }
.btn.danger { background: #2b1a1a; border: 1px solid rgba(239,68,68,.4); color: #fecaca; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.checkbox { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }

/* Utilities */
.hidden { display: none !important; }
.small { font-size: 12px; color: var(--muted); }

/* Mobile */
@media (max-width: 900px) {
  #app { height: 100vh; }
  .mobile-only { display: inline-block; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 80vw; max-width: 320px;
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 20;
    /* On mobile, allow the sidebar content to scroll if it overflows */
    overflow: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .overlay { z-index: 10; }
  .chat { margin-left: 0; }
}
