/**
 * E-School Panel — Dashboard & Panel Layout
 * Modern sidebar + content layout
 */

/* ── Reset & Base ──────────────────────────────────────────────── */
.esp-app * { margin: 0; padding: 0; box-sizing: border-box; }
.esp-app {
    font-family: 'Hind Siliguri', 'Noto Sans Bengali', 'Segoe UI', sans-serif;
    display: flex;
    min-height: 100vh;
    background: #f0f2f5;
    color: #333;
    font-size: 15px;
    line-height: 1.6;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
.esp-sidebar {
    width: 260px;
    background: linear-gradient(180deg, #1a237e 0%, #0d1642 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
    overflow-y: auto;
}
.esp-sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.esp-sidebar-header h2 {
    font-size: 18px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.esp-sidebar-close {
    display: none;
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    font-size: 20px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
    z-index: 5;
}
.esp-sidebar-close:hover {
    background: rgba(255,255,255,0.3);
}
.esp-sidebar-close:active {
    background: rgba(255,255,255,0.4);
}

/* Nav */
.esp-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}
.esp-nav-item {
    display: flex;
    align-items: center;
    padding: 11px 20px;
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    font-size: 14.5px;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.esp-nav-item:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}
.esp-nav-item.active {
    background: rgba(255,255,255,0.12);
    color: #fff;
    border-left-color: #ff9800;
    font-weight: 600;
}

.esp-sidebar-footer {
    padding: 12px 0;
    border-top: 1px solid rgba(255,255,255,0.1);
}
.esp-nav-logout { color: #ef5350 !important; }
.esp-nav-logout:hover { background: rgba(239,83,80,0.15) !important; }

/* ── Main Content ──────────────────────────────────────────────── */
.esp-main {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.esp-topbar {
    background: #fff;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    position: sticky;
    top: 0;
    z-index: 50;
}
.esp-topbar-user {
    font-size: 14px;
    color: #555;
    font-weight: 500;
}

.esp-content {
    flex: 1;
    padding: 24px;
}

/* ── Page Title ────────────────────────────────────────────────── */
.esp-page-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 20px;
    color: #1a237e;
}

/* ── Cards ─────────────────────────────────────────────────────── */
.esp-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.esp-card h2, .esp-card h3 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 16px;
    color: #333;
}

/* ── Dashboard Stats ───────────────────────────────────────────── */
.esp-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* Desktop: 3 columns */
    gap: 16px;
    margin-bottom: 24px;
}
.esp-stat-card {
    background: #fff;
    border-radius: 10px;
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    border-left: 4px solid var(--card-color, #1a73e8);
    transition: transform 0.15s;
}
.esp-stat-card:hover { transform: translateY(-2px); }
.esp-stat-icon { font-size: 32px; }
.esp-stat-num { font-size: 26px; font-weight: 700; display: block; color: #333; }
.esp-stat-label { font-size: 13px; color: #777; }

.esp-dashboard-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.esp-stat-mini {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #f5f5f5;
    border-radius: 8px;
    margin-right: 10px;
    margin-bottom: 8px;
}
.esp-stat-mini .esp-stat-num { font-size: 20px; }

.esp-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.esp-qa-btn {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    background: #e8eaf6;
    color: #1a237e;
    border-radius: 8px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s;
}
.esp-qa-btn:hover { background: #c5cae9; }

/* ── Forms ─────────────────────────────────────────────────────── */
.esp-form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 12px;
}
.esp-form-group { margin-bottom: 12px; }
.esp-form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #444;
    margin-bottom: 4px;
}
.esp-input, .esp-select, .esp-textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid #ddd;
    border-radius: 7px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s;
}
.esp-input:focus, .esp-select:focus, .esp-textarea:focus {
    outline: none;
    border-color: #1a73e8;
}
.esp-textarea { resize: vertical; }
.esp-file-input { font-size: 13px; }

.esp-form-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

/* ── Buttons ───────────────────────────────────────────────────── */
.esp-btn {
    padding: 9px 20px;
    border: none;
    border-radius: 7px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.esp-btn-primary { background: #1a237e; color: #fff; }
.esp-btn-primary:hover { background: #283593; }
.esp-btn-secondary { background: #e0e0e0; color: #333; }
.esp-btn-secondary:hover { background: #bdbdbd; }
.esp-btn-danger { background: #c62828; color: #fff; }
.esp-btn-danger:hover { background: #b71c1c; }
.esp-btn-success { background: #2e7d32; color: #fff; }
.esp-btn-success:hover { background: #1b5e20; }
.esp-btn-sm { padding: 5px 12px; font-size: 12px; }

/* ── Tables ────────────────────────────────────────────────────── */
.esp-table-wrap { overflow-x: auto; }
.esp-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
.esp-table th {
    background: #f5f5f5;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: #555;
    border-bottom: 2px solid #e0e0e0;
    white-space: nowrap;
}
.esp-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
}
.esp-table tr:hover td { background: #f8f9ff; }

/* ── Filter ────────────────────────────────────────────────────── */
.esp-filter-row {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}
.esp-filter-select { max-width: 200px; }

/* ── Photo Preview ─────────────────────────────────────────────── */
.esp-photo-preview img {
    max-width: 120px;
    max-height: 120px;
    border-radius: 8px;
    margin-top: 8px;
}

/* ── Admin Gallery Grid ────────────────────────────────────────── */
.esp-admin-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}
.esp-admin-gallery-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.esp-admin-gallery-item img {
    width: 100%;
    height: 140px;
    object-fit: cover;
}
.esp-admin-gallery-item .esp-gallery-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.6);
    padding: 6px;
    display: flex;
    justify-content: center;
    gap: 6px;
}

/* ── Modal ─────────────────────────────────────────────────────── */
.esp-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.esp-modal-content {
    background: #fff;
    border-radius: 12px;
    padding: 28px;
    max-width: 700px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}
.esp-modal-close {
    position: absolute;
    top: 12px; right: 16px;
    font-size: 24px;
    cursor: pointer;
    color: #999;
}

/* ── Info Table ────────────────────────────────────────────────── */
.esp-info-table {
    width: 100%;
    max-width: 400px;
}
.esp-info-table th {
    text-align: left;
    padding: 8px 16px 8px 0;
    font-weight: 600;
    color: #555;
}
.esp-info-table td { padding: 8px 0; }

/* ── Divider ───────────────────────────────────────────────────── */
.esp-divider { margin: 24px 0; border: none; border-top: 1px solid #e0e0e0; }

/* ── Description ───────────────────────────────────────────────── */
.esp-desc { color: #777; font-size: 13px; margin-bottom: 16px; }

/* ── Toast ─────────────────────────────────────────────────────── */
.esp-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 14px 24px;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    z-index: 999;
    animation: espToastIn 0.3s ease;
    max-width: 350px;
}
.esp-toast-success { background: #2e7d32; }
.esp-toast-error { background: #c62828; }
@keyframes espToastIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Global Search ─────────────────────────────────────────────── */
.esp-global-search-wrap { margin-bottom: 20px; }
.esp-global-search { position: relative; max-width: 500px; }
.esp-global-search .esp-input { padding-left: 40px; width: 100%; }
.esp-search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 16px; color: #999; }
.esp-search-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid #e0e0e0; border-radius: 0 0 8px 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); z-index: 300; max-height: 300px; overflow-y: auto; }
.esp-search-result-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid #f0f0f0; cursor: pointer; transition: background 0.15s; text-decoration: none; color: #333; }
.esp-search-result-item:hover { background: #e8eaf6; }
.esp-search-result-type { font-size: 11px; font-weight: 600; background: #e8eaf6; color: #1a237e; padding: 2px 8px; border-radius: 4px; }
.esp-search-result-name { font-size: 14px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Bar Chart (CSS-only) ──────────────────────────────────────── */
.esp-bar-chart { background: #fff; border-radius: 10px; padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.esp-bar-item { margin-bottom: 12px; }
.esp-bar-track { height: 24px; background: #f0f2f5; border-radius: 6px; overflow: hidden; }
.esp-bar-fill { height: 100%; border-radius: 6px; transition: width 0.6s ease; min-width: 2px; }
.esp-bar-label { font-size: 12px; color: #555; margin-top: 4px; display: block; }
.esp-bar-label b { color: #333; }

/* ── Export Row ────────────────────────────────────────────────── */
.esp-export-row { display: flex; gap: 10px; align-items: center; }
.esp-export-row .esp-select { max-width: 200px; }

/* ── Sidebar Overlay (mobile backdrop) ─────────────────────────── */
.esp-sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}
.esp-sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ── Hamburger Button (improved) ──────────────────────────────── */
.esp-topbar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #333;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.esp-topbar-toggle:hover {
    background: rgba(0, 0, 0, 0.06);
}
.esp-topbar-toggle:active {
    background: rgba(0, 0, 0, 0.12);
}

/* Body scroll lock when sidebar open on mobile */
body.esp-sidebar-open {
    overflow: hidden;
}

/* ── Responsive ────────────────────────────────────────────────── */

/* Tablet: 2 columns */
@media (max-width: 992px) {
    .esp-stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .esp-sidebar {
        transform: translateX(-100%);
        width: 280px;
        max-width: 85vw;
        z-index: 100;
        -webkit-overflow-scrolling: touch;
    }
    .esp-sidebar.open { transform: translateX(0); }
    .esp-sidebar-close { display: block; }
    .esp-topbar-toggle { display: block; }
    .esp-main { margin-left: 0; }
    .esp-dashboard-row { grid-template-columns: 1fr; }
    .esp-form-row { grid-template-columns: 1fr; }
    .esp-export-row { flex-direction: column; }
    .esp-export-row .esp-select { max-width: 100%; width: 100%; }
}

/* Mobile (≤720px): compact 2-column stat cards + room for bottom nav */
@media (max-width: 720px) {
    .esp-content {
        padding: 16px;
        padding-bottom: 88px; /* clear the fixed bottom nav (56px) + breathing room */
        box-sizing: border-box;
    }
    .esp-stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .esp-stat-card {
        padding: 12px;
        gap: 10px;
    }
    .esp-stat-icon { font-size: 22px; }
    .esp-stat-num { font-size: 18px; }
    .esp-stat-label { font-size: 11px; }
}

/* ── GA4 Analytics ──────────────────────────────────────────────── */
.esp-analytics-section {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.esp-analytics-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.esp-analytics-header h2 {
    font-size: 20px;
    font-weight: 700;
    color: #1a237e;
    margin: 0;
}
.esp-analytics-period {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.esp-period-btn {
    padding: 6px 14px;
    border: 1.5px solid #ddd;
    border-radius: 20px;
    background: #fff;
    color: #555;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
.esp-period-btn:hover {
    border-color: #1a73e8;
    color: #1a73e8;
}
.esp-period-btn.active {
    background: #1a73e8;
    color: #fff;
    border-color: #1a73e8;
}

/* GA4 Not Connected */
.esp-ga4-notice {
    background: #fff3e0;
    border: 1px solid #ffcc80;
    border-radius: 8px;
    padding: 20px;
    color: #e65100;
}
.esp-ga4-notice p {
    margin-bottom: 8px;
    font-size: 14px;
}

/* GA4 Overview */
.esp-ga4-overview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.esp-ga4-stat {
    background: #f8f9ff;
    border-radius: 10px;
    padding: 16px;
    text-align: center;
    border-top: 3px solid var(--stat-color, #1a73e8);
}
.esp-ga4-stat-icon { font-size: 22px; display: block; margin-bottom: 6px; }
.esp-ga4-stat-val { font-size: 26px; font-weight: 700; display: block; color: #333; }
.esp-ga4-stat-label { font-size: 12px; color: #777; display: block; margin-top: 4px; }

/* GA4 Chart Cards */
.esp-ga4-charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}
.esp-ga4-chart-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.esp-ga4-chart-card h3 {
    font-size: 15px;
    font-weight: 600;
    color: #333;
    margin: 0 0 12px;
}
.esp-ga4-chart-card canvas {
    width: 100% !important;
    max-height: 240px;
}

/* GA4 Loading */
.esp-ga4-loading {
    text-align: center;
    padding: 40px;
    color: #777;
    font-size: 15px;
}
.esp-ga4-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid #e0e0e0;
    border-top-color: #1a73e8;
    border-radius: 50%;
    animation: espSpin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}
@keyframes espSpin {
    to { transform: rotate(360deg); }
}

/* Skeleton loaders for dashboard cards */
.esp-stat-card .esp-stat-num,
.esp-ga4-stat-val {
    min-height: 32px;
    min-width: 40px;
    display: inline-block;
}
.esp-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: espSkeletonPulse 1.5s ease-in-out infinite;
    border-radius: 4px;
}
@keyframes espSkeletonPulse {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* GA4 Responsive */
@media (max-width: 768px) {
    .esp-analytics-header { flex-direction: column; align-items: flex-start; }
    .esp-ga4-overview { grid-template-columns: repeat(2, 1fr); }
    .esp-ga4-charts-row { grid-template-columns: 1fr; }
}

/* GA4 Mobile (≤720px): single column, card width capped at 520px, centered with margins */
@media (max-width: 720px) {
    .esp-analytics-section {
        padding: 14px;
        max-width: 520px;
        margin-left: auto;
        margin-right: auto;
        box-sizing: border-box;
        width: 100%;
    }
    .esp-ga4-overview {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .esp-ga4-stat {
        padding: 14px;
        max-width: 100%;
        box-sizing: border-box;
    }
    .esp-ga4-chart-card {
        padding: 14px;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    .esp-ga4-chart-card canvas { max-height: 200px; }
    .esp-period-btn { padding: 6px 10px; font-size: 12px; }
}

/* ── Analytics Charts Page (single-column stack of chart cards) ─── */
.esp-ga4-charts-col {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}
.esp-ga4-charts-col .esp-ga4-chart-card:last-child {
    grid-column: 1 / -1; /* Top Pages table spans full width */
}
@media (max-width: 900px) {
    .esp-ga4-charts-col { grid-template-columns: 1fr; }
}

/* Charts page mobile (≤720px): strict single column, card max-width 520px */
@media (max-width: 720px) {
    .esp-analytics-charts-section {
        max-width: 520px;
        margin-left: auto;
        margin-right: auto;
        width: 100%;
        box-sizing: border-box;
        padding: 14px;
    }
    .esp-ga4-charts-col {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .esp-ga4-charts-col .esp-ga4-chart-card {
        max-width: 100%;
        box-sizing: border-box;
    }
}

/* ── Tag Manager (Settings page) ───────────────────────────────── */
.esp-tag-manager { margin-top: 8px; }
.esp-tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
    min-height: 36px;
}
.esp-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #e8eaf6;
    color: #1a237e;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13.5px;
    font-weight: 500;
    transition: background 0.15s;
}
.esp-tag:hover { background: #c5cae9; }
.esp-tag-text { white-space: nowrap; }
.esp-tag-remove {
    background: none;
    border: none;
    color: #e53935;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    padding: 0;
    line-height: 1;
    transition: color 0.15s;
}
.esp-tag-remove:hover { color: #b71c1c; }
.esp-tag-add {
    display: flex;
    gap: 8px;
    align-items: center;
}
.esp-tag-add .esp-input { max-width: 250px; }

/* ── শাখা (Section) field toggle — controlled from Settings ─────── */
/* When disabled: hide the section field in the 5 CRUD forms
   (results, syllabus, class-routines, teacher-routines, students)
   and hide the 2nd table column (শাখা) in each of their list tables. */
.esp-sections-off .esp-section-formgroup {
    display: none;
}
.esp-sections-off #esp-result-table th:nth-child(2),
.esp-sections-off #esp-result-table td:nth-child(2),
.esp-sections-off #esp-syllabus-table th:nth-child(2),
.esp-sections-off #esp-syllabus-table td:nth-child(2),
.esp-sections-off #esp-cr-table th:nth-child(2),
.esp-sections-off #esp-cr-table td:nth-child(2),
.esp-sections-off #esp-tr-table th:nth-child(2),
.esp-sections-off #esp-tr-table td:nth-child(2),
.esp-sections-off #esp-student-count-table th:nth-child(2),
.esp-sections-off #esp-student-count-table td:nth-child(2) {
    display: none;
}
