/* =========================================
   TVET Student Portal - Global Styles
   ========================================= */
:root {
    --primary: #191F6E;
    --primary-dark: #10143f;
    --success: #16a34a;
    --danger:  #C80F0F;
    --warning: #d97706;
    --info:    #191F6E;
    --muted:   #64748b;
    --bg:      #f1f5f9;
    --card:    #ffffff;
    --border:  #e2e8f0;
    --text:    #0f172a;
    --radius:  0;
    --shadow:  0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .06);
    --accent:  #FFCC00;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
    max-width: 1720px; margin: 0 auto; padding: 12px 24px;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--primary); text-decoration: none; }
.topnav { display: flex; align-items: center; gap: 16px; }
.topnav a { color: var(--text); text-decoration: none; font-size: .95rem; }
.topnav a:hover { color: var(--primary); }
.user-chip {
    background: var(--bg); border: 1px solid var(--border);
    padding: 4px 12px; font-size: .85rem; color: var(--muted);
}

/* ---------- Layout ---------- */
.container { max-width: 1720px; width: 100%; margin: 28px auto; padding: 0 24px; flex: 1; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 18px; }

.page-title { margin: 0 0 6px; font-size: 1.5rem; }
.page-subtitle { margin: 0 0 24px; color: var(--muted); }

/* ---------- Cards ---------- */
.card {
    background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow); padding: 22px;
}
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.course-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* ---------- Locked module cards (sequential unlocking) ---------- */
.pcard.locked .pcard-media img { filter: grayscale(1) brightness(.75); }
.pcard.locked { opacity: .85; }
.lock-overlay {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 8px;
    background: rgba(15, 23, 42, .35); color: #fff;
}
.lock-overlay .lock-icon { font-size: 2.2rem; }
.lock-overlay .lock-text {
    font-size: .8rem; font-weight: 600; background: rgba(15,23,42,.7);
    padding: 5px 12px; max-width: 85%; text-align: center;
}
.seq-num {
    position: absolute; top: 12px; left: 12px; background: var(--accent, #FFCC00);
    color: #10143f; font-weight: 700; font-size: .8rem;
    padding: 4px 10px; box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.btn.disabled, .btn:disabled {
    background: var(--border); color: var(--muted); cursor: not-allowed; pointer-events: none;
}

/* ---------- Progress bar ---------- */
.progress { background: var(--border); height: 10px; overflow: hidden; }
.progress-fill { background: var(--primary); height: 100%; transition: width .4s; }
.progress-fill.done { background: var(--success); }
.progress-label { font-size: .8rem; color: var(--muted); margin-top: 4px; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block; padding: 3px 10px;
    font-size: .75rem; font-weight: 600; color: #fff;
}
.badge-success { background: var(--success); }
.badge-danger  { background: var(--danger); }
.badge-warning { background: var(--warning); }
.badge-info    { background: var(--info); }
.badge-muted   { background: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block; padding: 9px 18px;
    border: 1px solid transparent; background: var(--primary); color: #fff;
    font-size: .95rem; font-weight: 600; cursor: pointer; text-decoration: none;
    text-align: center;
}
.btn:hover { background: var(--primary-dark); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 5px 12px; font-size: .85rem; }
.btn-block { display: block; width: 100%; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: .9rem; }
.form-control {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border); font-size: .95rem; background: #fff;
}
.form-control:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.form-hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; margin-bottom: 20px; font-size: .92rem; }
.alert-success { background: #dcfce7; color: #14532d; border: 1px solid #bbf7d0; }
.alert-error   { background: #fee2e2; color: #7f1d1d; border: 1px solid #fecaca; }
.alert-info    { background: #e0f2fe; color: #0c4a6e; border: 1px solid #bae6fd; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data {
    width: 100%; border-collapse: collapse; background: var(--card); overflow: hidden; box-shadow: var(--shadow);
}
table.data th, table.data td { padding: 12px 14px; text-align: left; font-size: .9rem; }
table.data th { background: #0c559e; color: #ffffff; font-weight: 600; border-bottom: 1px solid var(--border); }
table.data td { border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #f8fafc; }

/* ---------- Login page ---------- */
.auth-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .logo { text-align: center; margin-bottom: 18px; }
.auth-card .logo h1 { font-size: 1.4rem; margin: 0; color: var(--primary); }
.auth-card .logo p { color: var(--muted); margin: 6px 0 0; font-size: .9rem; }

/* ---------- Picture cards (educavo-style: image, title, text, action) ---------- */
.pcard {
    background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow);
    overflow: hidden; display: flex; flex-direction: column;
    transition: transform .2s, box-shadow .2s;
}
.pcard:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(15, 23, 42, .14);
}
.pcard-media { position: relative; aspect-ratio: 420 / 600; background: var(--primary); }
.pcard-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pcard-media .badge { position: absolute; top: 12px; right: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.pcard-body { padding: 20px 22px 22px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.pcard-body h3 { margin: 0; font-size: 1.15rem; }
.pcard-body .desc { color: var(--muted); font-size: .92rem; line-height: 1.55; flex: 1; margin: 0; }
.pcard-body .btn { margin-top: 10px; align-self: flex-start; }
.pcard-body .btn.btn-block { align-self: stretch; }

/* Admin nav: 5 cards in ONE row on wide screens, wrap gracefully below */
.grid-nav5 { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
@media (min-width: 1280px) { .grid-nav5 { grid-template-columns: repeat(5, 1fr); } }

/* ---------- Program module sequence (drag & drop) ---------- */
.seq-list { list-style: none; margin: 10px 0 0; padding: 0; }
.seq-item {
    display: flex; align-items: center; gap: 12px;
    background: #f8fafc; border: 1px solid var(--border);
    padding: 9px 14px; margin-bottom: 6px; cursor: grab;
}
.seq-item.dragging { opacity: .45; border-style: dashed; }
.seq-handle { color: var(--muted); letter-spacing: -2px; cursor: grab; }
.seq-order {
    background: var(--primary); color: #fff; font-weight: 700; font-size: .8rem;
    width: 26px; height: 26px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.seq-title { flex: 1; font-size: .92rem; font-weight: 600; }
.seq-empty { color: var(--muted); font-size: .88rem; padding: 8px 4px; list-style: none; }

/* ---------- Reports ---------- */
.report-tabs {
    display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px;
    border-bottom: 1px solid var(--border); padding-bottom: 0;
}
.report-tabs .tab {
    padding: 9px 16px; text-decoration: none; color: var(--muted);
    font-size: .92rem; font-weight: 600;
    border: 1px solid transparent; border-bottom: none;
}
.report-tabs .tab:hover { color: var(--primary); }
.report-tabs .tab.active {
    color: #ffffff; background: #0c559e;
    border-color: #0c559e; position: relative; top: 1px;
}
.report-filter {
    display: flex; align-items: center; gap: 8px; margin-bottom: 20px;
    font-size: .9rem; color: var(--muted);
}
.report-filter select {
    padding: 6px 10px; border: 1px solid var(--border);
    background: #fff; font-size: .9rem;
}
.kpi-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 22px; }
.kpi { background: var(--card); border: 1px solid var(--border);
       box-shadow: var(--shadow); padding: 16px 18px; }
.kpi .kpi-value { font-size: 1.7rem; font-weight: 700; color: var(--text); }
.kpi .kpi-label { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.chart-card { position: relative; }
.chart-card h3 { margin: 0 0 4px; font-size: 1.02rem; }
.chart-card .chart-sub { color: var(--muted); font-size: .82rem; margin: 0 0 14px; }
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 380px; }
.report-grid-2 { display: grid; gap: 20px; grid-template-columns: 3fr 2fr; margin-bottom: 22px; }
@media (max-width: 900px) { .report-grid-2 { grid-template-columns: 1fr; } }

/* ---------- Player page (full-bleed iframe) ---------- */
.player-body { display: flex; flex-direction: column; height: 100vh; margin: 0; background: #0f172a; }
.player-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 16px; background: #1e293b; color: #e2e8f0; font-size: .9rem;
}
.player-bar a { color: #93c5fd; text-decoration: none; font-weight: 600; }
.player-bar .save-state { font-size: .8rem; color: #94a3b8; }
.player-frame { flex: 1; border: 0; width: 100%; background: #000; }

/* ---------- v4: expandable Modules column (students report) ---------- */
.mods-details summary {
    cursor: pointer; list-style: none; white-space: nowrap;
}
.mods-details summary::-webkit-details-marker { display: none; }
.mods-hint { color: var(--muted); font-size: .78rem; }
.mods-details[open] .mods-hint { display: none; }
.mods-pop {
    margin-top: 8px; padding: 10px 12px; background: #fafaf7;
    border: 1px solid var(--border, #e1e0d9);
    min-width: 380px;
}
.mod-line {
    display: flex; align-items: center; gap: 10px; padding: 3px 0;
}
.mod-name {
    flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; font-size: .85rem;
}
.mod-bar { width: 90px; flex: 0 0 auto; display: inline-block; }
.mod-bar .progress-fill { display: block; }
.mod-pct { width: 38px; flex: 0 0 auto; text-align: right; font-size: .8rem; color: var(--muted); }

/* ---------- v4: attempt history ---------- */
.attempt-block { margin-bottom: 18px; }
.attempt-block h4 { margin: 0 0 8px; }
.chip-q {
    display: inline-block; padding: 2px 8px; margin: 2px 3px 2px 0; font-size: .75rem; font-weight: 600;
    background: #fdeaea; color: #a02020; border: 1px solid #f0c4c4;
}
.chip-q.ok { background: #e8f6e8; color: #1c6b1c; border-color: #bfe3bf; }

/* ---------- v4.1: sortable table headers ---------- */
table.data th.th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
table.data th.th-sort::after { content: ' \2195'; color: rgba(255,255,255,.65); font-size: .8em; }
table.data th.th-sort.sorted-desc::after { content: ' \2193'; color: #ffffff; }
table.data th.th-sort.sorted-asc::after  { content: ' \2191'; color: #ffffff; }

/* ---------- v4.2: replace-package box in Modules table ---------- */
.replace-box { display: inline-block; margin-top: 6px; }
.replace-box summary { list-style: none; display: inline-block; cursor: pointer; }
.replace-box summary::-webkit-details-marker { display: none; }
.replace-box[open] {
    display: block; background: #fafaf7; border: 1px solid var(--border, #e1e0d9); padding: 10px; margin-top: 8px; max-width: 280px;
}

/* ---------- v4.4: logo in the top bar (responsive) ---------- */
.brand-logo { height: 44px; width: auto; display: block; }
@media (max-width: 768px)  { .brand-logo { height: 34px; } }
@media (max-width: 480px)  { .brand-logo { height: 28px; } }
.auth-logo { max-width: 260px; width: 80%; height: auto; display: block; margin: 0 auto 6px; }

/* ---------- v4.5: photo background on auth screens ---------- */
body:has(.auth-wrap) {
    background:
        linear-gradient(rgba(12, 20, 63, .60), rgba(12, 20, 63, .60)),
        url('../img/bg-auth.jpg') center / cover no-repeat fixed;
}
/* frosted-glass card over the photo (like the reference design) */
body:has(.auth-wrap) .card {
    background: rgba(255, 255, 255, .78);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, .55);
    box-shadow: 0 8px 40px rgba(0, 0, 0, .45);
}

/* ---------- v4.6: admin header ---------- */
.admin-welcome { font-weight: 600; color: var(--text); }
.admin-welcome small {
    display: block; font-weight: 400; color: #fff; font-size: .55rem;
    margin-top: 1px; background-color: #ff5656; text-align: center;
    padding: 1px 6px;
}

/* ---------- v4.7: buttons ALWAYS keep readable text (hover never recolors it) ---------- */
.topnav a.btn, a.btn, button.btn,
.topnav a.btn:hover, a.btn:hover, button.btn:hover,
.topnav a.btn:focus, a.btn:focus, button.btn:focus {
    color: #ffffff;
}
.topnav a.btn-outline, a.btn-outline, button.btn-outline {
    color: var(--primary);
}
.topnav a.btn-outline:hover, a.btn-outline:hover, button.btn-outline:hover {
    background: var(--primary);
    color: #ffffff;
}

/* ---------- v4.8: admin nav cards centered at half screen ---------- */
.nav-centered {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px;
    max-width: 1400px; margin-left: auto; margin-right: auto;
}
/* below laptop width (1366 stays 4-up): 2 per row, mobile: 1 per row */
@media (max-width: 1200px) { .nav-centered { grid-template-columns: repeat(2, 1fr); max-width: 720px; } }
@media (max-width: 640px)  { .nav-centered { grid-template-columns: 1fr; max-width: 380px; } }

/* ---------- v4.9: expand/collapse controls above the students table ---------- */
.expand-controls { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 8px; }

/* ---------- v4.9.1: outline buttons keep navy text after being clicked
   (the earlier :focus white rule was bleeding into outline buttons) ---------- */
a.btn-outline:focus, button.btn-outline:focus, .topnav a.btn-outline:focus {
    color: var(--primary);
    background: transparent;
}
a.btn-outline:focus:hover, button.btn-outline:focus:hover, .topnav a.btn-outline:focus:hover {
    color: #ffffff;
    background: var(--primary);
}

/* ---------- v4.10: flagged rows in the activity list ---------- */
tr.row-flag td { background: #fdf3f3; }

/* ---------- v5: Edit Student modal ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(12, 20, 63, .55);
    display: none; align-items: center; justify-content: center; z-index: 200;
}
.modal-overlay.show { display: flex; }
.modal-box {
    background: #fff; width: 540px; max-width: 94vw; max-height: 92vh;
    overflow-y: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
.modal-head {
    background: #0c559e; color: #fff; padding: 14px 18px;
    display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
}
.modal-head h2 { margin: 0; font-size: 1.05rem; color: #fff; }
.modal-head small { color: #cfe0f3; }
.modal-x { cursor: pointer; font-size: 1.4rem; color: #fff; background: none; border: none; line-height: 1; }
.modal-body { padding: 18px; }
.modal-sec { border: 1px solid var(--border); padding: 14px; margin-bottom: 14px; }
.modal-sec h3 { margin: 0 0 10px; font-size: .95rem; color: #0c559e; }
.modal-row { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.modal-foot { padding: 0 18px 18px; display: flex; justify-content: space-between; }
