:root {
  --bg: #f7f6f3;
  --sidebar-bg: #23211e;
  --sidebar-text: #d8d4cc;
  --accent: #c8552c;
  --accent-soft: #f4e3db;
  --text: #2a2723;
  --muted: #8a857c;
  --bubble-user: #e9e2d6;
  --bubble-assistant: #ffffff;
  --border: #e3ded4;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
}

#app { display: flex; height: 100vh; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px;
  gap: 8px;
}
.brand { font-weight: 700; letter-spacing: 0.04em; font-size: 15px; }
#new-chat-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}
#new-chat-btn:hover { filter: brightness(1.1); }

#chat-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  flex: 1;
}
#chat-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  margin-bottom: 2px;
}
#chat-list li:hover { background: rgba(255,255,255,0.07); }
#chat-list li.active { background: rgba(255,255,255,0.14); }
#chat-list .title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#chat-list .chat-action {
  background: none;
  border: none;
  color: var(--sidebar-text);
  opacity: 0;
  cursor: pointer;
  font-size: 12px;
  padding: 2px;
}
#chat-list li:hover .chat-action { opacity: 0.7; }
#chat-list .chat-action:hover { opacity: 1; }

/* ---------- main ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: #fffdf9;
}
#chat-title { font-weight: 600; font-size: 15px; }
.header-controls { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
#reasoning-select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  background: #fff;
  font-size: 13px;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 12px;
}
.msg {
  max-width: 760px;
  margin: 0 auto 18px;
  padding: 0 24px;
}
.msg .bubble {
  padding: 12px 16px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.55;
  font-size: 14.5px;
}
.msg.user .bubble {
  background: var(--bubble-user);
  margin-left: 60px;
}
.msg.assistant .bubble {
  background: var(--bubble-assistant);
  border: 1px solid var(--border);
  margin-right: 60px;
}
.msg .meta {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 5px;
  padding: 0 4px;
}
.msg .attachments {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
  padding: 0 4px;
}
.reasoning-block {
  font-size: 12.5px;
  color: var(--muted);
  border-left: 3px solid var(--accent-soft);
  padding: 4px 10px;
  margin: 0 0 8px;
  white-space: pre-wrap;
  max-height: 160px;
  overflow-y: auto;
}
.reasoning-toggle {
  font-size: 12px;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 4px 4px;
}
.empty-state {
  text-align: center;
  color: var(--muted);
  margin-top: 18vh;
  font-size: 15px;
}

/* ---------- composer ---------- */
#composer {
  border-top: 1px solid var(--border);
  background: #fffdf9;
  padding: 12px 24px 10px;
}
.composer-row {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
#message-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14.5px;
  font-family: inherit;
  max-height: 180px;
  outline: none;
}
#message-input:focus { border-color: var(--accent); }
#send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
}
#send-btn:disabled { opacity: 0.45; cursor: default; }
#attach-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  cursor: pointer;
  font-size: 15px;
}
#attachment-bar {
  max-width: 760px;
  margin: 0 auto 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.attachment-chip {
  background: var(--accent-soft);
  border-radius: 6px;
  font-size: 12px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.attachment-chip button { background: none; border: none; cursor: pointer; }
#status-line {
  max-width: 760px;
  margin: 6px auto 0;
  font-size: 12px;
  color: var(--muted);
  min-height: 15px;
}
#status-line.error { color: #b3362c; }

/* ---------------- storage status & backup controls ---------------- */
.sidebar-footer {
  margin-top: auto;
  padding: 10px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 11.5px;
}
#storage-status { color: #9ba8a2; margin-bottom: 8px; line-height: 1.35; }
#storage-status.ok { color: #7fbf8e; }
#storage-status.warn { color: #d9b45b; }
#storage-status.error { color: #e0776c; font-weight: 600; }
.backup-controls { display: flex; gap: 6px; }
.backup-controls button {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  color: #ddd;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 6px 4px;
  font-size: 11px;
  cursor: pointer;
}
.backup-controls button:hover { background: rgba(255, 255, 255, 0.16); }

/* ---------- sidebar legal links ---------- */
.legal-links { margin-top: 8px; font-size: 11px; color: #8b877f; }
.legal-links a { color: #8b877f; text-decoration: none; }
.legal-links a:hover { color: #d8d4cc; }

/* ---------- public pages (about/contact/privacy/terms/errors) ---------- */
body.public-page { height: auto; min-height: 100%; }
.public-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.public-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.public-brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 18px;
  color: var(--accent);
  text-decoration: none;
}
.public-nav { display: flex; gap: 14px; font-size: 14px; }
.public-nav a { color: var(--muted); text-decoration: none; }
.public-nav a:hover { color: var(--accent); }
.public-main { flex: 1; padding: 10px 0 30px; line-height: 1.6; font-size: 15px; }
.public-main h1 { font-size: 26px; margin: 22px 0 10px; }
.public-main h2 { font-size: 17px; margin: 24px 0 8px; }
.public-main a { color: var(--accent); }
.public-main ul { padding-left: 22px; }
.public-main li { margin-bottom: 6px; }
.page-date { color: var(--muted); font-size: 13px; }
.public-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  font-size: 12.5px;
  color: var(--muted);
}
.public-footer a { color: var(--muted); }
.public-footer a:hover { color: var(--accent); }
.disclosure { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* ---------- cloud backup status ---------- */
#cloud-status { color: #9ba8a2; margin: 10px 0 8px; line-height: 1.35; }
#cloud-status.ok { color: #7fbf8e; }
#cloud-status.warn { color: #d9b45b; }
#cloud-status.error { color: #e0776c; font-weight: 600; }

/* ---------- brand logo ---------- */
.logo-mark {
  height: 32px;
  width: auto;
  display: block;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
}
.brand-text {
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 15px;
}

/* ---------- login logo ---------- */
.login-logo {
  margin-bottom: 14px;
}
.login-logo img {
  height: 64px;
  width: auto;
  margin-bottom: 8px;
}
.login-wordmark {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}
.login-url {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  font-style: italic;
  color: var(--muted);
  margin-top: 2px;
}

/* ---------- public header brand ---------- */
.public-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.public-brand .logo-mark {
  height: 34px;
}
.public-brand .brand-text {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}

/* ---------- public hero ---------- */
.public-hero {
  text-align: center;
  padding: 28px 0 18px;
  margin-bottom: 8px;
}
.public-hero.small {
  padding: 14px 0 8px;
}
.public-hero img {
  height: 110px;
  width: auto;
  margin-bottom: 10px;
}
.public-hero.small img {
  height: 64px;
}
.hero-wordmark {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}
.hero-url {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  font-style: italic;
  color: var(--muted);
  margin-top: 4px;
}
.public-hero.small .hero-wordmark {
  font-size: 22px;
}
.public-hero.small .hero-url {
  font-size: 13px;
}
