/* ── AI Page layout ── */
#pageAi.active {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-bottom: 0 !important;
  overflow: hidden;
}

/* AI top bar */
.ai-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 0;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.ai-back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: all .15s;
  letter-spacing: .3px;
}


.ai-back-btn:hover {
  background: var(--cyan);
  border-color: var(--cyan);
}

.ai-back-btn:active {
  transform: scale(.95);
}

.ai-back-btn svg {
  stroke: currentColor;
  fill: none;
  flex-shrink: 0;
}

.ai-clear-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--s2);
  border: 1px solid var(--border2);
  border-radius: 999px;
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--ink3);
  cursor: pointer;
  transition: all .15s;
}


.ai-clear-btn:hover {
  color: var(--red);
  border-color: rgba(255, 62, 62, .3);
  background: var(--red-dim);
}

.ai-scroll-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px 14px;
  -webkit-overflow-scrolling: touch;
}

/* Фикс: инпут не прыгает вверх */
.ai-input-dock {
  flex-shrink: 0;
  position: relative;
  background: var(--s1);
  border-top: 1px solid var(--border2);
  padding: 10px 14px calc(env(safe-area-inset-bottom, 0px) + 14px);
  z-index: 10;
}

/* Статусбар */
.ai-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  padding: 10px 14px;
  margin-bottom: 14px;
}

.ai-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 7px rgba(57, 255, 20, .4);
  flex-shrink: 0;
}

.ai-status-dot.thinking {
  background: var(--amber);
  box-shadow: 0 0 7px rgba(245, 158, 11, .4);
  animation: blink 1s ease-in-out infinite;
}

.ai-status-text {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink2);
  flex: 1;
}

.ai-model-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(59, 130, 246, .2);
  padding: 4px 10px;
  border-radius: 20px;
}


/* Сообщения */
.ai-messages {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.ai-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: fadeUp .2s ease;
}

.ai-msg.user .ai-msg-bubble {
  background: var(--accent-dim);
  border: 1px solid rgba(59, 130, 246, .2);
  margin-left: 28px;
  border-radius: 13px 13px 4px 13px;
}

.ai-msg.assistant .ai-msg-bubble {
  background: var(--s2);
  border: 1px solid var(--border);
  margin-right: 28px;
  border-radius: 13px 13px 13px 4px;
}

.ai-msg-bubble {
  padding: 11px 14px;
}

.ai-msg-text {
  font-size: 14px;
  color: var(--ink);
  line-height: 1.6;
}

.ai-msg-time {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink3);
  padding: 0 2px;
}


.ai-msg.user .ai-msg-time {
  text-align: right;
}

/* Typing indicator */
.ai-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 11px 14px;
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: 13px 13px 13px 4px;
  margin-right: 28px;
  width: fit-content;
}

.ai-typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink3);
  animation: typing .9s infinite both;
}

.ai-typing-dot:nth-child(2) {
  animation-delay: .15s;
}

.ai-typing-dot:nth-child(3) {
  animation-delay: .30s;
}

@keyframes typing {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-4px);
    background: var(--accent);
  }
}

/* Quick actions */
.ai-quick-row {
  display: flex;
  gap: 5px;
  margin-bottom: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.ai-quick-row::-webkit-scrollbar {
  display: none;
}

.ai-quick-btn {
  background: var(--s2);
  border: 1px solid var(--border2);
  border-radius: 999px;
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink2);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  flex-shrink: 0;
}


.ai-quick-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ai-quick-btn:active {
  transform: scale(.93);
}

/* Input row */
.ai-input-row {
  display: flex;
  gap: 7px;
  align-items: flex-end;
}

.ai-input-wrap {
  flex: 1;
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  display: flex;
  align-items: center;
  padding: 9px 13px;
  gap: 8px;
  transition: border-color .2s;
}

.ai-input-wrap:focus-within {
  border-color: var(--accent);
}

.ai-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  resize: none;
  line-height: 1.5;
  max-height: 80px;
}


.ai-input::placeholder {
  color: var(--ink3);
}

.ai-send-btn {
  width: 42px;
  height: 42px;
  background: var(--accent);
  border: none;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all .15s;
}

.ai-send-btn:hover {
  background: var(--cyan);
}

.ai-send-btn:active {
  transform: scale(.9);
}

/* AI Signal Modal */
.ai-signal-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.ai-signal-modal.open {
  display: flex;
}

.ai-signal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 22, 30, .85);
  backdrop-filter: blur(5px);
}

.ai-signal-sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  background: var(--s1);
  border-top: 1px solid var(--border2);
  border-radius: var(--r) var(--r) 0 0;
  padding: 20px 16px calc(env(safe-area-inset-bottom, 0px) + var(--navbar-h, 62px) + 16px);
  animation: slideUp .3s cubic-bezier(.34, 1.4, .64, 1);
}

.ai-sheet-handle {
  width: 36px;
  height: 3px;
  background: var(--border2);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.ai-sheet-title {
  font-family: var(--font-head);
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 4px;
}

.ai-sheet-symbol {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--accent);
  margin-bottom: 14px;
}

.ai-sheet-body {
  font-size: 13px;
  color: var(--ink2);
  line-height: 1.7;
  min-height: 70px;
}

.ai-sheet-reply {
  font-size: 13px;
  color: var(--ink2);
  line-height: 1.7;
}

.ai-sheet-close {
  margin-top: 16px;
  width: 100%;
  padding: 13px;
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--ink2);
  cursor: pointer;
  transition: all .15s;
}