:root {
  --cream: #F4F1EA;
  --cream-2: #EDE9DF;
  --ink: #2B2926;
  --ink-soft: #5B584F;
  --terracotta: #C2652F;
  --terracotta-dark: #A6531F;
  --border: #E1DCCE;
  --white: #FFFFFF;
  --radius: 14px;
  --font-display: 'Fraunces', serif;
  --font-body: 'Inter', -apple-system, sans-serif;
}

:root[data-theme="dark"] {
  --cream: #1E1C1A;
  --cream-2: #262320;
  --ink: #EDE9E2;
  --ink-soft: #A9A399;
  --terracotta: #D97757;
  --terracotta-dark: #E8916F;
  --border: #38342E;
  --white: #292622;
}

body { transition: background-color 0.15s ease, color 0.15s ease; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--cream);
}
.hidden { display: none !important; }

/* ── Auth screen ─────────────────────────────────────────── */
.auth-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cream);
}
.auth-card {
  width: 360px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  text-align: center;
}
.auth-logo {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  color: var(--terracotta-dark);
}
.auth-sub { color: var(--ink-soft); font-size: 14px; margin: 6px 0 24px; }
.auth-tabs { display: flex; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.auth-tab {
  flex: 1; padding: 10px; border: none; background: none; cursor: pointer;
  font-size: 14px; color: var(--ink-soft); border-bottom: 2px solid transparent;
}
.auth-tab.active { color: var(--terracotta-dark); border-bottom-color: var(--terracotta); font-weight: 600; }
#auth-form { display: flex; flex-direction: column; gap: 10px; }
#auth-form input {
  padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border);
  font-size: 14px; font-family: var(--font-body); background: var(--cream);
}
.btn-primary {
  background: var(--terracotta); color: white; border: none;
  padding: 11px 16px; border-radius: 10px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background 0.15s ease;
}
.btn-primary:hover { background: var(--terracotta-dark); }
.auth-error { color: #B3261E; font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ── App layout ──────────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 260px; flex-shrink: 0; background: var(--cream-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.sidebar-header { padding: 4px 4px 16px 8px; display: flex; align-items: center; justify-content: space-between; }
.brand { font-family: var(--font-display); font-size: 20px; font-weight: 600; color: var(--terracotta-dark); }
.new-chat-btn {
  background: var(--white); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; text-align: left; cursor: pointer; margin-bottom: 12px;
}
.new-chat-btn:hover { background: var(--white); border-color: var(--terracotta); }
.session-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.session-item {
  padding: 9px 10px; border-radius: 8px; font-size: 13.5px; cursor: pointer;
  color: var(--ink-soft);
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
}
.session-item .session-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.session-item:hover, .session-item.active { background: var(--white); color: var(--ink); }
.session-item .del { opacity: 0; font-size: 12px; }
.session-item:hover .del { opacity: 0.6; }
.session-item .del:hover { opacity: 1; color: #B3261E; }
.sidebar-footer {
  border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px;
  display: flex; justify-content: space-between; align-items: center; font-size: 12.5px;
}
.user-email { color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.link-btn { background: none; border: none; color: var(--terracotta-dark); cursor: pointer; font-size: 12.5px; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header {
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; border-bottom: 1px solid var(--border); font-size: 14px; font-weight: 600;
}
.header-right { display: flex; align-items: center; gap: 10px; }
.model-badge {
  font-size: 11.5px; font-weight: 500; color: var(--ink-soft);
  background: var(--cream-2); padding: 4px 10px; border-radius: 100px; border: 1px solid var(--border);
}
.icon-btn {
  background: none; border: none; cursor: pointer; font-size: 16px; color: var(--ink-soft);
  padding: 6px 8px; border-radius: 8px;
}
.icon-btn:hover { background: var(--cream-2); }

.messages { flex: 1; overflow-y: auto; padding: 24px 18%; display: flex; flex-direction: column; gap: 18px; }
@media (max-width: 900px) { .messages { padding: 20px 5%; } }

.msg { display: flex; flex-direction: column; gap: 4px; max-width: 100%; }
.msg-role { font-size: 11.5px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }
.msg.user .msg-bubble {
  align-self: flex-end; background: var(--terracotta); color: white;
  padding: 10px 15px; border-radius: 16px 16px 4px 16px; max-width: 70%;
}
.msg.user { align-items: flex-end; }
.msg.assistant .msg-bubble {
  background: transparent; padding: 2px 0; line-height: 1.6; font-size: 15px;
}
.msg-bubble p { margin: 0 0 10px; }
.msg-bubble pre {
  background: var(--ink); color: var(--cream); padding: 12px 14px; border-radius: 10px;
  overflow-x: auto; font-size: 13px;
}
.msg-attachments { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.msg-attachments .att-chip {
  font-size: 11.5px; background: var(--cream-2); border: 1px solid var(--border);
  padding: 3px 8px; border-radius: 100px; color: var(--ink-soft);
}

.chat-input-bar {
  display: flex; align-items: flex-end; gap: 8px; padding: 14px 18%;
  border-top: 1px solid var(--border); background: var(--cream);
}
@media (max-width: 900px) { .chat-input-bar { padding: 12px 5%; } }
#chat-input {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 14px;
  padding: 11px 14px; font-family: var(--font-body); font-size: 14.5px; max-height: 160px;
  background: var(--white);
}
#chat-input:focus { outline: none; border-color: var(--terracotta); }
.send-btn { padding: 11px 18px; }
.attachment-preview { display: flex; gap: 6px; flex-wrap: wrap; }
.attachment-preview .chip {
  font-size: 11.5px; background: var(--cream-2); border: 1px solid var(--border);
  padding: 4px 8px; border-radius: 100px; display: flex; align-items: center; gap: 4px;
}
.attachment-preview .chip-thumb { width: 20px; height: 20px; border-radius: 4px; object-fit: cover; }
.attachment-preview .chip button { border: none; background: none; cursor: pointer; color: var(--ink-soft); }

/* ── Activity panel ──────────────────────────────────────── */
.activity-panel {
  width: 280px; flex-shrink: 0; border-left: 1px solid var(--border);
  background: var(--cream-2); display: flex; flex-direction: column;
}
.activity-header {
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; font-size: 13.5px; font-weight: 600; border-bottom: 1px solid var(--border);
}
.activity-log { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.activity-empty { color: var(--ink-soft); font-size: 13px; }
.switch-entry {
  background: var(--white); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  font-size: 12.5px;
}
.switch-entry .arrow { color: var(--ink-soft); }
.switch-entry .to { font-weight: 600; color: var(--terracotta-dark); }
.switch-entry .reason { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 11px; }
.switch-entry .ts { display: block; margin-top: 2px; color: var(--ink-soft); font-size: 10.5px; }
