/* =====================================================================
   IQ Test Platform - Main Stylesheet
   Modern, responsive UI using CSS custom properties and a mobile-first
   approach. Works on desktop, tablet and mobile.
   ===================================================================== */

/* ----------------------------- Variables --------------------------- */
:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --accent: #06b6d4;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --text: #1e293b;
    --text-muted: #64748b;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --radius: 14px;
    --radius-sm: 8px;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --maxw: 1100px;
}

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

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

.container {
    width: 100%;
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 0 1.25rem;
}

/* ----------------------------- Typography -------------------------- */
h1, h2, h3, h4 { color: var(--text); line-height: 1.25; margin: 0 0 .5rem; }

.site-main { min-height: 70vh; padding: 2rem 0; }

/* ----------------------------- Header / Nav ------------------------ */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    width: 36px; height: 36px;
    display: grid; place-items: center;
    border-radius: 10px;
    font-weight: 800;
}
.brand-text { font-size: 1.1rem; }

.nav-links { display: flex; align-items: center; gap: 1.25rem; }
.nav-links a { color: var(--text-muted); font-weight: 500; }
.nav-links a:hover { color: var(--primary); text-decoration: none; }
.nav-logout { color: var(--danger) !important; }

.nav-toggle { display: none; background: none; border: 0; cursor: pointer; padding: .5rem; }
.nav-toggle span { display: block; width: 24px; height: 2px; background: var(--text); margin: 5px 0; transition: .3s; }

/* ----------------------------- Buttons ----------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .7rem 1.3rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-weight: 600;
    font-size: .95rem;
    cursor: pointer;
    transition: transform .1s ease, background .2s ease, box-shadow .2s ease;
    font-family: inherit;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--primary); border-color: var(--border); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: .45rem .9rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ----------------------------- Cards ------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.25rem;
    margin-top: 1.5rem;
}
.card-title { font-size: 1.05rem; font-weight: 700; }
.card-sub { color: var(--text-muted); font-size: .9rem; margin-bottom: .75rem; }

/* ----------------------------- Forms ------------------------------- */
.form-group { margin-bottom: 1.1rem; }
.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 140px; }
label { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .9rem; }
.required { color: var(--danger); }
.hint { color: var(--text-muted); font-size: .8rem; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: .7rem .85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .95rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

/* ----------------------------- Alerts / Flash ---------------------- */
.alert { padding: .85rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .92rem; }
.alert ul { margin: 0; padding-left: 1.1rem; }
.alert-error { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: var(--success-light); color: #166534; border: 1px solid #bbf7d0; }
.alert-info { background: var(--primary-light); color: var(--primary-dark); border: 1px solid #c7d2fe; }

.flash {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 100;
    padding: .85rem 1.1rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    max-width: 320px;
    display: flex;
    align-items: center;
    gap: .5rem;
    animation: slideIn .3s ease;
}
.flash-success { background: var(--success); color: #fff; }
.flash-error { background: var(--danger); color: #fff; }
.flash-info { background: var(--primary); color: #fff; }
.flash-close { background: none; border: 0; color: #fff; font-size: 1.2rem; cursor: pointer; line-height: 1; }

@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ----------------------------- Auth -------------------------------- */
.auth-container { display: flex; justify-content: center; align-items: center; min-height: 75vh; padding: 2rem 1rem; }
.auth-card {
    background: var(--surface);
    width: 100%;
    max-width: 440px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem;
    border: 1px solid var(--border);
}
.auth-title { font-size: 1.5rem; text-align: center; }
.auth-subtitle { text-align: center; color: var(--text-muted); margin-bottom: 1.5rem; }
.auth-foot { text-align: center; margin-top: 1.25rem; color: var(--text-muted); font-size: .9rem; }

/* ----------------------------- Hero -------------------------------- */
.hero {
    text-align: center;
    padding: 3.5rem 1rem 2rem;
    background: linear-gradient(135deg, var(--primary-light), #fff);
    border-radius: var(--radius);
    margin-bottom: 2rem;
}
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; }
.hero p { color: var(--text-muted); font-size: 1.1rem; max-width: 600px; margin: 0 auto 1.5rem; }
.hero-actions { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

/* ----------------------------- Stats ------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin: 1.5rem 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; text-align: center; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--primary); }
.stat-label { color: var(--text-muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }

/* ----------------------------- Test UI ----------------------------- */
.test-wrap { max-width: 760px; margin: 0 auto; }
.test-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: .5rem; }
.timer {
    background: var(--text); color: #fff; padding: .5rem 1rem; border-radius: 999px;
    font-weight: 700; font-variant-numeric: tabular-nums; display: inline-flex; gap: .4rem; align-items: center;
}
.timer.warning { background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .6; } }

.progress {
    height: 12px; background: var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 1.25rem;
}
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); width: 0%; transition: width .4s ease; }

.question-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.75rem; box-shadow: var(--shadow-sm); }
.question-counter { color: var(--text-muted); font-size: .85rem; font-weight: 600; }
.question-text { font-size: 1.25rem; font-weight: 600; margin: .5rem 0 1.25rem; }

.options { display: grid; gap: .75rem; }
.option {
    display: flex; align-items: center; gap: .75rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: .85rem 1rem; cursor: pointer; transition: .15s; background: #fff;
}
.option:hover { border-color: var(--primary); background: var(--primary-light); }
.option input { accent-color: var(--primary); width: 18px; height: 18px; }
.option.selected { border-color: var(--primary); background: var(--primary-light); font-weight: 600; }

.test-nav { display: flex; justify-content: space-between; margin-top: 1.5rem; }

/* ----------------------------- Results ----------------------------- */
.result-score {
    text-align: center; background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff; border-radius: var(--radius); padding: 2.5rem 1.5rem; margin-bottom: 1.5rem;
}
.result-iq { font-size: 4rem; font-weight: 800; line-height: 1; }
.result-label { font-size: 1.1rem; opacity: .9; }
.result-percent { font-size: 1.3rem; font-weight: 600; margin-top: .5rem; }

.breakdown { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.breakdown .stat-value { font-size: 1.6rem; }
.feedback-box { background: var(--primary-light); border-left: 4px solid var(--primary); padding: 1.25rem; border-radius: var(--radius-sm); margin-bottom: 1.5rem; }

.review-list { display: grid; gap: .75rem; }
.review-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1rem; }
.review-item.correct { border-left: 4px solid var(--success); }
.review-item.incorrect { border-left: 4px solid var(--danger); }
.review-q { font-weight: 600; margin-bottom: .5rem; }
.review-a { font-size: .9rem; color: var(--text-muted); }
.tag { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.tag-correct { background: var(--success-light); color: #166534; }
.tag-wrong { background: var(--danger-light); color: #991b1b; }

/* ----------------------------- Tables ------------------------------ */
.table-wrap { overflow-x: auto; }
table.data {
    width: 100%; border-collapse: collapse; background: var(--surface);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
}
table.data th, table.data td { padding: .8rem 1rem; text-align: left; border-bottom: 1px solid var(--border); font-size: .92rem; }
table.data th { background: var(--primary-light); color: var(--primary-dark); font-weight: 700; text-transform: uppercase; font-size: .78rem; letter-spacing: .03em; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #f8fafc; }
.badge { display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-admin { background: #ede9fe; color: #6d28d9; }
.badge-user { background: var(--primary-light); color: var(--primary-dark); }
.badge-active { background: var(--success-light); color: #166534; }
.badge-inactive { background: var(--danger-light); color: #991b1b; }

/* ----------------------------- Toolbar ----------------------------- */
.toolbar { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; margin-bottom: 1.25rem; }
.toolbar .search { flex: 1; min-width: 200px; }
.toolbar select { min-width: 160px; }

/* ----------------------------- Footer ------------------------------ */
.site-footer { background: var(--text); color: #cbd5e1; padding: 2rem 0; margin-top: 3rem; text-align: center; }
.footer-small { color: #94a3b8; font-size: .85rem; }

/* ----------------------------- Print (PDF) ------------------------- */
@media print {
    .site-header, .site-footer, .no-print, .flash { display: none !important; }
    body { background: #fff; }
    .card, .question-card { box-shadow: none; border: 1px solid #ccc; }
    .result-score { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ----------------------------- Responsive -------------------------- */
@media (max-width: 768px) {
    .nav-toggle { display: block; }
    .nav-links {
        position: absolute; top: 64px; left: 0; right: 0; background: var(--surface);
        flex-direction: column; align-items: stretch; padding: 1rem 1.25rem; gap: .75rem;
        border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
        display: none;
    }
    .nav-links.open { display: flex; }
    .breakdown { grid-template-columns: 1fr; }
    .result-iq { font-size: 3rem; }
    .form-row { flex-direction: column; gap: 0; }
}

@media (max-width: 480px) {
    .auth-card { padding: 1.5rem; }
    .question-card { padding: 1.25rem; }
    .test-nav .btn { padding: .6rem 1rem; font-size: .9rem; }
}
