/* ==========================================================
   AK Learning – Custom Design Layer (Bootstrap 5 companion)
   Bootstrap loaded first in <head>; these styles override/extend it.
   ========================================================== */

/* ---- Tokens ---- */
:root {
    --brand:      #2563eb;
    --brand-dark: #1d4ed8;
    --danger:     #dc2626;
    --muted:      #6b7280;
    --surface:    #ffffff;
    --bg:         #f3f4f6;
    --border:     #e5e7eb;
    --text:       #111827;
}

/* ---- Global ---- */
* { box-sizing: border-box; }

body {
    margin: 0;
    color: var(--text);
    background: radial-gradient(circle at top right, #e0e7ff, var(--bg) 35%);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

a { color: var(--brand-dark); text-decoration: none; }
a:hover { color: var(--brand); }

/* ---- Topbar / Navbar ---- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 1030;
}

.brand {
    font-size: 1.2rem;
    font-weight: 800;
    color: #1f2937 !important;
}

.topbar .nav-link {
    font-weight: 600;
    color: #1f2937;
    padding: 0.25rem 0.5rem;
}

.topbar .nav-link:hover { color: var(--brand); }

/* ---- Utility ---- */
.muted { color: var(--muted); }
.is-hidden { display: none !important; }
.inline-form { display: inline-block; width: auto; }

.chip {
    display: inline-block;
    border-radius: 999px;
    background: #e2e8f0;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 600;
}

/* ---- Alerts / Messages ---- */
.msg {
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
}
.msg.success { background: #dcfce7; color: #166534; }
.msg.error   { background: #fee2e2; color: #991b1b; }

/* ---- Buttons ---- */
.btn-brand {
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-brand:hover { background: var(--brand-dark); color: #fff; }

.btn-ghost {
    background: #334155;
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 8px 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-ghost:hover { background: #1e293b; color: #fff; }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 8px 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-danger:hover { background: #b91c1c; color: #fff; }

.btn-small { padding: 4px 10px; font-size: 12px; }

/* ---- Form overrides (admin panels only) ---- */
.site-form input:not([type=file]):not([type=color]):not([type=range]):not([type=submit]),
.site-form select,
.site-form textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 11px;
    font: inherit;
    background: #fff;
    display: block;
    margin-bottom: 0;
}

.site-form input:focus,
.site-form select:focus,
.site-form textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* ---- Hero ---- */
.hero {
    border-radius: 18px;
    padding: 30px;
    margin-bottom: 20px;
}
.hero h1 { margin: 0 0 8px; font-size: 2rem; }
.hero p  { margin: 0; opacity: 0.92; }

/* ---- Search Pill ---- */
.search-pill {
    display: flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
    padding: 4px 4px 4px 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    max-width: 800px;
    margin: 0 auto;
}

.search-pill input {
    border: none;
    border-radius: 0;
    padding: 10px 0;
    box-shadow: none !important;
    outline: none;
    flex-grow: 1;
    width: auto;
    font-size: 1.05rem;
    background: transparent;
}
.search-pill input:focus { box-shadow: none !important; }

.search-pill select {
    border: none;
    border-left: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none !important;
    padding: 10px 15px;
    width: auto;
    background: transparent;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--muted);
}
.search-pill select:focus { box-shadow: none !important; }

.search-pill button {
    border-radius: 999px !important;
    background: #f4f4f5 !important;
    color: #18181b !important;
    padding: 12px 20px !important;
    margin-left: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none !important;
    transition: background 0.2s ease;
    font-weight: normal;
    box-shadow: none !important;
}
.search-pill button:hover { background: #e4e4e7 !important; }

/* ---- Course Cards ---- */
.course-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    height: 100%;
}

.course-banner {
    height: 120px;
    background: linear-gradient(120deg, #c7d2fe, #93c5fd);
}

.course-cover {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
}

.course-body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 220px;
}
.course-body a { margin-top: auto; }

.course-title  { margin: 0; font-size: 1.06rem; }
.course-meta   { color: var(--muted); font-size: 13px; margin: 0; }
.course-body p { margin: 0; }

.course-summary {
    line-height: 1.35;
    min-height: calc(1.35em * 3);
    max-height: calc(1.35em * 3);
    overflow: hidden;
    display: block;
}

.course-detail-cover {
    width: 100%;
    max-height: 360px;
    object-fit: cover;
    border-radius: 10px;
}

/* ---- Studio Panels (Instructor Dashboard) ---- */
.studio-course {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    overflow: hidden;
    margin-bottom: 14px;
}

.studio-cover {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.studio-meta .course-title {
    margin-bottom: 4px;
    display: flex;
    gap: 8px;
    align-items: center;
}
.studio-meta .course-meta { margin-bottom: 8px; }
.studio-meta p { margin: 6px 0; }

.studio-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Accordion-style panels */
.studio-panels {
    border-top: 1px solid var(--border);
    padding: 10px 12px 12px;
    display: grid;
    gap: 8px;
}

.studio-panel {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fcfcfd;
}

.studio-panel summary {
    cursor: pointer;
    list-style: none;
    padding: 10px 12px;
    font-weight: 600;
}
.studio-panel summary::-webkit-details-marker { display: none; }
.studio-panel[open] summary {
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.studio-panel form,
.studio-panel .lesson-list {
    padding: 10px 12px 12px;
    display: grid;
    gap: 10px;
}

/* ---- Upload Progress Bar ---- */
.upload-progress-wrap { margin: 12px 0 4px; }

.upload-progress-bar-track {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 6px;
}

.upload-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #3b82f6, #6366f1);
    border-radius: 999px;
    transition: width 0.3s ease;
}

.upload-progress-label {
    display: block;
    font-size: 0.82rem;
    color: var(--muted);
    font-weight: 600;
    text-align: center;
    letter-spacing: 0.03em;
}

.upload-status-note {
    margin: 10px 0 0;
    padding: 10px 12px;
    border-radius: 10px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 0.9rem;
    font-weight: 600;
}

.lesson-status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.lesson-state-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}

.lesson-state-ready {
    background: #dcfce7;
    color: #166534;
}

.lesson-state-processing {
    background: #fef3c7;
    color: #92400e;
}

.lesson-processing-note {
    color: #92400e;
    font-size: 0.88rem;
    font-weight: 600;
}

/* ---- Lesson Editor List ---- */
.lesson-list { list-style: none; margin: 0; padding: 0; }

.lesson-item {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 8px;
    background: #fff;
}

.lesson-item-compact { display: block; }

.lesson-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.lesson-desc { margin: 6px 0 10px; }

.lesson-edit {
    border-top: 1px dashed var(--border);
    padding-top: 8px;
}

.lesson-edit summary {
    cursor: pointer;
    font-size: 13px;
    color: var(--brand-dark);
    margin-bottom: 8px;
}

.lesson-edit form {
    display: grid;
    gap: 10px;
}

.row-no {
    min-width: 26px;
    height: 26px;
    border-radius: 999px;
    background: #dbeafe;
    color: #1d4ed8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

/* ---- Reference Lists ---- */
.reference-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.reference-item {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

.reference-link { display: grid; gap: 3px; padding: 10px; }
.reference-title { font-weight: 700; font-size: 13px; }

.reference-manage-row {
    display: flex;
    gap: 8px;
    padding: 6px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}
.reference-manage-row .reference-link { flex: 1; padding: 8px; }

/* ---- Watch Page Layout ---- */
.watch-page { max-width: 1320px; }

.watch-header { margin-bottom: 14px; }
.watch-header h1 { margin: 0; font-size: 2rem; letter-spacing: -0.02em; }
.watch-header p  { margin: 6px 0 0; color: var(--muted); }

.watch-main-col { display: grid; gap: 14px; }
.watch-side-col { display: grid; gap: 14px; }

.watch-page .card:not(.player-card) { padding: 14px 16px; }

.watch-panel-card { background: #fff; }

.watch-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}
.watch-panel-head h2 { margin: 0; font-size: 1.05rem; }

/* ---- Lesson Watch List ---- */
.watch-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
    max-height: 66vh;
    overflow: auto;
}

.watch-item { border: none; border-radius: 10px; background: transparent; }
.watch-item.is-active .watch-item-btn { background: rgba(0, 0, 0, 0.06); }

.watch-item-btn-wrap { display: flex; align-items: center; gap: 6px; }

.watch-item-btn {
    flex: 1;
    border: 0;
    background: transparent;
    color: #0f172a;
    text-align: left;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
}
.watch-item-btn:hover { background: rgba(0, 0, 0, 0.04); }

.watch-item-index {
    width: 20px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--muted);
    margin-right: 12px;
    flex-shrink: 0;
}

.watch-item-thumbnail {
    width: 120px;
    height: 68px;
    border-radius: 8px;
    background: #e2e8f0;
    position: relative;
    overflow: hidden;
    margin-right: 12px;
    flex-shrink: 0;
}
.watch-item-thumbnail img { width: 100%; height: 100%; object-fit: cover; }

.watch-item-content {
    flex-grow: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.watch-item-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: #111;
    margin: 0 0 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.watch-item-desc {
    font-size: 0.8rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.watch-player-card { padding: 14px; }

/* ---- Video Player ---- */
.player-card { background: linear-gradient(180deg, #ffffff, #f8fafc); }

.player-empty {
    border: 1px dashed #bfdbfe;
    background: #eff6ff;
    color: #1e40af;
    border-radius: 10px;
    padding: 12px;
}

.player-panel { display: grid; gap: 10px; }

.player-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.player-title { margin: 0; font-size: 1.1rem; }

.player-stage {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.custom-video {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: #000;
}

.player-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
    padding: 0 12px 6px;
    transition: opacity 0.2s ease;
}
.player-controls.is-chrome-hidden { opacity: 0; pointer-events: none; }

.player-controls .btn-ghost {
    background: transparent;
    border: none;
    min-width: unset;
    padding: 6px;
    color: #fff;
    cursor: pointer;
    transition: opacity 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.player-controls .btn-ghost:hover { background: transparent; opacity: 0.8; }

.player-controls input[type="range"] {
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.3);
    border: none;
    padding: 0;
    border-radius: 0;
    cursor: pointer;
}
.player-controls input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    background: var(--danger);
    border-radius: 50%;
}

.player-controls [data-player-progress] {
    width: 100%;
    margin: 0;
    margin-bottom: 8px;
    height: 4px;
    transition: transform 0.1s ease;
}
.player-controls [data-player-progress]:hover { transform: scaleY(1.5); }
.player-controls [data-player-progress]::-webkit-slider-thumb { width: 12px; height: 12px; }

.player-controls [data-player-prev]       { order: 1; }
.player-controls [data-player-toggle]     { order: 2; margin: 0 2px; }
.player-controls [data-player-next]       { order: 3; margin-right: 8px; }
.player-controls [data-player-mute]       { order: 4; }
.player-controls [data-player-volume]     { order: 5; width: 64px; height: 4px; margin: 0 12px 0 4px; border-radius: 2px; }
.player-controls [data-player-volume]::-webkit-slider-thumb { width: 10px; height: 10px; background: #fff; }
.player-time                               { order: 6; color: #e5e7eb; font-size: 12px; white-space: nowrap; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.player-controls [data-player-fullscreen] { order: 7; margin-left: auto; }

.player-center-toggle {
    position: absolute;
    z-index: 3;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: 0;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.2px;
}
.player-center-toggle:hover { background: rgba(0, 0, 0, 0.78); }

.player-lesson-meta {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    background: #fff;
}

.player-lesson-desc { margin: 0; color: #334155; line-height: 1.5; }
.player-lesson-desc.is-collapsed {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.player-desc-toggle {
    margin-top: 8px;
    background: transparent;
    color: var(--brand-dark);
    border: 0;
    padding: 0;
    font-size: 13px;
    font-weight: 700;
    width: auto;
}
.player-desc-toggle:hover { background: transparent; color: var(--brand); }

.player-stage:fullscreen {
    aspect-ratio: auto;
    border-radius: 0;
    border: none;
    height: 100%;
}

/* ---- Responsive overrides for custom components only ---- */
/* (Bootstrap handles grid/nav/column breakpoints)          */

@media (max-width: 767px) {
    .hero h1 { font-size: 1.5rem; }

    .watch-list { max-height: 40vh; }
    .watch-item-thumbnail { width: 88px; height: 50px; margin-right: 8px; }

    .player-controls { padding: 0 8px 4px; }
    .player-controls [data-player-volume] { display: none; }
    .player-center-toggle { width: 52px; height: 52px; }

    .search-pill {
        flex-direction: column;
        border-radius: 16px;
        padding: 8px;
        align-items: stretch;
        gap: 0;
    }
    .search-pill input {
        border-bottom: 1px solid var(--border);
        padding: 12px;
        text-align: center;
    }
    .search-pill select {
        border-left: none;
        border-bottom: 1px solid var(--border);
        padding: 12px;
        text-align: center;
        text-align-last: center;
        width: 100%;
    }
    .search-pill button {
        margin-left: 0 !important;
        border-radius: 10px !important;
        width: 100%;
        padding: 12px !important;
        margin-top: 6px;
    }

    .studio-actions { flex-direction: row; flex-wrap: wrap; }
    .watch-header h1 { font-size: 1.4rem; }
}

@media (max-width: 399px) {
    .watch-item-thumbnail { display: none; }
}

/* ---- Admin Dashboard Ext ---- */
.admin-sidebar {
    position: sticky;
    top: 74px;
    height: max-content;
    padding: 1.5rem 1rem;
    background: #ffffff;
    border-radius: 14px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.admin-nav .nav-link {
    color: #475569;
    font-weight: 600;
    padding: 10px 16px;
    border-radius: 10px;
    margin-bottom: 6px;
    transition: all 0.2s ease;
    text-align: left;
}

.admin-nav .nav-link:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.admin-nav .nav-link.active {
    background: var(--brand);
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

.metric-card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.25rem;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.metric-card h3 {
    margin: 0;
    font-size: 2.2rem;
    color: var(--brand);
    font-weight: 800;
}
.metric-card p {
    margin: 6px 0 0;
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}
