:root {
  --bg: #08090a;
  --bg-raised: #131415;
  --bg-input: #161718;
  --bg-sidebar: #0c0d0e;
  --border: #232425;
  --border-soft: #1b1c1d;
  --text: #ededee;
  --text-dim: #8d9094;
  --text-faint: #5a5d61;
  --accent: #ffffff;
  --accent-bg: #1f2021;
  --accent-violet: #6e6cf4;
  --accent-violet-hover: #5a57e6;
  --accent-violet-light: #a6a2ff;
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 264px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Snow canvas */
.snow {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  opacity: 0.55;
}

/* Shell layout */
.shell {
  position: relative;
  z-index: 2;
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-soft);
  padding: 18px 14px;
  gap: 14px;
}

.account {
  padding: 0 6px;
}

.account__signed-out:not([hidden]),
.account__signed-in:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 6px;
  animation: fade-in 0.18s ease-out;
}

.account__action {
  flex: 1;
  min-width: 0;
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}

.account__action--ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
}

.account__action--ghost:hover {
  background: var(--bg-raised);
  color: var(--text);
  border-color: #3a3a3a;
}

.account__action--solid {
  border: 1px solid transparent;
  background: var(--accent-violet);
  color: #ffffff;
}

.account__action--solid:hover {
  background: var(--accent-violet-hover);
  transform: translateY(-1px);
}

.account__avatar {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-violet);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.account__email {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  color: var(--text);
}

.account__logout {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.account__logout:hover {
  background: var(--bg-raised);
  border-color: rgba(239, 68, 68, 0.35);
  color: #f87171;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- Модальное окно входа / регистрации ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.modal-overlay:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 5, 6, 0.6);
  backdrop-filter: blur(2px);
  animation: overlay-in 0.15s ease-out;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  position: relative;
  width: min(360px, calc(100vw - 32px));
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: modal-in 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal__close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.modal__close:hover {
  background: var(--bg-input);
  color: var(--text);
}

.modal__title {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.modal__subtitle {
  margin: 0 0 18px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.modal__form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.modal__field[hidden] {
  display: none;
}

.modal__field input {
  border: 1px solid var(--border);
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease;
}

.modal__field input:focus {
  border-color: var(--accent-violet);
}

.modal__input-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.modal__input-row input {
  flex: 1;
  min-width: 0;
}

.modal__eye-btn,
.modal__code-btn {
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-faint);
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.modal__eye-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
}

.modal__eye-btn:hover {
  color: var(--text);
  border-color: #3a3a3a;
}

.modal__eye-btn.is-visible {
  color: var(--accent-violet-light);
  border-color: var(--accent-violet);
}

.modal__code-btn {
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.modal__code-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: #3a3a3a;
  background: var(--bg-raised);
}

.modal__code-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.modal__hint:not([hidden]) {
  margin: -4px 0 2px;
  font-size: 11.5px;
  color: var(--text-faint);
}

.modal__error:not([hidden]) {
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
  font-size: 12px;
  animation: shake 0.32s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.modal__submit {
  margin-top: 4px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--accent-violet);
  color: #ffffff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease;
}

.modal__submit:hover:not(:disabled) {
  background: var(--accent-violet-hover);
  transform: translateY(-1px);
}

.modal__submit:disabled {
  opacity: 0.6;
  cursor: default;
}

.modal__divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 10px;
  font-size: 11px;
  color: var(--text-faint);
}

.modal__divider::before,
.modal__divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.modal__google {
  display: flex;
  justify-content: center;
  min-height: 44px;
}

.modal__switch {
  margin: 14px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
}

.modal__link {
  border: none;
  background: none;
  color: var(--accent-violet-light);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 0 0 4px;
}

.modal__link:hover {
  text-decoration: underline;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 8px;
}

.brand__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #08090a;
  font-weight: 700;
  font-size: 14px;
  font-family: Georgia, 'Times New Roman', serif;
}

.brand__name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.new-chat-btn:hover {
  background: var(--accent-bg);
  border-color: #34373a;
}

.sidebar__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  padding: 4px 8px;
}

.history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 0 -4px;
  padding: 0 4px;
}

.history__empty {
  color: var(--text-faint);
  font-size: 12.5px;
  padding: 10px 8px;
  line-height: 1.5;
}

.history__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  cursor: pointer;
  text-align: left;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.history__item:hover {
  background: var(--bg-raised);
  color: var(--text);
}

.history__item.is-active {
  background: var(--accent-bg);
  border-color: var(--border);
  color: var(--text);
}

.history__title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history__remove {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.history__item:hover .history__remove {
  opacity: 1;
}

.history__remove:hover {
  background: #2a1414;
  color: #e7a3a3;
}

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

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 22px;
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

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

.model-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  border-radius: var(--radius-sm);
  padding: 0 6px 0 12px;
  margin-left: auto;
}

.model-picker__icon {
  color: var(--text-faint);
  flex-shrink: 0;
}

.model-picker__select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 9px 28px 9px 4px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238d9094' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
}

.model-picker__select option {
  background: var(--bg-raised);
  color: var(--text);
}

/* Chat area */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 28px 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.chat__inner {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex: 1;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 380px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
}

.empty-state__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--accent-bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 16px;
}

.empty-state__title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 10px;
  letter-spacing: 0.01em;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  animation: rise 0.18s ease-out;
}

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

.message--user {
  align-self: flex-end;
  align-items: flex-end;
}

.message--assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.message__role {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 6px;
  padding: 0 4px;
}

.message__bubble {
  border-radius: var(--radius);
  padding: 12px 15px;
  font-size: 14.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message--user .message__bubble {
  background: var(--accent-bg);
  border: 1px solid var(--border);
  border-bottom-right-radius: 4px;
}

.message--assistant .message__bubble {
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  border-bottom-left-radius: 4px;
}

.message--error .message__bubble {
  background: #1a0e0e;
  border-color: #3a1d1d;
  color: #e7a3a3;
}

.message__text + .message__text,
.message__text + .code-block,
.code-block + .message__text,
.code-block + .code-block {
  margin-top: 10px;
}

.message__text,
.code-block {
  animation: content-in 0.22s ease-out;
}

@keyframes content-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

.message__bubble strong {
  font-weight: 600;
  color: var(--text);
}

.message__bubble code {
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}

.stream-cursor {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 2px;
  background: currentColor;
  vertical-align: text-bottom;
  animation: cursor-blink 0.9s step-start infinite;
}

@keyframes cursor-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* Блоки кода */
.code-block {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: #0a0b0c;
  overflow: hidden;
}

.code-block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px 7px 14px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border-soft);
}

.code-block__lang {
  font-size: 12px;
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  text-transform: lowercase;
}

.code-block__actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.code-block__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.code-block__btn:hover {
  background: var(--accent-bg);
  color: var(--text);
}

.code-block__btn.is-done {
  color: #9fe09f;
}

.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
}

.code-block pre code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.55;
  background: transparent;
  border: none;
  padding: 0;
  white-space: pre;
}

.code-block pre code.hljs {
  background: transparent;
}

.code-block pre::-webkit-scrollbar {
  height: 8px;
}
.code-block pre::-webkit-scrollbar-track {
  background: transparent;
}
.code-block pre::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
}

.message__images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.message__images img {
  width: 140px;
  height: 140px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  object-fit: cover;
  display: block;
}

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: blink 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

.thinking-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-faint);
  font-size: 14px;
}

.thinking-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: thinking-pulse 1.4s infinite ease-in-out;
}

@keyframes thinking-pulse {
  0%, 100% { opacity: 0.25; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* Composer */
.composer {
  flex-shrink: 0;
  padding: 14px 22px 20px;
}

.composer > * {
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}

.composer__toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.composer__toolbar .model-picker {
  margin-left: 0;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.attachment {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.attachment img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.attachment--file {
  width: auto;
  height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px 0 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 12.5px;
  white-space: nowrap;
}

.attachment--file svg {
  flex-shrink: 0;
  color: var(--text-faint);
}

.attachment--file .attachment__name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment--file .attachment__remove {
  position: static;
  width: 16px;
  height: 16px;
  background: transparent;
  color: var(--text-faint);
}

.attachment--file .attachment__remove:hover {
  background: transparent;
  color: var(--text);
}

.attachment__remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.attachment__remove:hover {
  background: rgba(0,0,0,0.9);
}

.composer__row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 6px 6px 8px;
  transition: border-color 0.15s ease;
}

.composer__row:focus-within {
  border-color: #3a3a3a;
}

.composer__input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.5;
  padding: 8px 4px;
  max-height: 160px;
}

.composer__input::placeholder {
  color: var(--text-faint);
}

.mic-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-bottom: 0;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.mic-btn:hover {
  background: var(--bg-raised);
  border-color: var(--border);
  color: var(--text);
}

.mic-btn.is-recording {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.4);
  color: #f87171;
  animation: mic-pulse 1.4s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.35); }
  50% { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0); }
}

.send-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #08090a;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.send-btn:hover { opacity: 0.85; }
.send-btn:active { transform: scale(0.94); }

.send-btn:disabled {
  background: var(--accent-bg);
  color: var(--text-faint);
  cursor: default;
  opacity: 1;
}

.attach {
  position: relative;
  flex-shrink: 0;
}

.attach-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.attach-btn:hover,
.attach.is-open .attach-btn {
  background: var(--bg-input);
  color: var(--text);
}

.attach__menu:not([hidden]) {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 160px;
  padding: 6px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 32px rgba(0,0,0,0.45);
  z-index: 5;
}

.attach__option {
  display: flex;
  align-items: center;
  gap: 9px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}

.attach__option:hover {
  background: var(--bg-input);
  color: var(--text);
}

.attach__option svg {
  flex-shrink: 0;
  color: var(--text-faint);
}

/* Scrollbars */
.chat::-webkit-scrollbar,
.history::-webkit-scrollbar {
  width: 8px;
}
.chat::-webkit-scrollbar-track,
.history::-webkit-scrollbar-track {
  background: transparent;
}
.chat::-webkit-scrollbar-thumb,
.history::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
}
.chat::-webkit-scrollbar-thumb:hover,
.history::-webkit-scrollbar-thumb:hover {
  background: #333;
}

/* ---------- Hamburger button (hidden on desktop) ---------- */
.menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.menu-btn:hover,
.menu-btn:active {
  background: var(--bg-raised);
  color: var(--text);
}

/* ---------- Sidebar backdrop (mobile overlay) ---------- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 49;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-backdrop.is-visible {
  display: block;
  animation: overlay-in 0.2s ease;
}

/* ---------- Responsive — tablet ---------- */
@media (max-width: 880px) {
  :root { --sidebar-w: 220px; }
  .message { max-width: 92%; }
}

/* ---------- Responsive — mobile ---------- */
@media (max-width: 640px) {
  /* Correct height when browser chrome / keyboard appears */
  .shell {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  /* Sidebar: fixed slide-in overlay */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(82vw, 300px);
    height: 100%;
    max-height: none;
    border-right: 1px solid var(--border-soft);
    border-bottom: none;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.26s cubic-bezier(0.3, 0, 0, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar.is-open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0, 0, 0, 0.6);
  }

  /* Show hamburger on mobile */
  .menu-btn {
    display: inline-flex;
  }

  /* Header */
  .header {
    padding: 10px 14px;
    gap: 8px;
  }

  /* Model picker stretches to fill space */
  .model-picker {
    flex: 1;
    margin-left: 0;
    min-width: 0;
  }

  .model-picker__select {
    font-size: 12.5px;
    padding: 8px 22px 8px 2px;
    min-width: 0;
    width: 100%;
  }

  /* Chat area */
  .chat {
    padding: 14px 12px 8px;
  }

  .chat__inner {
    max-width: 100%;
    gap: 14px;
  }

  /* Messages */
  .message {
    max-width: 96%;
  }

  .message__bubble {
    font-size: 14px;
    padding: 10px 12px;
  }

  /* Always show delete button on touch (no hover) */
  .history__remove {
    opacity: 1;
    width: 30px;
    height: 30px;
  }

  .history__item {
    padding: 11px 10px;
    min-height: 44px;
  }

  /* Composer */
  .composer {
    padding: 8px 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .composer > * {
    max-width: 100%;
  }

  .composer__toolbar {
    margin-bottom: 8px;
  }

  .composer__row {
    padding: 4px 4px 4px 6px;
    gap: 4px;
  }

  .composer__input {
    font-size: 16px; /* prevents iOS zoom-in on focus */
    padding: 8px 4px;
  }

  /* Touch targets: min 44px */
  .send-btn,
  .mic-btn,
  .attach-btn {
    width: 40px;
    height: 40px;
  }

  /* Code blocks */
  .code-block pre {
    padding: 10px 12px;
  }

  .code-block pre code {
    font-size: 12px;
  }

  /* Generated images full width */
  .message__gen-image,
  .message__gen-loading {
    max-width: 100%;
  }

  /* Attachment thumbnails smaller */
  .message__images img {
    width: 110px;
    height: 110px;
  }

  /* Empty state */
  .empty-state {
    padding: 0 16px;
    font-size: 13.5px;
  }
}

/* ===================== AI IMAGES IN MESSAGES ===================== */
.message__gen-image {
  margin-top: 10px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-width: 480px;
}
.message__gen-image img {
  display: block;
  max-width: 100%;
  border-radius: var(--radius-sm);
  transition: opacity 0.3s;
}

.message__gen-loading {
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-dim);
  max-width: 480px;
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
