/* ==========================================================================
   FinrixLLM Responsive & Mobile Layout Stylesheet
   Supports 360px Mobile, Tablet & Desktop (≥1025px)
   ========================================================================== */

/* Global Viewport & Touch Reset */
html, body {
  overflow-x: hidden !important;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

/* Off-Canvas Drawer Overlay Backdrop */
.drawer-overlay {
  display: none;
  pointer-events: none;
}

.drawer-overlay.active {
  display: block !important;
  pointer-events: auto !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  background: rgba(0, 0, 0, 0.6) !important;
  z-index: 999 !important;
  backdrop-filter: blur(2px);
}

body.drawer-open {
  overflow: hidden !important;
  touch-action: none !important;
}

/* Hamburger Button Default Hidden on Desktop */
.hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  margin-right: 4px;
}

/* Bottom Sheet Handle Bar for Mobile Right Sidebar */
.bottom-sheet-handle {
  width: 36px;
  height: 4px;
  background-color: var(--panel-border);
  border-radius: 2px;
  margin: 8px auto 12px auto;
  display: none;
}

/* ==========================================================================
   MOBILE & TABLET BREAKPOINTS (≤ 768px)
   ========================================================================== */
@media (max-width: 768px) {
  /* Show Hamburger, Hide Desktop Toggle */
  .hamburger-btn {
    display: flex !important;
    flex-shrink: 0 !important;
    width: 36px !important;
    height: 36px !important;
    z-index: 10 !important;
  }

  #toggleLeftSidebar {
    display: none !important;
  }

  /* Main Container Single Column Layout */
  .app-container {
    display: block;
    width: 100%;
    height: 100%;
    height: 100dvh;
    position: relative;
    overflow: hidden;
  }

  /* Left Sidebar -> Off-Canvas Drawer */
  .sidebar-left,
  .sidebar-left.collapsed {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 290px !important;
    min-width: 290px !important;
    max-width: 85vw !important;
    height: 100% !important;
    height: 100dvh !important;
    background-color: var(--panel) !important;
    border-right: 1px solid var(--panel-border) !important;
    z-index: 1000 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 20px 14px !important;
  }

  .sidebar-left.open,
  .sidebar-left.open.collapsed {
    transform: translateX(0) !important;
    width: 290px !important;
    min-width: 290px !important;
    max-width: 85vw !important;
    padding: 20px 14px !important;
    overflow-y: auto !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  /* Right Sidebar -> Bottom-Sheet / Full-Screen Overlay */
  .sidebar-right {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100vw;
    max-width: 100vw;
    height: 85vh;
    height: 85dvh;
    background-color: var(--panel);
    border-top: 1px solid var(--panel-border);
    border-radius: 16px 16px 0 0;
    z-index: 1001;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.6);
    overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .sidebar-right.open {
    transform: translateY(0) !important;
  }

  .sidebar-right.collapsed {
    transform: translateY(100%) !important;
  }

  .bottom-sheet-handle {
    display: block;
  }

  /* Chat Area Full Width */
  .chat-area {
    width: 100% !important;
    height: 100% !important;
    height: 100dvh !important;
    display: flex;
    flex-direction: column;
    position: relative;
  }

  .chat-header {
    padding: 6px 10px !important;
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: var(--bg);
    border-bottom: 1px solid var(--border-subtle);
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 6px !important;
  }

  .chat-header-info {
    flex: 0 0 auto !important;
    gap: 6px !important;
  }

  .chat-header-icon,
  .chat-header-text {
    display: none !important; /* Mobilde başlık yazısını sakla, menü ve sekmelere yer aç */
  }

  .chat-header-tags {
    flex: 1 1 auto !important;
    justify-content: flex-end !important;
    gap: 4px !important;
  }

  .connection-status-pills {
    display: none !important; /* Hide status pills on phone to save header space */
  }

  .chat-footer {
    padding: 8px 10px max(10px, env(safe-area-inset-bottom)) 10px;
    background-color: var(--bg);
  }
}

/* ==========================================================================
   PHONE BREAKPOINT (≤ 480px)
   ========================================================================== */
@media (max-width: 480px) {
  .chat-header {
    padding: 4px 6px !important;
    gap: 2px !important;
  }

  .chat-header-tags {
    gap: 2px !important;
  }

  .panel-toggle-btn {
    width: 30px !important;
    height: 30px !important;
  }

  .view-tab-nav {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    gap: 2px !important;
    margin: 0 !important;
  }

  .view-tab-btn {
    padding: 4px 8px !important;
    border-radius: 8px !important;
    border: 1px solid transparent !important;
  }

  .view-tab-btn.active {
    background-color: var(--panel) !important;
    border-color: var(--panel-border) !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
  }

  .panel-toggle-btn {
    width: 32px !important;
    height: 32px !important;
  }

  #pdfExportToggle {
    display: none !important; /* Mobilde sıkışmayı önlemek için ikincil PDF indirme butonunu gizle */
  }

  .sidebar-left {
    width: 280px;
    max-width: 82vw;
  }

  .sidebar-right {
    height: 90vh;
    height: 90dvh;
  }

  .dashboard-toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .dashboard-actions {
    width: 100%;
    justify-content: space-between;
  }

  .dashboard-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ==========================================================================
   TABLET BREAKPOINT (769px - 1024px)
   ========================================================================== */
@media (min-width: 769px) and (max-width: 1024px) {
  .hamburger-btn {
    display: flex !important;
  }

  #toggleLeftSidebar {
    display: none !important;
  }

  .sidebar-left {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    height: 100%;
    height: 100dvh;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }

  .sidebar-left.open {
    transform: translateX(0) !important;
  }

  .sidebar-right {
    position: relative !important;
    transform: none !important;
    z-index: 10;
  }
}

/* ==========================================================================
   DESKTOP BREAKPOINT (≥ 1025px) - ORIGINAL 3-PANEL UNTOUCHED
   ========================================================================== */
@media (min-width: 1025px) {
  .hamburger-btn {
    display: none !important;
  }

  .drawer-overlay {
    display: none !important;
  }

  .sidebar-left {
    position: relative !important;
    transform: none !important;
  }

  .sidebar-right {
    position: relative !important;
    transform: none !important;
  }

  body.drawer-open {
    overflow: auto !important;
  }
}

/* ==========================================================================
   FAZ 2 — İÇERİK & BİLEŞEN MOBİL UYUM KURALLARI (≤ 768px)
   ========================================================================== */
@media (max-width: 768px) {
  /* 1. Chat Mesaj Balonları & Taşma Engeli */
  .message-bubble {
    max-width: 92% !important;
    font-size: 14px !important;
    line-height: 1.45 !important;
  }

  .bubble-md {
    max-width: 100% !important;
    overflow-x: hidden;
  }

  /* Markdown Tabloları — Kendi içinde yatay kaydırma (sayfa kaymaz) */
  .bubble-md table {
    display: block;
    width: 100% !important;
    overflow-x: auto !important;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    border-collapse: collapse;
  }

  /* Kod blokları, grafik ve görseller */
  .bubble-md pre,
  .bubble-md code {
    max-width: 100% !important;
    overflow-x: auto !important;
    white-space: pre-wrap;
    word-break: break-word;
  }

  .bubble-md img,
  .bubble-md svg {
    max-width: 100% !important;
    height: auto !important;
  }

  /* 2. Composer (Giriş Kutusu) & iOS Çentik Uyum */
  .chat-footer {
    position: sticky;
    bottom: 0;
    z-index: 90;
    padding-bottom: max(12px, env(safe-area-inset-bottom)) !important;
  }

  .composer-input,
  .chat-input,
  #input {
    font-size: 16px !important; /* iOS otomatik zoom engeli */
  }

  /* 3. Öneri Çipleri & Onboarding Kartları */
  .suggested-chips,
  .quick-ask-grid {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  .onboarding-card-grid,
  .investor-profile-grid {
    grid-template-columns: 1fr !important;
  }

/* ==========================================================================
   FAZ 3 — DOKUNMA & ERİŞİLEBİLİRLİK KURALLARI
   ========================================================================== */

/* 1. Dokunmatik Hedef Boyutları (≥ 44x44px) */
@media (max-width: 768px) {
  button,
  .panel-toggle-btn,
  .quick-ask-chip,
  .suggested-chip,
  .agent-item,
  .history-item,
  .widget-tab-btn,
  .language-toggle,
  .auth-submit-btn,
  .modal-close {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* 2. Hover'a Bağlı Gizli Aksiyonlar Mobilde Her Zaman Görünür */
  .history-item .history-delete-btn,
  .agent-item .agent-favorite-star,
  .widget-hide-btn,
  .widget-action-btn {
    opacity: 1 !important;
    visibility: visible !important;
    display: flex !important;
  }

  /* 3. Landscape (Yatay Telefon) Uyum */
  @media (orientation: landscape) and (max-height: 500px) {
    .sidebar-left,
    .sidebar-right {
      height: 100vh;
      height: 100dvh;
    }

    .chat-header {
      padding: 4px 10px;
    }

    .chat-footer {
      padding: 4px 10px;
    }
  }
}

/* 4. Focus-Visible Halkaları & Klavye Erişilebilirliği */
:focus-visible {
  outline: 2px solid var(--accent-green) !important;
  outline-offset: 2px !important;
}

/* 5. Prefers-Reduced-Motion Animasyon Sadeleştirme */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}


