/* ============ FABLE — modern light ============ */
:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-2: #f3f1ed;
  --border: #e7e3dc;
  --border-strong: #d8d3c9;
  --text: #1f1812;
  --text-soft: #4d453c;
  --muted: #948b7e;
  --accent: #ff5c1f;
  --accent-deep: #e04a12;
  --accent-soft: rgba(255, 92, 31, 0.1);
  --danger: #d33d2a;
  --radius: 14px;
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font: 'Instrument Sans', system-ui, sans-serif;
  --font-mono: 'Fira Code', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  position: relative;
  background:
    radial-gradient(600px 320px at 50% -160px, rgba(255, 92, 31, 0.07), transparent 65%),
    var(--bg);
}

/* --- header --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  box-shadow: 0 4px 14px rgba(255, 92, 31, 0.3);
}

.brand-text { display: flex; flex-direction: column; }

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
}

.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.18s ease;
}

.icon-btn svg { width: 17px; height: 17px; }

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

/* --- chat --- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 8px;
  scroll-behavior: smooth;
}

.chat::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
.chat::-webkit-scrollbar-thumb:hover { background: #c4beb1; }

/* --- empty state --- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 18px 20px;
  animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.empty-emblem {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  margin-bottom: 20px;
  box-shadow: 0 8px 28px rgba(255, 92, 31, 0.35);
}

.empty-state h1 {
  font-family: var(--font-display);
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 7px;
}

.empty-state p {
  color: var(--muted);
  font-size: 13.5px;
  margin-bottom: 26px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(31, 24, 18, 0.05);
  transition: all 0.18s ease;
}

.chip:hover {
  color: var(--accent-deep);
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

/* --- messages --- */
.messages { display: flex; flex-direction: column; gap: 14px; padding-bottom: 8px; }

.msg {
  max-width: 88%;
  animation: msg-in 0.3s ease both;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  padding: 9px 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.5;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(255, 92, 31, 0.25);
}

.msg.assistant {
  align-self: flex-start;
  width: 100%;
  max-width: 100%;
}

.msg-author {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-deep);
  margin-bottom: 6px;
}

.msg-body {
  line-height: 1.6;
  word-wrap: break-word;
  color: var(--text);
  font-size: 14px;
}

.msg-body p { margin: 0 0 10px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body h1, .msg-body h2, .msg-body h3 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 16px 0 8px;
}
.msg-body h1 { font-size: 17.5px; }
.msg-body h2 { font-size: 16px; }
.msg-body h3 { font-size: 14.5px; }
.msg-body ul, .msg-body ol { margin: 0 0 10px 20px; }
.msg-body li { margin-bottom: 4px; }
.msg-body li::marker { color: var(--accent); }
.msg-body a { color: var(--accent-deep); text-decoration-color: rgba(224, 74, 18, 0.35); }
.msg-body blockquote {
  border-left: 2px solid var(--accent);
  padding-left: 12px;
  margin: 0 0 10px;
  color: var(--text-soft);
}
.msg-body hr {
  border: none;
  height: 1px;
  margin: 14px 0;
  background: var(--border);
}
.msg-body strong { font-weight: 700; }

.msg-body code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
}

.code-block {
  margin: 10px 0;
  border: 1px solid #38302a;
  border-radius: 10px;
  overflow: hidden;
  background: #221c17;
}

.code-block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  background: #2d2620;
  border-bottom: 1px solid #3c342d;
  font-family: var(--font-mono);
  font-size: 11px;
  color: #a99d8d;
}

.code-copy {
  background: none;
  border: none;
  color: #a99d8d;
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 5px;
  transition: color 0.15s;
}
.code-copy:hover { color: #f5efe6; }

.code-block pre {
  padding: 10px 12px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  color: #f0e9dd;
}
.code-block pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
}

/* streaming caret */
.msg.streaming .msg-body::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 14px;
  margin-left: 3px;
  vertical-align: -2px;
  border-radius: 2px;
  background: var(--accent);
  animation: blink 0.9s steps(2) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.2s;
}
.msg.assistant:hover .msg-actions { opacity: 1; }

.msg-action-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11.5px;
  font-family: var(--font);
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 6px;
  transition: all 0.15s;
}
.msg-action-btn:hover { color: var(--text); background: var(--surface-2); }

.msg.error .msg-body { color: var(--danger); }

/* thinking dots */
.thinking {
  display: inline-flex;
  gap: 5px;
  padding: 4px 0;
}
.thinking span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}
.thinking span:nth-child(2) { animation-delay: 0.18s; }
.thinking span:nth-child(3) { animation-delay: 0.36s; }

@keyframes pulse {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* --- composer --- */
.composer-wrap {
  padding: 10px 14px 12px;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 6px;
  box-shadow: 0 1px 3px rgba(31, 24, 18, 0.06);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 92, 31, 0.13);
}

#input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 21px;
  padding: 6.5px 4px 6.5px 9px; /* 21px строка + 13px отступов = 34px, как кнопка */
  max-height: 150px;
}

#input::placeholder { color: var(--muted); }

.send-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: var(--accent);
  border: none;
  border-radius: 11px;
  color: #fff;
  cursor: pointer;
  transition: all 0.18s;
  box-shadow: 0 2px 10px rgba(255, 92, 31, 0.35);
}

.send-btn svg { width: 16px; height: 16px; }
.send-btn .ico-stop { display: none; }
.send-btn.stop .ico-send { display: none; }
.send-btn.stop .ico-stop { display: block; }

.send-btn:hover { background: var(--accent-deep); transform: translateY(-1px); }
.send-btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.send-btn.stop {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--danger);
  box-shadow: none;
}

.composer-hint {
  text-align: center;
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 7px;
}

/* --- history --- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 9;
  background: rgba(31, 24, 18, 0.32);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.scrim.open { opacity: 1; pointer-events: auto; }

.history {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  width: min(320px, 88vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform 0.3s cubic-bezier(0.25, 0.9, 0.3, 1);
  box-shadow: -24px 0 60px rgba(31, 24, 18, 0.18);
}
.history.open { transform: none; }

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.history-head h2 {
  font-family: var(--font-display);
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.history-group-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 8px 6px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
  color: var(--text-soft);
  font-family: var(--font);
  transition: all 0.15s;
}

.history-item:hover {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.history-item.active {
  background: var(--accent-soft);
  border-color: rgba(255, 92, 31, 0.35);
  color: var(--text);
}

.history-item-title {
  flex: 1;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-del {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  opacity: 0;
  transition: all 0.15s;
  display: grid;
  place-items: center;
}
.history-item:hover .history-item-del { opacity: 1; }
.history-item-del:hover { color: var(--danger); }
.history-item-del svg { width: 13px; height: 13px; }

.history-empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 30px 16px;
}

.clear-all {
  margin: 10px 14px 14px;
  padding: 9px;
  background: none;
  border: 1px solid rgba(211, 61, 42, 0.35);
  border-radius: 10px;
  color: var(--danger);
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
}
.clear-all:hover { background: rgba(211, 61, 42, 0.07); }
