/* Quimby — design tokens & layout (see qcat.app/DESIGN.md) */

:root {
  --bg:           #FBF8F3;
  --surface:      #FFFFFF;
  --surface-alt:  #F2EDE3;
  --ink:          #2A1F1A;
  --ink-soft:     #6B5A50;
  --brand:        #6BA37A;
  --brand-deep:   #4A7A58;
  --brand-soft:   #DBE9DE;
  --accent:       #D89B8C;
  --brody:        #C8915A;
  --warn:         #C8853A;
  --err:          #B5453A;

  --shadow-sm:    0 1px 2px rgba(42, 31, 26, 0.06);
  --shadow-md:    0 4px 16px rgba(42, 31, 26, 0.08);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-bubble: 18px;

  --font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --font-body:    'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --max-width: 720px;
  --gap: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #1A1614;
    --surface:     #26201D;
    --surface-alt: #332A26;
    --ink:         #F5EDE2;
    --ink-soft:    #A89A8E;
    --brand:       #8BC59A;
    --brand-deep:  #6BA37A;
    --brand-soft:  #2D3D33;
    --accent:      #E8B5A8;
    --brody:       #D8A572;
    --shadow-sm:   0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md:   0 4px 16px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

button { font-family: inherit; }
a { color: var(--brand-deep); }
a:hover { color: var(--brand); }

/* ── App shell ───────────────────────────────────────────────────────── */

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px env(safe-area-inset-bottom, 0);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--surface-alt);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.2rem;
  letter-spacing: -0.01em;
}

.topbar-brand img { width: 28px; height: 28px; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease, color 120ms ease;
}
.icon-btn:hover { background: var(--surface-alt); color: var(--ink); }

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--surface-alt);
}

/* ── Conversation surface ────────────────────────────────────────────── */

.thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px 0 96px;
  overflow-y: auto;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 14vh 8px 0;
  color: var(--ink-soft);
}
.empty-mark { width: 96px; height: 96px; opacity: 0.95; }
.empty-greeting {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 2.4rem;
  margin: 18px 0 4px;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.empty-prompt {
  font-size: 1.05rem;
  margin: 0;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: msg-in 220ms ease-out both;
}
.msg-user { align-self: flex-end; align-items: flex-end; }
.msg-quimby { align-self: flex-start; align-items: flex-start; }

.msg-meta {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 0 6px 4px;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}

.msg-bubble {
  background: var(--surface);
  border: 1px solid var(--surface-alt);
  border-radius: var(--radius-bubble);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  line-height: 1.5;
}
.msg-user .msg-bubble {
  background: var(--brand-soft);
  border-color: transparent;
  color: var(--ink);
  border-bottom-right-radius: 6px;
}
.msg-quimby .msg-bubble {
  border-bottom-left-radius: 6px;
}
.msg-bubble-soft {
  background: var(--surface-alt);
  border-color: transparent;
  color: var(--ink-soft);
  font-style: italic;
}

.msg-footer { margin-top: 6px; padding: 0 6px; }

.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border: 1px solid var(--ink-soft);
  color: var(--ink-soft);
  background: transparent;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: help;
}
.source-dot {
  width: 6px; height: 6px;
  background: currentColor;
  border-radius: 50%;
}
.source-badge.badge-openclaw {
  border-color: var(--brand);
  color: var(--brand-deep);
}
.source-badge.badge-bcat {
  border-color: var(--brody);
  color: var(--brody);
}

.msg-cursor {
  display: inline-block;
  width: 0.5ch;
  color: var(--ink-soft);
  animation: cursor-blink 1.1s steps(2, start) infinite;
  margin-left: 1px;
}
.msg-cursor.is-done { display: none; }

.thinking-line { display: inline-flex; align-items: center; gap: 8px; }
.thinking-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ink-soft);
  animation: pulse 1.2s ease-in-out infinite;
}
.thinking-dot.brody { background: var(--brody); }

/* ── Composer ────────────────────────────────────────────────────────── */

.composer {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 12px 0 max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--surface-alt);
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--surface-alt);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 14px;
  box-shadow: var(--shadow-md);
}
.composer-input {
  flex: 1;
  border: 0;
  background: transparent;
  resize: none;
  font: inherit;
  color: var(--ink);
  max-height: 30vh;
  min-height: 24px;
  padding: 6px 0;
  outline: none;
}
.composer-input::placeholder { color: var(--ink-soft); }

.composer-btn {
  appearance: none;
  border: 0;
  background: var(--brand);
  color: white;
  width: 38px; height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600;
  transition: background 120ms ease, transform 80ms ease;
}
.composer-btn:hover { background: var(--brand-deep); }
.composer-btn:disabled { background: var(--surface-alt); color: var(--ink-soft); cursor: not-allowed; }
.composer-btn:active:not(:disabled) { transform: scale(0.95); }

.composer-mic {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--surface-alt);
}
.composer-mic:hover { background: var(--surface-alt); color: var(--ink); }
.composer-mic.is-recording {
  color: var(--accent);
  border-color: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.composer-hint {
  margin: 6px 4px 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
  text-align: right;
}

/* ── Login ───────────────────────────────────────────────────────────── */

.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--surface-alt);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.login-mark { width: 64px; height: 64px; }
.login-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.6rem;
  margin: 14px 0 4px;
}
.login-sub { color: var(--ink-soft); margin: 0 0 24px; }

.login-providers {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.provider-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--surface-alt);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
  width: 100%;
  max-width: 280px;
  transition: background 120ms ease, border-color 120ms ease;
}
.provider-btn:hover { background: var(--surface-alt); }
.provider-icon {
  display: inline-block;
  width: 20px;
  text-align: center;
  font-weight: 700;
  color: var(--ink-soft);
}

.login-fineprint {
  margin-top: 22px;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

/* ── Dialogs / sheets ────────────────────────────────────────────────── */

dialog.qsheet {
  border: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  max-width: var(--max-width);
  margin: auto auto 0;
  box-shadow: var(--shadow-md);
}
dialog.qsheet::backdrop { background: rgba(42, 31, 26, 0.4); }

.qsheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--surface-alt);
}
.qsheet-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  margin: 0;
}
.qsheet-body { padding: 14px 18px 22px; }

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.tool-tile {
  appearance: none;
  border: 1px solid var(--surface-alt);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  padding: 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}
.tool-tile:hover { border-color: var(--brand); background: var(--surface-alt); }
.tool-tile-name { font-weight: 600; display: block; margin-bottom: 2px; }
.tool-tile-desc { color: var(--ink-soft); font-size: 0.85rem; }

/* ── Animations ──────────────────────────────────────────────────────── */

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}
@keyframes cursor-blink {
  0%, 50%   { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .msg, .thinking-dot, .msg-cursor, .composer-mic.is-recording { animation: none !important; }
}

/* Mobile tweaks */
@media (max-width: 480px) {
  .empty-greeting { font-size: 2rem; }
  .msg { max-width: 92%; }
}

/* ── Themes ──────────────────────────────────────────────────────────── */
/*
 * data-theme on <html>:
 *   warm_cottage   (default light)
 *   quiet_dark     (dark, low-contrast, cozy at night)
 *   polaroid_stack (sepia/cream w/ photo accents)
 *   auto           (follows OS — the prefers-color-scheme media block above)
 *
 * Themes only override tokens. Layout never changes.
 */

html[data-theme="warm_cottage"] {
  --bg:          #FBF8F3;
  --surface:     #FFFFFF;
  --surface-alt: #F2EDE3;
  --ink:         #2A1F1A;
  --ink-soft:    #6B5A50;
  --brand:       #6BA37A;
  --brand-deep:  #4A7A58;
  --brand-soft:  #DBE9DE;
  --accent:      #D89B8C;
  --brody:       #C8915A;
  color-scheme: light;
}

html[data-theme="quiet_dark"] {
  --bg:          #15110F;
  --surface:     #1F1A17;
  --surface-alt: #2A231F;
  --ink:         #EFE7DC;
  --ink-soft:    #998A7C;
  --brand:       #8BC59A;
  --brand-deep:  #6BA37A;
  --brand-soft:  #2D3D33;
  --accent:      #E8B5A8;
  --brody:       #D8A572;
  --shadow-sm:   0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-md:   0 4px 16px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

html[data-theme="polaroid_stack"] {
  --bg:          #EFE6D3;
  --surface:     #FAF1DD;
  --surface-alt: #E2D6BD;
  --ink:         #3A2A1F;
  --ink-soft:    #7B6248;
  --brand:       #7B8C5C;
  --brand-deep:  #5A6B40;
  --brand-soft:  #D8DCB8;
  --accent:      #C9846A;
  --brody:       #B7763C;
  --shadow-sm:   0 1px 2px rgba(60, 40, 20, 0.10);
  --shadow-md:   0 4px 16px rgba(60, 40, 20, 0.12);
  color-scheme: light;
}

/* ── Login (extended for full warm-cottage redesign) ─────────────────── */

.login-page {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(1100px 600px at 80% -10%, color-mix(in oklab, var(--accent) 30%, transparent) 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, color-mix(in oklab, var(--brand-soft) 60%, transparent) 0%, transparent 60%),
    var(--bg);
  display: grid;
  place-items: center;
  padding: 24px 16px;
  overflow: hidden;
}

.login-wrap {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.login-mast {
  text-align: center;
}
.login-mast img {
  width: 76px; height: 76px;
  border-radius: 22px;
  background: var(--surface);
  padding: 10px;
  box-shadow: var(--shadow-md);
}
.login-mast h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 2rem;
  letter-spacing: -0.01em;
  margin: 14px 0 4px;
}
.login-mast p {
  color: var(--ink-soft);
  margin: 0;
}

.login-stack {
  background: var(--surface);
  border: 1px solid var(--surface-alt);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.provider-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 11px 18px;
  border-radius: 12px;
  border: 1px solid var(--surface-alt);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
  width: 100%;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
}
.provider-btn:hover { background: var(--surface-alt); border-color: var(--ink-soft); }
.provider-btn:active { transform: scale(0.99); }
.provider-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.provider-apple {
  background: #000;
  color: #fff;
  border-color: #000;
}
.provider-apple:hover { background: #111; border-color: #111; }
.provider-apple svg { color: #fff; }

.divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  color: var(--ink-soft);
  font-size: 0.78rem;
  margin: 6px 2px;
}
.divider::before, .divider::after {
  content: "";
  height: 1px;
  background: var(--surface-alt);
}

.email-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.email-form label {
  font-size: 0.82rem;
  color: var(--ink-soft);
}
.email-input {
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--surface-alt);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  outline: none;
  transition: border-color 120ms ease, background 120ms ease;
}
.email-input:focus { border-color: var(--brand); background: var(--surface); }
.email-submit {
  appearance: none;
  border: 0;
  background: var(--brand);
  color: #fff;
  padding: 11px 18px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease;
}
.email-submit:hover { background: var(--brand-deep); }
.email-submit:active { transform: scale(0.99); }
.email-submit:disabled { background: var(--surface-alt); color: var(--ink-soft); cursor: not-allowed; }

.code-box {
  letter-spacing: 0.4em;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 1.2rem;
}

.login-banner {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  display: none;
}
.login-banner.is-error { background: color-mix(in oklab, var(--err) 12%, var(--surface)); color: var(--err); display: block; }
.login-banner.is-info  { background: var(--brand-soft); color: var(--brand-deep); display: block; }

.login-fineprint {
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 2px 0 0;
}

/* ── Profile page ────────────────────────────────────────────────────── */

.profile-wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}
.profile-section {
  background: var(--surface);
  border: 1px solid var(--surface-alt);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin: 14px 0;
  box-shadow: var(--shadow-sm);
}
.profile-section h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  margin: 0 0 10px;
}
.profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--surface-alt);
}
.profile-row:last-child { border-bottom: 0; }
.profile-row .label   { color: var(--ink); font-weight: 500; }
.profile-row .desc    { color: var(--ink-soft); font-size: 0.85rem; }

.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.theme-card {
  appearance: none;
  border: 2px solid var(--surface-alt);
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 10px;
  cursor: pointer;
  text-align: left;
  transition: border-color 120ms ease, transform 80ms ease;
}
.theme-card:hover { border-color: var(--ink-soft); }
.theme-card.is-active { border-color: var(--brand); }
.theme-card .swatch {
  display: flex;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 6px;
  border: 1px solid var(--surface-alt);
}
.theme-card .swatch span { flex: 1; }
.theme-card .name { font-weight: 600; font-size: 0.92rem; }
.theme-card .desc { color: var(--ink-soft); font-size: 0.78rem; }

.toggle {
  position: relative;
  width: 42px; height: 24px;
  appearance: none;
  background: var(--surface-alt);
  border-radius: 999px;
  cursor: pointer;
  transition: background 140ms ease;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 140ms ease;
  box-shadow: var(--shadow-sm);
}
.toggle:checked { background: var(--brand); }
.toggle:checked::after { transform: translateX(18px); }

.btn {
  appearance: none;
  border: 1px solid var(--surface-alt);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 999px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--surface-alt); }
.btn.btn-danger { color: var(--err); border-color: color-mix(in oklab, var(--err) 30%, var(--surface-alt)); }
.btn.btn-danger:hover { background: color-mix(in oklab, var(--err) 10%, var(--surface)); }
.btn.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.btn-primary:hover { background: var(--brand-deep); border-color: var(--brand-deep); }
