/* EDUSPACE School Management ERP — Mobile-First & Desktop Design System */

:root {
    --wa-green: #008069;
    --wa-green-dark: #075e54;
    --wa-green-light: #25d366;
    --wa-bg: #f8fafc;
    --primary: #008069;
    --primary-gradient: linear-gradient(135deg, #008069 0%, #075e54 100%);
    --primary-hover: #075e54;
    --primary-light: #e6f4f1;
    --secondary: #0ea5e9;
    --success: #10b981;
    --success-light: #dcf8c6;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --dark: #111b21;
    --slate-800: #111b21;
    --slate-700: #3b4a54;
    --slate-600: #667781;
    --slate-400: #8696a0;
    --slate-200: #e2e8f0;
    --slate-100: #f0f2f5;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px rgba(11, 20, 26, 0.08);
    --shadow-md: 0 4px 12px rgba(11, 20, 26, 0.12);
    --shadow-lg: 0 12px 24px rgba(11, 20, 26, 0.2);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100vw;
    max-width: 100%;
    overflow-x: hidden;
    background-color: var(--wa-bg);
    color: var(--dark);
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-bottom: 64px; /* Space for Mobile Bottom Bar */
}

/* =========================================================
   1. SINGLE CONSOLIDATED TOP HEADER BAR (ZERO OVERLAP)
   ========================================================= */
.app-header {
    background: var(--wa-green);
    color: var(--white);
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 9000;
    height: 56px;
    max-height: 56px;
    width: 100%;
    flex-wrap: nowrap;
    overflow: hidden;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.mobile-nav-toggle {
    background: none;
    border: none;
    color: var(--white);
    font-size: 1.3rem;
    cursor: pointer;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--white);
    flex-shrink: 0;
}

.logo-badge {
    background: rgba(255, 255, 255, 0.2);
    color: var(--white);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-weight: 900;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.header-title {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--white);
    line-height: 1;
    white-space: nowrap;
    flex-shrink: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.desktop-role-pills {
    display: none;
    align-items: center;
    gap: 4px;
    margin-right: 6px;
    flex-shrink: 0;
}

.role-label {
    font-size: 0.72rem;
    font-weight: 800;
    opacity: 0.85;
    margin-right: 2px;
    white-space: nowrap;
}

.role-pill {
    background: rgba(255, 255, 255, 0.18);
    color: var(--white);
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 800;
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.role-pill:hover, .role-pill.active {
    background: var(--white);
    color: var(--wa-green);
}

.header-icon-btn {
    background: none;
    border: none;
    color: var(--white);
    font-size: 1.15rem;
    cursor: pointer;
    position: relative;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.icon-badge {
    position: absolute;
    top: 3px;
    right: 3px;
    background: var(--wa-green-light);
    color: var(--dark);
    font-size: 0.65rem;
    font-weight: 900;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* User Dropdown Menu */
.user-dropdown-container {
    position: relative;
    flex-shrink: 0;
}

.user-avatar-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: var(--white);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.user-dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 48px;
    background: var(--white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    width: 250px;
    z-index: 999999 !important;
    padding: 8px 0;
    border: 1px solid var(--slate-200);
}

.user-dropdown-menu.open {
    display: block;
}

.dropdown-header {
    padding: 10px 16px;
    border-bottom: 1px solid var(--slate-200);
}

.dropdown-divider {
    height: 1px;
    background: var(--slate-200);
    margin: 6px 0;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--slate-800);
    text-decoration: none;
    min-height: 44px;
}

.dropdown-item:hover, .dropdown-item.active {
    background: var(--primary-light);
    color: var(--wa-green);
}

.dropdown-item.text-danger {
    color: var(--danger);
}

/* Mobile Horizontal Top Sub-Header Tab Bar (<768px) */
.wa-tab-bar {
    background: var(--wa-green);
    display: flex;
    align-items: center;
    overflow-x: auto;
    width: 100%;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 56px;
    z-index: 8900;
    -webkit-overflow-scrolling: touch;
}

.wa-tab-item {
    flex: 1;
    min-width: 90px;
    text-align: center;
    padding: 12px 10px;
    color: rgba(255, 255, 255, 0.75);
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.wa-tab-item.active {
    color: var(--white);
    border-bottom-color: var(--white);
    font-weight: 900;
    opacity: 1;
}

/* =========================================================
   2. APP LAYOUT & SIDEBAR DRAWER (<768PX MOBILE)
   ========================================================= */
.app-container {
    display: flex;
    flex: 1;
    width: 100%;
    position: relative;
}

.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background: var(--white);
    border-right: 1px solid var(--slate-200);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 9999;
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 6px 12px;
    border-bottom: 1px solid var(--slate-100);
    margin-bottom: 8px;
}

.sidebar-close-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--slate-600);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(11, 20, 26, 0.65);
    backdrop-filter: blur(3px);
    z-index: 9990;
    display: none;
}

.sidebar-overlay.open {
    display: block;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    color: var(--slate-700);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 700;
    min-height: 44px;
}

.nav-item:hover, .nav-item.active {
    background: var(--primary-light);
    color: var(--wa-green);
}

.app-main {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    width: 100%;
    min-width: 0;
}

/* =========================================================
   3. MOBILE CARD LIST & WHATSAPP ITEMS
   ========================================================= */
.wa-card {
    background: var(--white);
    border-radius: var(--radius-md);
    border: 1px solid var(--slate-200);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 14px;
}

.wa-list {
    display: flex;
    flex-direction: column;
}

.wa-list-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    background: var(--white);
    border-bottom: 1px solid var(--slate-100);
    text-decoration: none;
    color: var(--dark);
    cursor: pointer;
    min-height: 64px;
}

.wa-list-item:last-child {
    border-bottom: none;
}

.wa-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--wa-green-dark);
    color: var(--white);
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    flex-shrink: 0;
    position: relative;
}

.wa-avatar-online {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--wa-green-light);
    border: 2px solid var(--white);
}

.wa-item-body {
    flex: 1;
    min-width: 0;
}

.wa-item-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
}

.wa-item-title {
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--dark);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wa-item-time {
    font-size: 0.72rem;
    color: var(--wa-green);
    font-weight: 700;
    flex-shrink: 0;
}

.wa-item-subtext {
    font-size: 0.8rem;
    color: var(--slate-600);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wa-badge {
    background: var(--wa-green-light);
    color: var(--dark);
    font-size: 0.7rem;
    font-weight: 900;
    padding: 2px 7px;
    border-radius: 999px;
}

.wa-fab {
    position: fixed;
    bottom: 80px;
    right: 18px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--wa-green-light);
    color: var(--dark);
    box-shadow: 0 4px 14px rgba(37, 211, 102, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 8800;
    border: none;
    transition: transform 0.2s;
}

.wa-fab:active {
    transform: scale(0.92);
}

/* =========================================================
   4. STAT CARDS LAYOUT & OVERFLOW FIXES
   ========================================================= */
.urgent-alert-banner {
    background: var(--danger-light);
    border: 1px solid var(--danger);
    border-left: 4px solid var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius-md);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.urgent-alert-title {
    font-size: 0.82rem;
    font-weight: 800;
    color: var(--danger);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
    width: 100%;
}

.stat-card {
    background: var(--white);
    padding: 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--slate-200);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-width: 0;
    overflow: hidden;
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--slate-600);
    font-size: 0.72rem;
    font-weight: 800;
    min-width: 0;
}

.stat-header span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--dark);
    margin-top: 6px;
    line-height: 1.2;
}

.stat-subtitle {
    font-size: 0.7rem;
    color: var(--slate-600);
    margin-top: 4px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}

.section-title {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--dark);
    margin: 14px 0 10px;
}

.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
    width: 100%;
}

.btn-quick-action {
    background: var(--white);
    border: 1px solid var(--slate-200);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--dark);
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    min-height: 46px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-hero-action {
    width: 100%;
    padding: 14px;
    background: var(--wa-green);
    color: var(--white);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 128, 105, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
}

.card-table {
    background: var(--white);
    border-radius: var(--radius-md);
    border: 1px solid var(--slate-200);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 16px;
    width: 100%;
}

.table-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--slate-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    white-space: nowrap;
}

.data-table th {
    background: var(--slate-100);
    color: var(--slate-700);
    text-align: left;
    padding: 12px 14px;
    font-weight: 800;
}

.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--slate-200);
}

.status-dot-toggle {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
}

.dot-present { background: var(--success-light); border: 2px solid var(--success); color: var(--success); }
.dot-absent { background: var(--danger-light); border: 2px solid var(--danger); color: var(--danger); }
.dot-late { background: var(--warning-light); border: 2px solid var(--warning); color: var(--warning); }

.badge {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    display: inline-block;
}

.badge-success { background: var(--success-light); color: var(--dark); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-primary { background: var(--primary-light); color: var(--wa-green); }

.btn {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-weight: 800;
    font-size: 0.85rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
    min-height: 44px;
}

.btn-primary { background: var(--wa-green); color: var(--white); }
.btn-secondary { background: var(--slate-100); color: var(--dark); border: 1px solid var(--slate-200); }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; min-height: 38px; }

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(11, 20, 26, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 10000;
    padding: 0;
}

.modal-card {
    background: var(--white);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 740px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--slate-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--white);
    z-index: 10;
}

.modal-body {
    padding: 18px;
}

.modal-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--slate-200);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    position: sticky;
    bottom: 0;
    background: var(--white);
}

.form-group {
    margin-bottom: 14px;
}

.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 800;
    color: var(--slate-700);
    margin-bottom: 5px;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    outline: none;
    background: var(--white);
    min-height: 44px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
}

.mobile-bottom-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--white);
    border-top: 1px solid var(--slate-200);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
    z-index: 8900;
    justify-content: space-around;
    align-items: center;
    padding: 0 4px;
}

.bottom-bar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--slate-600);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 700;
    flex: 1;
    height: 100%;
    min-height: 44px;
}

.bottom-bar-item.active, .bottom-bar-item:hover {
    color: var(--wa-green);
}

.bottom-bar-icon {
    font-size: 1.25rem;
}

/* =========================================================
   5. DESKTOP BREAKPOINTS (≥768PX & ≥1024PX)
   ========================================================= */
@media (min-width: 768px) {
    body {
        padding-bottom: 0;
    }

    /* Hide Mobile Controls */
    .mobile-bottom-bar, .wa-tab-bar, .wa-fab, .mobile-nav-toggle {
        display: none !important;
    }

    /* Show Desktop Role Pills */
    .desktop-role-pills {
        display: flex !important;
    }

    /* Desktop Sidebar */
    .app-sidebar {
        position: static;
        transform: none !important;
        width: 250px;
        height: auto;
        box-shadow: none;
        display: flex !important;
    }

    .sidebar-header, .sidebar-overlay {
        display: none !important;
    }

    .app-main {
        padding: 24px;
    }

    /* Desktop Stat Grid */
    .stats-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 16px;
    }

    .stat-card {
        padding: 18px;
    }

    .stat-value {
        font-size: 1.8rem;
    }

    .quick-actions-grid {
        grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    }

    .desktop-only-table {
        display: block !important;
    }

    .mobile-card-list {
        display: none !important;
    }

    .modal-overlay {
        padding: 16px;
        align-items: center;
    }

    .modal-card {
        border-radius: var(--radius-lg);
    }
}

@media (min-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
}
