/* =============================================================================
   MERC MOBILE FIXES v2.1
   Drop-in overlay para corrigir layout responsivo em mobile/tablet sem quebrar
   o desktop. Inclua DEPOIS do <style> principal (no fim do <head>).

   v2.1: SVGs inline atualizados para o M de marca MERC (#E0FC07 em fundo preto).

   Cobre:
    1. Topbar — colapsa elementos, esconde label do user, encolhe logo
    2. Stats grid — 4 cols -> 2 -> 1
    3. Card grids — 3 cols -> 2 -> 1
    4. Two-col / three-col — empilha
    5. Tables — horizontal scroll
    6. Modais e painéis — full-screen no mobile
    7. Inputs — font-size 16px (evita zoom no iOS)
    8. Touch targets — minimo 44x44px
    9. Safe-area-inset para iPhones com notch
   10. Logo SVG default com M de marca quando nao ha logo upado
============================================================================= */


/* === RESET MOBILE-FIRST ==================================================== */
* { -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }


/* === LOGO DEFAULT (M de marca embutido como CSS var) ======================= */
:root {
  /* Wordmark completo: M de marca + "MERC GROUP" */
  --merc-logo-svg: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 380 100'><g transform='translate(0,18)'><rect width='64' height='64' fill='%23000000'/><path d='M 21,44 L 21,20 L 32,37 L 43,20 L 43,44' stroke='%23E0FC07' stroke-width='4.5' fill='none' stroke-linejoin='miter'/></g><text x='86' y='52' font-family='Bebas Neue,Oswald,Impact,Arial,sans-serif' font-size='44' letter-spacing='6' fill='%23FFFFFF'>MERC</text><text x='86' y='78' font-family='Inter,Arial,sans-serif' font-weight='500' font-size='11' letter-spacing='6' fill='%238B8FA8'>GROUP</text></svg>");
  /* Mark compacto: so o M de marca */
  --merc-logo-mark-svg: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'><rect width='64' height='64' fill='%23000000'/><path d='M 21,44 L 21,20 L 32,37 L 43,20 L 43,44' stroke='%23E0FC07' stroke-width='4.5' fill='none' stroke-linejoin='miter'/></svg>");
}

/* Aplica fundo SVG default quando o elemento esta vazio.
   Se o usuario subiu logo customizado, ele continua sobrepondo via <img>. */
.brand-logo:empty,
.topbar-logo:empty,
.login-logo:empty {
  background-image: var(--merc-logo-svg);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  min-height: 80px;
  min-width: 200px;
}

/* Class helper para mostrar a marca compacta em qualquer lugar */
.merc-mark {
  display: inline-block;
  width: 32px;
  height: 32px;
  background-image: var(--merc-logo-mark-svg);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  vertical-align: middle;
}


/* === TABLET (≤1024px) ====================================================== */
@media (max-width: 1024px) {
  .app, .main { max-width: 100% !important; padding: 18px 16px !important; }

  /* 4-col stats viram 2-col */
  .stats { grid-template-columns: repeat(2, 1fr) !important; }

  /* 3-col grids viram 2-col */
  .grid, .grid6, .three-col { grid-template-columns: repeat(2, 1fr) !important; }
}


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

  /* APP SHELL ----------------------------------------------------------- */
  .app, .main {
    padding: 12px 12px !important;
    max-width: 100% !important;
  }
  body { font-size: 14px; }


  /* TOPBAR -------------------------------------------------------------- */
  .topbar {
    flex-wrap: wrap !important;
    gap: 8px !important;
    padding: 10px 12px !important;
    align-items: center !important;
  }
  .topbar-left { gap: 8px !important; flex: 1 1 auto; min-width: 0; }
  .topbar-divider { display: none !important; }
  .topbar-section {
    font-size: 10px !important;
    letter-spacing: 0.05em !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Logo na topbar fica com tamanho do mark (M de marca) */
  .topbar-logo {
    width: 36px !important;
    height: 36px !important;
    min-height: 36px !important;
    min-width: 36px !important;
    background-image: var(--merc-logo-mark-svg) !important;
    background-size: contain !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    border-radius: 6px !important;
    font-size: 0 !important;            /* esconde o texto MERC */
  }
  .topbar-logo > * { display: none !important; }   /* esconde span filho */

  /* Right side: settings + user + logout colapsam */
  .topbar-right {
    gap: 4px !important;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .topbar-right .btn-ghost,
  .topbar-right .btn-sm {
    padding: 6px 10px !important;
    font-size: 11px !important;
    min-height: 36px !important;
  }
  .user-pill {
    padding: 4px 8px !important;
    gap: 6px !important;
  }
  .user-pill span { display: none !important; }   /* só avatar visível */
  .user-pill .profile-avatar { width: 28px; height: 28px; font-size: 11px; }


  /* STATS GRID (KPIs) --------------------------------------------------- */
  .stats {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    margin-bottom: 16px !important;
  }
  .stat { padding: 10px 12px !important; }
  .stat-val, .stat-value {
    font-size: 20px !important;
  }
  .stat-label, .stat-lbl {
    font-size: 9px !important;
  }


  /* CARD GRIDS (areas de agentes, listas) ------------------------------- */
  .grid, .grid6, .three-col {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .card {
    padding: 14px !important;
  }
  .card-name { font-size: 14px !important; }
  .card-sub { font-size: 12px !important; }


  /* TWO-COL / SIDE-BY-SIDE ---------------------------------------------- */
  .two-col, .three-col {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }


  /* HEADINGS ------------------------------------------------------------- */
  h1, .h1 { font-size: 22px !important; line-height: 1.25 !important; }
  h2, .h2 { font-size: 18px !important; }
  h3, .h3 { font-size: 16px !important; }


  /* BUTTONS - touch target minimo 44x44 --------------------------------- */
  .btn, button:not(.task-toggle-btn):not(.elicit-pill):not(.btn-sm) {
    min-height: 44px !important;
    min-width: 44px !important;
    padding: 10px 16px !important;
    font-size: 14px !important;
  }


  /* INPUTS - 16px previne zoom no iOS ----------------------------------- */
  input, textarea, select {
    font-size: 16px !important;
    padding: 12px 14px !important;
    min-height: 44px;
  }
  textarea { min-height: 100px !important; }


  /* TABLES - scroll horizontal seguro ----------------------------------- */
  table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    max-width: 100%;
  }
  table th, table td {
    padding: 8px 10px !important;
    font-size: 12px !important;
  }


  /* MODALS / DIALOGS / PANELS - full-screen ----------------------------- */
  .modal, .dialog, .modal-content, .approval-modal,
  .voice-picker, .video-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }


  /* TASK PANEL - bottom sheet pattern ----------------------------------- */
  .task-panel, #task-panel {
    width: 100% !important;
    max-width: 100% !important;
    height: 75vh !important;
    bottom: 0 !important;
    right: 0 !important;
    left: 0 !important;
    top: auto !important;
    border-radius: 16px 16px 0 0 !important;
    border-left: none !important;
    border-bottom: none !important;
  }
  .task-toggle-btn, #task-toggle {
    bottom: 16px !important;
    right: 16px !important;
    padding: 12px 16px !important;
    font-size: 12px !important;
  }


  /* WORKFLOW / EXECUTION VIEW - subcards parallel viram pilha ----------- */
  .parallel-row, .parallel-block {
    grid-template-columns: 1fr !important;
    flex-direction: column !important;
  }
  .parallel-row > *, .parallel-block > * {
    width: 100% !important;
  }


  /* AGENT NODE / ORG CHART ---------------------------------------------- */
  .org-chart, .area-pipeline {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
  }
  .agent-node {
    min-width: 64px;
    flex-shrink: 0;
  }


  /* APPROVAL CARDS / FILA DE APROVACAO ---------------------------------- */
  .approval-card, .approval-item {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
  }
  .approval-card .actions, .approval-item .actions {
    width: 100%;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }
  .approval-card .actions .btn,
  .approval-item .actions .btn {
    flex: 1 1 calc(50% - 6px);
  }


  /* DROPZONE ------------------------------------------------------------ */
  .dropzone, .upload-zone {
    padding: 24px 16px !important;
  }


  /* SECTIONS ------------------------------------------------------------ */
  .sec, .section, .panel {
    padding: 14px !important;
    margin-bottom: 12px !important;
  }


  /* CHAT / FORMS / SIDEBARS --------------------------------------------- */
  .sidebar { display: none !important; }                 /* esconde sidebars desktop */
  .sidebar.mobile-active { display: block !important; }  /* show via toggle */


  /* LOGIN VIEW ---------------------------------------------------------- */
  .login-wrap, [class*="login-wrap"], #login-view {
    padding: 24px 18px !important;
    min-height: 100vh;
    min-height: 100dvh;            /* dynamic viewport — barra de address não corta */
  }
  .brand-block, .login-brand {
    margin-bottom: 28px !important;
  }
  .brand-logo {
    font-size: 42px !important;
    letter-spacing: 6px !important;
  }
  .brand-tagline {
    font-size: 9px !important;
    letter-spacing: 2px !important;
  }
  .profiles {
    width: 100% !important;
    max-width: 360px !important;
  }
  /* v4: campos de senha não dão zoom no iOS */
  .profiles input[type="password"],
  .profiles input[type="email"] {
    font-size: 16px !important;
    padding: 12px !important;
  }
  /* v4: settings com 7 abas — scroll horizontal suave */
  .tabs {
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: thin;
  }
  .tabs .tab {
    padding: 10px 12px !important;
    font-size: 12px !important;
  }


  /* CALENDARIO MARKETING ------------------------------------------------ */
  .cal {
    font-size: 10px;
    gap: 3px !important;
  }
  .cal-day {
    padding: 4px !important;
    font-size: 9px;
  }


  /* VIDEO STUDIO -------------------------------------------------------- */
  .video-studio {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .video-preview {
    max-height: 60vh !important;
    aspect-ratio: 9/16;
  }


  /* PROFILE / AVATAR / BADGES ------------------------------------------- */
  .profile-avatar {
    width: 32px !important;
    height: 32px !important;
    font-size: 13px !important;
  }
  .badge {
    font-size: 9px !important;
    padding: 2px 6px !important;
  }


  /* STEP CARDS DA EXECUCAO ---------------------------------------------- */
  .step-card, .exec-step {
    padding: 12px !important;
  }
  .step-card .agent-info,
  .exec-step .agent-info {
    flex-wrap: wrap;
    gap: 8px;
  }


  /* CHIPS, TAGS, BREADCRUMBS -------------------------------------------- */
  .breadcrumb {
    font-size: 11px !important;
    line-height: 1.4;
  }
  .nav-bar {
    flex-wrap: wrap !important;
    gap: 8px !important;
    margin-bottom: 16px !important;
    padding-bottom: 12px !important;
  }


  /* OUTPUT BLOCKS (pre, code, monoespacado) ----------------------------- */
  pre, .output {
    font-size: 11px !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }


  /* FORMS - 1-col em mobile --------------------------------------------- */
  form .row, .form-row {
    grid-template-columns: 1fr !important;
    flex-direction: column !important;
    gap: 10px !important;
  }


  /* IMAGES NEVER OVERFLOW ----------------------------------------------- */
  img {
    max-width: 100%;
    height: auto;
  }
}


/* === SMALL PHONE (≤480px) ================================================== */
@media (max-width: 480px) {
  .app, .main { padding: 8px 10px !important; }

  /* Stats viram 1 coluna em telas pequenas mesmo */
  .stats { grid-template-columns: 1fr !important; }

  /* Section name na topbar some */
  .topbar-section { display: none !important; }

  /* Action buttons na approval ficam full-width */
  .approval-card .actions .btn,
  .approval-item .actions .btn {
    flex: 1 1 100% !important;
  }

  /* Video studio menor */
  .video-preview { max-height: 50vh !important; }

  /* Logo do login menor ainda */
  .brand-logo { font-size: 36px !important; letter-spacing: 4px !important; }
}


/* === SAFE-AREA INSET (iPhone com notch) ==================================== */
@supports (padding: max(0px)) {
  .app, .main {
    padding-left: max(12px, env(safe-area-inset-left)) !important;
    padding-right: max(12px, env(safe-area-inset-right)) !important;
  }
  .topbar {
    padding-top: max(10px, env(safe-area-inset-top)) !important;
  }
  .task-panel, #task-panel {
    padding-bottom: max(12px, env(safe-area-inset-bottom)) !important;
  }
  .login-wrap, [class*="login-wrap"], #login-view {
    padding-bottom: max(20px, env(safe-area-inset-bottom)) !important;
  }
}


/* === LANDSCAPE EM CELULAR ================================================== */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .login-wrap, [class*="login-wrap"], #login-view {
    padding: 12px 18px !important;
  }
  .brand-block, .login-brand { margin-bottom: 16px !important; }
  .brand-logo { font-size: 32px !important; }
}


/* === DARK MODE EXPLICITO PARA INPUTS NO IOS ================================ */
@supports (-webkit-touch-callout: none) {
  input, textarea, select {
    background-color: var(--bg-3, #161616) !important;
    color: var(--txt, #f5f5f5) !important;
  }
}


/* === ACCESSIBILITY: respeitar prefers-reduced-motion ======================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


/* === FIM DO ARQUIVO ======================================================== */
