/* ===========================================
   نظام إدارة المدرسة - School Management
   Green/Gold professional theme
   =========================================== */

:root {
    --primary: #16a085;
    --primary-light: #1abc9c;
    --primary-dark: #0e8c73;
    --gold: #c9a961;
    --gold-light: #e2c989;
    --dark: #0f1c1a;
    --darker: #0a1311;
    --gray: #1a2826;
    --gray-light: #2a3835;
    --light-gray: #a8b8b4;
    --white: #ffffff;
    --red: #e74c3c;
    --red-dark: #c0392b;
    --yellow: #f39c12;
    --blue: #3498db;
    --green: #25D366;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-light: 0 2px 10px rgba(0, 0, 0, 0.2);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.25s ease;
    --sidebar-width: 260px;
    --topbar-height: 64px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    font-family: 'Tajawal', -apple-system, sans-serif;
    background: var(--darker);
    color: var(--white);
    min-height: 100vh;
    direction: rtl;
}

body { overflow-x: hidden; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea, button { font-family: inherit; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

/* ===== Auth Screen ===== */
.auth-screen {
    position: fixed;
    inset: 0;
    background: var(--darker);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
}

.auth-bg {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 30%, rgba(22, 160, 133, 0.2), transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(201, 169, 97, 0.15), transparent 50%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    position: relative;
    background: var(--gray);
    border: 1px solid rgba(22, 160, 133, 0.3);
    border-radius: 20px;
    padding: 40px 32px;
    box-shadow: var(--shadow);
}

.auth-logo {
    width: 90px;
    height: 90px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border-radius: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.4rem;
    box-shadow: 0 8px 25px rgba(22, 160, 133, 0.4);
}

.auth-card h1 {
    color: var(--white);
    text-align: center;
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 4px;
}

.auth-tagline {
    text-align: center;
    color: var(--light-gray);
    margin-bottom: 28px;
    font-size: 0.95rem;
}

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    color: var(--light-gray);
    margin-bottom: 6px;
    font-size: 0.9rem;
    font-weight: 500;
}

.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 12px 14px;
    background: var(--darker);
    border: 1px solid rgba(22, 160, 133, 0.2);
    border-radius: 8px;
    color: var(--white);
    font-size: 0.95rem;
    transition: border-color var(--transition);
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group textarea { min-height: 90px; resize: vertical; }

.form-hint {
    text-align: center;
    color: var(--light-gray);
    font-size: 0.82rem;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-light);
}

.form-hint code {
    background: var(--darker);
    color: var(--primary-light);
    padding: 3px 8px;
    border-radius: 4px;
    font-family: monospace;
}

/* ===== App Shell ===== */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--topbar-height) 1fr;
    grid-template-areas: "sidebar topbar" "sidebar main";
    min-height: 100vh;
}

/* ===== Topbar ===== */
.topbar {
    grid-area: topbar;
    background: var(--gray);
    border-bottom: 1px solid rgba(22, 160, 133, 0.2);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 15px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    color: var(--white);
    transition: background var(--transition);
}

.menu-toggle:hover { background: var(--gray-light); }

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-logo {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: white;
    font-size: 0.95rem;
}

.topbar-title {
    font-weight: 800;
    color: var(--white);
    font-size: 1.05rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-right: auto;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--gray-light);
    color: var(--white);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    position: relative;
}

.icon-btn:hover { background: var(--primary); }

.user-menu { position: relative; }

.user-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 14px 4px 4px;
    background: var(--gray-light);
    border-radius: 24px;
    color: var(--white);
    transition: background var(--transition);
}

.user-btn:hover { background: var(--primary); }

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.95rem;
}

.user-avatar.large {
    width: 60px;
    height: 60px;
    font-size: 1.4rem;
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    background: var(--gray);
    border: 1px solid var(--gray-light);
    border-radius: 8px;
    min-width: 200px;
    overflow: hidden;
    box-shadow: var(--shadow);
    display: none;
    z-index: 100;
}

.user-dropdown.open { display: block; }
.user-dropdown a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    color: var(--white);
    transition: background var(--transition);
    font-size: 0.9rem;
}
.user-dropdown a:hover { background: var(--gray-light); color: var(--primary-light); }

/* ===== Sidebar ===== */
.sidebar {
    grid-area: sidebar;
    background: var(--dark);
    border-left: 1px solid rgba(22, 160, 133, 0.15);
    padding: 16px 0;
    overflow-y: auto;
    position: sticky;
    top: 0;
    height: 100vh;
}

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-section { margin-bottom: 16px; }

.nav-section-title {
    padding: 8px 24px;
    color: var(--light-gray);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 24px;
    color: var(--light-gray);
    transition: all var(--transition);
    font-weight: 500;
    border-right: 3px solid transparent;
}

.nav-item:hover {
    background: rgba(22, 160, 133, 0.1);
    color: var(--white);
}

.nav-item.active {
    background: rgba(22, 160, 133, 0.15);
    color: var(--primary-light);
    border-right-color: var(--primary);
}

.nav-item i { width: 20px; text-align: center; font-size: 1.05rem; }

.nav-badge {
    margin-right: auto;
    background: var(--red);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 700;
}

/* ===== Main Content ===== */
.main {
    grid-area: main;
    padding: 24px;
    overflow-x: hidden;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 15px;
}

.page-title {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--white);
}

.page-title small {
    display: block;
    font-size: 0.85rem;
    color: var(--light-gray);
    font-weight: 400;
    margin-top: 4px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.92rem;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: white; }
.btn-primary:hover { box-shadow: 0 6px 18px rgba(22, 160, 133, 0.4); }
.btn-secondary { background: var(--gray-light); color: var(--white); }
.btn-secondary:hover { background: var(--gray); }
.btn-success { background: var(--green); color: white; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: var(--red-dark); }
.btn-warning { background: var(--yellow); color: white; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: 6px; }

/* ===== Cards ===== */
.card {
    background: var(--gray);
    border: 1px solid var(--gray-light);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--gray-light);
}

.card-title { color: var(--primary-light); font-weight: 700; font-size: 1.05rem; }

/* ===== Stat Cards ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--gray);
    border: 1px solid var(--gray-light);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
    box-shadow: var(--shadow-light);
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-icon.gold { background: linear-gradient(135deg, var(--gold), var(--gold-light)); color: var(--dark); }
.stat-icon.red { background: linear-gradient(135deg, var(--red), var(--red-dark)); }
.stat-icon.yellow { background: linear-gradient(135deg, var(--yellow), #d68910); }
.stat-icon.blue { background: linear-gradient(135deg, var(--blue), #2980b9); }

.stat-info { flex: 1; }
.stat-info .num { font-size: 1.7rem; font-weight: 900; color: var(--white); line-height: 1.2; }
.stat-info .label { font-size: 0.82rem; color: var(--light-gray); margin-top: 2px; }

/* ===== Tables ===== */
.table-wrap {
    background: var(--gray);
    border-radius: var(--radius);
    border: 1px solid var(--gray-light);
    overflow: auto;
}

table { width: 100%; border-collapse: collapse; min-width: 600px; }

th {
    background: var(--darker);
    color: var(--primary-light);
    text-align: right;
    padding: 14px 16px;
    font-weight: 700;
    font-size: 0.88rem;
    border-bottom: 2px solid var(--gray-light);
    white-space: nowrap;
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-light);
    color: var(--white);
    font-size: 0.9rem;
}

tr:hover td { background: rgba(22, 160, 133, 0.04); }

td .actions { display: flex; gap: 6px; }

/* ===== Forms ===== */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 15px; }

/* ===== Search & Filters ===== */
.toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-box {
    flex: 1;
    min-width: 200px;
    position: relative;
}

.search-box i {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--light-gray);
}

.search-box input { padding-right: 40px; }

.filter-chip {
    padding: 8px 14px;
    background: var(--gray);
    border: 1px solid var(--gray-light);
    border-radius: 20px;
    color: var(--white);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.filter-chip.active, .filter-chip:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ===== Status ===== */
.status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 700;
}

.status.active, .status.paid, .status.present, .status.success {
    background: rgba(46, 204, 113, 0.18);
    color: #2ecc71;
}
.status.absent, .status.cancelled, .status.failed, .status.expired {
    background: rgba(231, 76, 60, 0.18);
    color: #e74c3c;
}
.status.late, .status.pending, .status.partial {
    background: rgba(243, 156, 18, 0.18);
    color: #f39c12;
}
.status.excused, .status.info {
    background: rgba(52, 152, 219, 0.18);
    color: #3498db;
}

/* ===== Modal ===== */
.modal-container {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal {
    position: relative;
    background: var(--gray);
    border: 1px solid var(--gray-light);
    border-radius: var(--radius);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal.modal-lg { max-width: 900px; }
.modal.modal-sm { max-width: 400px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid var(--gray-light);
}

.modal-header h3 { color: var(--primary-light); font-size: 1.15rem; }

.modal-body { padding: 22px; overflow-y: auto; flex: 1; }

.modal-footer {
    padding: 16px 22px;
    border-top: 1px solid var(--gray-light);
    display: flex;
    gap: 10px;
    justify-content: flex-start;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 80px;
    left: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--gray);
    border: 1px solid var(--primary);
    border-radius: 8px;
    padding: 12px 18px;
    color: var(--white);
    box-shadow: var(--shadow);
    min-width: 250px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastIn 0.3s ease;
}

.toast.success { border-color: #2ecc71; }
.toast.error { border-color: var(--red); }
.toast.warning { border-color: var(--yellow); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ===== Empty State ===== */
.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--light-gray);
}

.empty i { font-size: 3rem; color: var(--gray-light); margin-bottom: 15px; }
.empty h3 { color: var(--white); margin-bottom: 8px; }

/* ===== Charts ===== */
.charts-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.chart-card {
    background: var(--gray);
    border: 1px solid var(--gray-light);
    border-radius: var(--radius);
    padding: 20px;
    min-height: 300px;
}

.chart-card h3 { color: var(--primary-light); margin-bottom: 15px; font-size: 1rem; }
.chart-card canvas { max-height: 260px; }

/* ===== Welcome / Hero ===== */
.welcome {
    background: linear-gradient(135deg, var(--gray), var(--dark));
    border: 1px solid var(--gray-light);
    border-radius: 16px;
    padding: 28px;
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
}

.welcome::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -10%;
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(22, 160, 133, 0.15), transparent 70%);
    pointer-events: none;
}

.welcome h2 { font-size: 1.6rem; color: var(--white); margin-bottom: 6px; position: relative; }
.welcome p { color: var(--light-gray); font-size: 1rem; position: relative; }

/* ===== Detail grid ===== */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.detail-item { padding: 10px 0; border-bottom: 1px solid var(--gray-light); }
.detail-item .lbl { color: var(--light-gray); font-size: 0.82rem; }
.detail-item .val { color: var(--white); font-size: 0.95rem; font-weight: 500; margin-top: 3px; }

/* ===== Tabs ===== */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--gray-light);
    margin-bottom: 20px;
    overflow-x: auto;
}

.tab {
    padding: 10px 18px;
    color: var(--light-gray);
    background: none;
    font-weight: 600;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
    white-space: nowrap;
}

.tab:hover { color: var(--white); }
.tab.active { color: var(--primary-light); border-bottom-color: var(--primary); }

/* ===== Utility ===== */
.text-muted { color: var(--light-gray); }
.text-success { color: #2ecc71; }
.text-danger { color: var(--red); }
.text-warning { color: var(--yellow); }
.text-gold { color: var(--gold); }
.text-center { text-align: center; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }

/* ===== Reports ===== */
.report-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--gray-light);
}

.report-row .lbl { color: var(--light-gray); }
.report-row .val { color: var(--white); font-weight: 700; }

.report-row.total {
    font-size: 1.1rem;
    padding-top: 18px;
    border-top: 2px solid var(--primary);
    margin-top: 8px;
}

.report-row.total .val { color: var(--primary-light); }

/* ===== Attendance ===== */
.attendance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.attendance-row {
    background: var(--darker);
    border: 2px solid transparent;
    border-radius: 10px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: all var(--transition);
}

.attendance-row:hover { border-color: var(--gray-light); }

.attendance-row.s-present { border-color: rgba(46, 204, 113, 0.5); }
.attendance-row.s-absent { border-color: rgba(231, 76, 60, 0.5); }
.attendance-row.s-late { border-color: rgba(243, 156, 18, 0.5); }
.attendance-row.s-excused { border-color: rgba(52, 152, 219, 0.5); }

.attendance-info { flex: 1; }
.attendance-info strong { display: block; color: var(--white); }
.attendance-info small { color: var(--light-gray); font-size: 0.78rem; }

.attendance-buttons { display: flex; gap: 4px; }

.att-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: var(--gray);
    color: var(--light-gray);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.att-btn:hover { background: var(--gray-light); color: white; }
.att-btn.active.present { background: #2ecc71; color: white; }
.att-btn.active.absent { background: var(--red); color: white; }
.att-btn.active.late { background: var(--yellow); color: white; }
.att-btn.active.excused { background: var(--blue); color: white; }

/* ===== Responsive ===== */
@media (max-width: 968px) {
    .app-shell { grid-template-columns: 1fr; grid-template-areas: "topbar" "main"; }
    .sidebar {
        position: fixed;
        top: var(--topbar-height);
        right: 0;
        width: var(--sidebar-width);
        height: calc(100vh - var(--topbar-height));
        z-index: 100;
        transform: translateX(100%);
        transition: transform var(--transition);
    }
    .sidebar.open { transform: translateX(0); }
    .menu-toggle { display: inline-flex; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .main { padding: 16px 12px; }
    .topbar-title { font-size: 0.9rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .auth-card { padding: 30px 20px; }
    .page-title { font-size: 1.3rem; }
    .user-btn span { display: none; }
}

@media (max-width: 568px) {
    .stats-grid { grid-template-columns: 1fr; }
    .modal { max-height: 95vh; }
    .topbar-actions { gap: 4px; }
    .icon-btn { width: 36px; height: 36px; }
}
