/* ========================================
   AVR Branch Portal - Professional UI
   Fully Responsive (Desktop + iPhone + Android)
   ======================================== */

:root {
    --primary: #0f2744;
    --primary-dark: #0a1a2e;
    --accent: #0d9488;
    --accent-hover: #0f766e;
    --accent-light: #ccfbf1;
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --info: #0284c7;
    --bg: #f0f4f8;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-width: 260px;
    --header-height: 58px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --transition: all 0.22s ease;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--accent-hover); }

img { max-width: 100%; height: auto; }

/* ========== LOGIN PAGE ========== */
.login-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #0f2744 0%, #0a1628 50%, #0d3b3a 100%);
    padding: 20px 16px;
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    width: 400px; height: 400px;
    background: radial-gradient(circle, rgba(13,148,136,0.15) 0%, transparent 70%);
    top: -100px; right: -100px;
    border-radius: 50%;
}

.login-page::after {
    content: '';
    position: absolute;
    width: 300px; height: 300px;
    background: radial-gradient(circle, rgba(13,148,136,0.1) 0%, transparent 70%);
    bottom: -80px; left: -80px;
    border-radius: 50%;
}

.login-card {
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.25);
    width: 100%;
    max-width: 400px;
    padding: 36px 28px;
    position: relative;
    z-index: 1;
}

.login-card .logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-card .logo .logo-badge {
    width: 56px; height: 56px;
    background: linear-gradient(135deg, var(--accent), #14b8a6);
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 12px;
    box-shadow: 0 8px 20px rgba(13,148,136,0.3);
}

.login-card .logo h1 {
    font-size: 1.4rem;
    color: var(--primary);
    font-weight: 700;
    letter-spacing: -0.3px;
}

.login-card .logo p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 4px;
}

.login-card .form-group { margin-bottom: 16px; }

.login-card label {
    display: block;
    font-weight: 600;
    font-size: 0.82rem;
    margin-bottom: 6px;
    color: var(--text);
}

.login-card input {
    width: 100%;
    padding: 13px 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 0.95rem;
    transition: var(--transition);
    background: #f8fafc;
    -webkit-appearance: none;
}

.login-card input:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(13,148,136,0.15);
}

.login-card .btn-login {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--accent), #14b8a6);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 6px;
    box-shadow: 0 4px 14px rgba(13,148,136,0.3);
}

.login-card .btn-login:hover,
.login-card .btn-login:active {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(13,148,136,0.4);
}

.login-card .alert { margin-bottom: 14px; }

/* ========== LAYOUT ========== */
.app-wrapper { display: flex; min-height: 100vh; min-height: 100dvh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--primary);
    color: #fff;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sidebar-header {
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--header-height);
}

.sidebar-header .logo-icon {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--accent), #14b8a6);
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.sidebar-header h2 {
    font-size: 1rem;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: -0.2px;
}

.sidebar-nav { flex: 1; padding: 10px 0; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 18px;
    color: rgba(255,255,255,0.7);
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
    border-left: 3px solid transparent;
    margin: 1px 0;
}

.sidebar-nav a:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

.sidebar-nav a.active {
    background: rgba(13,148,136,0.15);
    color: #fff;
    border-left-color: var(--accent);
}

.sidebar-nav a i {
    width: 20px;
    text-align: center;
    font-size: 0.95rem;
    opacity: 0.9;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 0.75rem;
    color: rgba(255,255,255,0.45);
}

/* Main content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    transition: margin 0.28s ease;
    width: 100%;
}

/* Top header */
.top-header {
    height: var(--header-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.top-header .page-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.3px;
}

.top-header .header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
}

.user-info .avatar {
    width: 34px; height: 34px;
    background: linear-gradient(135deg, var(--accent), #14b8a6);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.78rem;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.35rem;
    color: var(--primary);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.menu-toggle:active { background: var(--bg); }

/* Content area */
.content {
    padding: 20px;
    flex: 1;
}

/* ========== CARDS & STATS ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 14px;
    transition: var(--transition);
    border: 1px solid var(--border);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-card .stat-icon {
    width: 44px; height: 44px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.stat-card .stat-icon.blue { background: #dbeafe; color: #2563eb; }
.stat-card .stat-icon.green { background: #d1fae5; color: #059669; }
.stat-card .stat-icon.orange { background: #ffedd5; color: #d97706; }
.stat-card .stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-card .stat-icon.red { background: #fee2e2; color: #dc2626; }
.stat-card .stat-icon.teal { background: #ccfbf1; color: #0d9488; }

.stat-card .stat-info h3 {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
    letter-spacing: -0.5px;
}

.stat-card .stat-info p {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 1px;
    font-weight: 500;
}

/* Generic card */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    overflow: hidden;
}

.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    background: #fafbfc;
}

.card-header h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body { padding: 18px; }

/* ========== BUTTONS ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 8px;
    font-size: 0.84rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #14b8a6);
    color: #fff;
    box-shadow: 0 2px 8px rgba(13,148,136,0.25);
}
.btn-primary:hover { color: #fff; box-shadow: 0 4px 12px rgba(13,148,136,0.35); }

.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; color: var(--text); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; color: #fff; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }

.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #b45309; color: #fff; }

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

.btn-sm { padding: 6px 11px; font-size: 0.78rem; border-radius: 6px; }
.btn-lg { padding: 12px 22px; font-size: 0.95rem; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ========== FORMS ========== */
.form-group { margin-bottom: 15px; }

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.82rem;
    margin-bottom: 5px;
    color: var(--text);
}

.form-group label .required { color: var(--danger); }

.form-control {
    width: 100%;
    padding: 10px 13px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    transition: var(--transition);
    background: #fafbfc;
    color: var(--text);
    -webkit-appearance: none;
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(13,148,136,0.12);
}

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

select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    cursor: pointer;
}

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

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

/* ========== TABLES ========== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding: 0 4px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
    min-width: 500px;
}

table thead { background: #f8fafc; }

table th {
    padding: 11px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

table tbody tr { transition: background 0.15s; }
table tbody tr:hover { background: #f8fafc; }

table .actions {
    display: flex;
    gap: 5px;
    flex-wrap: nowrap;
}

/* ========== BADGES ========== */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: 0.2px;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #ffedd5; color: #9a3412; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: #f1f5f9; color: #475569; }

/* ========== ALERTS ========== */
.alert {
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 0.875rem;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #ffedd5; color: #9a3412; border: 1px solid #fed7aa; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ========== SEARCH / FILTER ========== */
.filter-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    align-items: center;
}

.filter-bar .form-control { max-width: 200px; }
.filter-bar .search-input { max-width: 260px; flex: 1; min-width: 140px; }

/* ========== NOTICE CARDS ========== */
.notice-list { display: flex; flex-direction: column; gap: 10px; }

.notice-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 14px 16px;
    border-left: 4px solid var(--accent);
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.notice-card.priority-high { border-left-color: var(--danger); }
.notice-card.priority-medium { border-left-color: var(--warning); }
.notice-card.priority-low { border-left-color: var(--info); }

.notice-card h4 {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.notice-card .notice-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.notice-card p { font-size: 0.85rem; color: var(--text); line-height: 1.5; }

/* ========== QUICK ACTIONS ========== */
.quick-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

/* ========== EMPTY STATE ========== */
.empty-state {
    text-align: center;
    padding: 40px 16px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 2.5rem;
    margin-bottom: 10px;
    opacity: 0.3;
}

.empty-state h4 {
    font-size: 1rem;
    margin-bottom: 4px;
    color: var(--text);
}

.empty-state p { font-size: 0.85rem; }

/* ========== PAGINATION ========== */
.pagination { margin-top: 18px; }

.pagination ul {
    display: flex;
    gap: 4px;
    list-style: none;
    justify-content: center;
    flex-wrap: wrap;
}

.pagination a {
    display: block;
    padding: 7px 12px;
    border-radius: 7px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 500;
    transition: var(--transition);
    min-width: 36px;
    text-align: center;
}

.pagination li.active a,
.pagination a:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ========== PROFILE ========== */
.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 4px 20px;
}

.profile-item {
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
}

.profile-item .label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.profile-item .value {
    font-size: 0.92rem;
    font-weight: 600;
    margin-top: 2px;
}

/* ========== RESULT PRINT ========== */
.result-sheet {
    max-width: 680px;
    margin: 0 auto;
    background: #fff;
    padding: 28px;
    border: 2px solid var(--primary);
    border-radius: 10px;
}

.result-sheet .result-header {
    text-align: center;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 14px;
    margin-bottom: 20px;
}

.result-sheet .result-header h2 {
    color: var(--primary);
    font-size: 1.3rem;
}

.result-sheet .student-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.result-sheet .marks-table { width: 100%; margin-bottom: 18px; min-width: auto; }

.result-sheet .result-summary {
    text-align: center;
    padding: 16px;
    background: #f8fafc;
    border-radius: 8px;
}

.result-sheet .result-summary .grade {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

@media print {
    .sidebar, .top-header, .no-print, .btn, .filter-bar, .sidebar-overlay { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .content { padding: 0 !important; }
    .result-sheet { border: none; box-shadow: none; }
    body { background: #fff; }
}

/* ========== SIDEBAR OVERLAY ========== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 999;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* ========== RESPONSIVE - TABLET ========== */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ========== RESPONSIVE - MOBILE (iPhone) ========== */
@media (max-width: 576px) {
    .content { padding: 14px 12px; }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 14px 12px;
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }

    .stat-card .stat-icon {
        width: 40px; height: 40px;
        font-size: 1.05rem;
    }

    .stat-card .stat-info h3 { font-size: 1.25rem; }
    .stat-card .stat-info p { font-size: 0.72rem; }

    .card-header { padding: 12px 14px; }
    .card-body { padding: 14px; }

    .form-row { grid-template-columns: 1fr; gap: 0; }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-bar .form-control,
    .filter-bar .search-input {
        max-width: 100%;
        width: 100%;
    }

    .top-header { padding: 0 12px; }
    .top-header .page-title { font-size: 1rem; }

    .user-info span { display: none; }

    .login-card { padding: 28px 20px; border-radius: 16px; }

    .quick-actions { gap: 8px; }
    .quick-actions .btn { flex: 1; min-width: calc(50% - 8px); justify-content: center; font-size: 0.8rem; padding: 10px 8px; }

    .profile-grid { grid-template-columns: 1fr; }

    .result-sheet { padding: 16px; }
    .result-sheet .student-info { grid-template-columns: 1fr; }

    table { font-size: 0.8rem; }
    table th, table td { padding: 9px 8px; }

    .btn-group { width: 100%; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; justify-content: center; }

    .sidebar { width: 280px; }
    .sidebar-nav a { padding: 13px 20px; font-size: 0.9rem; }
}

/* Very small phones */
@media (max-width: 360px) {
    .stats-grid { grid-template-columns: 1fr; }
    .quick-actions .btn { min-width: 100%; }
}

/* Safe area for notched iPhones */
@supports (padding: max(0px)) {
    .top-header {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }
    .content {
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }
    .sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }
}
