/* ===========================================
   UNIFIED MOBILE DESIGN SYSTEM
   Version: 1.0.0

   This file defines the SINGLE source of truth
   for all mobile UI patterns across the app.

   HEADER TYPES:
   - .header-primary   (List/Dashboard/Materials)
   - .header-secondary (Detail pages)
   - .header-flow      (Forms/Steps)

   FOOTER TYPES:
   - .footer-persistent (List/Dashboard/Materials)
   - .footer-contextual (Profile/Details)
   - .footer-none       (Forms - no footer)
   =========================================== */

/* ============================================
   DESIGN TOKENS (Must match everywhere)
   ============================================ */
:root {
  /* Colors - Status */
  --status-attention: #DE350B;
  --status-attention-bg: #FFEBE6;
  --status-attention-subtle: rgba(222, 53, 11, 0.08);

  --status-success: #36B37E;
  --status-success-bg: #E3FCEF;
  --status-success-subtle: rgba(54, 179, 126, 0.08);

  --status-warning: #FF991F;
  --status-warning-bg: #FFFAE6;

  --status-info: #0052CC;
  --status-info-bg: #DEEBFF;

  /* Colors - Primary */
  --primary: #0052CC;
  --primary-dark: #0043A3;
  --primary-subtle: rgba(0, 82, 204, 0.08);

  /* Colors - Neutral */
  --text-primary: #172B4D;
  --text-secondary: #6B778C;
  --text-muted: #8993A4;
  --text-inverse: #FFFFFF;

  --bg-primary: #FFFFFF;
  --bg-secondary: #F4F5F7;
  --bg-tertiary: #FAFBFC;

  --border-default: #DFE1E6;
  --border-light: #EBECF0;

  /* Dimensions - LOCKED */
  --header-height: 52px;
  --header-height-small: 48px;
  --footer-height: 56px;
  --footer-height-small: 52px;

  /* Spacing - LOCKED */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 20px;
  --space-xxl: 24px;

  /* Radius - LOCKED */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows - LOCKED */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

  /* Touch targets */
  --touch-target: 44px;
  --touch-target-sm: 36px;
}

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

  /* ==========================================
     🟦 A. PRIMARY HEADER
     Used on: Student List, Advertising, Dashboard
     ========================================== */
  .header-primary,
  body.page-list .header,
  body.page-dashboard .header,
  body.page-materials .header {
    height: var(--header-height);
    min-height: var(--header-height-small);
    max-height: var(--header-height);
    padding: 0 var(--space-md);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .header-primary .header-content,
  body.page-list .header-content,
  body.page-dashboard .header-content,
  body.page-materials .header-content {
    height: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 0;
  }

  /* Primary header: App title on left */
  .header-primary .logo h1,
  body.page-list .logo h1,
  body.page-dashboard .logo h1,
  body.page-materials .logo h1 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
  }

  /* Primary header: Right side icons */
  .header-primary .header-actions,
  body.page-list .header-actions,
  body.page-dashboard .header-actions,
  body.page-materials .header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
  }

  /* Hide logo icon on mobile */
  .header-primary .logo-icon,
  body.page-list .logo-icon,
  body.page-dashboard .logo-icon,
  body.page-materials .logo-icon {
    display: none;
  }

  /* Avatar in primary header */
  .header-primary .user-avatar,
  body.page-list .user-avatar,
  body.page-dashboard .user-avatar {
    width: 28px;
    height: 28px;
    font-size: 11px;
  }

  /* ==========================================
     🟨 B. SECONDARY HEADER
     Used on: Student Profile, Contacts, Details
     ========================================== */
  .header-secondary,
  body.page-profile .header,
  body.page-contacts .header,
  body.page-detail .header {
    height: var(--header-height);
    min-height: var(--header-height-small);
    max-height: var(--header-height);
    padding: 0 var(--space-md);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .header-secondary .header-content,
  body.page-profile .header-content,
  body.page-contacts .header-content,
  body.page-detail .header-content {
    height: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 0;
  }

  /* Secondary header: Hide app title, show page title */
  .header-secondary .logo h1,
  body.page-profile .logo h1,
  body.page-contacts .logo h1,
  body.page-detail .logo h1 {
    font-size: 0;
  }

  .header-secondary .logo::after,
  body.page-profile .logo::after {
    content: attr(data-page-title);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
  }

  /* Secondary header: Back button always visible */
  .header-secondary .back-btn,
  body.page-profile .back-btn,
  body.page-contacts .back-btn,
  body.page-detail .back-btn {
    width: var(--touch-target-sm);
    height: var(--touch-target-sm);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-full);
    font-size: 0;
    order: -1;
  }

  .header-secondary .back-btn::before,
  body.page-profile .back-btn::before,
  body.page-contacts .back-btn::before,
  body.page-detail .back-btn::before {
    content: '←';
    font-size: 20px;
    color: var(--text-secondary);
  }

  .header-secondary .back-btn:active,
  body.page-profile .back-btn:active,
  body.page-contacts .back-btn:active {
    background: var(--bg-secondary);
  }

  /* ==========================================
     🟩 C. FLOW HEADER
     Used on: Add Student (all steps)
     ========================================== */
  .header-flow,
  body.page-form .header,
  body.page-add-student .header {
    height: auto;
    min-height: var(--header-height);
    padding: var(--space-md);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .header-flow .header-content,
  body.page-form .header-content,
  body.page-add-student .header-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    padding: 0;
  }

  .header-flow .header-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
  }

  /* Flow header: Back + Title */
  .header-flow .back-btn,
  body.page-form .back-btn,
  body.page-add-student .back-btn {
    width: var(--touch-target-sm);
    height: var(--touch-target-sm);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-full);
    font-size: 0;
  }

  .header-flow .back-btn::before,
  body.page-form .back-btn::before,
  body.page-add-student .back-btn::before {
    content: '←';
    font-size: 20px;
    color: var(--text-secondary);
  }

  /* Hide SVG and span inside back button on mobile (use ::before arrow) */
  .header-flow .back-btn svg,
  .header-flow .back-btn span,
  body.page-form .back-btn svg,
  body.page-form .back-btn span,
  body.page-add-student .back-btn svg,
  body.page-add-student .back-btn span {
    display: none;
  }

  /* Flow header: No avatar, no logout, no menu */
  .header-flow .user-avatar,
  .header-flow .logout-btn,
  .header-flow .overflow-menu-btn,
  body.page-form .user-avatar,
  body.page-form .logout-btn,
  body.page-form .overflow-menu-btn,
  body.page-add-student .user-avatar,
  body.page-add-student .logout-btn,
  body.page-add-student .overflow-menu-btn {
    display: none !important;
  }

  /* Flow header: Step indicator */
  .header-flow .step-indicator,
  body.page-form .step-indicator,
  body.page-add-student .step-indicator {
    font-size: 13px;
    color: var(--text-muted);
    padding-left: calc(var(--touch-target-sm) + var(--space-md));
  }

  /* ==========================================
     COMMON HEADER ELEMENTS
     ========================================== */

  /* Hide logout button - always in overflow */
  .header .logout-btn {
    display: none !important;
  }

  /* Overflow menu button */
  .header .overflow-menu-btn {
    display: flex !important;
    width: var(--touch-target-sm);
    height: var(--touch-target-sm);
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-full);
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
  }

  .header .overflow-menu-btn:active {
    background: var(--bg-secondary);
  }

  /* Search trigger button (icon only) */
  .mobile-search-trigger {
    display: flex !important;
    width: var(--touch-target-sm);
    height: var(--touch-target-sm);
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
  }

  .mobile-search-trigger svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
  }

  .mobile-search-trigger:active {
    background: var(--bg-secondary);
  }

  .mobile-search-trigger.has-search {
    background: var(--primary);
  }

  .mobile-search-trigger.has-search svg {
    color: var(--text-inverse);
  }

  /* ==========================================
     🟦 PERSISTENT FOOTER
     Used on: Student List, Advertising, Dashboard
     ========================================== */
  .footer-persistent,
  body.page-list .mobile-bottom-nav,
  body.page-dashboard .mobile-bottom-nav,
  body.page-materials .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--footer-height);
    background: var(--bg-primary);
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 var(--space-md);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 100;
  }

  .footer-persistent .nav-item,
  body.page-list .mobile-nav-item,
  body.page-dashboard .mobile-nav-item,
  body.page-materials .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--space-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    border: none;
    background: transparent;
    cursor: pointer;
    min-width: 64px;
  }

  .footer-persistent .nav-item svg,
  body.page-list .mobile-nav-item svg,
  body.page-dashboard .mobile-nav-item svg,
  body.page-materials .mobile-nav-item svg {
    width: 22px;
    height: 22px;
  }

  .footer-persistent .nav-item.active,
  body.page-list .mobile-nav-item.active,
  body.page-dashboard .mobile-nav-item.active,
  body.page-materials .mobile-nav-item.active {
    color: var(--primary);
  }

  /* Primary action button in footer */
  .footer-persistent .nav-item.primary,
  body.page-list .mobile-nav-item.add-btn,
  body.page-dashboard .mobile-nav-item.add-btn,
  body.page-materials .mobile-nav-item.add-btn {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--text-inverse);
    padding: var(--space-sm) var(--space-lg);
    border-radius: 22px;
    flex-direction: row;
    gap: var(--space-sm);
    box-shadow: 0 2px 8px rgba(0, 82, 204, 0.3);
  }

  .footer-persistent .nav-item.primary svg,
  body.page-list .mobile-nav-item.add-btn svg,
  body.page-dashboard .mobile-nav-item.add-btn svg {
    width: 16px;
    height: 16px;
  }

  /* ==========================================
     🟨 CONTEXTUAL FOOTER
     Used on: Student Profile
     ========================================== */
  .footer-contextual,
  body.page-profile .mobile-bottom-nav,
  body.page-contacts .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--footer-height);
    background: var(--bg-primary);
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 var(--space-md);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 100;
  }

  /* ==========================================
     🟩 NO FOOTER (Forms)
     ========================================== */
  body.page-form .mobile-bottom-nav,
  body.page-add-student .mobile-bottom-nav {
    display: none !important;
  }

  /* ==========================================
     OVERFLOW MENU (Standard)
     ========================================== */
  .overflow-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1500;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
  }

  .overflow-menu.open {
    opacity: 1;
    visibility: visible;
  }

  .overflow-menu-content {
    position: absolute;
    top: var(--header-height);
    right: var(--space-md);
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    overflow: hidden;
    transform: translateY(-10px) scale(0.95);
    opacity: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  .overflow-menu.open .overflow-menu-content {
    transform: translateY(0) scale(1);
    opacity: 1;
  }

  .overflow-menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 14px var(--space-lg);
    font-size: 15px;
    color: var(--text-primary);
    text-decoration: none;
    border: none;
    background: none;
    width: 100%;
    cursor: pointer;
  }

  .overflow-menu-item:active {
    background: var(--bg-secondary);
  }

  .overflow-menu-item svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
  }

  .overflow-menu-item.danger {
    color: var(--status-attention);
  }

  .overflow-menu-item.danger svg {
    color: var(--status-attention);
  }

  .overflow-menu-divider {
    height: 1px;
    background: var(--border-light);
    margin: var(--space-xs) 0;
  }

  /* ==========================================
     SEARCH OVERLAY (Standard)
     ========================================== */
  .search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    transform: translateY(-100%);
    opacity: 0;
    transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s ease;
    visibility: hidden;
  }

  .search-overlay.open {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
  }

  .search-overlay-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-light);
    min-height: var(--header-height);
  }

  .search-overlay-back {
    width: var(--touch-target-sm);
    height: var(--touch-target-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
  }

  .search-overlay-back svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
  }

  .search-overlay-input-wrapper {
    flex: 1;
    position: relative;
  }

  .search-overlay-input {
    width: 100%;
    padding: var(--space-md) var(--touch-target) var(--space-md) 14px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: 16px;
    background: var(--bg-secondary);
    outline: none;
  }

  .search-overlay-input:focus {
    border-color: var(--primary);
    background: var(--bg-primary);
  }

  .search-overlay-clear {
    position: absolute;
    right: var(--space-sm);
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
  }

  .search-overlay-clear.visible {
    display: flex;
  }

  .search-overlay-filters {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-secondary);
  }

  .search-filter-row {
    display: flex;
    gap: var(--space-sm);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .search-filter-row::-webkit-scrollbar {
    display: none;
  }

  .search-filter-chip {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: var(--space-sm) 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
  }

  .search-filter-chip.active {
    background: var(--primary-subtle);
    border-color: var(--primary);
    color: var(--primary);
  }

  .search-overlay-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
  }

  /* ==========================================
     STANDARDIZED STATUS BADGES
     ========================================== */
  .status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }

  .status-badge.attention {
    background: var(--status-attention-bg);
    color: var(--status-attention);
  }

  .status-badge.attention::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--status-attention);
    border-radius: var(--radius-full);
    animation: pulse-badge 1.5s ease-in-out infinite;
  }

  .status-badge.success {
    background: var(--status-success-bg);
    color: var(--status-success);
  }

  .status-badge.success::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--status-success);
    border-radius: var(--radius-full);
  }

  @keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
  }

  /* ==========================================
     STANDARDIZED CARDS
     ========================================== */
  .card {
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-md);
  }

  .card.status-left {
    border-left-width: 3px;
  }

  .card.status-left.attention {
    border-left-color: var(--status-attention);
  }

  .card.status-left.success {
    border-left-color: var(--status-success);
  }

  /* ==========================================
     STANDARDIZED BUTTONS
     ========================================== */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    min-height: var(--touch-target);
    transition: all 0.2s ease;
  }

  .btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--text-inverse);
  }

  .btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
  }

  .btn-success {
    background: linear-gradient(135deg, var(--status-success) 0%, #00875A 100%);
    color: var(--text-inverse);
  }

  .btn-danger {
    background: var(--status-attention-bg);
    color: var(--status-attention);
    border: 1px solid rgba(222, 53, 11, 0.2);
  }

  /* ==========================================
     FAB BUTTON (Standard)
     ========================================== */
  .fab {
    position: fixed;
    bottom: calc(var(--footer-height) + var(--space-lg));
    right: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 14px 20px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--text-inverse);
    border: none;
    border-radius: 28px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 82, 204, 0.35);
    z-index: 50;
  }

  .fab svg {
    width: 18px;
    height: 18px;
  }

  .fab:active {
    transform: scale(0.96);
  }

  .fab.success {
    background: linear-gradient(135deg, var(--status-success) 0%, #00875A 100%);
    box-shadow: 0 4px 16px rgba(54, 179, 126, 0.4);
  }

  /* Hide FAB when no footer (forms) */
  body.page-form .fab,
  body.page-add-student .fab {
    bottom: var(--space-lg);
  }

  /* ==========================================
     CONTENT AREA ADJUSTMENTS
     ========================================== */

  /* Add padding for persistent footer */
  body.page-list .main-content,
  body.page-dashboard .main-content,
  body.page-materials .main-content {
    padding-bottom: calc(var(--footer-height) + var(--space-lg) + env(safe-area-inset-bottom));
  }

  /* Add padding for contextual footer */
  body.page-profile .main-content,
  body.page-contacts .main-content {
    padding-bottom: calc(var(--footer-height) + var(--space-lg) + env(safe-area-inset-bottom));
  }

  /* No extra padding for forms */
  body.page-form .main-content,
  body.page-add-student .main-content {
    padding-bottom: var(--space-lg);
  }
}

/* ============================================
   DESKTOP - HIDE MOBILE ELEMENTS
   ============================================ */
@media (min-width: 769px) {
  .overflow-menu-btn,
  .overflow-menu,
  .mobile-search-trigger,
  .search-overlay,
  .mobile-bottom-nav,
  .fab {
    display: none !important;
  }
}
