/* ════════════════════════════════════════
   TALKIE — Design tokens (matches applesauce.chat)
   ════════════════════════════════════════ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root, [data-theme="dark"] {
  --bg: #111117;
  --bg-subtle: #1a1a22;
  --card-bg: #1a1a22;
  --card-border: rgba(255,255,255,0.06);
  --card-shadow: 0 2px 4px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.2);
  --card-hover-shadow: 0 4px 8px rgba(0,0,0,0.4), 0 8px 32px rgba(0,0,0,0.15);
  --text: #e4e4ec;
  --text-muted: #8e8e9e;
  --text-dim: #5a5a6a;
  --accent-primary: #a78bfa;
  --accent-green: #6EE7A0;
  --accent-red: #f87171;
  --accent-gold: #fbbf24;
  --font-heading: 'DM Serif Display', serif;
  --font-mono: 'Space Mono', monospace;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --ease-out: cubic-bezier(.4,0,.2,1);
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.85rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Noise overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
  opacity: 0.4;
}

h1, h2, h3 { font-family: var(--font-heading); line-height: 1.3; }
a { color: var(--accent-primary); text-decoration: none; }

.container { max-width: 960px; margin: 0 auto; padding: 0 20px; }

/* ════ Nav (login page) ════ */
.nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--card-border);
  background: var(--bg);
}
.nav-brand {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-heading); font-size: 1.25rem;
  color: var(--text); text-decoration: none;
}
.nav-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent-primary);
  box-shadow: 0 0 8px var(--accent-primary);
}
.nav-links { display: flex; gap: 4px; align-items: center; }
.nav-link {
  font-family: var(--font-body); font-size: 0.75rem; font-weight: 500;
  color: var(--text-muted); padding: 4px 12px;
  border-radius: var(--radius); transition: 0.15s ease;
}
.nav-link:hover { color: var(--text); background: var(--bg-subtle); }
.nav-link--dim { color: var(--text-dim); }

/* ════ Buttons ════ */
.btn-primary {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border: none; border-radius: var(--radius);
  font-family: var(--font-heading); font-size: 0.85rem;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-primary), color-mix(in srgb, var(--accent-primary) 80%, #000));
  box-shadow: 0 2px 0 color-mix(in srgb, var(--accent-primary) 50%, #000);
  cursor: pointer; text-decoration: none;
  transition: 0.2s var(--ease-out);
}
.btn-primary:hover { transform: translateY(-2px); }
.btn-primary:active { transform: translateY(1px) scale(0.97); transition-duration: 0.05s; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; border: 1px solid var(--card-border);
  border-radius: var(--radius); font-size: 0.75rem;
  color: var(--text-muted); background: transparent;
  cursor: pointer; text-decoration: none;
  transition: 0.15s ease; margin-left: 8px;
}
.btn-secondary:hover { color: var(--text); border-color: var(--accent-primary); }

/* ════ Login ════ */
.login-page {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 64px 20px;
}
.login-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-xl);
  padding: 32px;
  max-width: 360px; width: 100%;
}
.login-card h1 { font-size: 1.5rem; margin-bottom: 8px; }
.login-input {
  width: 100%; padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  color: var(--text); font-family: var(--font-mono); font-size: 0.85rem;
  margin: 16px 0 12px;
  outline: none; transition: 0.15s ease;
}
.login-input:focus { border-color: var(--accent-primary); }
.login-error {
  background: color-mix(in srgb, var(--accent-red) 10%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--accent-red) 25%, transparent);
  color: var(--accent-red);
  border-radius: var(--radius);
  padding: 8px 12px; font-size: 0.75rem; margin-bottom: 12px;
}
.login-sent {
  background: color-mix(in srgb, var(--accent-green) 10%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--accent-green) 25%, transparent);
  color: var(--accent-green);
  border-radius: var(--radius);
  padding: 12px; font-size: 0.85rem; text-align: center;
}
.text-muted { color: var(--text-muted); }

/* ════ Chat layout ════ */
.chat-body {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  min-height: 0;
}
.chat-body::before {
  /* hide noise overlay during chat for perf */
  opacity: 0.2;
}

.sidebar {
  background: var(--bg-subtle);
  border-right: 1px solid var(--card-border);
  display: flex; flex-direction: column;
  min-height: 0;
}
.sidebar-head {
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--card-border);
}
.sidebar-list {
  flex: 1; overflow-y: auto;
  padding: 8px;
}
.sidebar-item {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.75rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: 0.15s ease;
}
.sidebar-item:hover { background: var(--card-bg); color: var(--text); }
.sidebar-item--active { background: var(--card-bg); color: var(--text); border-left: 2px solid var(--accent-primary); }
.sidebar-empty {
  padding: 16px; font-size: 0.7rem; color: var(--text-dim);
  font-family: var(--font-mono); text-align: center;
}
.sidebar-foot {
  border-top: 1px solid var(--card-border);
  padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.7rem;
}
.sidebar-meta { color: var(--text-muted); line-height: 1.4; }
.sidebar-model { font-family: var(--font-mono); font-size: 0.6rem; color: var(--text-dim); }

.chat-main {
  display: flex; flex-direction: column;
  min-height: 0;
}

.chat-stream {
  flex: 1;
  overflow-y: auto;
  padding: 32px max(20px, calc(50% - 380px));
  display: flex; flex-direction: column; gap: 20px;
}

.chat-empty {
  margin: auto 0;
  text-align: left;
  max-width: 560px;
}
.chat-empty-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.chat-empty h1 {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}
.chat-empty p { color: var(--text-muted); }

.msg { display: flex; flex-direction: column; gap: 4px; }
.msg-role {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.msg--user .msg-role { color: var(--accent-primary); }
.msg--assistant .msg-role { color: var(--accent-green); }
.msg-body {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 0.9rem;
  line-height: 1.7;
}

.chat-input-wrap {
  border-top: 1px solid var(--card-border);
  padding: 16px max(20px, calc(50% - 380px));
  display: flex; gap: 12px;
  background: var(--bg);
}
.chat-input-wrap textarea {
  flex: 1;
  background: var(--bg-subtle);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 12px 14px;
  resize: none;
  outline: none;
  min-height: 44px;
  transition: 0.15s ease;
}
.chat-input-wrap textarea:focus { border-color: var(--accent-primary); }

/* ════ Footer (login page) ════ */
.footer {
  margin-top: auto;
  padding: 20px;
  border-top: 1px solid var(--card-border);
}
.footer-inner {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-dim);
}
.footer-sep { opacity: 0.3; }
.footer a { color: var(--text-dim); }
.footer a:hover { color: var(--text); }

@media (max-width: 720px) {
  .chat-body { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0;
    max-height: 40vh;
    border-right: 0; border-top: 1px solid var(--card-border);
  }
  .chat-main { height: 60vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
