/**
 * H2 Hostel Management System — Custom Styles
 * Covers: Responsive, Dark Mode, Print, Loading States, Toastr, DataTable Exports
 */

/* ═══════════════════════════════════════════════════════════
   #24 — MOBILE RESPONSIVE FIXES
   ═══════════════════════════════════════════════════════════ */

/* Fix small-box text overflow on mobile */
@media (max-width: 576px) {
    .small-box .inner h3 { font-size: 1.5rem; }
    .small-box .inner p { font-size: 0.75rem; }
    .small-box .icon { font-size: 40px; top: 8px; }

    .content-header h1 { font-size: 1.25rem; }
    .breadcrumb { font-size: 0.75rem; }

    /* Stack filter rows on mobile */
    .card-body .row > [class*="col-md-"] {
        margin-bottom: 8px;
    }

    /* Fix modal width */
    .modal-dialog.modal-xl,
    .modal-dialog.modal-lg {
        max-width: calc(100vw - 20px);
        margin: 10px;
    }

    /* DataTable responsive fixes */
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_length {
        text-align: left !important;
        margin-bottom: 8px;
    }

    /* Info boxes stack better */
    .info-box { min-height: auto; padding: 8px; }
    .info-box .info-box-icon { width: 50px; height: 50px; line-height: 50px; font-size: 1.2rem; }
    .info-box .info-box-content { padding: 5px 10px; }

    /* Quick action buttons */
    .btn-block i.fa-2x { font-size: 1.4rem !important; }

    /* Sidebar overlay on mobile */
    .sidebar-mini.sidebar-collapse .main-sidebar {
        box-shadow: 3px 0 15px rgba(0,0,0,0.2);
    }
}

@media (max-width: 768px) {
    /* Fix table horizontal scroll */
    .table-responsive { -webkit-overflow-scrolling: touch; }

    /* Compact card headers */
    .card-header { padding: 0.5rem 0.75rem; }
    .card-header .card-title { font-size: 0.9rem; }

    /* Fix button groups wrapping */
    .btn-group-sm > .btn { padding: 0.2rem 0.4rem; font-size: 0.7rem; }
}

/* ═══════════════════════════════════════════════════════════
   #25 — DARK MODE
   ═══════════════════════════════════════════════════════════ */

body.dark-mode {
    background-color: #1a1a2e !important;
    color: #e0e0e0;
}
body.dark-mode .content-wrapper {
    background-color: #1a1a2e !important;
}
body.dark-mode .main-header {
    background-color: #16213e !important;
    border-bottom-color: #0f3460 !important;
}
body.dark-mode .main-header .nav-link { color: #e0e0e0 !important; }
body.dark-mode .main-sidebar {
    background-color: #0f3460 !important;
}
body.dark-mode .nav-sidebar .nav-link { color: #ccc !important; }
body.dark-mode .nav-sidebar .nav-link.active {
    background-color: #1a56db !important;
    color: #fff !important;
}
body.dark-mode .card {
    background-color: #16213e;
    border-color: #0f3460;
    color: #e0e0e0;
}
body.dark-mode .card-header {
    background-color: #0f3460;
    border-bottom-color: #1a1a2e;
}
body.dark-mode .table { color: #e0e0e0; }
body.dark-mode .table thead { background-color: #0f3460 !important; }
body.dark-mode .table-hover tbody tr:hover { background-color: rgba(255,255,255,0.03); }
body.dark-mode .table-striped tbody tr:nth-of-type(odd) { background-color: rgba(255,255,255,0.02); }
body.dark-mode .form-control {
    background-color: #1a1a2e;
    border-color: #0f3460;
    color: #e0e0e0;
}
body.dark-mode .form-control:focus {
    background-color: #16213e;
    border-color: #1a56db;
    color: #fff;
}
body.dark-mode .select2-container--bootstrap4 .select2-selection {
    background-color: #1a1a2e;
    border-color: #0f3460;
    color: #e0e0e0;
}
body.dark-mode .modal-content {
    background-color: #16213e;
    border-color: #0f3460;
}
body.dark-mode .modal-header { border-bottom-color: #0f3460; }
body.dark-mode .modal-footer { border-top-color: #0f3460; background-color: #0f3460 !important; }
body.dark-mode .small-box { color: #fff; }
body.dark-mode .info-box { background-color: #16213e; border-color: #0f3460; }
body.dark-mode .badge-light { background-color: #0f3460; color: #e0e0e0; }
body.dark-mode .text-muted { color: #888 !important; }
body.dark-mode .border { border-color: #0f3460 !important; }
body.dark-mode .bg-light { background-color: #0f3460 !important; }
body.dark-mode .alert { border-color: #0f3460; }
body.dark-mode code { color: #7dd3fc; }
body.dark-mode a { color: #60a5fa; }
body.dark-mode .breadcrumb-item.active { color: #999; }
body.dark-mode .content-header { border-bottom-color: #0f3460; }
body.dark-mode .card-outline { border-top-width: 3px; }

/* Dark mode toggle button styling */
#darkModeToggle {
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 4px;
    transition: background 0.2s;
}
#darkModeToggle:hover { background: rgba(0,0,0,0.1); }
body.dark-mode #darkModeToggle:hover { background: rgba(255,255,255,0.1); }

/* ═══════════════════════════════════════════════════════════
   #30 — LOADING STATES / SKELETON
   ═══════════════════════════════════════════════════════════ */

.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
}
body.dark-mode .skeleton {
    background: linear-gradient(90deg, #1a1a2e 25%, #0f3460 50%, #1a1a2e 75%);
    background-size: 200% 100%;
}
@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.skeleton-text { height: 14px; margin-bottom: 8px; width: 80%; }
.skeleton-title { height: 20px; margin-bottom: 12px; width: 60%; }
.skeleton-avatar { width: 60px; height: 60px; border-radius: 50%; }
.skeleton-box { height: 80px; }

/* Loading overlay for AJAX calls */
.loading-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: inherit;
}
body.dark-mode .loading-overlay { background: rgba(26,26,46,0.85); }
.loading-overlay .spinner-border { width: 2rem; height: 2rem; }

/* ═══════════════════════════════════════════════════════════
   #31 — TOASTR CONSISTENCY
   ═══════════════════════════════════════════════════════════ */

#toast-container > .toast {
    border-radius: 8px !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
    padding: 12px 16px 12px 50px !important;
    opacity: 1 !important;
}
#toast-container > .toast-success { background-color: #28a745 !important; }
#toast-container > .toast-error { background-color: #dc3545 !important; }
#toast-container > .toast-warning { background-color: #ffc107 !important; color: #333 !important; }
#toast-container > .toast-info { background-color: #17a2b8 !important; }
#toast-container > .toast .toast-title { font-weight: 700; margin-bottom: 2px; }
#toast-container > .toast .toast-message { font-size: 0.85rem; }

/* ═══════════════════════════════════════════════════════════
   #32 — PRINT-FRIENDLY STYLES
   ═══════════════════════════════════════════════════════════ */

@media print {
    /* Hide non-essential elements */
    .main-sidebar, .main-header, .main-footer,
    .content-header .breadcrumb, .card-tools,
    .btn, .no-print, .dataTables_length,
    .dataTables_filter, .dataTables_paginate,
    .dataTables_info, .select2-container,
    #toast-container { display: none !important; }

    /* Full width content */
    .content-wrapper { margin-left: 0 !important; padding: 0 !important; }
    .content { padding: 0 !important; }

    /* Remove shadows and backgrounds */
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
    .card-header { background: #f8f9fa !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .small-box, .info-box { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

    /* Page breaks */
    .page-break-before { page-break-before: always; }
    .page-break-after { page-break-after: always; }
    .no-page-break { page-break-inside: avoid; }

    /* Table improvements for print */
    table { font-size: 10px !important; }
    table th { background-color: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .badge { border: 1px solid #ccc; }

    /* ID Card print */
    .id-card-print { page-break-inside: avoid; margin: 5mm; }
}

/* ═══════════════════════════════════════════════════════════
   #26 — DATATABLE EXPORT BUTTONS
   ═══════════════════════════════════════════════════════════ */

.dt-toolbar {
    padding: 8px 12px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    border-radius: 4px 4px 0 0;
}
body.dark-mode .dt-toolbar {
    background: #0f3460;
    border-bottom-color: #1a1a2e;
}
.dt-buttons-wrapper {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.dt-buttons-wrapper .btn {
    border-radius: 6px !important;
    padding: 4px 10px !important;
    font-size: 0.75rem !important;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.dt-search-wrapper input {
    border-radius: 20px !important;
    padding-left: 14px !important;
    font-size: 0.82rem;
}
.dataTables_wrapper .dataTables_filter { margin-bottom: 0; }
.dataTables_wrapper .dataTables_filter input {
    margin-left: 6px;
    border: 1px solid #ced4da;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.82rem;
    width: 180px;
    transition: width 0.3s;
}
.dataTables_wrapper .dataTables_filter input:focus { width: 240px; }
body.dark-mode .dt-export-buttons {
    background: #0f3460 !important;
    border-color: #1a1a2e !important;
}
body.dark-mode .dt-export-buttons .text-muted { color: #aaa !important; }

/* Skeleton loading for DataTables */
.dt-skeleton-loader { padding: 16px; }
.dt-loading-skeleton { padding: 12px 0; }
.dt-loading-skeleton .skeleton-row,
.dt-skeleton-loader .skeleton {
    height: 14px;
    margin-bottom: 12px;
    border-radius: 4px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
}
.dt-loading-skeleton .skeleton-row:nth-child(1) { width: 100%; }
.dt-loading-skeleton .skeleton-row:nth-child(2) { width: 95%; }
.dt-loading-skeleton .skeleton-row:nth-child(3) { width: 88%; }
.dt-loading-skeleton .skeleton-row:nth-child(4) { width: 92%; }
.dt-loading-skeleton .skeleton-row:nth-child(5) { width: 85%; }
body.dark-mode .dt-loading-skeleton .skeleton-row,
body.dark-mode .dt-skeleton-loader .skeleton {
    background: linear-gradient(90deg, #1a1a2e 25%, #0f3460 50%, #1a1a2e 75%);
    background-size: 200% 100%;
}

/* DataTable processing state */
.dataTables_processing {
    background: rgba(255,255,255,0.92) !important;
    border: none !important;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08) !important;
    border-radius: 8px !important;
    padding: 16px !important;
    z-index: 100 !important;
}
body.dark-mode .dataTables_processing {
    background: rgba(26,26,46,0.92) !important;
    color: #e0e0e0 !important;
}

/* ═══════════════════════════════════════════════════════════
   #27 — ADMISSION PIPELINE STEPPER
   ═══════════════════════════════════════════════════════════ */

.admission-stepper {
    display: flex;
    align-items: center;
    overflow-x: auto;
    padding: 16px 0;
    gap: 0;
}
.admission-stepper .step {
    display: flex;
    align-items: center;
    white-space: nowrap;
}
.admission-stepper .step-circle {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: bold;
    flex-shrink: 0;
    border: 2px solid #dee2e6;
    background: #fff;
    color: #6c757d;
    transition: all 0.3s;
}
.admission-stepper .step-label {
    font-size: 0.65rem;
    color: #6c757d;
    margin-top: 4px;
    text-align: center;
    max-width: 70px;
}
.admission-stepper .step-line {
    width: 30px;
    height: 2px;
    background: #dee2e6;
    flex-shrink: 0;
}
.admission-stepper .step.completed .step-circle {
    background: #28a745;
    border-color: #28a745;
    color: #fff;
}
.admission-stepper .step.completed .step-line { background: #28a745; }
.admission-stepper .step.active .step-circle {
    background: #007bff;
    border-color: #007bff;
    color: #fff;
    box-shadow: 0 0 0 4px rgba(0,123,255,0.2);
}
.admission-stepper .step.cancelled .step-circle {
    background: #dc3545;
    border-color: #dc3545;
    color: #fff;
}

/* ═══════════════════════════════════════════════════════════
   #28 — ROOM ALLOTMENT FLOOR MAP GRID
   ═══════════════════════════════════════════════════════════ */

.floor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 8px;
    padding: 12px;
}
.room-cell {
    border: 2px solid #dee2e6;
    border-radius: 8px;
    padding: 8px 4px;
    text-align: center;
    font-size: 0.75rem;
    transition: all 0.2s;
    cursor: pointer;
    position: relative;
}
.room-cell:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.room-cell.vacant { border-color: #28a745; background: rgba(40,167,69,0.05); }
.room-cell.allotted { border-color: #ffc107; background: rgba(255,193,7,0.05); }
.room-cell.full { border-color: #dc3545; background: rgba(220,53,69,0.05); }
.room-cell.maintenance { border-color: #6c757d; background: rgba(108,117,125,0.05); }
.room-cell .room-number { font-weight: bold; font-size: 0.8rem; }
.room-cell .room-occupancy { font-size: 0.65rem; color: #6c757d; }
.room-cell .room-badge {
    position: absolute;
    top: -4px; right: -4px;
    width: 16px; height: 16px;
    border-radius: 50%;
    font-size: 8px;
    line-height: 16px;
    color: #fff;
}
.room-cell.vacant .room-badge { background: #28a745; }
.room-cell.allotted .room-badge { background: #ffc107; }
.room-cell.full .room-badge { background: #dc3545; }

/* ═══════════════════════════════════════════════════════════
   #29 — CALENDAR VIEW BASE
   ═══════════════════════════════════════════════════════════ */

.mini-calendar {
    width: 100%;
}
.mini-calendar .cal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
}
.mini-calendar .cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    padding: 8px;
}
.mini-calendar .cal-day {
    text-align: center;
    padding: 6px 4px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
}
.mini-calendar .cal-day:hover { background: #e9ecef; }
.mini-calendar .cal-day.today { background: #007bff; color: #fff; font-weight: bold; }
.mini-calendar .cal-day.has-event { position: relative; }
.mini-calendar .cal-day.has-event::after {
    content: '';
    position: absolute;
    bottom: 2px; left: 50%;
    transform: translateX(-50%);
    width: 5px; height: 5px;
    border-radius: 50%;
    background: #dc3545;
}

/* ═══════════════════════════════════════════════════════════
   #33 — BATCH ID CARD PRINT
   ═══════════════════════════════════════════════════════════ */

.id-cards-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}
.id-card-wrapper {
    width: 225px;
    height: 350px;
    page-break-inside: avoid;
    break-inside: avoid;
}
@media print {
    .id-cards-container {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 5mm;
    }
    .id-card-wrapper { margin: 0; }
}

/* ═══════════════════════════════════════════════════════════
   #34 — STUDENT PORTAL MOBILE BOTTOM NAV
   ═══════════════════════════════════════════════════════════ */

.student-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: #fff;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.1);
    z-index: 1050;
    padding: 8px 0 env(safe-area-inset-bottom, 8px);
}
.student-bottom-nav .nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
}
.student-bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: #6c757d;
    font-size: 0.65rem;
    padding: 4px 8px;
    border-radius: 8px;
    transition: all 0.2s;
}
.student-bottom-nav .nav-item.active {
    color: #007bff;
    background: rgba(0,123,255,0.08);
}
.student-bottom-nav .nav-item i { font-size: 1.2rem; margin-bottom: 2px; }

@media (max-width: 768px) {
    .student-bottom-nav { display: block; }
    /* Add padding at bottom of content to prevent overlap */
    body.student-portal .content-wrapper { padding-bottom: 70px; }
    /* Hide sidebar on student portal mobile */
    body.student-portal .main-sidebar { display: none; }
    body.student-portal .content-wrapper { margin-left: 0 !important; }
}

body.dark-mode .student-bottom-nav {
    background: #16213e;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.3);
}
body.dark-mode .student-bottom-nav .nav-item { color: #888; }
body.dark-mode .student-bottom-nav .nav-item.active { color: #60a5fa; background: rgba(96,165,250,0.1); }
