/* ═══════════════════════════════════════════
   Velunis — responsive.css
   Mobile-first overrides — desktop untouched
   ═══════════════════════════════════════════ */

/* ══════════════════════════════════════════
   MOBILE  ≤ 768px
   ══════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Root: ensure full viewport, no overflow ── */
  html, body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  body {
    /* Remove flex-row — on mobile layout is a single column */
    display: block;
    position: relative;
    overflow: hidden;
    min-height: 100vh;
    min-height: 100dvh; /* dynamic viewport height on iOS */
  }

  /* ════════════════════════════════════════
     MOBILE OVERLAY (dark backdrop)
     ════════════════════════════════════════ */
  #mobileOverlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 299;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s cubic-bezier(.4,0,.2,1);
    -webkit-tap-highlight-color: transparent;
  }
  #mobileOverlay.visible {
    opacity: 1;
    pointer-events: all;
  }

  /* ════════════════════════════════════════
     SIDEBAR — full-screen drawer
     ════════════════════════════════════════ */
  .sidebar {
    /* Pull completely off-screen — no layout space consumed */
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80vw !important;
    max-width: 300px !important;
    height: 100% !important;
    min-height: 100dvh !important;
    z-index: 300 !important;
    /* GPU-accelerated slide — no width animation */
    transform: translateX(-100%) !important;
    transition: transform 0.28s cubic-bezier(.4,0,.2,1) !important;
    will-change: transform;
    overflow-y: auto;
    overflow-x: hidden;
    /* Restore all labels that desktop hides in collapsed state */
    padding: 12px 8px 20px;
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  /* Open state */
  .sidebar.mobile-open {
    transform: translateX(0) !important;
  }

  /* Restore collapsed overrides — on mobile we never "collapse", we slide */
  .sidebar .sidebar-label,
  .sidebar .sidebar-btn-label,
  .sidebar .sidebar-section-label,
  .sidebar .history-panel,
  .sidebar .history-list,
  .sidebar .sidebar-divider,
  .sidebar .coming-soon-tag {
    display: revert !important;
  }
  .sidebar .sidebar-btn {
    justify-content: flex-start !important;
    padding: 0 10px !important;
    width: 100% !important;
    margin: 0 !important;
  }
  .sidebar .sidebar-top-row {
    justify-content: space-between !important;
  }
  .sidebar .sidebar-logo {
    display: flex !important;
  }

  /* ════════════════════════════════════════
     MOBILE HEADER — sticky 56px bar
     ════════════════════════════════════════ */
  #mobileHeader {
    display: flex;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 56px;
    z-index: 200;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    padding-top: env(safe-area-inset-top);
    box-sizing: border-box;
    flex-shrink: 0;
    gap: 10px;
    /* Subtle shadow to lift it above content */
    box-shadow: 0 1px 8px rgba(0,0,0,0.06);
  }

  .mobile-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
  }

  /* Hamburger button */
  #mobileMenuBtn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    color: var(--text-dark);
    flex-shrink: 0;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
  }
  #mobileMenuBtn:active { background: rgba(0,0,0,0.07); }

  /* Brand in mobile header */
  .mobile-header-brand {
    display: flex;
    align-items: center;
    gap: 7px;
    text-decoration: none;
    flex-shrink: 0;
  }
  .mobile-header-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
  }
  .mobile-header-name {
    font-family: var(--font-body);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-dark);
    letter-spacing: 0.01em;
    user-select: none;
  }

  /* New Chat button in mobile header */
  #mobileNewChatBtn {
    height: 36px;
    padding: 0 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--text-mid);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
    -webkit-tap-highlight-color: transparent;
    min-width: 44px;
  }
  #mobileNewChatBtn:active {
    background: rgba(0,0,0,0.05);
    border-color: rgba(0,0,0,0.18);
  }

  /* ════════════════════════════════════════
     PAGE / MAIN LAYOUT
     ════════════════════════════════════════ */
  .page {
    display: flex;
    flex-direction: column;
    width: 100% !important;
    height: 100dvh !important;
    min-height: 100dvh !important;
    overflow: hidden;
    position: relative;
  }

  /* Hide the desktop chat header on mobile — replaced by #mobileHeader */
  .chat-header {
    display: none !important;
  }

  /* ════════════════════════════════════════
     CHAT CONTAINER
     ════════════════════════════════════════ */
  .chat-container {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    /* Account for fixed bottom input */
    padding-bottom: 0;
  }

  /* ════════════════════════════════════════
     HERO SECTION
     ════════════════════════════════════════ */
  .hero {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 16px 16px !important;
    box-sizing: border-box;
    width: 100%;
    min-height: 0;
  }

  .hero-content {
    width: 100%;
    max-width: 100% !important;
    padding: 0 8px !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0;
  }

  .hero-title {
    font-size: clamp(34px, 9vw, 48px) !important;
    line-height: 1.15 !important;
    margin-bottom: 12px !important;
    letter-spacing: -0.02em;
  }

  .hero-sub {
    font-size: 19px !important;
    margin-bottom: 28px !important;
    line-height: 1.6 !important;
  }
  .hero-sub br { display: none; }

  /* ════════════════════════════════════════
     CHAT BOX (message area)
     ════════════════════════════════════════ */
  #chat-box {
    padding: 16px 0 8px !important;
    /* Will be padded by JS-driven safe-area via wrapper */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .message-row {
    padding: 0 12px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }

  .message {
    max-width: 86% !important;
    font-size: 14.5px !important;
  }

  .message.user { max-width: 82% !important; }
  .message.bot  { max-width: 88% !important; }

  /* ════════════════════════════════════════
     INPUT AREA — fixed to bottom
     ════════════════════════════════════════ */
  .chat-input-wrapper {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    padding: 10px 0 0 !important;
    padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    background: var(--bg) !important;
    border-top: 1px solid var(--border) !important;
    z-index: 150 !important;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.06) !important;
    box-sizing: border-box;
    flex-shrink: 0;
    overflow: visible !important;
  }

  .chat-input-inner {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 12px !important;
    box-sizing: border-box;
    position: relative !important;
    overflow: visible !important;
  }

  .input-card {
    border-radius: 28px !important;
    padding: 6px 8px 6px 8px !important;
    gap: 8px !important;
    max-width: 100% !important;
  }

  .plus-btn,
  .mic-btn {
    width: 32px !important;
    height: 32px !important;
    flex-shrink: 0 !important;
  }

  .send-btn {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    flex-shrink: 0 !important;
  }

  /* On mobile, plus-dropdown always opens UPWARD (bar is always at bottom) */
  .plus-dropdown {
    bottom: calc(100% + 10px) !important;
    top: auto !important;
    transform-origin: bottom left !important;
    max-width: calc(100vw - 24px) !important;
  }


  /* Spacer below fixed input so last message isn't hidden */
  .chat-input-spacer {
    height: 90px;
    flex-shrink: 0;
    pointer-events: none;
  }

  /* ════════════════════════════════════════
     MESSAGE ACTIONS (HOVER FIX)
     ════════════════════════════════════════ */
  .message-actions {
    opacity: 1 !important;
    transform: translateY(0) !important;
    pointer-events: all !important;
  }

  /* ════════════════════════════════════════
     TYPING INDICATOR
     ════════════════════════════════════════ */
  .typing-indicator {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  /* ════════════════════════════════════════
     DROPDOWN — safe on mobile
     ════════════════════════════════════════ */
  .dropdown-menu {
    min-width: 180px !important;
    left: auto !important;
    right: 0 !important;
  }

  /* ════════════════════════════════════════
     TOAST — raised above fixed input
     ════════════════════════════════════════ */
  .cs-toast {
    bottom: calc(100px + env(safe-area-inset-bottom)) !important;
  }

  /* ════════════════════════════════════════
     ACCESSIBILITY — ensure 44px touch targets
     ════════════════════════════════════════ */
  .sidebar-btn {
    height: 48px !important;
  }
  .new-chat-link {
    min-height: 44px !important;
    padding: 8px 16px !important;
  }
  .history-del {
    min-width: 32px !important;
    min-height: 32px !important;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Prompt parameters on mobile: smaller, hidden unless image mode */
  .prompt-parameters {
    display: none;
  }
  /* Show param chips only when image mode is active */
  .param-chip-row-visible .prompt-parameters {
    display: flex !important;
  }

  /* Character counter: visible but smaller on mobile */
  .char-counter {
    font-size: 10px !important;
    top: 10px !important;
    right: 12px !important;
  }

  /* Suggestions grid: responsive carousel on mobile */
  .suggestions-grid {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 0 !important;
    padding: 0 16px !important;
    margin-top: auto !important;
    margin-bottom: 8px !important;
  }

  /* Scroll-to-bottom FAB: fixed position on mobile */
  #scrollToBottomBtn {
    position: fixed !important;
    bottom: calc(90px + env(safe-area-inset-bottom)) !important;
    right: 16px !important;
  }

  /* Lightbox: full screen on mobile */
  .lightbox-img {
    max-width: 100vw !important;
    max-height: 80vh !important;
  }

  /* ════════════════════════════════════════
     DEVELOPER BADGE (Mobile)
     ════════════════════════════════════════ */
  .developer-badge {
    bottom: auto !important;
    top: 70px !important;
    right: 16px !important;
    padding: 6px !important;
    border-radius: 50% !important;
    gap: 0 !important;
  }
  .developer-badge-text {
    display: none !important;
  }
  .developer-badge-dot {
    font-size: 14px !important;
  }
  /* ════════════════════════════════════════
     MESSAGE ACTIONS POPUP (MOBILE)
     ════════════════════════════════════════ */
  .message-row:hover .message-actions {
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
  }
  
  .message-row.show-actions-popup {
    position: relative;
    z-index: 200;
  }
  
  .message-row.show-actions-popup .message-actions {
    opacity: 1 !important;
    pointer-events: all !important;
    transform: translate(-50%, -50%) !important;
    
    /* Center it horizontally in the screen */
    position: absolute;
    top: 50%;
    left: 50%;
    bottom: auto;
    right: auto;
    
    background: var(--bg-card);
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
    padding: 8px 12px;
    border-radius: 16px;
    gap: 12px;
    z-index: 210;
  }
  
  .message-row.show-actions-popup .message-action-btn {
    width: 40px;
    height: 40px;
    background: rgba(0,0,0,0.04);
  }
  .message-row.show-actions-popup .message-action-btn svg {
    width: 18px;
    height: 18px;
  }

  /* ════════════════════════════════════════
     LUMIQ CREDITS BAR — Inside Sidebar on Mobile
     ════════════════════════════════════════ */
  .sidebar .lumiq-credits-bar {
    position: relative !important;
    top: auto !important;
    right: auto !important;
    left: auto !important;
    bottom: auto !important;
    margin-top: auto !important;
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 16px 8px 8px !important;
    border-top: 1px solid rgba(255, 255, 255, 0.15) !important;
    gap: 8px !important;
    box-sizing: border-box !important;
    z-index: 10 !important;
  }

  .sidebar .lumiq-upgrade-btn {
    background: #ffffff !important;
    color: #B5611A !important; /* matches var(--accent) */
    font-weight: 700 !important;
  }

  .sidebar .lumiq-upgrade-btn:hover {
    background: rgba(255, 255, 255, 0.9) !important;
  }

  .sidebar .lumiq-account-btn {
    border-color: rgba(255, 255, 255, 0.6) !important;
  }
} /* end @media (max-width: 768px) */

/* ══════════════════════════════════════════
   VERY SMALL SCREENS  ≤ 360px
   ══════════════════════════════════════════ */
@media (max-width: 360px) {
  .image-pill,
  .story-pill {
    font-size: 11px !important;
    padding: 4px 8px !important;
  }
  .hero-title {
    font-size: 24px !important;
  }
  #mobileNewChatBtn {
    font-size: 12px !important;
    padding: 0 10px !important;
  }
}

/* ══════════════════════════════════════════
   DESKTOP — ensure mobile-only elements hidden
   ══════════════════════════════════════════ */
@media (min-width: 769px) {
  #mobileHeader  { display: none !important; }
  #mobileOverlay { display: none !important; }
}
