/* ==========================================================================
   ClaudeDeck — chat + login styles
   A light, neutral (slate) theme with a single indigo accent.
   ========================================================================== */

/* --- Design tokens ------------------------------------------------------- */
:root {
  /* Surfaces */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e9eef5;

  /* Borders */
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  /* Text */
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --on-accent: #ffffff;

  /* Accent + semantic */
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warn: #d97706;
  --warn-soft: #fffbeb;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;

  /* Radius */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.16);

  --sidebar-w: 300px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

/* --- Base ---------------------------------------------------------------- */
* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); background-clip: content-box; }

/* --- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #fde2e2; }

.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 13px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* --- Form fields --------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--sp-1); margin-bottom: var(--sp-4); }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }

.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* --- Badges -------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid #dfe3ff;
  vertical-align: middle;
}

/* ==========================================================================
   LOGIN
   ========================================================================== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--sp-4);
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-6);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}
.login-logo {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 18px;
  box-shadow: var(--shadow);
}
.login-title { font-size: 20px; font-weight: 700; margin: 0; }
.login-sub { color: var(--text-muted); font-size: 13px; margin: 2px 0 0; }

.login-error {
  display: none;
  background: var(--danger-soft);
  border: 1px solid #f6cfcf;
  color: var(--danger);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: var(--sp-4);
}
.login-error.show { display: block; }

.login-foot { margin-top: var(--sp-4); text-align: center; color: var(--text-subtle); font-size: 12px; }

/* ==========================================================================
   CHAT APP LAYOUT
   ========================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* --- Sidebar ------------------------------------------------------------- */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.brand-logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px; flex: none;
}
.brand-name { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-actions { padding: var(--sp-3) var(--sp-4) var(--sp-2); }

.search-wrap { padding: 0 var(--sp-4) var(--sp-3); }
.search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--sp-2) var(--sp-3);
  min-height: 0;
}
.session-group-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-subtle);
  padding: var(--sp-3) var(--sp-3) var(--sp-1);
}

.session-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
}
.session-item:hover { background: var(--surface-2); }
.session-item.active { background: var(--accent-soft); }
.session-item.active .session-title { color: var(--accent); font-weight: 600; }

.session-main { flex: 1; min-width: 0; }
.session-title {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: 2px;
}
.session-meta .badge { font-size: 10px; padding: 1px 6px; }
.session-time { font-size: 11px; color: var(--text-subtle); }

.session-actions {
  display: none;
  gap: 2px;
  flex: none;
}
.session-item:hover .session-actions,
.session-item.active .session-actions { display: flex; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-4);
}
.user-row { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-3); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; flex: none; text-transform: uppercase;
}
.user-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.footer-links { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-3); }
.footer-links button, .footer-links a {
  font-size: 12px; color: var(--text-muted); background: none; padding: 2px 0;
}
.footer-links button:hover, .footer-links a:hover { color: var(--accent); text-decoration: none; }

/* --- Main pane ----------------------------------------------------------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  min-height: 56px;
}
.menu-toggle { display: none; }
.chat-header-titles { flex: 1; min-width: 0; }
.chat-title {
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

/* --- CLI auth banner ----------------------------------------------------- */
.cli-banner {
  display: none;
  align-items: center;
  gap: var(--sp-3);
  background: var(--warn-soft);
  border-bottom: 1px solid #f3e0b5;
  color: #92400e;
  padding: 10px var(--sp-5);
  font-size: 13px;
}
.cli-banner.show { display: flex; }
.cli-banner code { background: rgba(0,0,0,0.06); padding: 1px 6px; border-radius: 4px; }

/* --- Messages ------------------------------------------------------------ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-5);
  min-height: 0;
}
.messages-inner {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.assistant, .msg.system { justify-content: flex-start; }

.bubble {
  max-width: 88%;
  padding: 11px 15px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--accent);
  color: var(--on-accent);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.msg.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.system .bubble {
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
  font-size: 13px;
  white-space: pre-wrap;
}

/* Rendered markdown inside assistant bubbles */
.markdown > *:first-child { margin-top: 0; }
.markdown > *:last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 0.7em; }
.markdown h1, .markdown h2, .markdown h3 { margin: 1em 0 0.5em; line-height: 1.3; }
.markdown h1 { font-size: 1.4em; }
.markdown h2 { font-size: 1.25em; }
.markdown h3 { font-size: 1.1em; }
.markdown ul, .markdown ol { margin: 0 0 0.7em; padding-left: 1.4em; }
.markdown li { margin: 0.15em 0; }
.markdown code {
  background: var(--surface-2);
  padding: 0.15em 0.4em;
  border-radius: 5px;
  font-size: 0.88em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.markdown pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 0 0 0.7em;
}
.markdown pre code { background: none; padding: 0; color: inherit; font-size: 0.85em; }
.markdown blockquote {
  border-left: 3px solid var(--border-strong);
  margin: 0 0 0.7em;
  padding: 0.1em 0 0.1em 1em;
  color: var(--text-muted);
}
.markdown table { border-collapse: collapse; margin: 0 0 0.7em; display: block; overflow-x: auto; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.markdown th { background: var(--surface-2); }
.markdown a { text-decoration: underline; }
.markdown img { max-width: 100%; border-radius: var(--radius-sm); }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }

/* Streaming caret */
.bubble.streaming .markdown::after {
  content: "";
  display: inline-block;
  width: 7px; height: 1.05em;
  background: var(--accent);
  margin-left: 2px;
  border-radius: 1px;
  vertical-align: text-bottom;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Typing/preparing indicators */
.inline-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text-muted);
  font-size: 13px;
}
.dots { display: inline-flex; gap: 3px; }
.dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-subtle);
  animation: bounce 1.2s infinite ease-in-out both;
}
.dots span:nth-child(2) { animation-delay: 0.15s; }
.dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

.turns-note {
  font-size: 12px;
  color: var(--warn);
  margin-top: var(--sp-2);
}

/* --- Artifact card ------------------------------------------------------- */
.artifact-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.artifact-icon {
  width: 34px; height: 34px; border-radius: 8px; flex: none;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.artifact-info { flex: 1; min-width: 0; }
.artifact-title { font-weight: 600; font-size: 14px; }
.artifact-desc { font-size: 12px; color: var(--text-muted); }
.artifact-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* --- Questions card ------------------------------------------------------ */
.questions-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  box-shadow: var(--shadow-sm);
}
.questions-head { font-weight: 600; margin-bottom: var(--sp-3); display: flex; align-items: center; gap: var(--sp-2); }
.question { padding: var(--sp-3) 0; border-top: 1px solid var(--border); }
.question:first-of-type { border-top: none; padding-top: 0; }
.question-text { font-weight: 500; margin-bottom: var(--sp-2); }
.option-row { display: flex; align-items: center; gap: var(--sp-2); padding: 3px 0; cursor: pointer; }
.option-row input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.q-text-input { width: 100%; min-height: 70px; resize: vertical; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); }
.q-other-label { font-size: 12px; color: var(--text-muted); margin-top: var(--sp-2); }
.q-other-input { width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 3px; }
.questions-actions { margin-top: var(--sp-4); }

/* --- Empty state --------------------------------------------------------- */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--sp-6);
  gap: var(--sp-4);
}
.empty-logo {
  width: 56px; height: 56px; border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 24px;
  box-shadow: var(--shadow);
}
.empty-title { font-size: 22px; font-weight: 700; margin: 0; }
.empty-sub { color: var(--text-muted); margin: 0; max-width: 460px; }
.prompt-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); width: 100%; max-width: 560px; margin-top: var(--sp-2); }
.prompt-card {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}
.prompt-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.prompt-card-title { font-weight: 600; font-size: 14px; }
.prompt-card-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* --- Composer ------------------------------------------------------------ */
.composer-wrap { padding: var(--sp-3) var(--sp-5) var(--sp-4); border-top: 1px solid var(--border); background: var(--surface); }
.composer {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--sp-2);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: none;
  padding: 8px 10px;
  max-height: 200px;
  line-height: 1.5;
}
.composer-hint { max-width: 820px; margin: 6px auto 0; font-size: 11px; color: var(--text-subtle); text-align: center; }

/* ==========================================================================
   MODALS
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  z-index: 100;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal.wide { max-width: 860px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-footer { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--sp-2); }

.agent-option {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%; text-align: left;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--sp-2);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.agent-option:hover { border-color: var(--accent); background: var(--accent-soft); }
.agent-option .agent-avatar {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}

/* ==========================================================================
   TOASTS
   ========================================================================== */
.toasts {
  position: fixed;
  bottom: var(--sp-5);
  right: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: 200;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 11px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  animation: toast-in 0.18s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }
.toast.info { background: #1e293b; }
.toast-close { margin-left: auto; opacity: 0.7; color: inherit; background: none; line-height: 1; }
.toast-close:hover { opacity: 1; }

/* ==========================================================================
   UTILITIES
   ========================================================================== */
.hidden { display: none !important; }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { display: flex; align-items: center; justify-content: center; gap: var(--sp-2); padding: var(--sp-6); color: var(--text-muted); }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(86vw, var(--sidebar-w));
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .sidebar-scrim {
    position: fixed; inset: 0; background: rgba(15,23,42,0.4); z-index: 80; display: none;
  }
  .sidebar-scrim.show { display: block; }
  .prompt-grid { grid-template-columns: 1fr; }
}
