* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b1020;
  color: #e5e7eb;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(520px, 100%);
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.35);
}
.brand-row { display: flex; align-items: center; gap: 14px; }
.brand-row.compact { gap: 10px; }
.brand-logo { width: 56px; height: 56px; }
.brand-logo.small { width: 42px; height: 42px; }
body.public-page .brand-logo.small {
  width: 128px;
  height: 128px;
}
.eyebrow { text-transform: uppercase; letter-spacing: 0.14em; color: #7dd3fc; font-size: 11px; margin-bottom: 4px; }
h1, h2 { margin: 0; }
.lede { color: #cbd5e1; line-height: 1.5; margin: 18px 0 22px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.auth-tab, .secondary, .composer button, .auth-form button {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #7c3aed, #06b6d4);
  color: white;
  font-weight: 700;
}
.auth-tab { background: rgba(30, 41, 59, 0.9); color: #cbd5e1; }
.auth-tab.active { background: linear-gradient(135deg, #7c3aed, #06b6d4); color: white; }
.auth-form { display: none; gap: 12px; }
.auth-form.active { display: grid; }
.auth-form label { display: grid; gap: 8px; color: #cbd5e1; }
.auth-form input, .composer textarea, .memory-box {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(2, 6, 23, 0.6);
  color: #e2e8f0;
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
}
.status-line { margin-top: 14px; min-height: 20px; color: #fca5a5; }

.public-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  position: relative;
}
.public-sidebar {
  background: #0f172a;
  border-right: 1px solid rgba(148, 163, 184, 0.12);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.sidebar-actions { display: flex; gap: 10px; align-items: center; }
.public-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  position: relative;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: radial-gradient(circle at top, rgba(59, 130, 246, 0.12), transparent 30%), #0b1020;
}
body.public-page {
  overflow: hidden;
}

.dashboard-shell {
  display: grid;
  grid-template-columns: 300px 320px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}
.users-pane, .threads-pane {
  background: #0f172a;
  border-right: 1px solid rgba(148, 163, 184, 0.12);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  overflow-y: auto;
}
.threads-pane { background: #0c1427; }
.detail-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  background: radial-gradient(circle at top, rgba(59, 130, 246, 0.12), transparent 30%), #0b1020;
}
.sidebar-header, .chat-header, .sidebar-footer { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.chat-header-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; width: 100%; }
.panel { background: rgba(15, 23, 42, 0.75); border: 1px solid rgba(148, 163, 184, 0.1); border-radius: 18px; padding: 14px; }
.panel-title { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: #94a3b8; margin-bottom: 10px; }
.dashboard-list { display: grid; gap: 8px; }
.conversation-item {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid transparent;
  color: #e2e8f0;
  text-align: left;
}
.conversation-item.active { border-color: rgba(96, 165, 250, 0.6); background: rgba(15, 23, 42, 1); }
.conversation-item small { display: block; color: #94a3b8; margin-top: 4px; }
.user-item {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid transparent;
  color: #e2e8f0;
  text-align: left;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}
.user-item.active { border-color: rgba(34, 197, 94, 0.55); background: rgba(15, 23, 42, 1); }
.user-item small { display: block; color: #94a3b8; margin-top: 4px; }
.user-select {
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  text-align: left;
  display: grid;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
.user-select span,
.user-select small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.delete-user-btn {
  white-space: nowrap;
  align-self: center;
}
.danger {
  background: linear-gradient(135deg, #b91c1c, #ef4444);
  color: white;
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.summary-grid div {
  border-radius: 14px;
  background: rgba(30, 41, 59, 0.7);
  padding: 12px;
}
.summary-grid strong { display: block; font-size: 22px; }
.summary-grid span { color: #94a3b8; font-size: 12px; }
.readonly-box {
  min-height: 150px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  color: #cbd5e1;
  line-height: 1.5;
}
.linkish { background: none; color: #93c5fd; border: 0; padding: 0; }
.small { padding: 10px 12px; font-size: 14px; }
.subtle { color: #94a3b8; font-size: 14px; }

.chat-header {
  padding: 22px 24px 18px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}
.memory-preview {
  max-width: 420px;
  color: #cbd5e1;
  font-size: 14px;
  text-align: right;
  white-space: pre-wrap;
}
.typing-indicator {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(96, 165, 250, 0.35);
  color: #bfdbfe;
  font-size: 13px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}
.return-bottom-btn {
  position: absolute;
  right: 20px;
  bottom: 96px;
  z-index: 6;
  border: 1px solid rgba(96, 165, 250, 0.35);
  background: rgba(15, 23, 42, 0.92);
  color: #e2e8f0;
  padding: 10px 14px;
  border-radius: 999px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}
.hidden { display: none !important; }
.message-list {
  padding: 24px;
  overflow-y: auto;
  min-height: 0;
  display: grid;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.message {
  max-width: 860px;
  width: fit-content;
  padding: 10px 12px;
  border-radius: 18px;
  line-height: 1.55;
  white-space: pre-wrap;
  border: 1px solid rgba(148, 163, 184, 0.12);
}
.message.user { margin-left: auto; background: rgba(37, 99, 235, 0.18); }
.message.assistant { background: rgba(15, 23, 42, 0.95); }
.message-meta { font-size: 12px; color: #94a3b8; margin-bottom: 6px; }
.composer {
  padding: 18px 24px 24px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
  background: linear-gradient(180deg, transparent, rgba(15, 23, 42, 0.8));
}
.composer textarea {
  min-height: 56px;
  max-height: 180px;
  resize: none;
  overflow-y: auto;
  line-height: 1.4;
}
.empty-state { color: #94a3b8; text-align: center; margin: auto; padding: 60px 24px; }
.scroll-anchor { height: 1px; }
.sidebar-overlay { display: none; }

@media (max-width: 960px) {
  .public-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    min-height: 100dvh;
  }
  .public-sidebar {
    border-right: 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
    max-height: 34dvh;
  }
  .public-main { height: 100%; min-height: 0; }
}

@media (max-width: 760px) {
  .mobile-only { display: inline-flex; }
  .sidebar-actions { flex-direction: column; align-items: stretch; }
  .public-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 340px);
    max-height: none;
    z-index: 15;
    transform: translateX(-102%);
    transition: transform 0.24s ease;
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.45);
  }
  body.public-page .brand-logo.small {
    width: 104px;
    height: 104px;
  }
  body.public-page.sidebar-open .public-sidebar { transform: translateX(0); }
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 14;
    background: rgba(2, 6, 23, 0.62);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    backdrop-filter: blur(2px);
  }
  body.public-page.sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }
  .dashboard-shell { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .users-pane, .threads-pane { border-right: 0; border-bottom: 1px solid rgba(148, 163, 184, 0.12); }
  .detail-pane { height: auto; min-height: 100vh; }
  .chat-header { padding: 16px 16px 12px; }
  .chat-header-top { align-items: center; }
  .memory-preview { text-align: left; }
  .typing-indicator { top: 10px; }
  .return-bottom-btn { right: 12px; bottom: calc(88px + env(safe-area-inset-bottom)); }
  .public-sidebar { padding: 14px; }
  .message-list { padding: 16px; }
  .composer { padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); }
}

@media (min-width: 761px) {
  .mobile-only { display: none !important; }
}
