/* ═══════════════════════════════════════════════════════
   TaalFlash AI Assistant — Phase 1 styles
   ═══════════════════════════════════════════════════════ */

/* ── AI кнопки — контейнер под картой (flip mode) ─────── */
.flip-ai-btns {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  max-width: 640px;
  margin: 10px auto 14px;
  padding: 0 4px;
}

/* ── AI Explain button ─────────────────────────────────── */
.ai-explain-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 11px 16px;  /* min 44px touch target (iOS HIG): 11*2 + 13*1.4 ≈ 40px → border+line-height доводит до 44 */
  min-height: 44px;
  font-size: 13px;
  font-weight: 500;
  border: 1.5px solid var(--orange, #FF6B2B);
  border-radius: 20px;
  background: transparent;
  color: var(--orange, #FF6B2B);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.ai-explain-btn:hover {
  background: var(--orange, #FF6B2B);
  color: #fff;
}
.ai-explain-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.ai-explain-btn .ai-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: ai-spin 0.6s linear infinite;
}
.ai-explain-btn.loading .ai-spinner { display: inline-block; }
.ai-explain-btn.loading .ai-btn-icon { display: none; }

@keyframes ai-spin {
  to { transform: rotate(360deg); }
}

/* ── NL A2 button variant (Fietje) ───────────────────── */
.ai-explain-btn--nl {
  border-color: #0066cc;
  color: #0066cc;
}
.ai-explain-btn--nl:hover {
  background: #0066cc;
  color: #fff;
}

/* ── AI Modal backdrop ────────────────────────────────── */
.ai-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1000;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.ai-modal-backdrop.open {
  display: flex;
}

/* ── AI Modal panel (bottom sheet on mobile) ─────────── */
.ai-modal-panel {
  background: var(--bg-card, #fff);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  max-height: 90dvh;            /* dvh учитывает адресную строку браузера */
  display: flex;
  flex-direction: column;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
  animation: ai-slide-up 0.22s ease-out;
  overflow: hidden;             /* дочерние блоки сами управляют скроллом */
}

/* ── Скролл-область контента (между header и footer) ─── */
.ai-modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 20px 16px;
}

@keyframes ai-slide-up {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Desktop: centered dialog instead of bottom sheet ── */
@media (min-width: 768px) {
  .ai-modal-backdrop { align-items: center; }
  .ai-modal-panel {
    border-radius: 20px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.22);
    max-height: 85vh;
    max-height: 85dvh;
    animation: ai-pop-in 0.2s ease-out;
  }
}
@keyframes ai-pop-in {
  from { transform: scale(0.96) translateY(8px); opacity: 0; }
  to   { transform: scale(1)    translateY(0);   opacity: 1; }
}

/* ── Modal header — всегда видна, не скроллится ──────── */
.ai-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding: 18px 20px 14px;
}
.ai-modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text, #1a1a1a);
  display: flex;
  align-items: center;
  gap: 8px;
}
.ai-modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-s, #888);
  /* Минимум 44×44 px (iOS HIG) — критично для мобильного нажатия */
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.ai-modal-close:hover {
  background: var(--bg, #f5f5f5);
}
.ai-modal-close:active {
  background: var(--border, #e8e8e8);
}

/* ── Modal content sections ───────────────────────────── */
.ai-section {
  margin-bottom: 16px;
}
.ai-section:last-child {
  margin-bottom: 0;
}
.ai-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-s, #888);
  margin-bottom: 6px;
}
.ai-explanation {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text, #1a1a1a);
}

/* ── Grammar notes list ───────────────────────────────── */
.ai-grammar-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-grammar-list li {
  font-size: 13px;
  line-height: 1.5;
  padding: 7px 12px;
  background: var(--bg, #f8f8f8);
  border-radius: 8px;
  color: var(--text, #1a1a1a);
  border-left: 3px solid var(--orange, #FF6B2B);
}

/* ── Cultural notes ───────────────────────────────────── */
.ai-cultural {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-s, #555);
  font-style: italic;
  padding: 8px 12px;
  background: var(--bg, #f8f8f8);
  border-radius: 8px;
}

/* ── Related words chips ──────────────────────────────── */
.ai-related-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.ai-related-chip {
  font-size: 13px;
  padding: 4px 12px;
  border-radius: 16px;
  background: var(--bg, #f0f0f0);
  color: var(--text, #1a1a1a);
  border: 1px solid var(--border, #ddd);
}
.ai-related-chip .ai-rel-type {
  font-size: 10px;
  color: var(--text-s, #888);
  margin-left: 4px;
}

/* ── Cache / model badge ──────────────────────────────── */
.ai-modal-meta {
  font-size: 10px;
  color: var(--text-s, #aaa);
  text-align: right;
  margin-top: 16px;
}

/* ── Error state ──────────────────────────────────────── */
.ai-error {
  font-size: 13px;
  color: var(--red, #c0392b);
  padding: 12px;
  background: var(--red-bg, #ffeaea);
  border-radius: 8px;
  text-align: center;
}

/* ══════════════════════════════════════════════════════
   Phase 2.4: Feedback bar (👍/👎 + Copy + Regenerate)
   ══════════════════════════════════════════════════════ */

/* ── Feedback bar — всегда внизу, не скроллится ──────── */
.ai-feedback-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
  padding: 12px 20px;
  /* Учитываем home indicator на iPhone (safe area) */
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border, #e0e0ee);
  background: var(--bg-card, #fff);
}

.ai-feedback-label {
  font-size: 12px;
  color: var(--text-s, #888);
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Thumb кнопки (👍/👎) — минимум 44×44px (iOS HIG) ── */
.ai-thumb-btn {
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--border, #ddd);
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.ai-thumb-btn:hover {
  border-color: var(--orange, #FF6B2B);
  background: var(--orange-bg, #FFF3EE);
}
.ai-thumb-btn:active {
  transform: scale(0.92);
}
.ai-thumb-btn--selected {
  background: var(--orange, #FF6B2B);
  border-color: var(--orange, #FF6B2B);
  box-shadow: 0 2px 8px rgba(255, 107, 43, 0.40);
  transform: scale(1.1);
}
.ai-thumb-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* Spacer — растягивает пространство между thumb и action кнопками */
.ai-feedback-sep {
  flex: 1;
  min-width: 4px;
}

/* ── Action кнопки (Copy, Regenerate) ─────────────────── */
.ai-action-btn {
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
  border: 1.5px solid var(--border, #ddd);
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.ai-action-btn:hover {
  border-color: var(--orange, #FF6B2B);
  background: var(--orange-bg, #FFF3EE);
}
.ai-action-btn:active {
  transform: scale(0.92);
}

/* ══════════════════════════════════════════════════════
   Phase 2.4: Toast уведомления
   ══════════════════════════════════════════════════════ */

.ai-feedback-toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #2d2d2d;
  color: #fff;
  padding: 10px 22px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 2000;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.ai-feedback-toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.ai-feedback-toast--error {
  background: #c0392b;
}

/* ══════════════════════════════════════════════════════
   Skeleton loading state
   ══════════════════════════════════════════════════════ */

.ai-skeleton-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 0 20px;
}

.ai-skeleton-line {
  height: 14px;
  border-radius: 8px;
  background: linear-gradient(
    90deg,
    var(--border, #e0e0ee) 25%,
    var(--bg, #f4f4f8)     50%,
    var(--border, #e0e0ee) 75%
  );
  background-size: 200% 100%;
  animation: ai-shimmer 1.5s ease-in-out infinite;
}

.ai-skeleton-line--wide  { width: 92%; }
.ai-skeleton-line--mid   { width: 72%; }
.ai-skeleton-line--short { width: 55%; }

.ai-skeleton-label {
  height: 10px;
  width: 40%;
  border-radius: 5px;
  background: var(--border, #e0e0ee);
  margin-bottom: 4px;
  opacity: 0.6;
}

@keyframes ai-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.ai-loading-tip {
  font-size: 12px;
  color: var(--text-s, #888);
  text-align: center;
  margin-top: 4px;
  padding: 10px 16px;
  border-radius: var(--radius-s, 8px);
  background: var(--bg, #f8f8fc);
  border: 1px solid var(--border, #e0e0ee);
  line-height: 1.55;
  transition: opacity 0.35s ease;
  min-height: 38px;
}

[data-theme="dark"] .ai-skeleton-line {
  background: linear-gradient(
    90deg,
    var(--border, #2a2a45) 25%,
    var(--bg,    #181830) 50%,
    var(--border, #2a2a45) 75%
  );
  background-size: 200% 100%;
  animation: ai-shimmer 1.5s ease-in-out infinite;
}

/* ── Streaming modal ─────────────────────────────────── */

/* Panel в режиме стриминга — сразу занимает достаточно места */
.ai-modal-panel:has(.ai-stream-body) {
  min-height: min(60vh, 60dvh);
}

/* Тело стриминга — белое пространство, читаемый шрифт */
.ai-stream-body {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text, #1a1a1a);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Мигающий курсор пока идёт генерация */
.ai-stream-cursor {
  display: inline-block;
  animation: ai-blink 0.9s step-end infinite;
  color: var(--orange, #FF6B2B);
  margin-left: 1px;
  vertical-align: baseline;
  font-size: 0.85em;
}
@keyframes ai-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Dark mode overrides (if main.css uses [data-theme=dark]) ── */
[data-theme="dark"] .ai-modal-panel {
  background: var(--bg-card, #1e1e2e);
}
[data-theme="dark"] .ai-modal-close:hover {
  background: var(--bg, #2a2a3a);
}
[data-theme="dark"] .ai-feedback-bar {
  border-top-color: var(--border, #2a2a3a);
  background: var(--bg-card, #1e1e2e);
}
[data-theme="dark"] .ai-thumb-btn,
[data-theme="dark"] .ai-action-btn {
  border-color: var(--border, #3a3a4a);
  color: var(--text, #e8e8f0);
}
[data-theme="dark"] .ai-thumb-btn:hover,
[data-theme="dark"] .ai-action-btn:hover {
  background: var(--orange-bg, #2a1810);
  border-color: var(--orange, #FF6B2B);
}
[data-theme="dark"] .ai-feedback-toast {
  background: #1a1a2e;
  border: 1px solid var(--border, #3a3a4a);
}
