/* ===========================================
   MOBILE DASHBOARD COMPACT UI
   Version: 4.0.0
   Goals: True mobile-first, expandable search
   =========================================== */

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

  /* ==========================================
     1. ULTRA-COMPACT HEADER (48-56px)
     ========================================== */
  .header {
    padding: 0;
    min-height: 48px;
    max-height: 56px;
  }

  .header-content {
    height: 48px;
    min-height: 48px;
    max-height: 56px;
    padding: 0 12px;
    gap: 12px;
  }

  /* Show compact logo icon on mobile */
  .logo-icon {
    display: flex;
  }

  .logo-icon svg {
    width: 28px;
    height: 28px;
  }

  .logo {
    gap: 8px;
  }

  .logo h1 {
    font-size: 16px;
    font-weight: 600;
  }

  /* User info container alignment */
  .user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
  }

  /* Compact user avatar */
  .user-avatar {
    width: 28px;
    height: 28px;
    font-size: 11px;
    flex-shrink: 0;
    order: 1;
  }

  /* Hide logout button - moved to overflow */
  .logout-btn {
    display: none !important;
  }

  /* Hide welcome text on mobile */
  .welcome-text {
    display: none !important;
  }

  /* Overflow menu button */
  .overflow-menu-btn {
    display: flex !important;
    width: 36px;
    height: 36px;
    min-width: 36px;
    align-items: center;
    justify-content: center;
    background: var(--dash-bg, #F0F2F5);
    border: 1px solid var(--dash-border, #E4E6EA);
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    font-weight: bold;
    color: var(--dash-text, #1C1E21);
    padding: 0;
    flex-shrink: 0;
  }

  .overflow-menu-btn:active {
    background: var(--dash-border, #E4E6EA);
  }

  /* ==========================================
     2. STATS ROW WITH SEARCH ICON
     ========================================== */
  .stats-cards {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    margin-bottom: 10px;
    padding: 0;
    background: transparent;
    align-items: center;
  }

  .stat-card {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 20px;
    background: var(--dash-bg-card);
    border: 1px solid var(--dash-border);
    box-shadow: none;
    min-width: auto;
  }

  /* Hide "Loaded" and "Filtered" stats */
  .stat-card:nth-child(2),
  .stat-card:nth-child(3) {
    display: none !important;
  }

  .stat-card:hover {
    transform: none;
    box-shadow: none;
  }

  .stat-card-icon {
    width: 16px;
    height: 16px;
    min-width: 16px;
    border-radius: 50%;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
  }

  .stat-card-icon svg {
    width: 11px;
    height: 11px;
  }

  .stat-card-value {
    font-size: 14px;
    font-weight: 700;
    margin: 0;
    line-height: 1;
  }

  .stat-card-label {
    font-size: 12px;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    color: var(--dash-text-secondary);
  }

  /* Attention chip - tappable */
  .stat-card:has(.stat-card-icon.attention) {
    background: var(--dash-danger-subtle);
    border-color: rgba(222, 53, 11, 0.2);
    cursor: pointer;
  }

  .stat-card:has(.stat-card-icon.attention):active {
    transform: scale(0.97);
  }

  /* ==========================================
     3. SEARCH TRIGGER BUTTON (Magnifier Only)
     ========================================== */
  .mobile-search-trigger {
    display: flex !important;
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    align-items: center;
    justify-content: center;
    background: var(--dash-bg-card, #FFFFFF);
    border: 1px solid var(--dash-border, #E4E6EA);
    border-radius: 50%;
    cursor: pointer;
    margin-left: auto;
    flex-shrink: 0;
    transition: all 0.2s ease;
    aspect-ratio: 1 / 1;
  }

  .mobile-search-trigger svg {
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    color: var(--dash-text-secondary, #65676B);
    flex-shrink: 0;
  }

  .mobile-search-trigger:active {
    transform: scale(0.95);
    background: var(--dash-primary-subtle);
  }

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

  .mobile-search-trigger.has-search svg {
    color: white;
  }

  /* ==========================================
     4. HIDE DEFAULT SEARCH CONTROLS
     ========================================== */
  .controls {
    display: none !important;
  }

  .controls-header {
    display: none !important;
  }

  .controls-row {
    display: none !important;
  }

  /* Hide all redundant displays */
  .stats-bar,
  .mobile-students-summary,
  .attention-filter-chip {
    display: none !important;
  }

  /* ==========================================
     5. SEARCH OVERLAY - Clean Design
     ========================================== */
  .search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #F7F8FA;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    opacity: 0;
    transition: transform 0.3s 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 */
  .search-overlay-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #FFFFFF;
    border-bottom: 1px solid #EBEDF0;
    min-height: 60px;
  }

  .search-overlay-back {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F0F2F5;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
  }

  .search-overlay-back svg {
    width: 20px;
    height: 20px;
    color: #1C1E21;
    stroke: #1C1E21;
  }

  .search-overlay-back:active {
    transform: scale(0.94);
    background: #E4E6EA;
  }

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

  .search-overlay-input {
    width: 100%;
    padding: 12px 42px 12px 16px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    background: #F0F2F5;
    outline: none;
    transition: all 0.2s ease;
    color: #1C1E21;
  }

  .search-overlay-input:focus {
    background: #FFFFFF;
    box-shadow: 0 0 0 2px rgba(0, 82, 204, 0.15);
  }

  .search-overlay-input::placeholder {
    color: #8A8D91;
  }

  .search-overlay-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    display: none;
    align-items: center;
    justify-content: center;
    background: #E4E6EA;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.15s ease;
  }

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

  .search-overlay-clear:active {
    transform: translateY(-50%) scale(0.9);
  }

  .search-overlay-clear svg {
    width: 14px;
    height: 14px;
    color: #65676B;
  }

  /* Filter section in overlay */
  .search-overlay-filters {
    padding: 12px 16px;
    background: #FFFFFF;
    border-bottom: 1px solid #EBEDF0;
  }

  .search-filter-row {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 2px 0;
  }

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

  .search-filter-chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    background: #F0F2F5;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    color: #65676B;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
  }

  .search-filter-chip:active {
    transform: scale(0.96);
  }

  .search-filter-chip.active {
    background: #0052CC;
    color: #FFFFFF;
  }

  .search-filter-chip svg {
    width: 14px;
    height: 14px;
  }

  /* Search overlay content */
  .search-overlay-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
  }

  /* Search results in overlay */
  .search-overlay-results {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .search-results-count {
    font-size: 13px;
    font-weight: 500;
    color: #8A8D91;
    margin-bottom: 12px;
    padding: 0;
  }

  /* Empty search state */
  .search-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
  }

  .search-empty-state svg {
    width: 56px;
    height: 56px;
    color: #BCC0C4;
    margin-bottom: 16px;
  }

  .search-empty-state-title {
    font-size: 17px;
    font-weight: 600;
    color: #1C1E21;
    margin-bottom: 6px;
  }

  .search-empty-state-text {
    font-size: 14px;
    color: #8A8D91;
    line-height: 1.4;
  }

  /* ==========================================
     FILTER BOTTOM SHEET
     ========================================== */

  /* Backdrop overlay */
  .filter-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2500;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
  }

  .filter-overlay.open {
    opacity: 1;
    visibility: visible;
  }

  /* Bottom sheet */
  .filter-bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--dash-bg-card, #FFFFFF);
    border-radius: 20px 20px 0 0;
    z-index: 2600;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .filter-bottom-sheet.open {
    transform: translateY(0);
  }

  /* Sheet header */
  .filter-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--dash-border-light, #F0F2F5);
    position: relative;
  }

  .filter-sheet-header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: var(--dash-border, #E4E6EA);
    border-radius: 2px;
  }

  .filter-sheet-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--dash-text, #1C1E21);
  }

  .filter-sheet-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--dash-bg, #F0F2F5);
    border: none;
    border-radius: 50%;
    cursor: pointer;
  }

  .filter-sheet-close svg {
    color: var(--dash-text-secondary, #65676B);
  }

  .filter-sheet-close:active {
    background: var(--dash-border, #E4E6EA);
  }

  /* Sheet content */
  .filter-sheet-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
  }

  .filter-group {
    margin-bottom: 20px;
  }

  .filter-group:last-child {
    margin-bottom: 0;
  }

  .filter-group-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--dash-text-secondary, #65676B);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
  }

  .filter-group select {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    border: 1px solid var(--dash-border, #E4E6EA);
    border-radius: 12px;
    background: var(--dash-bg-card, #FFFFFF);
    color: var(--dash-text, #1C1E21);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2365676B' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
  }

  .filter-group select:focus {
    outline: none;
    border-color: var(--dash-primary, #0052CC);
  }

  /* Sheet actions */
  .filter-sheet-actions {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--dash-border-light, #F0F2F5);
    background: var(--dash-bg-card, #FFFFFF);
  }

  .filter-reset-btn {
    flex: 1;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    background: var(--dash-bg, #F0F2F5);
    color: var(--dash-text-secondary, #65676B);
    border: none;
    border-radius: 12px;
    cursor: pointer;
  }

  .filter-reset-btn:active {
    background: var(--dash-border, #E4E6EA);
  }

  .filter-apply-btn {
    flex: 2;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    background: var(--dash-primary, #0052CC);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
  }

  .filter-apply-btn:active {
    background: var(--dash-primary-dark, #003E99);
  }

  /* ==========================================
     6. OVERFLOW MENU (Header Menu)
     ========================================== */
  .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: 52px;
    right: 12px;
    background: var(--dash-bg-card);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    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: 12px;
    padding: 14px 16px;
    font-size: 15px;
    color: var(--dash-text);
    text-decoration: none;
    border: none;
    background: none;
    width: 100%;
    cursor: pointer;
    transition: background 0.15s;
  }

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

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

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

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

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

  /* ==========================================
     7. REDUCED GLOBAL PADDING
     ========================================== */
  .main-content {
    padding: 10px;
    padding-bottom: calc(60px + env(safe-area-inset-bottom));
  }

  /* ==========================================
     8. OPTIMIZED BOTTOM NAVIGATION
     ========================================== */
  .mobile-bottom-nav {
    height: 54px;
  }

  .mobile-nav-content {
    height: 100%;
    padding: 0 12px;
  }

  .mobile-nav-item {
    padding: 6px 10px;
    gap: 2px;
    font-size: 10px;
  }

  .mobile-nav-item svg {
    width: 20px;
    height: 20px;
  }

  .mobile-nav-item.add-btn {
    background: linear-gradient(135deg, var(--dash-primary) 0%, var(--dash-primary-dark) 100%);
    padding: 8px 16px;
    margin: -4px 0;
    border-radius: 22px;
    flex-direction: row;
    gap: 6px;
    box-shadow: 0 2px 8px rgba(0, 82, 204, 0.3);
  }

  .mobile-nav-item.add-btn::after {
    content: 'Add Student';
    font-size: 13px;
    font-weight: 600;
  }

  .mobile-nav-item.add-btn svg {
    width: 16px;
    height: 16px;
  }

  /* ==========================================
     9. STUDENT CARD - ULTRA COMPACT
     ========================================== */
  .students-grid {
    gap: 8px;
  }

  .student-card {
    border-radius: 10px;
    border: 1px solid var(--dash-border);
    overflow: visible;
  }

  .student-card::before {
    display: none;
  }

  .student-card.attention {
    border-left: 3px solid var(--dash-danger);
  }

  .student-card.normal {
    border-left: 3px solid var(--dash-success);
  }

  .card-main-content {
    padding: 10px 12px;
    padding-right: 32px;
  }

  .student-header {
    flex-direction: row;
    align-items: center;
    margin-bottom: 6px;
    gap: 8px;
  }

  .student-info {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-wrap: wrap;
  }

  .student-name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 0;
    line-height: 1.2;
  }

  .student-passport {
    font-size: 11px;
    color: var(--dash-text-muted);
    font-weight: 500;
  }

  .attention-badge,
  .normal-badge {
    padding: 3px 8px;
    font-size: 9px;
    gap: 4px;
    border-radius: 10px;
    flex-shrink: 0;
  }

  .attention-badge::before,
  .normal-badge::before {
    width: 5px;
    height: 5px;
  }

  .student-details {
    gap: 0;
  }

  .detail-row {
    padding: 3px 0;
    border-bottom: none;
  }

  .detail-row .detail-label {
    display: none;
  }

  .detail-row .detail-value {
    max-width: 100%;
    text-align: left;
    font-size: 13px;
    color: var(--dash-text-secondary);
    line-height: 1.3;
  }

  .detail-row:first-child .detail-value {
    font-size: 14px;
    font-weight: 500;
    color: var(--dash-text);
  }

  .detail-row:nth-child(2) .detail-value {
    font-size: 13px;
    color: var(--dash-text-secondary);
  }

  .detail-row:nth-child(n+3) {
    display: none;
  }

  .record-id {
    display: none;
  }

  .student-card::after {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23B0B3B8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M9 5l7 7-7 7'/%3E%3C/svg%3E");
    background-size: contain;
    opacity: 0.4;
    pointer-events: none;
  }

  .student-card:active {
    background: var(--dash-bg);
  }

  .student-card:active::after {
    opacity: 0.8;
  }

  /* ==========================================
     10. EMPTY STATE - COMPACT
     ========================================== */
  .empty-state {
    padding: 36px 20px;
    margin: 12px 0;
    border-radius: 12px;
  }

  .empty-state-icon {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
  }

  .empty-state h3 {
    font-size: 17px;
    margin-bottom: 6px;
  }

  .empty-state-description {
    font-size: 14px;
    margin-bottom: 20px;
  }
}

/* ============================================
   EXTRA SMALL MOBILE (< 480px)
   ============================================ */
@media (max-width: 480px) {
  .header-content {
    height: 44px;
    min-height: 44px;
    padding: 0 10px;
  }

  .logo h1 {
    font-size: 15px;
  }

  .user-avatar {
    width: 26px;
    height: 26px;
    font-size: 10px;
  }

  .overflow-menu-btn {
    width: 28px;
    height: 28px;
    font-size: 16px;
  }

  .stats-cards {
    gap: 6px;
  }

  .stat-card {
    padding: 6px 10px;
  }

  .stat-card-icon {
    width: 14px;
    height: 14px;
  }

  .stat-card-value {
    font-size: 13px;
  }

  .stat-card-label {
    font-size: 11px;
  }

  .mobile-search-trigger {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
  }

  .mobile-search-trigger svg {
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
  }

  .main-content {
    padding: 8px;
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
  }

  .students-grid {
    gap: 6px;
  }

  .student-card {
    border-radius: 8px;
  }

  .card-main-content {
    padding: 8px 10px;
    padding-right: 28px;
  }

  .student-name {
    font-size: 14px;
  }

  .student-passport {
    font-size: 10px;
  }

  .attention-badge,
  .normal-badge {
    padding: 2px 6px;
    font-size: 8px;
  }

  .detail-row:first-child .detail-value {
    font-size: 13px;
  }

  .detail-row:nth-child(2) .detail-value {
    font-size: 12px;
  }

  .mobile-bottom-nav {
    height: 50px;
  }

  .mobile-nav-item {
    font-size: 9px;
  }

  .mobile-nav-item svg {
    width: 18px;
    height: 18px;
  }

  .mobile-nav-item.add-btn {
    padding: 6px 12px;
    border-radius: 18px;
  }

  .mobile-nav-item.add-btn::after {
    font-size: 12px;
  }

  .mobile-nav-item.add-btn svg {
    width: 14px;
    height: 14px;
  }

  /* Search overlay adjustments */
  .search-overlay-header {
    min-height: 52px;
    padding: 8px 10px;
  }

  .search-overlay-input {
    font-size: 15px;
    padding: 8px 36px 8px 12px;
  }

  .search-filter-chip {
    padding: 6px 12px;
    font-size: 12px;
  }

  .overflow-menu-content {
    top: 48px;
    right: 10px;
    min-width: 160px;
  }

  .overflow-menu-item {
    padding: 12px 14px;
    font-size: 14px;
  }
}

/* ============================================
   TINY MOBILE (< 360px)
   ============================================ */
@media (max-width: 360px) {
  .header-content {
    height: 42px;
    padding: 0 8px;
  }

  .logo h1 {
    font-size: 14px;
  }

  .stat-card-label {
    display: none;
  }

  .stat-card {
    padding: 5px 8px;
  }

  .mobile-search-trigger {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
  }

  .main-content {
    padding: 6px;
  }

  .students-grid {
    gap: 5px;
  }

  .card-main-content {
    padding: 6px 8px;
    padding-right: 24px;
  }

  .student-name {
    font-size: 13px;
  }

  .detail-row .detail-value {
    font-size: 12px;
  }

  .mobile-bottom-nav {
    height: 48px;
  }

  .mobile-nav-item.add-btn::after {
    content: 'Add';
    font-size: 11px;
  }
}

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