/**
 * mobile-global.css v5
 * Header 2 linhas integrado + drawer índigo + FAB
 */

/* 1024px: alinhado a lessons-mobile.css (evita tela branca em tablet 768–1024) */
@media (max-width: 1024px) {
  :root {
    --mg-ink:      #0f172a;
    --mg-muted:    #64748b;
    --mg-rule:     rgba(15,23,42,.08);
    --mg-surface:  #f8fafc;
    --mg-primary:  #4F46E5;
    --mg-primary-soft: #EEF2FF;
    --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: 1024px) {

  /* ══ 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;
    padding-top: var(--mg-nav-current, var(--mg-nav-base)) !important;
  }

  /* ══════════════════════════════════════
     HEADER FIXO  #mobileNavBar
     ══════════════════════════════════════ */
  #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, #e2e8f0);
    box-shadow:     0 1px 0 rgba(15,23,42,.04), 0 2px 12px rgba(15,23,42,.06);
    padding-top:    env(safe-area-inset-top, 0px);
    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-primary-soft, #EEF2FF); }
  #mobileMenuBtn svg    { display: block; color: #4F46E5; }

  .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: 8.5px; font-weight: 700;
    letter-spacing: .12em; text-transform: uppercase;
    color: #64748b;
    line-height: 1; display: block;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .mnb-title {
    font-family: 'DM Serif Display', Georgia, serif;
    font-size: 16px; font-weight: 400; font-style: italic;
    color: #0f172a; letter-spacing: -.01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    line-height: 1.15; 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:hover,
  .mnb-btn:active { background: var(--mg-primary-soft, #EEF2FF); }
  .mnb-btn svg    { display: block; color: #4F46E5; stroke: #4F46E5; }

  /* ─── ROW 2: tabs de nível ─── */
  .mnb-row2 {
    display:     none;
    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;
    -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(255,255,255,.45);
    display:     inline-flex; align-items: center; justify-content: center;
    font-family: var(--mg-f-mono); font-size: 10px; font-weight: 700;
    color:       #0c4a6e; flex-shrink: 0;
    transition:  background .15s, color .15s;
  }
  .mnb-tab-name {
    font-size: 12px; font-weight: 600; color: rgba(12,74,110,.75);
    transition: color .15s; max-width: 70px;
    overflow: hidden; text-overflow: ellipsis;
  }
  .mnb-tab-count {
    font-family: var(--mg-f-mono); font-size: 9px;
    color: #0c4a6e; background: rgba(255,255,255,.40);
    padding: 1px 5px; border-radius: 6px;
  }

  .mnb-tab-wrap {
    display:     inline-flex;
    align-items: center;
    flex-shrink: 0;
    gap:         4px;
    padding:     0 4px 0 0;
  }

  .mnb-tab-edit { display: none; }

  .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: #0c4a6e; }
  .mnb-tab-active .mnb-tab-badge       { background: #0c4a6e; color: #fff; }
  .mnb-tab-active .mnb-tab-name        { color: #0c4a6e; font-weight: 800; }
  .mnb-tab-active .mnb-tab-count       { background: rgba(12,74,110,.15); color: #0c4a6e; }

  /* Tab rascunho */
  .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" */
  .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);
    -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); 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)} }
  @keyframes msd-slide-out { to{transform:translateX(-100%)} }
  #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; }

  /* ── Cabeçalho do drawer — gradiente sutil ── */
  .msd-head {
    padding:     calc(24px + env(safe-area-inset-top,0px)) 20px 20px;
    background:  linear-gradient(135deg, rgba(56,190,202,.55) 0%, rgba(249,168,212,.45) 100%);
    border-bottom: 1px solid rgba(255,255,255,.30);
    display:     flex;
    align-items: center;
    gap:         14px;
    flex-shrink: 0;
  }
  .msd-avatar {
    width: 46px; height: 46px; border-radius: 14px;
    background: rgba(255,255,255,.50);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: 700; flex-shrink: 0; color: #0c4a6e;
    box-shadow: 0 2px 8px rgba(0,0,0,.08), inset 0 1px 0 rgba(255,255,255,.7);
    border: 1.5px solid rgba(255,255,255,.60);
  }
  .msd-user-name  { font-family:var(--mg-f-body); font-size:15px; font-weight:800; color:#0c4a6e; letter-spacing:-.02em; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .msd-user-email { font-family:var(--mg-f-mono); font-size:9.5px; color:rgba(12,74,110,.65); letter-spacing:.05em; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin-top:3px; }

  .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: #94a3b8;
    padding: 14px 12px 6px; display: block;
  }
  .msd-nav-item {
    display: flex; align-items: center; gap: 12px; padding: 13px 12px; border-radius: 12px;
    background: none; border: none; cursor: pointer; width: 100%; text-align: left;
    font-family: var(--mg-f-body); font-size: 15px; font-weight: 600; color: #1e293b;
    margin-bottom: 3px; transition: background .15s, transform .14s; -webkit-tap-highlight-color: transparent;
  }
  .msd-nav-item:active { background: rgba(56,190,202,.08); transform: scale(.98); }
  .msd-nav-item.active {
    background: linear-gradient(135deg, rgba(56,190,202,.12) 0%, rgba(249,168,212,.10) 100%);
    color: #0c4a6e; font-weight: 800;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.8);
  }
  .msd-nav-icon {
    width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 18px; background: #f1f5f9;
    border: 1px solid #e2e8f0;
    transition: background .15s, border-color .15s;
  }
  .msd-nav-item.active .msd-nav-icon {
    background: linear-gradient(135deg, rgba(56,190,202,.15) 0%, rgba(249,168,212,.12) 100%);
    border-color: rgba(56,190,202,.25);
  }
  .msd-nav-item-arrow {
    margin-left: auto; font-size: 11px; color: #cbd5e1;
    transition: transform .15s;
  }
  .msd-nav-item:hover .msd-nav-item-arrow { transform: translateX(3px); color: #94a3b8; }

  /* View toggle no drawer mobile */
  .msd-view-toggle {
    display: flex; align-items: center; gap: 4px;
    padding: 4px; border-radius: 10px;
    background: #f1f5f9; border: 1px solid #e2e8f0;
    margin: 0 12px 12px;
  }
  .msd-vt-btn {
    flex: 1; padding: 7px 0; border: none; border-radius: 7px;
    background: transparent; cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 5px;
    font-family: var(--mg-f-mono); font-size: 10px; font-weight: 700;
    letter-spacing: .04em; text-transform: uppercase; color: #94a3b8;
    transition: all .18s; -webkit-tap-highlight-color: transparent;
  }
  .msd-vt-btn.active {
    background: #fff; color: #1e293b;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
  }
  .msd-vt-btn:active { transform: scale(.95); }

  .msd-footer { padding:10px; border-top:1px solid #e2e8f0; flex-shrink:0; }
  .msd-logout {
    display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px;
    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);
    border: 1px solid rgba(239,68,68,.15);
    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 — 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; }
}
