/**
 * mobile-global.css v4
 * Header 2 linhas integrado + drawer + FAB
 */

@media (max-width: 767px) {
  :root {
    --mg-ink:      #0d0d0d;
    --mg-muted:    #7a7570;
    --mg-rule:     rgba(13,13,13,.08);
    --mg-surface:  #f7f7f5;
    --mg-primary:  #6366f1;
    --mg-f-dis:    'DM Serif Display', Georgia, serif;
    --mg-f-mono:   'DM Mono', monospace;
    --mg-f-body:   'DM Sans', system-ui, sans-serif;
    --mg-ease:     cubic-bezier(.22,.68,0,1.2);
    --mg-row1:     52px;   /* linha superior */
    --mg-row2:     46px;   /* linha de tabs (só unitsView) */
    --mg-nav-base: 52px;   /* altura quando sem row2 */
  }
}

@media (max-width: 767px) {

  /* ══ BASE ══ */
  #kpab-root   { display: none !important; }
  .app-sidebar { display: none !important; }
  #app         { padding-left: 0 !important; margin-left: 0 !important; }

  .app-main {
    width: 100vw !important; max-width: 100vw !important;
    margin: 0 !important; padding: 0 !important;
    min-height: 100dvh !important;
    /* JS define padding-top dinamicamente via --mg-nav-current */
    padding-top: var(--mg-nav-current, var(--mg-nav-base)) !important;
  }

  /* ══════════════════════════════════════
     HEADER FIXO  #mobileNavBar
     Estrutura flex-column:
       row-1: hamburger | título | ação
       row-2 (opcional): tabs de nível
     ══════════════════════════════════════ */
  #mobileNavBar {
    position:       fixed;
    top:            0; left: 0; right: 0;
    z-index:        200;
    display:        flex;
    flex-direction: column;
    background:     #fff;
    border-bottom:  1px solid var(--mg-rule);
    box-shadow:     0 2px 12px rgba(13,13,13,.07);
    padding-top:    env(safe-area-inset-top, 0px);
    /* transition para quando row-2 aparece/desaparece */
    transition:     box-shadow .2s;
  }

  /* ─── ROW 1 ─── */
  .mnb-row1 {
    display:     flex;
    align-items: center;
    height:      var(--mg-row1);
    flex-shrink: 0;
  }

  .mnb-left {
    width:           var(--mg-row1);
    height:          var(--mg-row1);
    display:         flex;
    align-items:     center;
    justify-content: center;
    flex-shrink:     0;
  }
  #mobileMenuBtn {
    width: 42px; height: 42px;
    display: inline-flex; align-items: center; justify-content: center;
    background: none; border: none; border-radius: 10px;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
    transition: background .14s;
  }
  #mobileMenuBtn:active { background: var(--mg-surface); }
  #mobileMenuBtn svg    { display: block; }

  .mnb-center {
    flex: 1; min-width: 0; padding: 0 2px;
    display: flex; flex-direction: column;
    justify-content: center; gap: 1px;
  }
  .mnb-eyebrow {
    font-family: var(--mg-f-mono); font-size: 9px; font-weight: 600;
    letter-spacing: .1em; text-transform: uppercase; color: var(--mg-muted);
    line-height: 1; display: block;
  }
  .mnb-title {
    font-family: var(--mg-f-body); font-size: 15px; font-weight: 700;
    color: var(--mg-ink); letter-spacing: -.02em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    line-height: 1.2; display: block;
  }

  .mnb-right {
    display: flex; align-items: center;
    padding: 0 6px 0 0; gap: 2px;
    flex-shrink: 0; min-width: var(--mg-row1);
    justify-content: flex-end;
  }
  .mnb-btn {
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    background: none; border: none; border-radius: 10px;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
    transition: background .14s;
  }
  .mnb-btn:active { background: var(--mg-surface); }
  .mnb-btn svg    { display: block; }

  /* ─── ROW 2: tabs de nível ─── */
  .mnb-row2 {
    display:        none;   /* JS mostra quando unitsView */
    align-items:    stretch;
    height:         var(--mg-row2);
    border-top:     1px solid var(--mg-rule);
    background:     #fff;
    overflow:       hidden;
    flex-shrink:    0;
  }
  .mnb-row2.mnb-row2-visible { display: flex; }

  /* Scroll horizontal das tabs */
  .mnb-tabs-scroll {
    flex:        1;
    display:     flex;
    align-items: stretch;
    overflow-x:  auto;
    overflow-y:  hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    /* fade lateral */
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 10px, #000 calc(100% - 10px), transparent 100%);
    mask-image:         linear-gradient(to right, transparent 0, #000 10px, #000 calc(100% - 10px), transparent 100%);
  }
  .mnb-tabs-scroll::-webkit-scrollbar { display: none; }

  /* Tab chip */
  .mnb-tab {
    display:        inline-flex;
    align-items:    center;
    gap:            6px;
    padding:        0 10px 0 12px;
    background:     none;
    border:         none;
    border-bottom:  2.5px solid transparent;
    cursor:         pointer;
    white-space:    nowrap;
    flex-shrink:    0;
    font-family:    var(--mg-f-body);
    height:         var(--mg-row2);
    -webkit-tap-highlight-color: transparent;
    transition:     border-color .18s, background .14s;
    position:       relative;
  }
  .mnb-tab:active { background: rgba(13,13,13,.03); }

  .mnb-tab-badge {
    width:           22px; height: 22px; border-radius: 6px;
    background:      rgba(13,13,13,.08);
    display:         inline-flex; align-items: center; justify-content: center;
    font-family:     var(--mg-f-mono); font-size: 10px; font-weight: 700;
    color:           var(--mg-muted); flex-shrink: 0;
    transition:      background .15s, color .15s;
  }
  .mnb-tab-name {
    font-size: 12px; font-weight: 500; color: var(--mg-muted);
    transition: color .15s; max-width: 70px;
    overflow: hidden; text-overflow: ellipsis;
  }
  .mnb-tab-count {
    font-family: var(--mg-f-mono); font-size: 9px;
    color: var(--mg-muted); background: rgba(13,13,13,.06);
    padding: 1px 5px; border-radius: 6px;
  }

  /* ── Wrapper de tab + botão editar ──
     Estrutura: div.mnb-tab-wrap > button.mnb-tab + button.mnb-tab-edit
     NÃO usamos button dentro de button (HTML inválido)
  */
  .mnb-tab-wrap {
    display:     inline-flex;
    align-items: center;
    flex-shrink: 0;
    gap:         4px;
    padding:     0 4px 0 0;
  }

  /* Botão editar: oculto em tabs inativas */
  .mnb-tab-edit { display: none; }

  /* Visível apenas quando a wrap tem a classe active */
  .mnb-tab-edit.mnb-tab-edit-visible {
    display:         inline-flex;
    align-items:     center;
    justify-content: center;
    gap:             3px;
    height:          26px;
    padding:         0 9px;
    border-radius:   13px;
    background:      #6366f1;
    border:          none;
    cursor:          pointer;
    font-family:     var(--mg-f-body);
    font-size:       11px;
    font-weight:     700;
    color:           #fff;
    letter-spacing:  -.01em;
    white-space:     nowrap;
    flex-shrink:     0;
    box-shadow:      0 2px 8px rgba(99,102,241,.4);
    -webkit-tap-highlight-color: transparent;
    transition:      transform .14s var(--mg-ease), box-shadow .14s;
    animation:       mnb-edit-pulse 1.8s ease 0.4s 2 both;
  }
  @keyframes mnb-edit-pulse {
    0%,100% { box-shadow: 0 2px 8px rgba(99,102,241,.4); transform: scale(1); }
    50%      { box-shadow: 0 2px 16px rgba(99,102,241,.75); transform: scale(1.1); }
  }
  .mnb-tab-edit.mnb-tab-edit-visible:active {
    transform:  scale(.88);
    box-shadow: 0 1px 4px rgba(99,102,241,.25);
  }

  /* Tab ativa */
  .mnb-tab-active { border-bottom-color: var(--mg-ink); }
  .mnb-tab-active .mnb-tab-badge { background: var(--mg-ink); color: #fff; }
  .mnb-tab-active .mnb-tab-name  { color: var(--mg-ink); font-weight: 700; }
  .mnb-tab-active .mnb-tab-count { background: rgba(13,13,13,.1); color: var(--mg-ink); }

  /* Tab rascunho ativa */
  .mnb-tab-draft .mnb-tab-badge         { background: rgba(245,158,11,.15); color: #d97706; }
  .mnb-tab-draft.mnb-tab-active         { border-bottom-color: #f59e0b; }
  .mnb-tab-draft.mnb-tab-active .mnb-tab-badge { background: #f59e0b; color: #fff; }
  .mnb-tab-draft.mnb-tab-active .mnb-tab-name  { color: #d97706; }
  .mnb-tab-draft.mnb-tab-active .mnb-tab-edit  {
    background:  linear-gradient(135deg,#f59e0b,#ea580c);
    box-shadow:  0 2px 8px rgba(245,158,11,.45);
  }

  /* Área "+ Nível" à direita das tabs */
  .mnb-add-level-wrap {
    display:     flex;
    align-items: center;
    padding:     0 10px;
    border-left: 1px solid var(--mg-rule);
    flex-shrink: 0;
    background:  #fff;
  }
  .mnb-add-level-btn {
    display:        inline-flex; align-items: center; gap: 4px;
    height:         30px; padding: 0 12px;
    background:     linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
    color:          #fff; border: none; border-radius: 15px;
    font-family:    var(--mg-f-body); font-size: 12px; font-weight: 700;
    letter-spacing: -.01em; cursor: pointer; white-space: nowrap;
    box-shadow:     0 2px 10px rgba(99,102,241,.38);
    transition:     transform .18s var(--mg-ease), box-shadow .18s, background .15s;
    -webkit-tap-highlight-color: transparent; flex-shrink: 0;
  }
  .mnb-add-level-btn:active  { transform: scale(.91); box-shadow: 0 1px 4px rgba(99,102,241,.2); }
  .mnb-add-level-btn-plus    { font-size: 15px; line-height: 1; }
  .mnb-add-level-btn.mnb-add-disabled {
    background: rgba(13,13,13,.1) !important; box-shadow: none !important;
    color: rgba(13,13,13,.28) !important; pointer-events: none !important;
  }

  /* ══ SIDEBAR DRAWER ══ */
  #mobileSidebarDrawer { position: fixed; inset: 0; z-index: 9000; display: none; }
  #mobileSidebarDrawer.msd-open { display: block; }
  .msd-backdrop {
    position: absolute; inset: 0; background: rgba(0,0,0,.44);
    backdrop-filter: blur(1px); animation: msd-fade-in .2s ease both;
  }
  @keyframes msd-fade-in { from{opacity:0} to{opacity:1} }
  .msd-panel {
    position: absolute; left:0; top:0; bottom:0;
    width: min(300px, 85vw); background: #fff;
    display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 4px 0 32px rgba(13,13,13,.18);
    animation: msd-slide-in .26s var(--mg-ease) both;
  }
  @keyframes msd-slide-in { from{transform:translateX(-100%)} to{transform:translateX(0)} }
  #mobileSidebarDrawer.msd-closing .msd-panel    { animation: msd-slide-out .2s ease both; }
  #mobileSidebarDrawer.msd-closing .msd-backdrop { animation: msd-fade-in .2s ease reverse both; }
  @keyframes msd-slide-out { to{transform:translateX(-100%)} }

  .msd-head {
    padding: calc(20px + env(safe-area-inset-top,0px)) 18px 16px;
    background: linear-gradient(135deg,#0d0d0d 0%,#1a1a2e 100%);
    display: flex; align-items: center; gap: 12px; flex-shrink: 0;
  }
  .msd-avatar {
    width:42px; height:42px; border-radius:50%;
    background: linear-gradient(135deg,#6366f1,#8b5cf6);
    display:inline-flex; align-items:center; justify-content:center;
    font-size:18px; font-weight:700; flex-shrink:0; color:#fff;
    box-shadow:0 2px 12px rgba(99,102,241,.4); border:2px solid rgba(255,255,255,.2);
  }
  .msd-user-name  { font-family:var(--mg-f-body); font-size:14px; font-weight:700; color:#fff; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .msd-user-email { font-family:var(--mg-f-mono); font-size:10px; color:rgba(255,255,255,.5); letter-spacing:.04em; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin-top:2px; }

  .msd-nav { flex:1; overflow-y:auto; padding:12px 10px; }
  .msd-nav::-webkit-scrollbar { display:none; }
  .msd-nav-label { font-family:var(--mg-f-mono); font-size:9px; font-weight:700; letter-spacing:.12em; text-transform:uppercase; color:var(--mg-muted); padding:10px 10px 6px; display:block; }
  .msd-nav-item {
    display:flex; align-items:center; gap:12px; padding:11px 12px; border-radius:10px;
    background:none; border:none; cursor:pointer; width:100%; text-align:left;
    font-family:var(--mg-f-body); font-size:14px; font-weight:500; color:var(--mg-ink);
    margin-bottom:2px; transition:background .15s; -webkit-tap-highlight-color:transparent;
  }
  .msd-nav-item:active { background:var(--mg-surface); }
  .msd-nav-item.active { background:rgba(99,102,241,.09); color:var(--mg-primary); font-weight:700; }
  .msd-nav-icon { width:36px; height:36px; border-radius:10px; flex-shrink:0; display:inline-flex; align-items:center; justify-content:center; font-size:17px; background:var(--mg-surface); }
  .msd-nav-item.active .msd-nav-icon { background:rgba(99,102,241,.12); }
  .msd-footer { padding:10px; border-top:1px solid var(--mg-rule); flex-shrink:0; }
  .msd-logout { display:flex; align-items:center; gap:12px; padding:11px 12px; border-radius:10px; background:none; border:none; cursor:pointer; width:100%; text-align:left; font-family:var(--mg-f-body); font-size:14px; font-weight:600; color:#ef4444; -webkit-tap-highlight-color:transparent; }
  .msd-logout:active { background:rgba(239,68,68,.08); }
  .msd-logout-icon { width:36px; height:36px; border-radius:10px; flex-shrink:0; background:rgba(239,68,68,.08); display:inline-flex; align-items:center; justify-content:center; font-size:17px; }

  /* ══ VIEWS ══ */
  #coursesView .view-header { display: none !important; }
  #coursesView .view-content { padding: 12px 13px calc(78px + env(safe-area-inset-bottom,0px)) !important; }
  #coursesGrid { grid-template-columns: 1fr !important; gap: 10px !important; margin-bottom: 0 !important; }

  #unitsView .view-header  { display: none !important; }
  #unitsBreadcrumb         { display: none !important; }
  #levelsSidebar           { display: none !important; }
  #unitsView .view-content {
    flex-direction: column !important; padding: 0 !important;
    overflow-y: auto !important; overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
  }
  #unitsGrid {
    width:100% !important; flex:unset !important; margin:0 !important;
    padding: 12px 12px calc(78px + env(safe-area-inset-bottom,0px)) !important;
    box-sizing:border-box !important;
    grid-template-columns:1fr !important; gap:10px !important;
    overflow-y:visible !important; min-height:0 !important;
  }

  /* Ocultar card "+ nova unit" e botões de ação — FAB substitui */
  .card-add { display: none !important; }
  .unit-card .menu-item-actions,
  .unit-card [class*="card-actions"],
  [class*="unit-card"] .btn,
  [class*="unit-card"] button:not([class*="unit-open"]):not([class*="unit-nav"]) {
    display: none !important;
  }
  .unit-card, [class*="unit-card"] { cursor: pointer !important; }

  .cards-grid { grid-template-columns:1fr !important; gap:10px !important; margin-bottom:0 !important; }
  .modal-content { border-radius:0 !important; margin:0 !important; max-height:100dvh !important; }
}
