/* ============================================================
   Modern UI Enhancement Layer
   - Loaded after style.css & light-theme.css
   - Uses theme CSS variables only, so it adapts to both themes
   ============================================================ */

/* ---------- Missing variable aliases ----------
   Several templates (letter_challenge, manage_sentences, ...)
   use these names; map them to the active theme palette. */
:root {
    --card-bg: var(--surface-glass);
    --bg-color: var(--surface-glass-2);
    --border-color: var(--border-glass);
    --primary-color: var(--brand-accent);
    --text-color: var(--text-primary);
    --hover-bg: var(--hover-overlay);
    --danger-color: var(--state-error);
    --success-color: var(--state-success);
}

/* ---------- Typography & rendering ---------- */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    letter-spacing: 0.1px;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
}

/* ---------- Smooth theme switching ---------- */
.theme-transition,
.theme-transition *,
.theme-transition *::before,
.theme-transition *::after {
    transition: background-color 0.35s ease, color 0.35s ease,
                border-color 0.35s ease, box-shadow 0.35s ease !important;
}

/* ---------- Text selection ---------- */
::selection {
    background: var(--brand-accent);
    color: var(--brand-cta);
}

/* ---------- Modern scrollbar ---------- */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--brand-accent) transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--surface-glass-3);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--brand-accent);
    background-clip: padding-box;
}

/* ---------- Ambient background glow ---------- */
body {
    background-attachment: fixed;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(ellipse 60% 45% at 85% -5%, var(--surface-glass-3), transparent 65%),
        radial-gradient(ellipse 50% 40% at 10% 105%, var(--surface-glass-3), transparent 65%);
}

/* ---------- Navbar: sticky glass bar ---------- */
.navbar {
    position: sticky;
    top: 0;
    z-index: 600;
    backdrop-filter: blur(24px) saturate(150%);
    -webkit-backdrop-filter: blur(24px) saturate(150%);
}

.navbar h1 {
    background: linear-gradient(135deg, var(--text-primary) 30%, var(--brand-highlight));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-btn {
    position: relative;
}

.nav-btn.active {
    background: var(--brand-accent);
    color: var(--brand-cta);
    border-color: var(--brand-accent);
    box-shadow: 0 4px 14px var(--surface-glass-3);
}

.admin-badge {
    background: linear-gradient(135deg, var(--brand-accent), var(--brand-highlight));
    color: var(--brand-cta);
    letter-spacing: 0.3px;
    box-shadow: 0 2px 10px var(--surface-glass-3);
}

/* ---------- Buttons: depth & press feedback ---------- */
.btn {
    background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.09), rgba(0, 0, 0, 0.06));
}

.btn:active {
    transform: translateY(0) scale(0.98);
}

.btn-icon {
    border-radius: 8px;
}

/* ---------- Accessible focus rings ---------- */
.btn:focus-visible,
.nav-btn:focus-visible,
.btn-icon:focus-visible,
.form-control:focus-visible,
a:focus-visible,
button:focus-visible {
    outline: 2px solid var(--brand-highlight);
    outline-offset: 2px;
}

/* ---------- Form controls ---------- */
.form-control {
    transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.form-control:focus {
    box-shadow: 0 0 0 3px var(--surface-glass-3);
}

/* ---------- Cards: refined hover & accent line ---------- */
.stat-card,
.class-card,
.subject-card,
.quick-actions,
.action-card {
    position: relative;
    overflow: hidden;
}

.class-card::before,
.subject-card::before,
.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--brand-accent), var(--brand-highlight), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.class-card:hover::before,
.subject-card:hover::before,
.stat-card:hover::before {
    opacity: 1;
}

/* ---------- Flash messages ---------- */
.flash-message {
    border-radius: 14px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow-medium);
    border-inline-start-width: 4px;
    font-weight: 500;
}

/* ---------- Tables ---------- */
.table {
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid var(--border-glass);
}

.table thead th {
    font-weight: 700;
    letter-spacing: 0.2px;
}

/* ---------- Modals ---------- */
.modal {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    /* Allow the whole overlay to scroll if a modal is taller than the viewport */
    overflow-y: auto;
}

.modal-content {
    border-radius: 18px;
    box-shadow: var(--shadow-medium), 0 0 0 1px var(--border-glass);
    /* Keep tall modals within the viewport and scroll their content,
       so footer buttons (Save/Cancel) stay reachable */
    max-height: 90vh;
    overflow-y: auto;
}

/* ---------- Login form ---------- */
.login-form {
    background: var(--surface-glass);
    border: 1px solid var(--border-glass);
    box-shadow: var(--shadow-medium);
}

/* ---------- Reduced motion preference ---------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ---------- Print: keep documents clean ---------- */
@media print {
    .navbar,
    .flash-messages,
    #theme-toggle {
        display: none !important;
    }

    body::before {
        display: none;
    }
}
