:root {
    --primary: var(--accent-color);
    --primary-light: var(--accent-transparent);
    --bg-main: var(--bg-main);
    --card-bg: var(--card-bg);
    --glass-bg: var(--accent-soft);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-dark: #1e293b;
    --text-muted: #64748b;
    --border-color: rgba(226, 232, 240, 0.8);
    --input-bg: rgba(255, 255, 255, 0.5);
    --loader-bg: #f3f6f9;
    --backdrop-blur: blur(12px);
}

[data-theme='dark'] {
    --bg-main: var(--bg-main);
    --card-bg: var(--card-bg);
    --glass-bg: var(--accent-soft);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-dark: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: rgba(51, 65, 85, 0.5);
    --input-bg: rgba(15, 23, 42, 0.4);
    --primary-light: var(--accent-transparent);
    --loader-bg: #0f172a;
    --backdrop-blur: blur(16px);
}

html,
body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    width: 100%;
    height: 100dvh;
    background-color: var(--bg-main);
    background: var(--bg-main);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-image: linear-gradient(135deg, var(--bg-main) 0%, var(--border-color) 100%);
    min-height: 100dvh;
    /* Dynamic viewport height */
    display: flex;
    justify-content: center;
    align-items: center;
    /* Center login on screen */
}

/* Theme Toggle Button */
.theme-toggle {
    position: fixed;
    top: calc(20px + env(safe-area-inset-top));
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 1001;
    color: var(--text-dark);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    transform: scale(1.05);
}

.theme-toggle i {
    font-size: 18px;
}

/* Background blur shape */
.background-blur {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-main);
    z-index: 0;
    overflow: hidden;
}

.background-blur::before,
.background-blur::after {
    content: '';
    position: absolute;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-color), var(--accent-glow));
    filter: blur(80px);
    opacity: 0.15;
    z-index: -1;
    animation: move 20s infinite alternate ease-in-out;
}

.background-blur::before {
    top: -100px;
    left: -100px;
}

.background-blur::after {
    bottom: -100px;
    right: -100px;
    animation-delay: -10s;
}

@keyframes move {
    0% {
        transform: translate(0, 0);
    }

    100% {
        transform: translate(100px, 100px);
    }
}

.login-container {
    background: var(--card-bg);
    backdrop-filter: var(--backdrop-blur);
    -webkit-backdrop-filter: var(--backdrop-blur);
    width: 100%;
    max-width: 480px;
    padding: 30px 20px;
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
    z-index: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    margin: 20px;
    transition: max-width 0.3s ease;
}

/* Responsive adjustments for larger screens */
@media (min-width: 768px) {
    .login-container {
        max-width: 520px;
    }
}

@media (min-height: 700px) {
    .login-container {
        padding: 32px 24px;
    }
}

.login-container::-webkit-scrollbar {
    display: none;
}

/* Logo */
.logo-container {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
    /* Reduced from 20px */
}

@media (min-height: 700px) {
    .logo-container {
        margin-bottom: 20px;
    }
}

.logo-box {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--accent-color), var(--accent-glow));
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 24px;
    font-weight: 800;
    box-shadow: 0 8px 16px rgba(37, 99, 235, 0.2);
    perspective: 1000px;
    animation: logoFlip 4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    transform-style: preserve-3d;
}

@keyframes logoFlip {

    0%,
    100% {
        transform: rotateY(0deg);
    }

    45% {
        transform: rotateY(180deg);
    }

    55% {
        transform: rotateY(180deg);
    }

    95% {
        transform: rotateY(360deg);
    }
}

/* Spinner Speed Improvement */
.fa-spin {
    animation: fa-spin 1s linear infinite !important;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 24px;
}

.logo-wrapper {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 12px;
    padding: 20px; /* Safe space for particles and glow */
}

.login-logo {
    font-size: 38px !important;
    justify-content: center;
    gap: 12px;
    opacity: 0;
    filter: blur(15px);
    transform: scale(0.85);
    animation: cinematicIntro 1.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    position: relative;
    z-index: 10;
}

.login-logo .brand-rn {
    display: inline-block;
    transform: translateX(-40px);
    opacity: 0;
    animation: assembleLeft 1.4s cubic-bezier(0.16, 1, 0.3, 1) forwards 0.4s,
               logoShimmer 4s linear infinite 1.8s,
               logoGlow 3s ease-in-out infinite 1.8s;
}

.login-logo .brand-tech {
    display: inline-block;
    transform: translateX(40px);
    opacity: 0;
    animation: assembleRight 1.4s cubic-bezier(0.16, 1, 0.3, 1) forwards 0.4s;
}

@keyframes cinematicIntro {
    0% { opacity: 0; filter: blur(15px); transform: scale(0.85); }
    40% { opacity: 0.3; filter: blur(8px); }
    100% { opacity: 1; filter: blur(0); transform: scale(1); }
}

@keyframes assembleLeft {
    to { opacity: 1; transform: translateX(0); }
}

@keyframes assembleRight {
    to { opacity: 1; transform: translateX(0); }
}

.logo-halo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 160px;
    height: 160px;
    background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
    opacity: 0;
    filter: blur(30px);
    z-index: -1;
    animation: haloActivate 2.5s ease-out forwards 0.2s,
               haloPulse 4s ease-in-out infinite 2.5s;
}

@keyframes haloActivate {
    0% { opacity: 0; scale: 0.5; }
    100% { opacity: 0.5; scale: 1; }
}

@keyframes haloPulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.4; }
    50% { transform: translate(-50%, -50%) scale(1.4); opacity: 0.7; }
}

.logo-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    opacity: 0;
    animation: fadeIn 1s ease forwards 0.8s;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

.header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

.header p {
    font-size: 14px;
    color: var(--text-muted);
}

/* Role Selector */
.role-selector {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

.role-card {
    flex: 1;
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    background-color: var(--card-bg);
}

.role-icon {
    font-size: 24px;
    color: #64748b;
}

.role-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
}

.check-icon {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 14px;
    color: var(--primary);
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* Active Role Card */
.role-card.active {
    background-color: var(--primary-light);
    border-color: var(--primary);
}

.role-card.active .role-icon {
    color: var(--text-dark);
}

.role-card.active .check-icon {
    opacity: 1;
}

/* Form Groups */
.form-group {
    margin-bottom: 16px;
}

.label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.label-row label {
    margin-bottom: 0;
}

.forgot-link {
    font-size: 13px;
    font-weight: 500;
    color: var(--primary);
    text-decoration: none;
}

.forgot-link:hover {
    text-decoration: underline;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper .icon {
    position: absolute;
    left: 16px;
    font-size: 16px;
    color: var(--text-muted);
    pointer-events: none;
    z-index: 5;
    transition: all 0.3s ease;
}

.input-wrapper input {
    width: 100%;
    height: 54px; /* Premium height */
    padding: 12px 16px 12px 48px; /* Increased left padding for icons */
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    font-size: 16px;
    color: var(--text-dark);
    background-color: var(--input-bg);
    outline: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 0.3px;
}

.input-wrapper input:focus {
    border-color: var(--primary);
    background-color: var(--card-bg);
    box-shadow: 0 0 0 4px var(--primary-light);
}

.input-wrapper input::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

.eye-icon {
    position: absolute;
    right: 14px;
    font-size: 15px;
    color: #94a3b8;
    cursor: pointer;
    z-index: 5;
    padding: 5px;
    /* Increase tap target */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Remove default IE/Edge reveal button */
input::-ms-reveal,
input::-ms-clear {
    display: none;
}

/* Login Button */
.theme-select {
    width: 100%;
    padding: 12px 14px 12px 40px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-dark);
    background-color: var(--card-bg);
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    transition: all 0.2s ease;
}

.theme-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.theme-select option {
    background-color: var(--card-bg);
    color: var(--text-dark);
    padding: 12px;
}

.select-arrow {
    position: absolute;
    right: 14px;
    font-size: 12px;
    color: var(--text-muted);
    pointer-events: none;
    transition: transform 0.2s ease;
}

.theme-select:focus+.select-arrow {
    transform: rotate(180deg);
    color: var(--primary);
}

.login-btn {
    width: 100%;
    padding: 14px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    transition: background-color 0.2s;
}

.login-btn:hover {
    background-color: #034891;
}

.form-footer {
    text-align: center;
    margin-top: 16px;
    /* Reduced from 20px */
    font-size: 14px;
    color: var(--text-muted);
}

@media (min-height: 700px) {
    .form-footer {
        margin-top: 24px;
    }
}

/* Modern immersive safe-area handling for developer credit */
.dev-credit {
    padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    margin-top: 20px !important;
    opacity: 0.6;
    background: transparent;
    width: 100%;
}

/* Custom Modal System */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--card-bg);
    backdrop-filter: var(--backdrop-blur);
    -webkit-backdrop-filter: var(--backdrop-blur);
    width: 100%;
    max-width: 360px;
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    padding: 30px 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-header {
    text-align: center;
    margin-bottom: 24px;
}

.modal-icon {
    width: 60px;
    height: 60px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin: 0 auto 16px;
}

.modal-icon.error {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.modal-icon.success {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.modal-header h3 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.modal-header p {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.5;
}

.modal-footer {
    display: flex;
    justify-content: center;
}

.modal-btn {
    padding: 12px 32px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.modal-btn.primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.modal-btn.primary:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
}
/* =============================================
   GLOBAL EDGE-TO-EDGE RESPONSIVE SYSTEM
   Targets: 360px | 380px | 480px | 768px+
   ============================================= */

/* --- Baseline overflow protection --- */
html, body {
    max-width: 100vw;
    overflow-x: hidden;
}

*, *::before, *::after {
    box-sizing: border-box;
}

/* --- App Container Scaling --- */
.app-container {
    width: 100% !important;
    max-width: 540px !important;
    margin: 0 auto;
    transition: max-width 0.3s ease;
}

@media (min-width: 768px)  { .app-container { max-width: 720px !important; } }
@media (min-width: 1024px) { .app-container { max-width: 900px !important; } }

/* --- Tap Target Safety --- */
button, .nav-item, .role-card, .btn-primary, .btn-secondary,
.back-btn, .filter-btn, .theme-toggle-header, .action-hint {
    min-height: 44px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* --- Input font-size: prevent auto-zoom on iOS/Android --- */
input, select, textarea,
.rn-input, .input-wrapper input,
.form-group input, .form-group select {
    font-size: 16px !important;
}

/* --- Modal responsive max-width --- */
.modal-content, .edit-modal-content {
    width: 95% !important;
    max-width: 440px !important;
    margin: 0 auto;
}
@media (min-width: 768px) {
    .modal-content, .edit-modal-content {
        max-width: 540px !important;
    }
}

/* --- Bottom Nav: global baseline --- */
.bottom-nav {
    width: 94% !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    padding: 7px !important;
}

.nav-content {
    gap: 4px;
    width: 100%;
}

.nav-item {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    padding: 7px 4px;
}

.nav-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
}

/* --- Cards & Lists --- */
.class-card, .student-card-profile, .history-card,
.stat-card, .setting-item, .stat-item {
    width: 100%;
    box-sizing: border-box;
}

/* --- Charts / Grids --- */
.stats-grid, .profile-stats {
    width: 100%;
    box-sizing: border-box;
}

/* =============================================
   MEDIUM PHONES (< 480px) adjustments
   ============================================= */
@media (max-width: 479px) {
    /* Tighten page-level headers */
    .ts-header, .classes-header, .profile-header,
    .page-header, .reports-header, .dashboard-header {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    /* Reduce outer scroll container padding */
    .ts-content, .classes-content, .profile-content,
    .dashboard-content, .main-content, .reports-content {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    /* Form layouts */
    .form-row {
        grid-template-columns: 1fr !important;
    }

    .modal-content, .edit-modal-content {
        padding: 20px 16px !important;
        border-radius: 22px !important;
    }

    h1, .header-title  { font-size: 19px !important; }
    h2                 { font-size: 16px !important; }
}

/* =============================================
   SMALL PHONES (< 380px) — 360×800 TARGET
   ============================================= */
@media (max-width: 380px) {

    /* --- App Container --- */
    .app-container {
        max-width: 100% !important;
    }

    /* --- Page Headers --- */
    .ts-header, .classes-header, .profile-header,
    .page-header, .reports-header, .dashboard-header {
        padding-left: 6px !important;
        padding-right: 6px !important;
    }

    h1, .header-title { font-size: 17px !important; }
    h2                { font-size: 15px !important; }

    .back-btn {
        width: 34px !important;
        height: 34px !important;
        min-height: 34px !important;
    }

    /* --- Scroll Containers --- */
    .ts-content, .classes-content, .profile-content,
    .dashboard-content, .main-content, .reports-content {
        padding-left: 4px !important;
        padding-right: 4px !important;
    }

    /* --- Bottom Navigation --- */
    .bottom-nav {
        width: 94% !important;
        padding: 5px !important;
        bottom: 16px !important;
        border-radius: 20px !important;
    }

    .nav-content {
        gap: 2px !important;
    }

    .nav-item {
        padding: 6px 2px !important;
        min-width: 0 !important;
        gap: 2px !important;
        border-radius: 14px !important;
        min-height: 0 !important;
    }

    .nav-item i {
        font-size: 16px !important;
    }

    .nav-label {
        font-size: 8px !important;
        letter-spacing: -0.2px !important;
    }

    .nav-item.active {
        padding: 8px 12px !important;
    }

    .nav-divider {
        display: none !important;
    }

    /* --- Modals & Forms --- */
    .modal-content, .edit-modal-content {
        width: 98% !important;
        padding: 16px 12px !important;
        border-radius: 18px !important;
    }

    .form-group input, .form-group select,
    .rn-input {
        padding: 10px 12px !important;
        font-size: 15px !important;
    }

    .input-wrapper input {
        padding-left: 48px !important; /* Force icon spacing on mobile */
        height: 50px !important;
        font-size: 15px !important;
    }

    .form-row {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    /* --- Cards (General) --- */
    .class-card {
        padding: 16px 12px !important;
        border-radius: 18px !important;
    }

    .history-card {
        padding: 12px 10px !important;
        border-radius: 14px !important;
    }

    .stat-card {
        padding: 10px 8px !important;
        border-radius: 16px !important;
    }

    /* --- Dashboard Stats Grid --- */
    .stats-grid {
        gap: 8px !important;
    }

    .stat-value {
        font-size: 17px !important;
    }

    .stat-label {
        font-size: 9px !important;
    }

    /* --- Profile Stats --- */
    .profile-stats {
        gap: 8px !important;
    }

    .stat-item {
        padding: 12px 6px !important;
        border-radius: 16px !important;
    }

    .stat-item .stat-value {
        font-size: 15px !important;
    }

    /* --- Search Inputs --- */
    .search-input-wrapper {
        height: 40px !important;
        padding: 0 10px !important;
    }

    .search-input-wrapper input {
        font-size: 13px !important;
    }

    .filter-btn {
        width: 40px !important;
        height: 40px !important;
        min-height: 40px !important;
    }

    /* --- Chart / Analytics Scaling --- */
    .circular-progress-container {
        width: clamp(80px, 22vw, 100px) !important;
        height: clamp(80px, 22vw, 100px) !important;
    }
}

/* --- Signup Page Overflow & Scrollbar Fix (Requirement 14, 15) --- */
/* Target only the Signup state using the .signup-mode class added in script.js */
.login-container.signup-mode {
    max-height: 88vh; /* Ensure it fits with safe margins */
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none; /* Hide for Firefox */
    -ms-overflow-style: none; /* Hide for IE/Edge */
    overscroll-behavior: contain; /* Prevent body scroll chain */
    -webkit-overflow-scrolling: touch; /* Smooth inertia scrolling for iOS/Android */
    padding-bottom: 30px; /* Safe space at the bottom */
}

/* Visually hide scrollbar for Chrome/Safari/Webkit/Capacitor */
.login-container.signup-mode::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

/* Optimization for small 360x800 screens */
@media (max-height: 720px) {
    .login-container.signup-mode {
        margin: 10px;
        padding: 24px 18px;
        max-height: 92vh;
    }
    
    .login-container.signup-mode .header {
        margin-bottom: 16px;
    }
    
    .login-container.signup-mode .logo-container {
        margin-bottom: 12px;
    }
    
    .login-container.signup-mode .form-group {
        margin-bottom: 12px;
    }
}

