:root {
  --bg: #0b1120;
  --sidebar: #111827;
  --card: #1e293b;
  --card-hover: #263449;
  --border: #2e3b4e;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #10b981;
  --warn: #f59e0b;
  --err: #ef4444;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior-y: none;
}

button, input, select, textarea {
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

button {
  background: var(--accent);
  border-color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s;
}
button:hover { background: var(--accent-hover); }
button.secondary { background: transparent; border-color: var(--border); }
button.secondary:hover { background: var(--card-hover); }
button.danger { background: var(--err); border-color: var(--err); }
button.ok { background: var(--ok); border-color: var(--ok); }
button.icon-btn {
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* === Auth === */
#auth-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.auth-card {
  width: min(94vw, 390px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
}
.auth-card h2 { margin: 0 0 6px; font-size: 20px; }
.auth-card p { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button { flex: 1; background: transparent; border-color: var(--border); }
.tabs button.active { background: var(--accent); border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.msg-err { color: var(--err); font-size: 13px; margin-top: 8px; }
.msg-ok { color: var(--ok); font-size: 13px; margin-top: 8px; }

/* === App Layout === */
#app-screen {
  display: none;
  height: 100%;
  width: 100%;
}

.sidebar {
  width: 280px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  z-index: 30;
}

.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.brand img { width: 22px; height: 22px; }

.sidebar-section { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.sidebar-label { font-size: 11px; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; letter-spacing: 0.04em; }

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.chat-item:hover { background: var(--card); }
.chat-item.active { background: var(--card); border-color: var(--accent); }
.chat-item-info { min-width: 0; flex: 1; }
.chat-item-title {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-meta { font-size: 11px; color: var(--muted); }
.chat-item-actions { display: flex; gap: 2px; opacity: 0.7; }
.chat-item-actions button { padding: 2px 6px; font-size: 11px; background: transparent; border: none; }
.chat-item-actions button:hover { background: var(--card-hover); }

.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

/* === Main Chat === */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
}

.topbar {
  padding: 10px 14px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#menu-toggle { display: none; }

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

.bubble {
  max-width: min(88%, 760px);
  padding: 12px 15px;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 14px;
  word-break: break-word;
}
.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  white-space: pre-wrap;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--border);
}
.bubble.assistant pre {
  background: #0b1120;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  overflow-x: auto;
  font-size: 12px;
}
.bubble.assistant code {
  background: rgba(15, 23, 42, 0.7);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
}
.bubble-footer {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}
.tool-details {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 6px;
  font-size: 12px;
  color: var(--muted);
}
.tool-details summary { cursor: pointer; color: #93c5fd; }
.tool-details pre { max-height: 200px; overflow: auto; }

.confirm-box {
  align-self: flex-start;
  background: #1e1b4b;
  border: 1px solid #6366f1;
  border-radius: 10px;
  padding: 12px 14px;
  max-width: min(88%, 620px);
}
.confirm-actions { display: flex; gap: 8px; margin-top: 10px; }

.composer {
  padding: 8px 12px;
  background: var(--sidebar);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  line-height: 1.4;
  font-size: 16px;
  border-radius: 20px;
  padding: 9px 14px;
  overflow-y: hidden;
}
.action-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid var(--border);
}
.action-btn.send-mode {
  background: var(--accent);
  border-color: var(--accent);
}
.action-btn.recording {
  background: var(--err);
  border-color: var(--err);
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* === Modals === */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 50;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(96vw, 680px);
  max-height: 88vh;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-body textarea { width: 100%; min-height: 240px; font-family: monospace; font-size: 12.5px; }
.skill-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* === Mobile === */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 25;
}
@media (max-width: 780px) {
  #menu-toggle { display: inline-flex; }
  .sidebar {
    position: fixed;
    left: -290px;
    top: 0;
    bottom: 0;
    transition: left 0.2s ease;
  }
  .sidebar.open { left: 0; }
  .sidebar-overlay.open { display: block; }
}
