/* ===========================================================
   Clod — design system
   The chrome is the joke: a polished, real-feeling product
   that takes itself completely seriously.
   =========================================================== */

:root {
  --bg: #fafaf7;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --ink-2: #4a4a4a;
  --muted: #8a8a85;
  --line: #ececec;
  --line-2: #e3e3e0;
  --accent: #111111;
  --accent-ink: #ffffff;
  --chip: #f1efe9;
  --danger: #c2410c;
  --good: #166534;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 10px;
  --radius-sm: 6px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Inter",
    "Segoe UI", Helvetica, Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Apple Garamond", Baskerville,
    "Times New Roman", Times, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}

input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

/* ===========================================================
   Themes
   =========================================================== */
html[data-theme="dark"] {
  --bg: #14130f;
  --panel: #1c1b16;
  --ink: #f3efe6;
  --ink-2: #c8c3b5;
  --muted: #8a8576;
  --line: #2a2823;
  --line-2: #34322c;
  --accent: #f1efe6;
  --accent-ink: #14130f;
  --chip: #25231d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.3);
}
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #14130f;
    --panel: #1c1b16;
    --ink: #f3efe6;
    --ink-2: #c8c3b5;
    --muted: #8a8576;
    --line: #2a2823;
    --line-2: #34322c;
    --accent: #f1efe6;
    --accent-ink: #14130f;
    --chip: #25231d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.3);
  }
}
html[data-theme="dark"] .sidebar { background: var(--chip); }
html[data-theme="dark"] .bubble { background: #25231d; }
html[data-theme="dark"] .composer textarea { background: #25231d; color: var(--ink); }
html[data-theme="dark"] .persona-card { background: #1c1b16; }
html[data-theme="dark"] .persona-card.selected { background: #25231d; }
html[data-theme="dark"] .testimonials blockquote { background: #1c1b16; }
html[data-theme="dark"] .btn { background: #1c1b16; }
html[data-theme="dark"] .btn:hover { background: #25231d; }
html[data-theme="dark"] .btn.danger { background: #2a1d18; }
html[data-theme="dark"] .share-btn { background: #1c1b16; }

/* Dev console: only visible when URL has ?dev=1 */
html:not(.show-dev) .view-dev { display: none !important; }

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

/* ===========================================================
   Buttons
   =========================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--ink);
  font-weight: 500;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s;
}
.btn:hover {
  background: #f5f5f0;
}
.btn:active {
  transform: translateY(1px);
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn.primary:hover {
  background: #000;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
}
.btn.ghost:hover {
  background: var(--chip);
}
.btn.wide {
  width: 100%;
}
.btn.danger {
  border-color: #f0c8b0;
  color: var(--danger);
  background: #fff5ef;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===========================================================
   Onboarding / Personality picker
   =========================================================== */
.onboarding {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.onb-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 720px;
  padding: 40px 44px;
}
.onb-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.logo-mark {
  width: 40px;
  height: 40px;
  background: transparent url("clod-mascot.png") center / 116% no-repeat;
  border-radius: 10px;
  flex: 0 0 auto;
}
.logo-mark.small {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: transparent url("clod-mascot.png") center / 116% no-repeat;
}
.logo-word {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.01em;
}
.onb-card h1 {
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}
.onb-sub {
  color: var(--muted);
  margin: 0 0 24px;
}
.persona-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.persona-card {
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 18px 18px 16px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, transform 0.05s;
  text-align: left;
  display: block;
  width: 100%;
}
.persona-card:hover {
  border-color: #c7c7c0;
}
.persona-card.selected {
  border-color: var(--accent);
  background: #faf8f2;
}
.persona-card .pc-version {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.persona-card .pc-name {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 6px;
}
.persona-card .pc-desc {
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.45;
}
.onb-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  font-size: 13px;
}

/* ===========================================================
   App shell
   =========================================================== */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  /* Fall back to dvh where supported — excludes iOS Safari's URL bar so the
     composer is always above the fold even when the address bar is showing. */
  height: 100dvh;
}

/* sidebar */
.sidebar {
  background: var(--chip);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 14px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.brand-name {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.brand-tag {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}
.nav-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-size: 14px;
}
.nav-item:hover {
  background: rgba(0, 0, 0, 0.04);
}
.nav-item.active {
  background: rgba(0, 0, 0, 0.07);
  color: var(--ink);
  font-weight: 500;
}

.sidebar-section {
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.ss-title {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 8px 8px;
}
.recent {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.recent li {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.recent li:hover {
  background: rgba(0, 0, 0, 0.04);
}
.recent-empty {
  color: var(--muted) !important;
  font-style: italic;
  cursor: default !important;
}
.recent-empty:hover {
  background: transparent !important;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 4px;
  font-size: 12px;
  color: var(--muted);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b5b5b0;
}
.status-dot.live {
  background: #22c55e;
}
.status-dot.demo {
  background: #d4a017;
}

/* main */
.main {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  position: relative;
  overflow: hidden;
}
.view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.view.hidden {
  display: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
}
.persona-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 8px;
  background: var(--chip);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
}
.persona-chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.topbar-right {
  font-size: 12px;
  color: var(--muted);
}

/* chat */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}
.msg-row {
  display: flex;
  gap: 12px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}
.msg-row.user {
  flex-direction: row-reverse;
}
.avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  background: transparent url("clod-mascot.png") center / contain no-repeat;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
  margin-top: 2px;
  color: transparent;
}
.msg-row.user .avatar {
  background: #c7c5be;
  color: #fff;
}
.bubble {
  background: #f5f4ee;
  padding: 11px 14px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.55;
  font-size: 15px;
}
.msg-row.user .bubble {
  background: #111;
  color: #fff;
}
.msg-row {
  flex-wrap: wrap;
}
.bubble-actions {
  width: 100%;
  padding-left: 44px; /* align under bubble, past avatar */
  margin-top: 6px;
}
.msg-row.user .bubble-actions {
  display: none;
}
.share-btn {
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.share-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Share preview modal */
.share-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 14, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
  backdrop-filter: blur(3px);
}
.share-modal {
  background: var(--panel);
  border-radius: 18px;
  padding: 18px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.share-canvas-wrap {
  margin-bottom: 14px;
}
.share-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.bubble.typing::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

.composer {
  display: flex;
  gap: 10px;
  padding: 14px 24px 22px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}
#input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  outline: none;
  max-height: 180px;
  line-height: 1.4;
  transition: border-color 0.12s, box-shadow 0.12s;
}
#input:focus {
  border-color: #b5b5b0;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04);
}

/* ===========================================================
   Other views
   =========================================================== */
.view-settings,
.view-about,
.view-persona {
  padding: 32px 40px;
  overflow-y: auto;
}
.view h2 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 28px;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
.view h3 {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-2);
  margin: 28px 0 10px;
}
.setting {
  border-top: 1px solid var(--line);
  padding: 18px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.setting label {
  font-weight: 500;
  font-size: 13px;
  color: var(--ink-2);
}
.setting input[type="password"],
.setting input[type="text"],
.setting select {
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 8px;
  padding: 9px 12px;
  width: 100%;
  max-width: 480px;
}
.setting .row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--ink-2);
}

.testimonials {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 8px;
}
.testimonials blockquote {
  margin: 0;
  padding: 14px 18px;
  background: #f6f5ef;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--ink-2);
  font-style: italic;
}
.testimonials cite {
  display: block;
  font-style: normal;
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  font-family: var(--font);
  letter-spacing: 0.02em;
}

/* ===========================================================
   Responsive
   =========================================================== */
.hamburger {
  display: none;
  background: transparent;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 20px;
  line-height: 1;
  margin-right: 10px;
  cursor: pointer;
  color: var(--ink);
  padding: 0;
}
.hamburger:hover { background: var(--chip); }

.sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 90;
}
.sidebar-scrim.show { display: block; }

@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    height: 100dvh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.2);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .hamburger { display: inline-flex; align-items: center; justify-content: center; }
  .onb-card {
    padding: 22px 18px 16px;
  }
  .onb-card h1 { font-size: 24px; }
  .onb-sub { margin-bottom: 14px; font-size: 13px; }
  .persona-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 14px;
  }
  .persona-card {
    padding: 10px 12px 9px;
  }
  .persona-card .pc-version { font-size: 10px; margin-bottom: 2px; }
  .persona-card .pc-name { font-size: 14px; margin-bottom: 3px; }
  .persona-card .pc-desc { font-size: 11px; line-height: 1.35; }
  .onb-foot { padding-top: 10px; }
  .onb-logo { margin-bottom: 14px; }
  .view-settings,
  .view-about,
  .view-persona {
    padding: 22px 18px;
  }
  .topbar { padding: 12px 16px; }
  .composer { padding: 12px 16px 16px; }
  .messages { padding: 18px 16px 8px; }
  .msg-row { max-width: 100%; }
}
