/* Polly: тёплая светлая тема и графитовая тёмная. Акцент задаёт Полина. */

:root {
  --accent: #d97757;
  --accent-ink: #1f1a16;
  --bg: #fbf6f0;
  --surface: #ffffff;
  --raised: #f5eee6;
  --text: #2a2420;
  --muted: #74685e;
  --faint: #b7aca2;
  --border: #ece3d9;
  --user-bubble: color-mix(in srgb, var(--accent) 13%, #ffffff);
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --accent-strong: color-mix(in srgb, var(--accent) 82%, #000000);
  --danger: #c4483b;
  --ok: #3f9a6b;
  --shadow: 0 1px 2px rgb(60 40 20 / 6%), 0 8px 24px rgb(60 40 20 / 8%);
  --overlay: rgb(30 20 10 / 32%);
  --radius: 16px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --sidebar: 288px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141414;
    --surface: #1c1c1c;
    --raised: #242424;
    --text: #ececec;
    --muted: #9b9b9b;
    --faint: #6a6a6a;
    --border: #2c2c2c;
    --user-bubble: color-mix(in srgb, var(--accent) 10%, #2a2a2a);
    --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
    --accent-strong: color-mix(in srgb, var(--accent) 80%, #ffffff);
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 35%);
    --overlay: rgb(0 0 0 / 55%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #141414;
  --surface: #1c1c1c;
  --raised: #242424;
  --text: #ececec;
  --muted: #9b9b9b;
  --faint: #6a6a6a;
  --border: #2c2c2c;
  --user-bubble: color-mix(in srgb, var(--accent) 10%, #2a2a2a);
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --accent-strong: color-mix(in srgb, var(--accent) 80%, #ffffff);
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 35%);
  --overlay: rgb(0 0 0 / 55%);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { overflow: hidden; overscroll-behavior: none; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
a { color: var(--accent-strong); }
[hidden] { display: none !important; }

.icon { width: 20px; height: 20px; flex: none; display: block; }
.icon-sm { width: 16px; height: 16px; }

/* ---------- Каркас ---------- */

.app {
  display: grid;
  grid-template-columns: 1fr;
  height: 100dvh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(86vw, 320px);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 12px) 12px calc(var(--safe-bottom) + 12px);
  transform: translateX(-102%);
  transition: transform 0.25s ease;
  z-index: 30;
}

.app.drawer-open .sidebar { transform: none; box-shadow: var(--shadow); }

.scrim {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 25;
}

.app.drawer-open .scrim { opacity: 1; pointer-events: auto; }

@media (min-width: 900px) {
  .app { grid-template-columns: var(--sidebar) 1fr; }
  .sidebar {
    position: static;
    width: auto;
    transform: none;
    transition: none;
    padding-top: 16px;
  }
  .scrim, .menu-button { display: none !important; }
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 12px;
}

.sidebar-head .clawd { width: 34px; height: 34px; }

.brand {
  font-family: var(--font-round);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.01em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  margin-bottom: 10px;
}

.new-chat:active { transform: scale(0.98); }

.search {
  position: relative;
  margin-bottom: 8px;
}

.search > .icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.search input {
  width: 100%;
  padding: 9px 34px 9px 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 15px;
}

.search .clear {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  border-radius: 8px;
}

.search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }

.chat-list {
  flex: 1;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px;
  -webkit-overflow-scrolling: touch;
}

.list-group {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 14px 10px 6px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
}

.chat-item:hover { background: var(--raised); }
.chat-item.active { background: var(--accent-soft); }

.chat-item .title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item .no-memory { color: var(--muted); }

.search-hit {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: 10px;
}

.search-hit:hover { background: var(--raised); }
.search-hit .hit-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.search-hit .hit-text { font-size: 14px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 1px; }

.empty-note { color: var(--muted); font-size: 14px; padding: 12px 10px; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 8px;
  display: grid;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  font-size: 15px;
  text-decoration: none;
  color: var(--text);
  text-align: left;
}

.nav-item:hover, .nav-item.active { background: var(--raised); }

/* ---------- Основная колонка ---------- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(var(--safe-top) + 8px) 10px 8px;
  min-height: 52px;
  border-bottom: 1px solid transparent;
}

.topbar.scrolled { border-bottom-color: var(--border); }

.topbar .title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

@media (min-width: 900px) {
  .topbar .title { text-align: left; padding-left: 10px; }
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: var(--text);
  flex: none;
}

.icon-button:hover { background: var(--raised); }
.icon-button:active { transform: scale(0.95); }

.offline-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 12px 6px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--raised);
  color: var(--muted);
  font-size: 14px;
}

.offline-bar .clawd { width: 30px; height: 30px; flex: none; }

.view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.thread {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}

/* ---------- Приветствие ---------- */

.welcome {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 20px 40px;
  gap: 6px;
}

.welcome .clawd { width: 132px; height: 121px; margin-bottom: 12px; }

.welcome h1 {
  font-family: var(--font-round);
  font-size: 28px;
  line-height: 1.2;
  margin: 0;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.welcome p { color: var(--muted); margin: 0; max-width: 340px; text-wrap: balance; }

.welcome .chip-row { margin-top: 12px; }

/* ---------- Сообщения ---------- */

.msg { margin: 0 0 18px; scroll-margin-top: 16px; }
.msg.flash { animation: flash 1.6s ease; }

@keyframes flash {
  0%, 30% { background: var(--accent-soft); border-radius: 12px; }
  100% { background: transparent; }
}

.msg.user { display: flex; flex-direction: column; align-items: flex-end; }

.bubble {
  background: var(--user-bubble);
  padding: 9px 14px;
  border-radius: 18px 18px 6px 18px;
  max-width: min(86%, 560px);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.pending .bubble { opacity: 0.7; }

.pending-note {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  margin-bottom: 6px;
  max-width: min(86%, 560px);
}

.attachments img {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--raised);
  cursor: zoom-in;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--raised);
  font-size: 14px;
  max-width: 240px;
}

.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.voice {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--user-bubble);
  border-radius: 18px 18px 6px 18px;
  padding: 10px 14px;
  max-width: min(86%, 420px);
}

.voice-player { display: flex; align-items: center; gap: 10px; }

.voice-play {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.voice-track {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--text) 15%, transparent);
  overflow: hidden;
  min-width: 90px;
}

.voice-track i { display: block; height: 100%; width: 0; background: var(--accent); }
.voice-time { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.voice-text { font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.voice.busy .voice-text { color: var(--muted); }

.msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 4px;
  opacity: 0.85;
}

.msg-actions .icon-button { width: 34px; height: 34px; color: var(--muted); border-radius: 10px; }
.msg-actions .icon-button:hover { color: var(--text); }

@media (hover: hover) and (min-width: 900px) {
  .msg.user .msg-actions { opacity: 0; transition: opacity 0.15s; }
  .msg.user:hover .msg-actions { opacity: 1; }
}

.msg.bot .md { overflow-wrap: anywhere; }

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.75em; }
.md ul, .md ol { margin: 0 0 0.75em; padding-left: 1.4em; }
.md li { margin: 0.2em 0; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--font-round); line-height: 1.3; margin: 1em 0 0.5em; }
.md h1 { font-size: 1.35em; }
.md h2 { font-size: 1.2em; }
.md h3, .md h4 { font-size: 1.05em; }
.md blockquote { margin: 0 0 0.75em; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.md code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.88em; background: var(--raised); padding: 1px 5px; border-radius: 6px; }
.md pre { background: var(--raised); padding: 12px 14px; border-radius: 12px; overflow-x: auto; margin: 0 0 0.75em; }
.md pre code { background: none; padding: 0; font-size: 0.85em; }
.md table { border-collapse: collapse; margin: 0 0 0.75em; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1em 0; }
.md img { max-width: 100%; }

.typing {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  min-height: 40px;
}

.typing .clawd { width: 40px; height: 37px; flex: none; }

.thinking {
  margin: 0 0 8px;
  border-radius: 12px;
  background: var(--raised);
  font-size: 14px;
}

.thinking summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  cursor: pointer;
  color: var(--muted);
  list-style: none;
  user-select: none;
}

.thinking summary::-webkit-details-marker { display: none; }
.thinking[open] summary .chev { transform: rotate(90deg); }
.thinking .chev { transition: transform 0.15s; }

.thinking .thinking-text {
  padding: 0 12px 10px;
  color: var(--muted);
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
}

.memory-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  margin: 8px 0 0;
  padding: 6px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 14px;
}

.memory-note.undone { opacity: 0.6; text-decoration: line-through; }
.memory-note span { min-width: 0; }
.memory-note button { color: var(--accent-strong); font-weight: 600; font-size: 14px; min-height: 32px; padding: 0 4px; flex: none; }

.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.source {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
}

.source span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source img { width: 14px; height: 14px; border-radius: 3px; }

.notice {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  background: var(--raised);
  color: var(--muted);
}

.notice.error { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }

.status-line { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.status-line .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; }

@keyframes pulse { 50% { opacity: 0.3; } }

.to-bottom {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 150px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

/* ---------- Поле ввода ---------- */

.composer {
  padding: 6px 12px calc(var(--safe-bottom) + 10px);
  background: linear-gradient(to bottom, transparent, var(--bg) 18px);
}

.composer-inner { max-width: 760px; margin: 0 auto; }

.composer-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px 4px;
}

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 10px 5px 8px;
  border-radius: 999px;
  background: var(--raised);
  font-size: 13px;
  color: var(--muted);
  max-width: 100%;
}

.model-chip strong { color: var(--text); font-weight: 600; }
.model-chip .costly-dot { width: 7px; height: 7px; border-radius: 50%; background: #e0a33a; }

.memory-chip {
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.box {
  display: flex;
  flex-direction: column;
  padding: 6px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.box-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.box textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  padding: 8px 4px;
  max-height: 180px;
  line-height: 1.4;
  font-size: 16px;
}

.box textarea::placeholder { color: var(--faint); }

.round {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  color: var(--muted);
}

.round:hover { background: var(--raised); color: var(--text); }
.round.primary { background: var(--accent); color: var(--accent-ink); }
.round.primary:disabled { opacity: 0.4; }

.mic {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.mic.recording { background: var(--danger); color: #ffffff; transform: scale(1.12); }

.pending-files { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 4px 8px; }

.pending-file {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 56px;
  min-width: 56px;
  max-width: 200px;
  border-radius: 12px;
  background: var(--raised);
  font-size: 13px;
  padding: 0 28px 0 10px;
}

.pending-file.image { padding: 0; width: 56px; overflow: hidden; }
.pending-file img { width: 56px; height: 56px; object-fit: cover; }
.pending-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-file.loading { opacity: 0.6; }

.pending-file .remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgb(0 0 0 / 55%);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.recording-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  min-width: 0;
  font-size: 15px;
}

.recording-bar .rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; flex: none; }
.recording-bar .rec-time { font-variant-numeric: tabular-nums; min-width: 42px; }
.recording-bar .rec-hint { color: var(--muted); flex: 1; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recording-bar.cancel .rec-hint { color: var(--danger); }

.hint-toast .toast-action { margin-left: 10px; color: inherit; text-decoration: underline; font-weight: 600; min-height: 32px; padding: 0 4px; }

.hint-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 110px);
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 60;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: var(--shadow);
}

/* ---------- Шторки и окна ---------- */

.sheet-scrim {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.2s ease;
}

@keyframes fade { from { opacity: 0; } }

.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  overflow-y: auto;
  border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(var(--safe-bottom) + 16px);
  animation: rise 0.25s ease;
}

@keyframes rise { from { transform: translateY(40px); opacity: 0.5; } }

@media (min-width: 700px) {
  .sheet-scrim { align-items: center; }
  .sheet { border-radius: 22px; padding-top: 18px; padding-bottom: 18px; }
  .sheet-grip { display: none; }
}

.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 10px; }
.sheet h2 { font-family: var(--font-round); font-size: 19px; margin: 4px 4px 12px; }
.sheet h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 16px 4px 8px; }

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border-radius: 14px;
  border: 1px solid transparent;
}

.option:hover { background: var(--raised); }
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option .opt-body { flex: 1; min-width: 0; }
.option .opt-title { font-weight: 600; }
.option .opt-hint { font-size: 13px; color: var(--muted); }
.option .check { color: var(--accent); }

.segmented {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--raised);
}

.segmented button {
  padding: 9px 2px;
  min-width: 0;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.2;
  color: var(--muted);
}

.segmented button.selected { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgb(0 0 0 / 12%); }

.effort-hint { font-size: 13px; color: var(--muted); margin: 8px 4px 0; min-height: 20px; }
.costly-note { color: #b97a10; font-weight: 600; }

:root[data-theme="dark"] .costly-note { color: #e8b04a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .costly-note { color: #e8b04a; } }

.sheet-actions { display: flex; gap: 8px; margin-top: 16px; }

.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  border-radius: 14px;
  font-weight: 600;
  background: var(--raised);
  text-align: center;
}

.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.5; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 88%);
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- Страницы: память, настройки ---------- */

.page { max-width: 640px; margin: 0 auto; padding: 8px 16px 40px; }

.page-hero { display: flex; align-items: center; gap: 14px; margin: 8px 0 18px; }
.page-hero .clawd { width: 56px; height: 52px; flex: none; }
.page-hero h1 { font-family: var(--font-round); font-size: 24px; margin: 0; line-height: 1.2; }
.page-hero p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 10px; }

.memory-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.memory-item:last-child { border-bottom: 0; }
.memory-item .text { flex: 1; padding-top: 7px; overflow-wrap: anywhere; }
.memory-item input { flex: 1; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label, .field-label { font-size: 14px; font-weight: 600; }

.input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 16px;
}

.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; min-width: 0; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 15px;
}

.chip.selected { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.chip.add { color: var(--muted); }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}

.swatch.selected { box-shadow: 0 0 0 2px var(--text); }
.swatch-custom { position: relative; overflow: hidden; background: conic-gradient(#e06c75, #e5c07b, #98c379, #56b6c2, #61afef, #c678dd, #e06c75); }
.swatch-custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.row-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 0;
  text-align: left;
  font-size: 15px;
}

.row-link + .row-link { border-top: 1px solid var(--border); }
.saved-note { color: var(--ok); font-size: 13px; min-height: 18px; margin: 4px 4px 0; }

/* ---------- Знакомство ---------- */

.onboarding {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 16px);
  overflow-y: auto;
}

.ob-top { display: flex; align-items: center; justify-content: space-between; min-height: 40px; max-width: 520px; width: 100%; margin: 0 auto; }
.ob-dots { display: flex; gap: 6px; }
.ob-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.ob-dots i.on { background: var(--accent); }
.ob-skip { color: var(--muted); font-size: 15px; padding: 8px; }

.ob-body {
  flex: 1;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 12px 0;
}

.ob-clawd { display: flex; justify-content: center; }
.ob-clawd .clawd { width: 112px; height: 103px; }
.ob-body h1 { font-family: var(--font-round); font-size: 26px; line-height: 1.2; text-align: center; margin: 0; text-wrap: balance; }
.ob-body .lead { text-align: center; color: var(--muted); margin: -6px 0 6px; text-wrap: balance; }

.ob-options { display: grid; gap: 8px; }
.ob-options.grid-2 { grid-template-columns: 1fr 1fr; }

.ob-option {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 13px 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1.5px solid var(--border);
}

.ob-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.ob-option .emoji { font-size: 22px; line-height: 1; flex: none; }
.ob-option .opt-title { font-weight: 600; }
.ob-option .opt-hint { font-size: 13px; color: var(--muted); }

.look-option { flex-direction: column; gap: 4px; padding: 10px 6px; text-align: center; font-size: 14px; }
.look-option .clawd { width: 64px; height: 59px; }

.ob-nav { display: flex; gap: 10px; width: 100%; max-width: 520px; margin: 0 auto; }

.intro-chat { display: flex; flex-direction: column; gap: 10px; }
.intro-chat .msg { margin: 0; }
.intro-chat .bot-line { background: var(--surface); border: 1px solid var(--border); padding: 10px 14px; border-radius: 18px 18px 18px 6px; max-width: 90%; white-space: pre-wrap; }

.persona-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}

.persona-card .clawd { width: 96px; height: 88px; margin: 0 auto 8px; display: block; }
.persona-card h2 { font-family: var(--font-round); margin: 0 0 6px; font-size: 22px; }
.persona-card .greeting { color: var(--muted); margin: 0 0 14px; text-wrap: balance; }
.persona-card ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; text-align: left; }
.persona-card li { display: flex; gap: 10px; align-items: flex-start; }
.persona-card li::before { content: ""; width: 8px; height: 8px; background: var(--accent); flex: none; margin-top: 8px; }
.persona-card .facts { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 14px; color: var(--muted); text-align: left; }

/* ---------- Вход ---------- */

.gate {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: calc(var(--safe-top) + 24px) 20px calc(var(--safe-bottom) + 24px);
  gap: 12px;
  overflow-y: auto;
}

.gate .clawd { width: 140px; height: 129px; }
.gate h1 { font-family: var(--font-round); font-size: 28px; line-height: 1.2; margin: 8px 0 0; text-wrap: balance; }
.gate p { color: var(--muted); max-width: 360px; margin: 0; text-wrap: balance; }
.gate form { width: 100%; max-width: 360px; display: grid; gap: 10px; margin-top: 8px; }
.gate .error { color: var(--danger); font-size: 14px; min-height: 20px; }
.gate .steps { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 12px 16px; max-width: 360px; font-size: 15px; }
.gate .steps ol { margin: 6px 0 0; padding-left: 20px; }
.gate .steps li { margin: 4px 0; }

/* ---------- Clawd ---------- */

.clawd { display: block; overflow: visible; shape-rendering: crispEdges; }
.clawd .eyes { transform-box: fill-box; transform-origin: center; animation: blink 4.5s infinite; }
.clawd .zz { display: none; }
.clawd .closed { display: none; }
.clawd .dots { display: none; }

@keyframes blink {
  0%, 93%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}

.clawd.wave .arm-r { animation: wave 0.9s steps(1) 3; }

@keyframes wave {
  0% { transform: translateY(0); }
  25% { transform: translateY(-1px); }
  50% { transform: translateY(0); }
  75% { transform: translateY(-1px); }
}

.clawd.think .body-group { animation: bob 0.8s steps(2) infinite; }
.clawd.think .dots { display: inline; }
.clawd.think .dots rect { animation: dot 1.2s infinite; opacity: 0.2; }
.clawd.think .dots rect:nth-child(2) { animation-delay: 0.2s; }
.clawd.think .dots rect:nth-child(3) { animation-delay: 0.4s; }

@keyframes bob { 50% { transform: translateY(-0.5px); } }
@keyframes dot { 30% { opacity: 1; } 60% { opacity: 0.2; } }

.clawd.sleep .eyes { display: none; }
.clawd.sleep .closed { display: inline; }
.clawd.sleep .zz { display: inline; }
.clawd.sleep .zz rect { animation: zz 2.4s infinite; opacity: 0; }
.clawd.sleep .zz rect:nth-child(2) { animation-delay: 0.8s; }
.clawd.sleep .zz rect:nth-child(3) { animation-delay: 1.6s; }
.clawd.sleep .body-group { animation: breathe 3s ease-in-out infinite; transform-origin: 50% 100%; transform-box: fill-box; }

@keyframes zz {
  0% { opacity: 0; transform: translate(0, 0); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translate(1px, -2px); }
}

@keyframes breathe { 50% { transform: scaleY(0.96); } }

.clawd.hop .body-group { animation: hop 0.5s steps(2) 2; }
@keyframes hop { 50% { transform: translateY(-1px); } }

@media (prefers-reduced-motion: reduce) {
  .clawd *, .clawd { animation: none !important; }
  .sidebar, .sheet, .sheet-scrim { animation: none; transition: none; }
}

/* ---------- Админка ---------- */

.admin-wrap { height: 100dvh; overflow-y: auto; }
.admin { max-width: 860px; margin: 0 auto; padding: calc(var(--safe-top) + 16px) 16px 40px; }
.admin-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.admin-head .clawd { width: 44px; height: 41px; }
.admin-head h1 { font-family: var(--font-round); font-size: 24px; margin: 0; flex: 1; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; padding: 6px 4px; border-bottom: 1px solid var(--border); }
table.list td { padding: 8px 4px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar { height: 6px; border-radius: 3px; background: var(--accent); min-width: 2px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--raised); color: var(--muted); white-space: nowrap; }
.badge.active { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge.revoked, .badge.expired { color: var(--danger); }
.link-button { color: var(--accent-strong); font-weight: 600; font-size: 14px; min-height: 32px; padding: 0 4px; display: inline-flex; align-items: center; text-decoration: none; }
.invite-result { display: grid; gap: 10px; justify-items: center; text-align: center; margin-top: 12px; }
.invite-result .qr { background: #ffffff; padding: 10px; border-radius: 14px; width: 220px; height: 220px; }
.invite-result .qr svg { width: 100%; height: 100%; display: block; }
.invite-result code { word-break: break-all; font-size: 13px; background: var(--raised); padding: 6px 10px; border-radius: 8px; max-width: 100%; }
.error-line { font-family: ui-monospace, Menlo, monospace; font-size: 12px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Переносы без одиноких слов в конце абзаца */
p, .lead, .opt-hint, .effort-hint, .notice, .empty-note { text-wrap: pretty; }

/* Знакомство: ответ бота с разметкой */
.intro-chat .bot-line { white-space: normal; }
.intro-chat .bot-line p { margin: 0 0 0.5em; }
.intro-chat .bot-line > :last-child { margin-bottom: 0; }

/* Админка на телефоне: форма в столбик, даты без переносов */
@media (max-width: 600px) {
  #inviteForm { flex-direction: column; }
  #inviteForm .input, #inviteForm .btn { width: 100% !important; flex: none; }
}
table.list td.when, table.list th { white-space: nowrap; }
