/* AIO School ERP - Mobile-first unified dashboard */

:root {
    --aio-primary: #1e40af;
    --aio-primary-dark: #1e3a8a;
    --aio-secondary: #0f766e;
    --aio-success: #15803d;
    --aio-warning: #b45309;
    --aio-danger: #b91c1c;
    --aio-bg: #f1f5f9;
    --aio-card: #ffffff;
    --aio-text: #0f172a;
    --aio-muted: #64748b;
    --aio-border: #e2e8f0;
    --aio-sidebar-width: 260px;
    --aio-topbar-height: 56px;
    --aio-radius: 12px;
    --aio-shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
    --aio-topbar-text: #ffffff;
}

* { box-sizing: border-box; }

body.aio-dashboard-active,
body.aio-portal-page {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--aio-bg);
    color: var(--aio-text);
    line-height: 1.5;
}

/* Portal isolation: own full-height shell, no fight with theme sticky headers */
body.aio-portal-page .aio-dashboard {
    position: relative;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--aio-bg);
    z-index: 1;
}

/* ===== Login ===== */
.aio-login-wrapper {
    min-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.aio-login-card {
    background: var(--aio-card);
    border-radius: var(--aio-radius);
    box-shadow: var(--aio-shadow);
    padding: 32px 28px;
    width: 100%;
    max-width: 400px;
}
.aio-login-card h2 {
    margin: 0 0 24px;
    text-align: center;
    color: var(--aio-primary);
}

/* ===== Dashboard Shell ===== */
.aio-dashboard {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top bar — logo + hamburger only */
.aio-topbar {
    height: var(--aio-topbar-height);
    min-height: var(--aio-topbar-height);
    background: var(--aio-primary);
    color: var(--aio-topbar-text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px 0 8px;
    position: sticky;
    top: 0;
    z-index: 10020;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
    flex-shrink: 0;
}
.aio-topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.aio-menu-toggle {
    background: rgba(255,255,255,.12);
    border: none;
    color: var(--aio-topbar-text);
    font-size: 1.35rem;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    display: block;
    line-height: 1;
    flex-shrink: 0;
}
.aio-menu-toggle:active { background: rgba(255,255,255,.22); }
.aio-logo {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--aio-topbar-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.aio-logo-img {
    height: 32px;
    width: auto;
    max-width: 160px;
    object-fit: contain;
    display: block;
}

.aio-dashboard-body {
    display: flex;
    flex: 1;
    position: relative;
    min-height: 0;
}

/* ===== Mobile sidebar drawer ===== */
.aio-sidebar {
    width: min(var(--aio-sidebar-width), 86vw);
    max-width: 320px;
    background: var(--aio-card);
    border-right: 1px solid var(--aio-border);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    z-index: 10040;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: none;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
}
.aio-sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 28px rgba(0,0,0,.22);
}
.aio-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 14px 14px 12px;
    background: var(--aio-primary);
    color: var(--aio-topbar-text);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 2;
}
.aio-sidebar-brand {
    min-width: 0;
    flex: 1;
    display: flex;
    align-items: center;
}
.aio-sidebar-brand .aio-logo {
    color: var(--aio-topbar-text);
    font-size: 1.05rem;
}
.aio-sidebar-brand .aio-logo-img {
    max-height: 36px;
    filter: brightness(0) invert(1);
}
.aio-sidebar-close {
    background: rgba(255,255,255,.15);
    border: none;
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
}
.aio-sidebar-close:active { background: rgba(255,255,255,.28); }

.aio-nav {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.aio-nav-list {
    list-style: none;
    margin: 0;
    padding: 8px 0 40px;
}
.aio-nav-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 18px;
    color: var(--aio-text);
    text-decoration: none;
    font-size: 0.95rem;
    transition: background 0.15s;
    min-height: 48px; /* touch target */
}
.aio-nav-item a:hover,
.aio-nav-item.active a {
    background: #eff6ff;
    color: var(--aio-primary);
    font-weight: 600;
}
.aio-nav-item.active a {
    border-right: 3px solid var(--aio-primary);
}

/* Overlay BELOW sidebar */
.aio-sidebar-overlay {
    display: none !important;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 10030;
    border: none;
    padding: 0;
    margin: 0;
}
.aio-sidebar-overlay.show {
    display: block !important;
}

/* Main content */
.aio-main {
    flex: 1;
    padding: 12px 16px 24px;
    margin-left: 0;
    min-width: 0;
    width: 100%;
}

/* User bar inside dashboard (not in sticky topbar) */
.aio-user-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--aio-card);
    border: 1px solid var(--aio-border);
    border-radius: var(--aio-radius);
    padding: 12px 14px;
    margin-bottom: 16px;
    box-shadow: var(--aio-shadow);
}
.aio-user-bar-info {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.aio-user-bar-name {
    font-size: 1rem;
    color: var(--aio-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.aio-user-bar-role {
    font-size: 0.8rem;
    color: var(--aio-muted);
    text-transform: capitalize;
}
.aio-user-bar-logout {
    flex-shrink: 0;
    padding: 8px 14px;
    font-size: 0.85rem;
}

.aio-content-header h1 {
    margin: 0 0 16px;
    font-size: 1.25rem;
    font-weight: 700;
}

/* Stats grid */
.aio-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.aio-stat-card {
    background: var(--aio-card);
    border-radius: var(--aio-radius);
    padding: 16px;
    box-shadow: var(--aio-shadow);
    text-align: center;
}
.aio-stat-icon { font-size: 1.6rem; margin-bottom: 6px; }
.aio-stat-value { font-size: 1.35rem; font-weight: 700; color: var(--aio-primary); word-break: break-word; }
.aio-stat-label { font-size: 0.8rem; color: var(--aio-muted); margin-top: 4px; }

.aio-welcome-card,
.aio-placeholder {
    background: var(--aio-card);
    border-radius: var(--aio-radius);
    padding: 20px;
    box-shadow: var(--aio-shadow);
    margin-bottom: 16px;
}
.aio-placeholder {
    border: 1px dashed var(--aio-border);
    color: var(--aio-muted);
    text-align: center;
}

.aio-notice {
    padding: 14px 18px;
    border-radius: 8px;
    margin: 16px 0;
}
.aio-notice-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

/* Desktop: permanent sidebar */
@media (min-width: 768px) {
    .aio-menu-toggle { display: none; }
    .aio-sidebar {
        position: relative;
        top: auto;
        left: auto;
        bottom: auto;
        height: auto;
        min-height: calc(100vh - var(--aio-topbar-height));
        width: var(--aio-sidebar-width);
        max-width: none;
        transform: none !important;
        flex-shrink: 0;
        box-shadow: none !important;
        z-index: 1;
    }
    .aio-sidebar-header {
        display: none; /* brand already in topbar on desktop */
    }
    .aio-sidebar-overlay { display: none !important; }
    .aio-main {
        padding: 20px 24px 32px;
        width: auto;
    }
    .aio-stats-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 16px;
    }
}

/* Body lock when menu open (mobile) */
body.aio-menu-open {
    overflow: hidden;
}
/* Never disable clicks in main content — overlay handles blocking */

/* ===== Module UI ===== */
.aio-module-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}
.aio-module-header h2 {
    margin: 0;
    font-size: 1.25rem;
}
.aio-badge {
    display: inline-block;
    background: #dbeafe;
    color: #1e40af;
    font-size: 0.8rem;
    padding: 2px 8px;
    border-radius: 999px;
    margin-left: 6px;
    font-weight: 600;
}

.aio-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    text-decoration: none;
    line-height: 1.2;
}
.aio-btn:active { transform: scale(0.98); }
.aio-btn-primary {
    background: var(--aio-primary);
    color: #fff;
}
.aio-btn-primary:hover { background: var(--aio-primary-dark); color: #fff; }
.aio-btn-secondary {
    background: #e2e8f0;
    color: var(--aio-text);
}
.aio-btn-secondary:hover { background: #cbd5e1; }

.aio-form-card {
    background: var(--aio-card);
    border-radius: var(--aio-radius);
    padding: 16px;
    box-shadow: var(--aio-shadow);
    margin-bottom: 16px;
}
.aio-form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
@media (min-width: 600px) {
    .aio-form-grid {
        grid-template-columns: 1fr 1fr;
    }
}
.aio-form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--aio-muted);
}
.aio-form-group input,
.aio-form-group select,
.aio-form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--aio-border);
    border-radius: 8px;
    font-size: 1rem;
    background: #fff;
    color: var(--aio-text);
}
.aio-form-group input:focus,
.aio-form-group select:focus,
.aio-form-group textarea:focus {
    outline: 2px solid var(--aio-primary);
    outline-offset: 1px;
    border-color: var(--aio-primary);
}
.aio-form-full { grid-column: 1 / -1; }
.aio-form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

/* Tables — mobile card-style */
.aio-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--aio-card);
    border-radius: var(--aio-radius);
    box-shadow: var(--aio-shadow);
}
.aio-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.aio-table th,
.aio-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--aio-border);
}
.aio-table th {
    background: #f8fafc;
    font-weight: 600;
    color: var(--aio-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.aio-table tr:last-child td { border-bottom: none; }
.aio-empty { text-align: center; color: var(--aio-muted); padding: 24px !important; }
.aio-actions { white-space: nowrap; }
.aio-link-btn {
    background: none;
    border: none;
    color: var(--aio-primary);
    font-weight: 600;
    cursor: pointer;
    padding: 4px 6px;
    font-size: 0.85rem;
    text-decoration: none;
}
.aio-link-btn.aio-danger { color: var(--aio-danger); }

@media (max-width: 700px) {
    .aio-table thead { display: none; }
    .aio-table tr {
        display: block;
        padding: 12px;
        border-bottom: 1px solid var(--aio-border);
    }
    .aio-table td {
        display: flex;
        justify-content: space-between;
        gap: 12px;
        padding: 6px 0;
        border: none;
    }
    .aio-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--aio-muted);
        flex-shrink: 0;
    }
    .aio-table td.aio-actions {
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}

.aio-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #e2e8f0;
}
.aio-status-active, .aio-status-paid { background: #dcfce7; color: #15803d; }
.aio-status-unpaid { background: #fee2e2; color: #b91c1c; }
.aio-status-partial { background: #fef3c7; color: #b45309; }

/* Toast */
.aio-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #0f172a;
    color: #fff;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 0.9rem;
    z-index: 9999;
    opacity: 0;
    transition: opacity .2s, transform .2s;
    max-width: 90vw;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.aio-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.aio-toast.error { background: var(--aio-danger); }

/* Safe areas for notched phones */
@supports (padding: env(safe-area-inset-top)) {
    .aio-topbar {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
}
