:root {
    --primary:   #1a3c5e;
    --accent:    #c8a84b;
    --bg:        #f4f6f9;
    --surface:   #ffffff;
    --text:      #1e2d3d;
    --muted:     #6b7a8d;
    --border:    #dde2ea;
    --danger:    #c0392b;
    --success:   #27ae60;
    --radius:    8px;
    --shadow:    0 2px 12px rgba(0,0,0,.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
h1, h2, h3, h4, h5, h6 { font-size: inherit; font-weight: inherit; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
}

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

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 22px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .18s, transform .12s;
}
.btn:hover { opacity: .88; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-accent   { background: var(--accent);  color: #fff; }
.btn-outline  { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-full     { width: 100%; justify-content: center; }

/* ── Form elements ── */
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    background: var(--surface);
    color: var(--text);
    transition: border-color .18s, box-shadow .18s;
    outline: none;
}
.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,60,94,.12);
}

/* ── Alerts ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 18px;
}
.alert-danger  { background: #fdecea; color: var(--danger); border-left: 4px solid var(--danger); }
.alert-success { background: #eaf7ef; color: var(--success); border-left: 4px solid var(--success); }

/* ── Card ── */
.card {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 28px;
}

/* ── Login page ── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, #0f2540 100%);
    padding: 20px;
}

.login-box {
    width: 100%;
    max-width: 420px;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}
.login-logo-img {
    width: 220px;
    height: auto;
    display: block;
    margin: 0 auto 12px;
    background: #fff;
    border-radius: 10px;
    padding: 12px 16px;
}
.login-logo p {
    color: rgba(255,255,255,.65);
    font-size: 13px;
    margin-top: 4px;
}

.login-card {
    background: var(--surface);
    border-radius: 14px;
    padding: 36px 32px;
    box-shadow: 0 8px 40px rgba(0,0,0,.22);
}

.login-card h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text);
}
.login-card .subtitle {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 28px;
}

/* ── Responsive login ── */
@media (max-width: 480px) {
    .login-card { padding: 28px 20px; }
}

/* ════════════════════════════════════════
   APP LAYOUT
════════════════════════════════════════ */
.app-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: 240px;
    height: 100vh;
    background: var(--primary);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    overflow-y: auto;
    z-index: 200;
    transition: transform .25s ease;
}

.sidebar-logo {
    background: #fff;
    padding: 14px 16px 10px;
    border-bottom: 1px solid rgba(255,255,255,.1);
    text-align: center;
}
.sidebar-logo a { display: block; line-height: 0; }
.sidebar-logo-img {
    width: 100%;
    max-width: 160px;
    height: auto;
    display: inline-block;
}
.sidebar-logo-sub {
    color: var(--accent);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    margin-top: 4px;
}

/* ── Nav ── */
.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}
.nav-section-label {
    color: rgba(255,255,255,.4);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 8px 10px 4px;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: rgba(255,255,255,.75);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 2px;
    transition: background .15s, color .15s;
    text-decoration: none;
}
.nav-link svg {
    width: 18px; height: 18px;
    flex-shrink: 0;
    opacity: .75;
}
.nav-link:hover {
    background: rgba(255,255,255,.1);
    color: #fff;
    text-decoration: none;
}
.nav-link:hover svg { opacity: 1; }
.nav-link.active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}
.nav-link.active svg { opacity: 1; }

/* ── Sidebar user ── */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 16px;
    border-top: 1px solid rgba(255,255,255,.1);
}
.sidebar-user-avatar {
    width: 34px; height: 34px;
    background: var(--accent);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    color: rgba(255,255,255,.5);
    font-size: 11px;
}
.sidebar-logout {
    color: rgba(255,255,255,.5);
    transition: color .15s;
    flex-shrink: 0;
    line-height: 0;
}
.sidebar-logout:hover { color: #fff; text-decoration: none; }

/* ── Main wrap ── */
.main-wrap {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ── Topbar ── */
.topbar {
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.topbar-burger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    padding: 4px;
    line-height: 0;
}
.topbar-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
}

/* ── Main content ── */
.main-content {
    padding: 28px 28px;
    flex: 1;
}

/* ── Page header ── */
.page-header {
    margin-bottom: 24px;
}
.page-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}
.page-header p {
    color: var(--muted);
    font-size: 14px;
    margin-top: 4px;
}

/* ── Overlay ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 199;
}
.sidebar-overlay.show { display: block; }

/* ── Mobile ── */
@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
    }
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100vh;
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .topbar-burger {
        display: block;
    }
    .main-content {
        padding: 20px 16px;
    }
}

/* ════════════════════════════════════════
   BADGES
════════════════════════════════════════ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.badge-admin    { background: #e8f0fe; color: #1a3c5e; }
.badge-user     { background: #f0f4f8; color: var(--muted); }
.badge-active   { background: #eaf7ef; color: var(--success); }
.badge-inactive { background: #fdecea; color: var(--danger); }

/* ════════════════════════════════════════
   ADMIN USERS PAGE
════════════════════════════════════════ */
.admin-users-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 24px;
    align-items: start;
}

.users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.users-table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 2px solid var(--border);
}
.users-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.users-table tbody tr:last-child td { border-bottom: none; }
.users-table tbody tr:hover { background: #f8fafc; }
.row-inactive td { opacity: .55; }

.user-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}
.user-avatar-sm {
    width: 32px; height: 32px;
    background: var(--primary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}
.text-muted { color: var(--muted); font-size: 13px; }

.row-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}
.btn-icon {
    width: 32px; height: 32px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    transition: border-color .15s, color .15s;
    text-decoration: none;
}
.btn-icon:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn-icon-danger:hover { border-color: var(--danger); color: var(--danger); }

@media (max-width: 900px) {
    .admin-users-layout {
        grid-template-columns: 1fr;
    }
}

/* ════════════════════════════════════════
   LESSONS LIST
════════════════════════════════════════ */
.progress-bar-wrap {
    width: 160px;
    height: 8px;
    background: var(--border);
    border-radius: 99px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 99px;
    transition: width .4s ease;
}

.lessons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
}
.lesson-card {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 20px;
    text-decoration: none;
    color: var(--text);
    border: 2px solid transparent;
    transition: border-color .18s, box-shadow .18s, transform .14s;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.lesson-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 20px rgba(0,0,0,.12);
    transform: translateY(-2px);
    text-decoration: none;
    color: var(--text);
}
.lesson-card.lesson-done  { border-color: var(--success); }
.lesson-card.lesson-locked { opacity: .55; cursor: default; }
.lesson-card.lesson-locked:hover { transform: none; border-color: transparent; box-shadow: var(--shadow); }

.lesson-day   { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.lesson-title { font-size: 14px; font-weight: 600; line-height: 1.4; flex: 1; }

.status-done   { font-size: 12px; color: var(--success); font-weight: 600; }
.status-open   { font-size: 12px; color: var(--primary); font-weight: 600; }
.status-locked { font-size: 12px; color: var(--muted); }

/* ════════════════════════════════════════
   LESSON DETAIL PAGE
════════════════════════════════════════ */
.lesson-header { margin-bottom: 20px; }
.lesson-header-day   { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 6px; }
.lesson-header-title { font-size: 24px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.lesson-header-desc  { color: var(--muted); font-size: 15px; }
.lesson-done-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 14px;
    background: #eaf7ef;
    color: var(--success);
    font-weight: 600;
    font-size: 13px;
    padding: 6px 14px;
    border-radius: 99px;
}

.lesson-goals-card,
.lesson-section-card,
.lesson-homework-card { margin-bottom: 20px; }

.section-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 14px;
}
.section-number {
    width: 24px; height: 24px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.goals-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.goals-list li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 15px;
}
.goals-list li::before {
    content: '';
    width: 8px; height: 8px;
    background: var(--accent);
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 7px;
}

.lesson-content {
    font-size: 15px;
    line-height: 1.75;
    color: var(--text);
}
.lesson-content p  { margin-bottom: 12px; }
.lesson-content ul,
.lesson-content ol { padding-left: 22px; margin-bottom: 12px; }
.lesson-content li { margin-bottom: 6px; }
.lesson-content strong { font-weight: 700; }
.lesson-content h3 { font-size: 17px; font-weight: 700; margin: 18px 0 8px; color: var(--primary); }
.lesson-content h4 { font-size: 15px; font-weight: 700; margin: 14px 0 6px; }
.lesson-content img { max-width: 100%; height: auto; border-radius: var(--radius); margin: 12px 0; display: block; }
.lesson-content blockquote {
    border-left: 4px solid var(--accent);
    padding: 10px 16px;
    margin: 16px 0;
    background: #fdf9f0;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-style: italic;
    color: var(--muted);
}

.lesson-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}
.lesson-nav { flex: 1; }

/* ════════════════════════════════════════
   ADMIN LESSON EDIT
════════════════════════════════════════ */
.lesson-edit-layout {
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 24px;
    align-items: start;
}

.section-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.section-row:last-child { border-bottom: none; }

/* Toggle switch */
.toggle-wrap {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}
.toggle-wrap input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 99px;
    cursor: pointer;
    transition: background .2s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px; height: 18px;
    left: 3px; top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform .2s;
}
.toggle-wrap input:checked + .toggle-slider { background: var(--success); }
.toggle-wrap input:checked + .toggle-slider::before { transform: translateX(18px); }

@media (max-width: 900px) {
    .lesson-edit-layout { grid-template-columns: 1fr; }
    .lesson-footer { flex-wrap: wrap; }
}

/* ════════════════════════════════════════
   VIDEO GRID
════════════════════════════════════════ */
.video-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
}
@media (max-width: 900px) {
    .video-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .video-grid { grid-template-columns: 1fr; }
}
.video-card {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
    text-decoration: none;
    color: var(--text);
    border: 2px solid transparent;
    transition: border-color .18s, box-shadow .18s, transform .14s;
    display: flex;
    flex-direction: column;
}
.video-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 20px rgba(0,0,0,.12);
    transform: translateY(-2px);
    text-decoration: none;
    color: var(--text);
}
.video-card.video-watched { border-color: var(--success); }

.video-thumb {
    position: relative;
    overflow: hidden;
    background: #000;
}
.video-thumb img {
    width: 100%;
    display: block;
    aspect-ratio: 16/9;
    object-fit: cover;
    transition: opacity .2s;
}
.video-card:hover .video-thumb img { opacity: .85; }

.video-play-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,.9);
    opacity: 0;
    transition: opacity .2s;
    background: rgba(0,0,0,.25);
}
.video-card:hover .video-play-icon { opacity: 1; }

.video-duration {
    position: absolute;
    bottom: 8px; right: 8px;
    background: rgba(0,0,0,.75);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
}
.video-watched-badge {
    position: absolute;
    top: 8px; left: 8px;
    background: var(--success);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 99px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.video-info {
    padding: 14px 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.video-title { font-size: 14px; font-weight: 600; line-height: 1.4; }
.video-meta  { font-size: 12px; color: var(--accent); font-weight: 600; }
.video-desc  { font-size: 12px; color: var(--muted); line-height: 1.4; margin-top: 2px; }

/* ── Contenteditable section editor ── */
[contenteditable]:focus { outline: none; }
[contenteditable] table { border-collapse: collapse; width: 100%; margin: 12px 0; }
[contenteditable] table td, [contenteditable] table th { border: 1px solid var(--border); padding: 8px 12px; }
[contenteditable] table th { background: var(--primary); color: #fff; }

/* ── Quill editor ── */
.ql-toolbar.ql-snow {
    border: 1.5px solid var(--border);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    background: #f8fafc;
}
.ql-container.ql-snow {
    border: 1.5px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 15px;
}
.ql-editor { min-height: 120px; line-height: 1.7; }
.ql-editor p { margin-bottom: 8px; }
.ql-editor .callout { padding: 12px 16px; border-radius: 6px; margin: 12px 0; }
.ql-editor .callout-tip     { background: #eaf7ef; border-left: 4px solid #27ae60; }
.ql-editor .callout-warning { background: #fff8e1; border-left: 4px solid #f59e0b; }
.ql-editor .callout-info    { background: #e8f0fe; border-left: 4px solid #1a3c5e; }

/* ════════════════════════════════════════
   CALLOUT BOXES (lesson content)
════════════════════════════════════════ */
.callout {
    padding: 14px 18px;
    border-radius: var(--radius);
    margin: 16px 0;
    font-size: 14.5px;
    line-height: 1.65;
}
.callout p { margin-bottom: 6px; }
.callout p:last-child { margin-bottom: 0; }
.callout ul, .callout ol { padding-left: 20px; margin-bottom: 6px; }
.callout strong { font-weight: 700; }

.callout-tip {
    background: #eaf7ef;
    border-left: 4px solid var(--success);
    color: #1a5c35;
}
.callout-warning {
    background: #fff8e1;
    border-left: 4px solid #f59e0b;
    color: #7c5200;
}
.callout-info {
    background: #e8f0fe;
    border-left: 4px solid var(--primary);
    color: var(--primary);
}

/* ════════════════════════════════════════
   LESSON TABLE
════════════════════════════════════════ */
.table-scroll-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 16px 0;
    border-radius: var(--radius);
    box-shadow: 0 1px 6px rgba(0,0,0,.07);
}
.lesson-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    font-size: 14px;
    border-radius: var(--radius);
    overflow: hidden;
}
.lesson-table th {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    text-align: left;
    padding: 10px 14px;
    font-size: 13px;
}
.lesson-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.lesson-table tbody tr:last-child td { border-bottom: none; }
.lesson-table tbody tr:nth-child(even) { background: #f8fafc; }
