/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens ── */
:root {
  --bg:         #1a1a1a;
  --bg-sidebar: #141414;
  --bg-input:   #222222;
  --bg-hover:   #2a2a2a;
  --bg-tool:    #1e1e1e;
  --border:     #2e2e2e;
  --text:       #e8e8e8;
  --text-dim:   #666;
  --text-muted: #999;
  --orange:     #d97706;
  --radius:     10px;
  --font-ui:    'DM Sans', system-ui, sans-serif;
  --font-prose: 'Lora', Georgia, serif;
  --font-mono:  'JetBrains Mono', monospace;
  --topbar-h:   0px;
}

/* ── Base ── */
html { height: 100%; }
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  overflow: hidden;
}

/* ── Mobile top bar (hidden on desktop) ── */
.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  height: 52px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  -webkit-app-region: no-drag;
}

.topbar-logo {
  font-weight: 500;
  font-size: 16px;
  letter-spacing: 0.03em;
}

.topbar-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.topbar-btn:active { background: var(--bg-hover); }

/* ── Sidebar overlay ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 150;
}

/* ── Layout ── */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 240px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-weight: 500;
  font-size: 17px;
  letter-spacing: 0.03em;
}

.new-chat-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.new-chat-btn:hover { background: var(--bg-hover); color: var(--text); }

.sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.session-item {
  padding: 9px 16px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  margin: 1px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.session-item:hover, .session-item.active { background: var(--bg-hover); color: var(--text); }

/* ── Main ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Messages ── */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 28px 0 8px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.message {
  max-width: 720px;
  margin: 0 auto 24px;
  padding: 0 16px;
}

/* User message */
.message.user .bubble {
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 11px 15px;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text);
  display: inline-block;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Assistant message */
.message.assistant .prose {
  font-family: var(--font-prose);
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
}

.message.assistant .prose p { margin-bottom: 12px; }
.message.assistant .prose p:last-child { margin-bottom: 0; }
.message.assistant .prose strong { font-weight: 600; }
.message.assistant .prose em { font-style: italic; }

.message.assistant .prose code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--bg-tool);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  color: #e2a96e;
}

.message.assistant .prose pre {
  background: var(--bg-tool);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  overflow-x: auto;
  margin: 12px 0;
  -webkit-overflow-scrolling: touch;
}

.message.assistant .prose pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 12.5px;
  color: var(--text);
}

.message.assistant .prose ul,
.message.assistant .prose ol {
  padding-left: 20px;
  margin-bottom: 12px;
}
.message.assistant .prose li { margin-bottom: 4px; }

.message.assistant .prose h1,
.message.assistant .prose h2,
.message.assistant .prose h3 {
  font-family: var(--font-ui);
  font-weight: 500;
  margin: 20px 0 8px;
}
.message.assistant .prose h1 { font-size: 19px; }
.message.assistant .prose h2 { font-size: 16px; }
.message.assistant .prose h3 { font-size: 14.5px; }

/* ── Prose fade-in ── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
.prose { animation: fadeIn 0.15s ease; }

/* ── Tool block ── */
.tool-block {
  margin: 10px 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-tool);
  animation: fadeIn 0.15s ease;
}

.tool-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
}

.tool-dot { color: var(--orange); font-size: 13px; flex-shrink: 0; }
.tool-name { color: var(--text); font-weight: 500; flex-shrink: 0; }
.tool-sep  { color: var(--text-dim); flex-shrink: 0; }

.tool-args {
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  font-size: 11.5px;
}

.tool-output {
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  line-height: 1.5;
  -webkit-overflow-scrolling: touch;
}

.tool-expand {
  color: var(--orange);
  cursor: pointer;
  font-size: 11px;
}
.tool-expand:hover { text-decoration: underline; }

/* ── Spinner ── */
.spinner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 4px 0;
}

.spinner-dot {
  width: 6px; height: 6px;
  background: var(--orange);
  border-radius: 50%;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50%       { opacity: 1;   transform: scale(1);   }
}

/* ── Input area ── */
.input-area {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color 0.15s;
}
.input-box:focus-within { border-color: #444; }

textarea#input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--text);
  line-height: 1.5;
  max-height: 160px;
  overflow-y: auto;
  -webkit-appearance: none;
}
textarea#input::placeholder { color: var(--text-dim); }

.send-btn {
  background: var(--orange);
  border: none;
  border-radius: 7px;
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  flex-shrink: 0;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.send-btn:active { opacity: 0.75; }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.input-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 2px 0;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-ui);
}

/* ── Welcome ── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 8px;
  color: var(--text-dim);
}
.welcome-logo {
  font-size: 30px;
  font-weight: 300;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}
.welcome-sub { font-size: 13px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

/* ════════════════════════════════════════════
   MOBILE  (≤ 640px)
════════════════════════════════════════════ */
@media (max-width: 640px) {
  :root { --topbar-h: 52px; }

  /* Show topbar, hide sidebar header logo on mobile */
  .topbar { display: flex; }

  .layout {
    flex-direction: column;
    height: 100dvh; /* dynamic viewport height - handles mobile keyboard */
    padding-top: var(--topbar-h);
  }

  /* Sidebar slides in from left as overlay */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    border-right: 1px solid var(--border);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  /* Hide desktop sidebar header on mobile since we have topbar */
  .sidebar-header { display: flex; }

  .main {
    flex: 1;
    min-height: 0;
  }

  .messages {
    padding: 16px 0 8px;
  }

  .message {
    padding: 0 12px;
    margin-bottom: 20px;
  }

  .message.assistant .prose {
    font-size: 14.5px;
  }

  .input-area {
    padding: 10px 12px 12px;
  }

  textarea#input {
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  .tool-args { max-width: 160px; }
  .input-meta { display: none; } /* hide ctx bar on small screens */
}
