/* ═══════════════════════════════════════════════════════════════════════════
   Tindra 2.0 — Vollbild-Chat-Seite
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Page-Level: Kein Scrolling ─────────────────────────────────────────── */
html:has(.tindra-layout), html:has(.tindra-layout) body {
  height: 100vh; height: 100dvh; margin: 0; padding: 0; overflow: hidden;
}

/* PWA: Tindra-Seite hat eigene mobile-tabs — globale Bottom-Nav ausblenden */
html:has(.tindra-layout) .pwa-bottom-nav { display: none !important; }
html:has(.tindra-layout) body { padding-bottom: 0 !important; }

/* ─── Toolbar ────────────────────────────────────────────────────────────── */
.tindra-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; background: var(--ff-bg-secondary);
  border-bottom: 1px solid rgba(var(--ff-gold-rgb), 0.1);
  height: 50px; flex-shrink: 0;
}
.tindra-toolbar-left, .tindra-toolbar-right { display: flex; align-items: center; gap: 10px; }
.tindra-back { color: var(--ff-text-muted); text-decoration: none; font-size: 1.2rem; padding: 4px; }
.tindra-back:hover { color: var(--ff-gold); }
.tindra-avatar-small { width: 28px; height: 28px; border-radius: 50%; }
.tindra-title { font-weight: 700; color: var(--ff-gold); font-size: 1rem; }
.tindra-subtitle { color: var(--ff-text-muted); font-size: 0.8rem; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tindra-model-badge { font-size: 0.7rem; padding: 2px 8px; background: rgba(var(--ff-gold-rgb), 0.1); border-radius: 4px; color: var(--ff-text-muted); }
.tindra-model-select {
  font-size: 0.75rem; padding: 3px 8px; background: var(--ff-bg-tertiary);
  border: 1px solid rgba(var(--ff-gold-rgb), 0.2); border-radius: 6px;
  color: var(--ff-text-primary); font-family: var(--ff-font-body); cursor: pointer;
}
.tindra-model-select:focus { outline: none; border-color: var(--ff-gold); }
.tindra-feedback-btn { background: none; border: 1px solid rgba(var(--ff-gold-rgb), 0.2); color: var(--ff-text-muted); border-radius: 6px; padding: 3px 8px; cursor: pointer; font-size: 0.8rem; }
.tindra-feedback-btn:hover { border-color: var(--ff-gold); color: var(--ff-gold); }

/* Context meter (toolbar) */
.tindra-context-meter { width: 80px; height: 6px; background: rgba(var(--ff-gold-rgb), 0.1); border-radius: 3px; position: relative; }
.tindra-context-bar { height: 100%; border-radius: 3px; background: var(--ff-gold); transition: width 0.3s; width: 0%; }
.tindra-context-label { position: absolute; right: -30px; top: -2px; font-size: 0.6rem; color: var(--ff-text-muted); }

/* ─── 3-Spalten-Layout ───────────────────────────────────────────────────── */
.tindra-layout {
  display: flex; height: calc(100vh - 50px); height: calc(100dvh - 50px); overflow: hidden;
}

/* ─── Linke Spalte: Chat-Verlauf ─────────────────────────────────────────── */
.tindra-sidebar {
  width: 260px; min-width: 260px; background: var(--ff-bg-tertiary);
  border-right: 1px solid rgba(var(--ff-gold-rgb), 0.1);
  display: flex; flex-direction: column; overflow: hidden;
}
.tindra-sidebar-header { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.tindra-new-chat {
  padding: 8px; background: rgba(var(--ff-gold-rgb), 0.1); border: 1px solid rgba(var(--ff-gold-rgb), 0.2);
  color: var(--ff-gold); border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 0.85rem;
  transition: all 0.15s;
}
.tindra-new-chat:hover { background: rgba(var(--ff-gold-rgb), 0.2); }
.tindra-search {
  padding: 6px 10px; background: rgba(var(--ff-bg-primary-rgb), 0.5);
  border: 1px solid rgba(var(--ff-gold-rgb), 0.15); border-radius: 6px;
  color: var(--ff-text-primary); font-size: 0.8rem; font-family: var(--ff-font-body);
}
.tindra-chat-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.tindra-chat-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 4px;
  transition: background 0.15s; font-size: 0.82rem;
}
.tindra-chat-item:hover { background: rgba(var(--ff-gold-rgb), 0.08); }
.tindra-chat-item.active { background: rgba(var(--ff-gold-rgb), 0.15); border-left: 3px solid var(--ff-gold); }
.tindra-chat-item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tindra-chat-item-date { font-size: 0.7rem; color: var(--ff-text-muted); margin-top: 2px; }

/* ─── Mittlere Spalte: Chat ──────────────────────────────────────────────── */
.tindra-chat {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
}
.tindra-messages {
  flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 12px;
}
.tindra-welcome { text-align: center; padding: 60px 20px; }
.tindra-welcome-avatar { width: 80px; height: 80px; border-radius: 50%; margin-bottom: 16px; }
.tindra-welcome h2 { color: var(--ff-gold); margin-bottom: 8px; }
.tindra-welcome p { color: var(--ff-text-muted); max-width: 400px; margin: 0 auto; line-height: 1.5; }

/* Messages */
.tindra-msg { display: flex; gap: 10px; max-width: 80%; animation: tindraFadeIn 0.2s ease; }
@keyframes tindraFadeIn { from { opacity: 0; transform: translateY(4px); } }
.tindra-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.tindra-msg.assistant { align-self: flex-start; }
.tindra-msg-avatar { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; }
.tindra-msg-bubble {
  padding: 10px 14px; border-radius: 12px; font-size: 0.88rem; line-height: 1.5;
  word-wrap: break-word; overflow-wrap: break-word;
}
.tindra-msg.user .tindra-msg-bubble { background: rgba(var(--ff-gold-rgb), 0.15); border-bottom-right-radius: 4px; }
.tindra-msg.assistant .tindra-msg-bubble { background: var(--ff-bg-tertiary); border-bottom-left-radius: 4px; }

/* Tool-Aktivität */
.tindra-tool-bubble {
  padding: 8px 12px; border-radius: 8px; font-size: 0.78rem;
  background: rgba(100, 180, 255, 0.08); border: 1px solid rgba(100, 180, 255, 0.15);
  color: var(--ff-text-muted); cursor: pointer; max-width: 80%; align-self: flex-start;
}
.tindra-tool-bubble summary { list-style: none; }
.tindra-tool-bubble summary::-webkit-details-marker { display: none; }
.tindra-tool-detail { margin-top: 6px; font-size: 0.72rem; white-space: pre-wrap; max-height: 150px; overflow-y: auto; }

/* Inline Element-Karten */
.tindra-inline-element {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  background: rgba(var(--ff-gold-rgb), 0.08); border: 1px solid rgba(var(--ff-gold-rgb), 0.15);
  border-radius: 6px; font-size: 0.78rem; cursor: pointer; text-decoration: none; color: inherit;
  margin: 4px 2px;
}
.tindra-inline-element:hover { border-color: var(--ff-gold); }

/* Cost badge */
.tindra-cost-badge {
  font-size: 0.7rem; color: var(--ff-text-muted); margin-top: 4px; padding: 2px 8px;
  background: rgba(var(--ff-gold-rgb), 0.06); border-radius: 4px; display: inline-block;
}

/* Plan block */
.tindra-plan-block {
  margin: 8px 0; padding: 10px 14px; background: rgba(100, 180, 255, 0.06);
  border: 1px solid rgba(100, 180, 255, 0.15); border-radius: 8px;
}
.tindra-plan-block summary { cursor: pointer; font-weight: 600; font-size: 0.85rem; }
.tindra-plan-content { margin: 8px 0; font-size: 0.8rem; white-space: pre-wrap; line-height: 1.5; }
.tindra-plan-execute {
  padding: 6px 14px; background: var(--ff-gold); color: var(--ff-bg-primary);
  border: none; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 0.82rem;
  margin-top: 6px;
}
.tindra-plan-execute:hover { opacity: 0.85; }

/* Typing indicator */
.tindra-typing { color: var(--ff-text-muted); animation: tindraTyping 1s infinite; }
@keyframes tindraTyping { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

/* Input area */
.tindra-input-area {
  display: flex; gap: 8px; padding: 12px 16px;
  border-top: 1px solid rgba(var(--ff-gold-rgb), 0.1);
  background: var(--ff-bg-secondary);
}
#tindra-input {
  flex: 1; padding: 10px 14px; background: var(--ff-bg-tertiary);
  border: 1px solid rgba(var(--ff-gold-rgb), 0.15); border-radius: 10px;
  color: var(--ff-text-primary);
  /* iOS Safari/WKWebView zoomt beim Fokus auf jedes Input mit font-size < 16px.
     Explizite 16px (nicht 1rem!) verhindern den Auto-Zoom — sonst verschwindet
     der Senden-Button hinter der Tastatur. */
  font-size: 16px;
  font-family: var(--ff-font-body);
  resize: none; min-height: 20px; max-height: 120px;
}
#tindra-input:focus { outline: none; border-color: var(--ff-gold); }
.tindra-send-btn {
  padding: 8px 16px; background: var(--ff-gold); color: var(--ff-bg-primary);
  border: none; border-radius: 10px; cursor: pointer; font-size: 1rem;
  font-weight: 600; transition: opacity 0.15s;
}
.tindra-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.tindra-send-btn:hover:not(:disabled) { opacity: 0.85; }

/* ─── Rechte Spalte: Kontextfenster ──────────────────────────────────────── */
.tindra-context {
  width: 280px; min-width: 280px; background: var(--ff-bg-tertiary);
  border-left: 1px solid rgba(var(--ff-gold-rgb), 0.1);
  overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column;
}
.tindra-context-title { margin: 0 0 12px; font-size: 0.9rem; color: var(--ff-gold); }
.tindra-ctx-section { margin-bottom: 8px; }
.tindra-ctx-section summary {
  padding: 6px 0; cursor: pointer; font-size: 0.8rem; font-weight: 600;
  color: var(--ff-text-secondary); user-select: none;
}
.tindra-ctx-section summary:hover { color: var(--ff-gold); }
.tindra-ctx-body { padding: 6px 0; font-size: 0.75rem; color: var(--ff-text-muted); line-height: 1.5; }
.tindra-ctx-prompt { max-height: 200px; overflow-y: auto; white-space: pre-wrap; font-family: monospace; font-size: 0.65rem; }

/* Context footer links */
.tindra-ctx-footer {
  margin-top: auto; padding-top: 12px;
  border-top: 1px solid rgba(var(--ff-gold-rgb), 0.1);
  display: flex; flex-wrap: wrap; gap: 6px 12px;
  font-size: 0.7rem;
}
.tindra-ctx-footer a { color: var(--ff-text-muted); text-decoration: none; }
.tindra-ctx-footer a:hover { color: var(--ff-gold); }

/* Context meter large */
.tindra-context-meter-large { width: 100%; height: 8px; background: rgba(var(--ff-gold-rgb), 0.1); border-radius: 4px; margin-bottom: 4px; }
.tindra-context-bar-large { height: 100%; border-radius: 4px; background: var(--ff-gold); transition: width 0.3s; width: 0%; }

/* ─── Cost hint ──────────────────────────────────────────────────────────── */
.tindra-cost-hint {
  padding: 4px 16px; font-size: 0.7rem; color: var(--ff-text-muted);
  background: var(--ff-bg-secondary); border-top: 1px solid rgba(var(--ff-gold-rgb), 0.05);
}

/* ─── Suggestion chips ───────────────────────────────────────────────────── */
.tindra-suggestion-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.tindra-chip {
  padding: 8px 16px; background: rgba(var(--ff-gold-rgb), 0.08);
  border: 1px solid rgba(var(--ff-gold-rgb), 0.2); border-radius: 20px;
  color: var(--ff-gold); cursor: pointer; font-size: 0.82rem;
  transition: all 0.15s; font-family: var(--ff-font-body);
}
.tindra-chip:hover { background: rgba(var(--ff-gold-rgb), 0.15); border-color: var(--ff-gold); transform: translateY(-1px); }

/* ─── Onboarding ─────────────────────────────────────────────────────────── */
.tindra-onboarding-overlay {
  position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.7); animation: tindraFadeIn 0.3s ease;
}
.tindra-onboarding-card {
  background: var(--ff-bg-secondary); border: 1px solid rgba(var(--ff-gold-rgb), 0.2);
  border-radius: 16px; padding: 32px; max-width: 420px; width: 90%; text-align: center;
}
.tindra-onboarding-card h3 { color: var(--ff-gold); margin-bottom: 12px; font-size: 1.2rem; }
.tindra-onboarding-card p { color: var(--ff-text-secondary); line-height: 1.6; font-size: 0.9rem; margin-bottom: 20px; }
.tindra-onboarding-nav { display: flex; justify-content: space-between; align-items: center; }
.tindra-onboarding-dots { display: flex; gap: 6px; }
.tindra-ob-dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(var(--ff-gold-rgb), 0.2); }
.tindra-ob-dot.active { background: var(--ff-gold); }

/* ─── Mobile Tabs ────────────────────────────────────────────────────────── */
.tindra-mobile-tabs { display: none; }

@media (max-width: 768px) {
  /* Sidebar: Off-screen links, Slide-in */
  .tindra-sidebar {
    display: none; position: fixed; left: 0; top: 50px; bottom: 48px; z-index: 100;
    width: 85vw; max-width: 320px; box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
  .tindra-sidebar.open { display: flex; }

  /* Context: Off-screen rechts, Slide-in */
  .tindra-context {
    display: none; position: fixed; right: 0; top: 50px; bottom: 48px; z-index: 100;
    width: 85vw; max-width: 320px; box-shadow: -4px 0 20px rgba(0,0,0,0.5);
  }
  .tindra-context.open { display: flex; }

  /* Overlay zum Schließen */
  .tindra-mobile-overlay {
    display: none; position: fixed; inset: 0; z-index: 99; background: rgba(0,0,0,0.5);
  }
  .tindra-mobile-overlay.active { display: block; }

  /* Bottom Tabs */
  .tindra-mobile-tabs {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--ff-bg-secondary); border-top: 1px solid rgba(var(--ff-gold-rgb), 0.1);
    justify-content: space-around; padding: 8px 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .tindra-tab { background: none; border: none; color: var(--ff-text-muted); font-size: 1.2rem; padding: 6px 16px; cursor: pointer; }
  .tindra-tab.tindra-tab-active { color: var(--ff-gold); }

  /* Layout anpassen — Höhe mit dynamic vh + safe-area, damit das
     Eingabefeld nicht hinter den mobile-tabs verschwindet (iOS Notch). */
  .tindra-layout {
    height: calc(100vh - 50px - 48px - env(safe-area-inset-bottom, 0px));
    height: calc(100dvh - 50px - 48px - env(safe-area-inset-bottom, 0px));
  }

  /* Chat vollflächig */
  .tindra-chat { width: 100%; }
  .tindra-messages { padding: 12px 12px; }
  .tindra-msg { max-width: 90%; }
  /* Eingabefeld bündig an den mobile-tabs (Fußzeile) — kein vertikaler Außenabstand */
  .tindra-input-area { padding: 6px 10px; }
  .tindra-cost-hint { display: none; }
  /* font-size: 16px wird vom Base-Style geerbt — kein Override hier, sonst
     riskieren wir, ihn versehentlich unter den iOS-Zoom-Threshold zu schieben. */

  /* Toolbar kompakter */
  .tindra-toolbar { padding: 6px 12px; }
  .tindra-toolbar-right { gap: 4px; }
  .tindra-context-meter { display: none; }
  .tindra-subtitle { display: none; }
  .tindra-model-select { font-size: 0.7rem; max-width: 120px; }
  .tindra-feedback-btn { display: none; }

  /* Welcome fullscreen */
  .tindra-welcome { padding: 40px 16px; }
  .tindra-suggestion-chips { flex-direction: column; align-items: center; }
  .tindra-chip { width: 80%; text-align: center; }
}

@media (max-width: 1024px) and (min-width: 769px) {
  .tindra-context { width: 220px; min-width: 220px; }
  .tindra-sidebar { width: 220px; min-width: 220px; }
}
