/* =========================================================
   CS Learning Platform — Stylesheet
   ========================================================= */

:root {
    --color-bg:        #f6f7fb;
    --color-surface:   #ffffff;
    --color-text:      #1f2937;
    --color-muted:     #6b7280;
    --color-border:    #e5e7eb;
    --color-primary:   #2563eb;
    --color-primary-d: #1d4ed8;
    --color-success:   #047857;
    --color-success-bg:#d1fae5;
    --color-error:     #b91c1c;
    --color-error-bg:  #fee2e2;
    --color-admin:     #7c3aed;
    --radius:          10px;
    --shadow-sm:       0 1px 2px rgba(0,0,0,0.06);
    --shadow-md:       0 4px 12px rgba(0,0,0,0.08);
    --max-width:       1100px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.55;
}

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

img { max-width: 100%; }

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 20px;
}

/* ---------- Header ---------- */
.site-header,
.admin-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}
.admin-header { background: #1e1e2d; color: #fff; }
.admin-header a { color: #fff; }
.admin-header .logo span { color: #c4b5fd; }

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
}

.logo {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--color-text);
}
.logo span { color: var(--color-primary); }

.main-nav {
    display: flex;
    gap: 18px;
    align-items: center;
    flex-wrap: wrap;
}
.main-nav a {
    color: inherit;
    font-weight: 500;
}
.admin-link {
    background: var(--color-admin);
    color: #fff !important;
    padding: 4px 10px;
    border-radius: 6px;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    padding: 9px 16px;
    border-radius: var(--radius);
    font-weight: 600;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-d); text-decoration: none; }

.btn-outline {
    background: transparent;
    border-color: var(--color-border);
    color: var(--color-text);
}
.btn-outline:hover { border-color: var(--color-primary); color: var(--color-primary); }

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

.btn-small { padding: 5px 10px; font-size: 0.85rem; }

/* ---------- Hero ---------- */
.hero {
    text-align: center;
    padding: 60px 20px 40px;
}
.hero h1 {
    font-size: 2.4rem;
    margin: 0 0 12px;
}
.hero p {
    color: var(--color-muted);
    max-width: 620px;
    margin: 0 auto 28px;
    font-size: 1.05rem;
}
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------- Sections ---------- */
.section { margin: 40px 0; }
.section-title {
    font-size: 1.4rem;
    margin: 0 0 16px;
    border-left: 4px solid var(--color-primary);
    padding-left: 10px;
}
.page-title { margin-top: 24px; }
.lead { color: var(--color-muted); font-size: 1.05rem; }

/* ---------- Cards (track grid) ---------- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 18px;
}
.card {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 18px;
    color: inherit;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s, transform 0.15s;
}
.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    text-decoration: none;
}
.card h3 { margin: 0 0 8px; }
.card p { color: var(--color-muted); margin: 0 0 14px; }
.card-link { color: var(--color-primary); font-weight: 600; }

/* ---------- Article list ---------- */
.article-list { display: flex; flex-direction: column; gap: 16px; }
.article {
    background: var(--color-surface);
    padding: 18px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
}
.article h3 { margin: 0 0 6px; }

/* ---------- Module list & cards ---------- */
.module-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.module-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
    color: inherit;
    box-shadow: var(--shadow-sm);
    display: block;
    transition: transform 0.15s;
}
.module-card:hover { transform: translateY(-2px); text-decoration: none; }
.module-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}
.module-card h3 { margin: 0; font-size: 1.05rem; }

.badge {
    background: var(--color-primary);
    color: #fff;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--color-border);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 10px;
}
.progress-fill {
    height: 100%;
    background: var(--color-primary);
    transition: width 0.4s ease;
    width: 0%;
}

/* ---------- Lessons ---------- */
.lesson-list { display: flex; flex-direction: column; gap: 14px; }
.lesson {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 18px;
}
.lesson h3 { margin: 0 0 8px; }
.lesson-content { color: var(--color-text); }

.progress-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin: 16px 0 24px;
}
.progress-form {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.progress-form input[type="range"] { flex: 1; min-width: 180px; }

/* ---------- Stats ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin: 20px 0 30px;
}
.stat {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 18px;
    text-align: center;
    color: inherit;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
}
.stat-num { display: block; font-size: 1.8rem; font-weight: 700; color: var(--color-primary); }
.stat-label { color: var(--color-muted); font-size: 0.9rem; }

/* ---------- Forms ---------- */
.form-wrap {
    background: var(--color-surface);
    padding: 22px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    margin: 20px 0;
    box-shadow: var(--shadow-sm);
}
.form-wrap.narrow { max-width: 460px; margin: 30px auto; }
.form { display: flex; flex-direction: column; gap: 6px; }
.form label {
    font-weight: 600;
    margin-top: 10px;
    font-size: 0.95rem;
}
.form input[type="text"],
.form input[type="email"],
.form input[type="password"],
.form input[type="number"],
.form select,
.form textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    background: #fff;
}
.form input:focus, .form select:focus, .form textarea:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
    border-color: var(--color-primary);
}
.form textarea { resize: vertical; }
.form-actions { margin-top: 14px; display: flex; gap: 10px; }
.checkbox { display: flex; align-items: center; gap: 8px; margin-top: 12px; }

/* ---------- Tables (admin) ---------- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}
.data-table th, .data-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
    font-size: 0.95rem;
}
.data-table th { background: #f3f4f6; font-weight: 600; }
.data-table tr:last-child td { border-bottom: none; }
.inline-form { display: inline; margin-left: 4px; }

/* ---------- Alerts ---------- */
.alert {
    padding: 12px 14px;
    border-radius: var(--radius);
    margin: 16px 0;
    font-size: 0.95rem;
}
.alert ul { margin: 0; padding-left: 18px; }
.alert-success { background: var(--color-success-bg); color: var(--color-success); }
.alert-error   { background: var(--color-error-bg);   color: var(--color-error); }

/* ---------- Misc ---------- */
.muted { color: var(--color-muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
hr { border: none; border-top: 1px solid var(--color-border); margin: 16px 0; }

.breadcrumb {
    margin: 18px 0 8px;
    color: var(--color-muted);
    font-size: 0.9rem;
}
.breadcrumb a { color: var(--color-muted); }
.breadcrumb a:hover { color: var(--color-primary); }

/* ---------- Footer ---------- */
.site-footer {
    margin-top: 60px;
    padding: 24px 0;
    text-align: center;
    color: var(--color-muted);
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .header-inner { flex-direction: column; gap: 10px; align-items: flex-start; }
    .hero h1 { font-size: 1.8rem; }
    .data-table { font-size: 0.85rem; }
    .data-table th, .data-table td { padding: 8px; }
}

/* ── Video embed (16:9 responsive) ── */
.video-wrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    height: 0;
    overflow: hidden;
    border-radius: 8px;
    margin-top: 1rem;
    background: #000;
}

.video-wrapper iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* ── Fallback link ── */
.lesson-video-link {
    margin-top: 0.75rem;
}

.lesson-video-link a {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
    color: var(--accent, #e00);
    text-decoration: none;
}

.lesson-video-link a:hover {
    text-decoration: underline;
}

.video-wrapper {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
    border-radius: 8px;
    margin-top: 1rem;
    background: #000;
}

.video-wrapper iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
}

.lesson-video-link {
    margin-top: 0.75rem;
}

.lesson-video-link a {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
    text-decoration: none;
}

.lesson-video-link a:hover {
    text-decoration: underline;
}

/* ================================
   ACTIVE NAV LINK STYLE
================================ */

.main-nav a.active {
    color: #ffffff;
    background-color: #2563eb; /* nice blue highlight */
    padding: 6px 12px;
    border-radius: 6px;
    font-weight: 600;
}