/* ═══════════════════════════════════════════════════════════════
   FlowCraft mobile UI — app-like experience  (v21 · 2026-06-05)
   ═══════════════════════════════════════════════════════════════ */

/* ── Safe-area paddings for notched phones ───────────────────── */
@supports (padding: env(safe-area-inset-top)) {
  .topbar { padding-top: calc(env(safe-area-inset-top) + 8px) !important; }
  .fc-bottom-nav { padding-bottom: env(safe-area-inset-bottom); }
}

@media (max-width: 768px) {
  /* ── Base / natural body-scroll (was locked to 100vh) ─────── */
  body { font-size: 15px; -webkit-text-size-adjust: 100%; overscroll-behavior-y: contain; }
  .app-layout {
    display: block !important;
    height: auto !important;
    min-height: 100vh;
    overflow: visible !important;
  }
  .main-content {
    margin-left: 0 !important; width: 100% !important;
    min-height: 100vh; overflow: visible !important;
    display: block !important;
  }
  .content-area { overflow: visible !important; }

  /* ── Promo banners → slim single line ────────────────────── */
  #fc-eb-banner, #fc-beta-banner {
    padding: 7px 32px 7px 13px !important;
    font-size: .72rem !important;
    line-height: 1.35 !important;
    letter-spacing: 0 !important;
  }
  #fc-eb-banner .eb-full,
  #fc-beta-banner .beta-full { display: none !important; }
  #fc-eb-banner .eb-short { display: inline !important; }
  #fc-eb-banner > button, #fc-beta-banner > button {
    width: 22px !important; height: 22px !important; right: 6px !important;
    font-size: 13px !important;
  }

  /* ── Sticky compact header ───────────────────────────────── */
  .topbar {
    position: sticky !important; top: 0; z-index: 50;
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    background: rgba(15, 15, 28, .9) !important;
    border-bottom: 1px solid rgba(255,255,255,.06) !important;
    padding: 10px 14px !important;
    min-height: 56px; height: auto !important;
    display: flex !important; align-items: center !important; justify-content: space-between !important;
    gap: 8px;
  }
  body.light .topbar { background: rgba(255,255,255,.9) !important; }
  .topbar-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
  .topbar-title {
    font-size: 1.05rem !important; font-weight: 800;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    background: var(--gradient-main); -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
  }
  /* These move into the drawer on mobile */
  .topbar-status { display: none !important; }
  .topbar-lang-btn { display: none !important; }
  #btn-theme { display: none !important; }
  #fc-profile-chip { display: none !important; }

  .topbar-user {
    padding: 4px 9px 4px 4px !important;
    background: rgba(168,85,247,.12);
    border: 1px solid rgba(168,85,247,.3);
    border-radius: 999px;
    gap: 6px;
  }
  .topbar-user img, .topbar-user > div:first-child { width: 26px !important; height: 26px !important; }
  .topbar-user span:not(.plan-badge) { font-size: .8rem !important; max-width: 78px; overflow: hidden; text-overflow: ellipsis; }
  .topbar-user .plan-badge { font-size: .58rem !important; padding: 1px 6px !important; }

  /* Hamburger — touch-friendly */
  .sidebar-toggle {
    width: 42px; height: 42px; min-width: 42px;
    border-radius: 12px; background: rgba(168,85,247,.12);
    border: 1px solid rgba(168,85,247,.28);
    color: var(--text); font-size: 1.3rem;
    display: flex !important; align-items: center; justify-content: center;
    padding: 0 !important;
  }

  /* ── Sidebar = full-height drawer ────────────────────────── */
  .sidebar {
    position: fixed !important;
    top: 0 !important; left: -110% !important;
    width: 84% !important; max-width: 330px;
    height: 100vh !important; height: 100dvh !important;
    z-index: 100;
    transition: left .28s cubic-bezier(.4,.0,.2,1) !important;
    box-shadow: 0 0 50px rgba(0,0,0,.5);
    overflow-y: auto;
  }
  .sidebar.open { left: 0 !important; }
  #sidebar-overlay { backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
  .sidebar-brand { padding: 18px 16px !important; }
  .sidebar-nav { padding: 6px 12px 40px !important; }
  .sidebar-nav .nav-item { margin: 1px 0; }
  .sidebar-nav .nav-item a {
    padding: 13px 14px !important;
    border-radius: 12px;
    font-size: .96rem !important;
    min-height: 48px;
  }
  .sidebar-nav .nav-icon { font-size: 1.2rem; width: 26px; }
  .sidebar-nav .nav-section-label { padding: 14px 14px 6px !important; }

  /* Quick controls (theme + lang) injected into drawer */
  .fc-drawer-controls { display: flex !important; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .fc-drawer-controls button {
    flex: 1; min-height: 44px; border-radius: 12px;
    background: var(--bg-hover); border: 1px solid var(--border); color: var(--text);
    font-weight: 700; font-size: .82rem;
    display: flex; align-items: center; justify-content: center; gap: 7px;
  }
  .fc-drawer-controls button .ic { font-size: 1.05rem; }
  .fc-drawer-controls button:active { transform: scale(.97); }

  /* ── Content padding (airier) ────────────────────────────── */
  .content-area {
    padding: 16px !important;
    padding-bottom: calc(88px + env(safe-area-inset-bottom, 0)) !important;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Headings & page header ──────────────────────────────── */
  .content-area h1, .page-header h1 { font-size: 1.5rem !important; line-height: 1.18; }
  .content-area h2 { font-size: 1.12rem !important; }
  .content-area h3 { font-size: 1rem !important; }
  .page-header { margin-bottom: 18px !important; }
  .page-desc, .page-header .page-desc { font-size: .9rem !important; }

  /* ── Cards ───────────────────────────────────────────────── */
  .card, .ov-card, .fc-card, .usage-card, .plan-card, .stat-box, .feature {
    border-radius: 16px !important;
    padding: 18px !important;
    box-shadow: 0 2px 14px rgba(0,0,0,.2);
  }
  .card-header { margin-bottom: 12px !important; }
  .card-header h2 { font-size: .98rem !important; }
  body.light .card, body.light .ov-card { box-shadow: 0 2px 10px rgba(0,0,0,.05); }

  /* Dashboard hero */
  .hero-card { padding: 22px !important; margin-bottom: 18px !important; border-radius: 18px !important; }
  .hero-card h1 { font-size: 1.34rem !important; }
  .hero-card p { font-size: .92rem !important; }
  .hero-card .hero-btn { margin-top: 14px !important; padding: 11px 20px !important; }

  /* Quick links */
  .quick-link { padding: 14px !important; border-radius: 14px !important; }
  .ql-icon { width: 42px; height: 42px; }

  /* ── Forms ───────────────────────────────────────────────── */
  input, select, textarea {
    font-size: 16px !important;        /* prevents iOS zoom */
    border-radius: 12px !important;
    padding: 12px 14px !important;
    min-height: 46px;
  }
  textarea { min-height: 96px; }
  label { font-size: .86rem !important; margin-bottom: 5px !important; }
  .form-group { margin-bottom: 14px !important; }

  /* ── Buttons ─────────────────────────────────────────────── */
  .btn, button:not(.sidebar-toggle):not(.fc-bn-item) {
    min-height: 46px;
    padding: 11px 18px !important;
    font-size: .94rem !important;
    border-radius: 12px !important;
    touch-action: manipulation;
  }
  .btn-sm { min-height: 38px; padding: 8px 13px !important; font-size: .84rem !important; }
  .btn-lg { padding: 14px 24px !important; font-size: 1.02rem !important; }
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; min-height: 20px; }

  /* Toggle-row a touch roomier */
  .toggle-row { padding: 12px 0 !important; }

  /* ── Tables & lists ──────────────────────────────────────── */
  table { font-size: .84rem; }
  .url-box input { font-size: .76rem !important; }

  /* ── Grids: stack big content, tile small metrics ────────── */
  .grid, .grid-2, .grid-3, [class*='grid-'],
  .features, .plans-grid, .pricing-cards { grid-template-columns: 1fr !important; gap: 14px !important; }
  /* metric tiles stay 2-up for a real app-dashboard feel */
  .grid-4, .stats-grid, .stat-grid { grid-template-columns: 1fr 1fr !important; gap: 11px !important; }
  .voices-grid { grid-template-columns: 1fr 1fr !important; }
  /* narrow paired fields */
  .fc-field-row.three { grid-template-columns: 1fr 1fr !important; }

  /* compact stat tiles */
  .stat-card { padding: 15px !important; border-radius: 16px !important; }
  .stat-card .icon { width: 38px; height: 38px; font-size: 1.2rem; margin-bottom: 9px; }
  .stat-card .val { font-size: 1.55rem !important; }
  .stat-card .lab { font-size: .75rem !important; }

  /* ── Modals fill the screen ──────────────────────────────── */
  .fc-modal, .modal {
    inset: 0 !important; margin: 0 !important;
    border-radius: 0 !important; max-height: 100vh !important;
    width: 100% !important; max-width: 100% !important;
    align-items: flex-start !important;
  }
  .modal-box, .fc-modal-body {
    border-radius: 0 !important; max-width: 100% !important;
    width: 100% !important; min-height: 100vh; padding: 18px !important;
  }

  /* ── Toasts span screen width ────────────────────────────── */
  .toast, .alert-stack, .toast-stack {
    left: 12px !important; right: 12px !important; bottom: calc(80px + env(safe-area-inset-bottom,0)) !important;
    max-width: none !important; border-radius: 14px !important; font-size: .9rem;
  }

  /* ── Support FAB lifted above bottom nav ─────────────────── */
  #fc-support-fab {
    bottom: calc(78px + env(safe-area-inset-bottom, 0)) !important;
    right: 16px !important;
    width: 52px !important; height: 52px !important; font-size: 22px !important;
  }
  #fc-support-panel {
    bottom: calc(140px + env(safe-area-inset-bottom, 0)) !important;
    right: 12px !important; left: 12px !important;
    width: auto !important; max-width: none !important;
    height: min(60vh, 460px) !important; max-height: calc(100vh - 220px) !important;
  }

  /* ── Landing page ────────────────────────────────────────── */
  .hero { padding: 50px 0 30px !important; }
  .hero h1 { font-size: 34px !important; }
  .hero p { font-size: 1rem !important; }
  .section-title { font-size: 1.5rem !important; }
  .feature h3 { font-size: 1rem !important; }
  nav .logo .name { font-size: 18px !important; }
  nav a { font-size: 12px !important; margin-left: 12px !important; }

  /* ── Overlay studio preview ──────────────────────────────── */
  .preview-wrap, #studio-preview { height: 320px !important; width: 100% !important; }

  /* ── Hide truly desktop-only widgets ─────────────────────── */
  .desktop-only { display: none !important; }

  /* ── App-like bottom nav (HTML in base.html) ─────────────── */
  .fc-bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: 64px;
    background: rgba(15, 15, 28, .94);
    border-top: 1px solid rgba(255,255,255,.07);
    backdrop-filter: blur(16px) saturate(160%);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    display: flex; align-items: stretch; justify-content: space-around;
    z-index: 60;
  }
  body.light .fc-bottom-nav { background: rgba(255,255,255,.95); border-top-color: rgba(0,0,0,.06); }
  .fc-bn-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--text-muted); text-decoration: none; font-size: .68rem; font-weight: 600;
    padding-top: 7px; gap: 3px; position: relative;
    transition: color .15s;
  }
  .fc-bn-item .fc-bn-icon { font-size: 1.34rem; line-height: 1; transition: transform .15s; }
  .fc-bn-item.active { color: var(--accent); }
  .fc-bn-item.active::before {
    content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 26px; height: 3px; border-radius: 0 0 3px 3px; background: var(--gradient-main);
  }
  .fc-bn-item.active .fc-bn-icon { transform: scale(1.1); }
  .fc-bn-item:active .fc-bn-icon { transform: scale(.9); }
}

/* ── ≤480 px refinement ───────────────────────────────────── */
@media (max-width: 480px) {
  .content-area { padding: 14px !important; padding-bottom: calc(86px + env(safe-area-inset-bottom,0)) !important; }
  .topbar { padding: 9px 13px !important; min-height: 54px; }
  .topbar-title { font-size: 1rem !important; }
  .content-area h1, .page-header h1 { font-size: 1.36rem !important; }
  .voices-grid { grid-template-columns: 1fr !important; }
  .fc-bn-item { font-size: .64rem; }
  .fc-bn-item .fc-bn-icon { font-size: 1.26rem; }
}

/* ── ≤360 px (tiny phones) ─────────────────────────────────── */
@media (max-width: 360px) {
  .grid-4, .stats-grid, .stat-grid { gap: 9px !important; }
  .fc-bn-item .fc-bn-label { display: none; }
  .fc-bn-item .fc-bn-icon { font-size: 1.45rem; }
}

/* ── Touch devices: kill sticky-hover, add tap feedback ──────── */
@media (hover: none) {
  .card:hover, .stat-card:hover, .quick-link:hover, .ov-card:hover, .feature:hover {
    transform: none !important;
    box-shadow: var(--shadow-card) !important;
    border-color: var(--border) !important;
  }
  .btn:active, .quick-link:active, .stat-card:active, .card:active { transform: scale(.985) !important; transition: transform .08s !important; }
  .nav-item a:active { background: var(--accent-dim); }
}

/* ── Hide bottom nav + drawer controls on desktop ────────────── */
@media (min-width: 769px) {
  .fc-bottom-nav { display: none !important; }
  .fc-drawer-controls { display: none !important; }
}
