﻿/* ========================================
   School Management System - Premium CSS
   ======================================== */

:root {
    --primary: #4361ee;
    --primary-dark: #3a56d4;
    --primary-light: #eef2ff;
    --secondary: #7209b7;
    --success: #06d6a0;
    --success-light: #e6fff7;
    --danger: #ef476f;
    --danger-light: #fde8ed;
    --warning: #ffd166;
    --warning-light: #fff8e6;
    --info: #118ab2;
    --info-light: #e6f5fa;
    --dark: #1e293b;
    --gray-100: #f8fafc;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --sidebar-width: 260px;
    --sidebar-collapsed: 70px;
    --topbar-height: 64px;
    --border-radius: 12px;
    --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 10px 30px rgba(0,0,0,0.12);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { overflow-x: hidden; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--gray-100);
    color: var(--dark);
    overflow-x: hidden;
}

/* Sidebar */
.wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--dark) 0%, #0f172a 100%);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: var(--transition);
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .nav-section { display: none; }

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo-container { display: flex; align-items: center; gap: 12px; }
.logo-icon { font-size: 28px; color: var(--primary); }
.logo-text { font-size: 20px; font-weight: 700; color: white; letter-spacing: -0.5px; }

.sidebar-nav { list-style: none; padding: 10px 0; }

.nav-section {
    padding: 15px 20px 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--gray-400);
    font-weight: 600;
}

.nav-item { margin: 2px 8px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    color: var(--gray-300);
    text-decoration: none;
    border-radius: 8px;
    transition: var(--transition);
    font-size: 14px;
    font-weight: 500;
}

.nav-link:hover {
    background: rgba(67, 97, 238, 0.15);
    color: white;
    transform: translateX(4px);
}

.nav-link.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(67, 97, 238, 0.4);
}

.nav-link i { width: 20px; text-align: center; font-size: 16px; }

/* Content */
.content {
    margin-left: var(--sidebar-width);
    flex: 1;
    transition: var(--transition);
    min-height: 100vh;
}

.sidebar.collapsed ~ .content { margin-left: var(--sidebar-collapsed); }

/* Top Navbar */
.top-navbar {
    height: var(--topbar-height);
    background: white;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 999;
    box-shadow: var(--shadow-sm);
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--gray-500);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: var(--transition);
}

.sidebar-toggle:hover { background: var(--gray-100); color: var(--primary); }

.user-dropdown {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--dark);
    padding: 6px 12px;
    border-radius: 8px;
    transition: var(--transition);
}

.user-dropdown:hover { background: var(--gray-100); }

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    overflow: hidden;
}

.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-name { font-weight: 500; font-size: 14px; }

/* Main Content */
.main-content { padding: 24px; }

.page-header {
    margin-bottom: 24px;
    animation: fadeInDown 0.5s ease;
}

.page-header h2 { font-weight: 700; color: var(--dark); font-size: 24px; }

/* Cards */
.card {
    border: none;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    overflow: hidden;
}

.card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.card-header {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 16px 20px;
}

.stat-card {
    position: relative;
    overflow: hidden;
}

.stat-card .card-body { padding: 20px; }

.stat-card .stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-bottom: 16px;
    background: rgba(255,255,255,0.25);
    color: #fff;
}

.stat-card .stat-value { 
    font-size: 28px; 
    font-weight: 700; 
    color: #fff !important;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.stat-card .stat-label { 
    font-size: 14px; 
    font-weight: 500;
    color: rgba(255,255,255,0.95) !important; 
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card.bg-primary { background: linear-gradient(135deg, #4361ee 0%, #3a56d4 100%) !important; }
.stat-card.bg-success { background: linear-gradient(135deg, #06d6a0 0%, #05b88a 100%) !important; }
.stat-card.bg-warning { background: linear-gradient(135deg, #ffc107 0%, #e6a800 100%) !important; }
.stat-card.bg-danger { background: linear-gradient(135deg, #ef476f 0%, #d63d60 100%) !important; }
.stat-card.bg-info { background: linear-gradient(135deg, #118ab2 0%, #0e7498 100%) !important; }

.stat-card { position: relative; overflow: hidden; }
.stat-card::after {
    content: '';
    position: absolute;
    top: -30px;
    right: -30px;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    opacity: 0.15;
    background: #fff;
}

/* Tables */
.table { font-size: 14px; }
.table thead th {
    background: var(--gray-100);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-500);
    border-bottom: 2px solid var(--gray-200);
    padding: 12px 16px;
}

.table tbody td {
    padding: 12px 16px;
    vertical-align: middle;
    border-color: var(--gray-200);
}

.table-hover tbody tr:hover { background: var(--primary-light); }

/* Buttons */
.btn {
    padding: 8px 20px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    transition: var(--transition);
    border: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(67, 97, 238, 0.4);
}

.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: var(--dark); }

.btn-outline-primary {
    border: 2px solid var(--primary);
    color: var(--primary);
    background: transparent;
}

.btn-outline-primary:hover {
    background: var(--primary);
    color: white;
}

/* Form Controls */
.form-control, .form-select {
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    transition: var(--transition);
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
}

.form-label { font-weight: 500; font-size: 14px; color: var(--gray-600); }

/* Login Page */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.login-bg {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--dark) 0%, #0f172a 100%);
}

.bg-shape {
    position: absolute;
    border-radius: 50%;
    opacity: 0.1;
    animation: float 20s infinite;
}

.shape-1 { width: 400px; height: 400px; background: var(--primary); top: -100px; right: -100px; }
.shape-2 { width: 300px; height: 300px; background: var(--secondary); bottom: -50px; left: -50px; animation-delay: -5s; }
.shape-3 { width: 200px; height: 200px; background: var(--success); top: 50%; left: 30%; animation-delay: -10s; }

.login-container { position: relative; z-index: 1; width: 100%; max-width: 420px; padding: 20px; }

.login-card {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}

.login-header { text-align: center; margin-bottom: 30px; }

.login-logo {
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 32px;
    color: white;
    box-shadow: 0 8px 25px rgba(67, 97, 238, 0.4);
}

.login-header h2 { font-weight: 700; color: var(--dark); }
.login-header p { color: var(--gray-500); font-size: 14px; }

.btn-login {
    padding: 12px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 10px;
    margin-top: 10px;
}

.login-footer { text-align: center; margin-top: 20px; }

/* Profile */
.profile-card .avatar-placeholder {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    font-size: 48px;
    color: var(--primary);
}

/* Badges */
.badge { padding: 6px 12px; font-weight: 500; border-radius: 6px; }

/* Animations */
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-30px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(40px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    33% { transform: translateY(-20px) rotate(5deg); }
    66% { transform: translateY(10px) rotate(-3deg); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.animate-fade-in { animation: fadeInDown 0.4s ease; }
.animate-slide-up { animation: slideUp 0.6s ease; }
.animate-shake { animation: shake 0.5s ease; }

/* Stagger animation for cards */
.stat-card:nth-child(1) { animation-delay: 0.1s; }
.stat-card:nth-child(2) { animation-delay: 0.2s; }
.stat-card:nth-child(3) { animation-delay: 0.3s; }
.stat-card:nth-child(4) { animation-delay: 0.4s; }

/* Chart container */
.chart-container {
    position: relative;
    padding: 20px;
}

/* Toast customization */
.toast { border: none; border-radius: 10px; }
.toast-body { padding: 12px 16px; }

/* Search box */
.search-box {
    position: relative;
}

.search-box .form-control {
    padding-left: 40px;
}

.search-box i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
}

/* Responsive */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
    }
    .sidebar.active { 
        transform: translateX(0); 
    }
    .sidebar.collapsed {
        transform: translateX(-100%);
    }
    .content { 
        margin-left: 0 !important; 
    }
    .main-content { 
        padding: 16px; 
    }
}

@media (max-width: 768px) {
    .user-name { 
        display: none; 
    }
    .top-navbar {
        padding: 0 16px;
    }
    .page-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 12px;
    }
    .page-header h2 { 
        font-size: 20px; 
    }
    .page-header .btn {
        width: 100%;
    }
    .stat-card {
        margin-bottom: 16px;
    }
    .stat-card .stat-value { 
        font-size: 22px; 
    }
    .stat-card .stat-icon {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }
    .table-responsive {
        font-size: 13px;
    }
    .table thead th,
    .table tbody td {
        padding: 10px 12px;
    }
    .card-body {
        padding: 16px;
    }
    .form-control, .form-select {
        padding: 10px 12px;
    }
    .btn {
        padding: 8px 16px;
        font-size: 13px;
    }
    .ai-assistant-btn {
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
}

@media (max-width: 576px) {
    .login-card { 
        padding: 24px 16px; 
    }
    .login-logo {
        width: 56px;
        height: 56px;
        font-size: 24px;
    }
    .login-header h2 {
        font-size: 20px;
    }
    .page-header h2 { 
        font-size: 18px; 
    }
    .nav-link {
        padding: 12px 16px;
    }
    .nav-link i {
        font-size: 18px;
    }
    .dropdown-menu {
        width: 100%;
    }
    .modal-dialog {
        margin: 10px;
    }
    .modal-content {
        border-radius: 12px;
    }
    .toast-container {
        left: 10px !important;
        right: 10px !important;
    }
    .toast {
        width: 100%;
    }
}

@media (max-width: 400px) {
    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }
    .card {
        border-radius: 8px;
    }
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    .btn-group .btn {
        width: 100%;
        margin-bottom: 4px;
        border-radius: 8px;
    }
    .badge {
        padding: 4px 8px;
        font-size: 11px;
    }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

@media (max-width: 992px) {
    .sidebar-overlay.active {
        display: block;
    }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--gray-100); }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* Loading Spinner */
.spinner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Action buttons in tables */
.action-btns { white-space: nowrap; }
.action-btns .btn { padding: 4px 10px; font-size: 12px; margin: 0 2px; }

/* Status badges */
.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-present { background: var(--success-light); color: #059669; }
.status-absent { background: var(--danger-light); color: var(--danger); }
.status-late { background: var(--warning-light); color: #d97706; }
.status-paid { background: var(--success-light); color: #059669; }
.status-pending { background: var(--warning-light); color: #d97706; }
.status-overdue { background: var(--danger-light); color: var(--danger); }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-400);
}

.empty-state i { font-size: 64px; margin-bottom: 16px; }
.empty-state h5 { color: var(--gray-500); }

/* AI Assistant Floating Button */
.ai-assistant-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7209b7 0%, #4361ee 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 4px 20px rgba(114, 9, 183, 0.4);
    z-index: 9999;
    transition: all 0.3s ease;
    animation: ai-pulse 2s infinite;
}

.ai-assistant-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(114, 9, 183, 0.6);
}

@keyframes ai-pulse {
    0% { box-shadow: 0 0 0 0 rgba(114, 9, 183, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(114, 9, 183, 0); }
    100% { box-shadow: 0 0 0 0 rgba(114, 9, 183, 0); }
}

/* =============================================
   ENHANCED MOBILE RESPONSIVENESS
   ============================================= */

/* --- Page header button groups --- */
@media (max-width: 768px) {
    .page-header {
        flex-wrap: wrap;
        gap: 10px;
    }
    /* When header has a nested d-flex button group */
    .page-header > .d-flex {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }
    .page-header > .d-flex .btn {
        flex: 1 1 auto;
        min-width: 120px;
        text-align: center;
    }
    /* Single direct btn in page-header */
    .page-header > .btn {
        width: 100%;
        text-align: center;
    }

    /* Card headers with flex actions */
    .card-header.d-flex {
        flex-wrap: wrap;
        gap: 8px;
    }
    .card-header.d-flex h5,
    .card-header.d-flex h6 {
        flex: 1;
    }

    /* Filter form rows in card-header */
    .card-header .row.g-3 {
        row-gap: 8px !important;
    }

    /* Stat card value â€” prevent overflow for long numbers */
    .stat-card .stat-value {
        font-size: 20px !important;
        word-break: break-all;
    }

    /* Table action btn-group: allow wrap */
    .action-btns {
        white-space: normal;
    }
    td .action-btns .btn {
        margin-bottom: 2px;
    }

    /* Dashboard chart container height reduction */
    .chart-container canvas {
        max-height: 220px;
    }
}

/* --- Small phones --- */
@media (max-width: 576px) {
    /* Main content tighter padding */
    .main-content {
        padding: 12px;
    }

    /* Page header title */
    .page-header h2 {
        font-size: 17px !important;
    }

    /* Card body tighter */
    .card-body {
        padding: 14px;
    }

    /* Card header smaller padding */
    .card-header {
        padding: 12px 14px;
    }

    /* Any d-flex gap-2 button rows wrap on mobile */
    .d-flex.gap-2,
    .d-flex.gap-3 {
        flex-wrap: wrap;
    }

    /* Table: smaller font & padding */
    .table-responsive {
        font-size: 12px;
    }
    .table thead th,
    .table tbody td {
        padding: 8px 10px;
    }

    /* Action btn-group stacks vertically */
    .btn-group.btn-group-sm {
        display: inline-flex;
        flex-wrap: wrap;
        gap: 3px;
    }
    .btn-group.btn-group-sm .btn {
        border-radius: 6px !important;
        flex: 0 0 auto;
    }

    /* Stat card compact */
    .stat-card .card-body {
        padding: 14px;
    }
    .stat-card .stat-value {
        font-size: 18px !important;
    }
    .stat-card .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 18px;
        margin-bottom: 10px;
    }

    /* Quick action buttons in dashboards */
    .col-6 .btn.py-3 {
        padding: 10px 6px !important;
        font-size: 12px;
    }
    .col-6 .btn.py-3 i.d-block {
        font-size: 1.2rem !important;
    }

    /* Form: save/cancel button group full width */
    form .d-flex.gap-2 > .btn {
        flex: 1 1 auto;
        min-width: 110px;
    }

    /* Certificate row in teacher form */
    .certificate-row .row > [class*="col-md-2"] {
        width: 100%;
    }

    /* Dashboard chart height reduction */
    div[style*="height: 300px"] {
        height: 200px !important;
    }
    div[style*="height: 180px"] {
        height: 150px !important;
    }

    /* Login card portal buttons wrap */
    .portal-links .d-flex.gap-2 {
        flex-direction: column;
        align-items: stretch;
    }
    .portal-links .d-flex.gap-2 .btn {
        width: 100%;
    }

    /* Top navbar: more compact */
    .top-navbar {
        padding: 0 12px;
    }

    /* Sidebar overlay backdrop */
    .sidebar-overlay.active {
        display: block;
    }

    /* Pagination on small screens */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
    .pagination .page-link {
        padding: 5px 10px;
        font-size: 13px;
    }

    /* Empty state icon smaller */
    .empty-state i {
        font-size: 48px;
    }
    .empty-state {
        padding: 40px 16px;
    }

    /* Alert dismiss button alignment */
    .alert {
        font-size: 13px;
    }
}

/* --- Very small phones (â‰¤400px) --- */
@media (max-width: 400px) {
    .page-header h2 {
        font-size: 15px !important;
    }
    .stat-card .stat-value {
        font-size: 16px !important;
    }
    .table-responsive {
        font-size: 11px;
    }
    .table thead th,
    .table tbody td {
        padding: 6px 8px;
    }
    .card-header.d-flex.justify-content-between {
        flex-direction: column;
        gap: 6px;
        align-items: flex-start !important;
    }
    .main-content {
        padding: 8px;
    }
    .badge {
        padding: 3px 7px;
        font-size: 10px;
    }
}
