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

:root {
  --bg: #0a0a0a;
  --bg-surface: #141414;
  --bg-elevated: #1e1e1e;
  --bg-hover: #2a2a2a;
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #c97539;
  --accent-dim: #a05e2d;
  --border: #2a2a2a;
  --user-bg: #1a3a1a;
  --assistant-bg: #1a1a2a;
  --tool-bg: #1a1a1a;
  --danger: #cc4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

.screen {
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

/* Auth */
.auth-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 2rem;
  gap: 1rem;
}

.auth-logo {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  background: var(--accent);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 700;
}

.auth-container h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.auth-container p {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 32px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 1rem;
}

.btn-primary:active { opacity: 0.8; }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  width: 100%;
}

/* Header */
#chat-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(52px + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding-left: 8px;
  padding-right: 8px;
  z-index: 100;
}

.header-title {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #444;
  display: inline-block;
}
.status-dot.connected { background: #4a4; }
.status-dot.thinking { background: var(--accent); animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  padding: 8px 12px;
  cursor: pointer;
  line-height: 1;
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.2s ease;
}
.sidebar.hidden { transform: translateX(-100%); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  padding-top: calc(16px + var(--safe-top));
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { font-size: 1.1rem; }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 199;
}
.sidebar-overlay.hidden { display: none; }

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

.session-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.session-item:hover, .session-item.active { background: var(--bg-hover); color: var(--text); }
.session-item .session-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .session-date { font-size: 0.75rem; color: var(--text-dim); margin-left: 8px; flex-shrink: 0; }
.session-item .session-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 4px;
  margin-left: 4px;
}
.session-item:hover .session-delete { opacity: 0.6; }
.session-item .session-delete:hover { opacity: 1; }

.sidebar-footer { padding: 16px; padding-bottom: calc(16px + var(--safe-bottom)); }

/* Messages */
.messages {
  position: fixed;
  top: calc(52px + var(--safe-top));
  bottom: calc(56px + var(--safe-bottom));
  left: 0;
  right: 0;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.9rem;
  word-break: break-word;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bg);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
  border-bottom-left-radius: 4px;
}

.message.tool {
  align-self: flex-start;
  background: var(--tool-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 6px 10px;
  max-width: 90%;
  font-family: 'SF Mono', 'Menlo', monospace;
}

.message.tool .tool-icon { margin-right: 6px; }

.message.status {
  align-self: center;
  background: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 4px;
}

.message.error {
  align-self: center;
  color: var(--danger);
  font-size: 0.85rem;
}

.message code {
  background: var(--bg-elevated);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 0.85em;
}

.message pre {
  background: var(--bg);
  padding: 8px 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
  font-size: 0.82em;
}

.message pre code {
  background: none;
  padding: 0;
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-dim);
  gap: 8px;
  padding: 2rem;
  text-align: center;
}
.welcome .logo { font-size: 3rem; opacity: 0.3; }

/* Input */
#input-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  padding-bottom: calc(8px + var(--safe-bottom));
}

.input-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elevated);
  border-radius: 20px;
  padding: 4px 4px 4px 16px;
}

#input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  padding: 8px 0;
  line-height: 1.4;
  outline: none;
}

#input::placeholder { color: var(--text-dim); }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.send-btn:disabled { opacity: 0.3; }

.cost-bar {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  padding-top: 4px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
