:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #e5e7eb;
    --text: #171d28;
    --muted: #6b7280;
    --muted-2: #9aa2af;
    --brand: #2f5d94;
    --brand-ink: #24476f;
    --brand-soft: #eaf1f9;
    --danger: #b4442f;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 10px 28px rgba(16, 24, 40, .12);
    --header-h: 60px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

.container { width: 100%; max-width: 1140px; margin: 0 auto; padding: 0 20px; }
.page { padding: 28px 0 56px; }

/* ---------- Header ---------- */
.site-header {
    position: sticky; top: 0; z-index: 20;
    height: var(--header-h);
    background: linear-gradient(100deg, #24476f, #2f5d94);
    color: #fff;
    display: flex; align-items: center;
    box-shadow: var(--shadow-sm);
}
.site-header .container { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.logout-form { display: inline-flex; align-items: center; gap: 10px; margin: 0; }
.logout-form .user { color: rgba(255,255,255,.9); font-size: 14px; }
.logout-btn {
    background: rgba(255,255,255,.16); color: #fff; border: 1px solid rgba(255,255,255,.25);
    font-size: 13px; font-family: inherit; padding: 6px 12px; border-radius: 8px; cursor: pointer;
    transition: background .15s;
}
.logout-btn:hover { background: rgba(255,255,255,.28); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 17px; letter-spacing: .3px; }
.brand:hover { text-decoration: none; opacity: .95; }
.brand .logo {
    width: 30px; height: 30px; border-radius: 8px;
    background: rgba(255,255,255,.16);
    display: inline-flex; align-items: center; justify-content: center;
}
.brand .logo svg { width: 17px; height: 17px; }

/* ---------- Icons ---------- */
.ic { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.12em; }

/* ---------- Page head ---------- */
.page-head { margin-bottom: 22px; }
.page-head h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: .3px; }
.page-head .sub { color: var(--muted); font-size: 14px; }

.breadcrumb {
    display: inline-flex; align-items: center; gap: 6px;
    color: var(--muted); font-size: 14px; margin-bottom: 14px;
}
.breadcrumb a { color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.breadcrumb a:hover { color: var(--brand); text-decoration: none; }

/* ---------- List toolbar（搜尋列） ---------- */
.list-toolbar {
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    margin-bottom: 18px;
}
.search-box { position: relative; flex: 1 1 240px; min-width: 200px; max-width: 420px; }
.search-box > .ic {
    position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
    width: 17px; height: 17px; color: var(--muted-2); pointer-events: none;
}
.list-search {
    width: 100%; font-family: inherit; font-size: 14px;
    padding: 10px 14px 10px 38px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); color: var(--text);
    box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.list-search::placeholder { color: var(--muted-2); }
.list-search:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.list-count { color: var(--muted); font-size: 13px; white-space: nowrap; margin-left: auto; }
.search-empty { padding: 40px 20px; }

/* ---------- Pager（分頁） ---------- */
.pager { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 26px; }
.pager-btn {
    min-width: 36px; height: 36px; padding: 0 10px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
    color: var(--text); font-size: 14px; font-family: inherit; font-weight: 600;
    cursor: pointer; transition: background .15s, border-color .15s, color .15s;
}
.pager-btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.pager-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; cursor: default; }
.pager-btn.active:hover { background: var(--brand); color: #fff; }
.pager-btn:disabled { cursor: default; }
.pager-btn:disabled:not(.active) { color: var(--muted-2); background: var(--surface); }
.pager-btn.ellipsis { border-color: transparent; background: transparent; color: var(--muted-2); }

/* ---------- Course grid ---------- */
.course-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.course-card {
    display: flex; flex-direction: row; align-items: center; gap: 14px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px 18px;
    color: inherit; box-shadow: var(--shadow-sm);
    transition: box-shadow .18s ease, transform .18s ease, border-color .18s ease;
}
.course-card:hover { text-decoration: none; box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--brand); }
.course-ic {
    flex: none; width: 46px; height: 46px; border-radius: 11px;
    background: var(--brand-soft); color: var(--brand-ink);
    display: flex; align-items: center; justify-content: center;
}
.course-ic svg { width: 24px; height: 24px; }

.card-body { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; min-width: 0; flex: 1; }
.card-title { font-weight: 700; font-size: 16px; line-height: 1.4;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-metas { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
    display: inline-flex; align-items: center; gap: 5px;
    background: var(--brand-soft); color: var(--brand-ink);
    font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
}
.pill-muted { background: var(--surface-2); color: var(--muted); }

/* 資料夾卡片圖示（與影片課程以暖色調區分） */
.course-ic.folder-ic { background: #fbf0d9; color: #9a6a12; }

/* 整個資料夾分享按鈕列 */
.folder-share { margin: 0 0 18px; }

/* ---------- Lessons page ---------- */
.course-hero {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 22px 24px; margin-bottom: 22px;
    box-shadow: var(--shadow-sm);
}
.course-hero h1 { margin: 0 0 10px; font-size: 24px; }
.hero-metas { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface-2); color: var(--text);
    font-size: 13px; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border);
}
.chip svg { color: var(--muted); }
.course-hero .desc { color: #3d4757; white-space: pre-wrap; margin: 0; font-size: 15px; }

.section-title { font-size: 15px; font-weight: 700; color: var(--muted); margin: 0 0 12px; text-transform: none; }

.lesson-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.lesson-row {
    display: flex; align-items: center; gap: 12px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 11px 14px;
    box-shadow: var(--shadow-sm);
    transition: border-color .15s, box-shadow .15s;
}
.lesson-row:hover { border-color: var(--brand); box-shadow: var(--shadow-md); }
.lesson-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; color: inherit; }
.lesson-link:hover { text-decoration: none; }
.lesson-idx {
    flex: none; width: 34px; height: 34px; border-radius: 50%;
    background: var(--brand-soft); color: var(--brand-ink);
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
}
.lesson-main { flex: 1; min-width: 0; }
.lesson-title { font-weight: 600; font-size: 15px; }
.lesson-date { color: var(--muted); font-size: 13px; margin-top: 2px; display: inline-flex; align-items: center; gap: 5px; }

/* 複製連結按鈕 */
.copy-btn {
    flex: none; display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
    font-size: 13px; font-weight: 600; font-family: inherit;
    padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
    transition: background .15s, color .15s, border-color .15s;
}
.copy-btn:hover { background: var(--brand-soft); color: var(--brand-ink); border-color: var(--brand); }
.copy-btn svg { width: 15px; height: 15px; }
.copy-btn.copied { background: #e7f5ec; color: #1c7c43; border-color: #9dd7b4; }

/* ---------- Watch (play) page ---------- */
.watch { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.stage {
    background: #000; border-radius: var(--radius); overflow: hidden;
    box-shadow: var(--shadow-md); aspect-ratio: 16 / 9;
}
.stage video { width: 100%; height: 100%; display: block; background: #000; }
.watch-head { display: flex; align-items: flex-start; gap: 14px; margin: 16px 0 8px; }
.watch-title { font-size: 21px; margin: 0; flex: 1; min-width: 0; }
.watch-head .copy-btn { margin-top: 2px; }
.watch-metas { display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); font-size: 14px; }
.watch-metas span { display: inline-flex; align-items: center; gap: 6px; }
.note {
    margin-top: 16px; padding: 11px 14px; border-radius: var(--radius-sm);
    background: #fdf3f0; color: var(--danger); font-size: 13px;
    display: inline-flex; align-items: center; gap: 8px;
}

.playlist {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
    position: sticky; top: calc(var(--header-h) + 16px);
}
.playlist-head { padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 14px;
    display: flex; align-items: center; justify-content: space-between; }
.playlist-head .count { color: var(--muted); font-weight: 600; }
.playlist-items { list-style: none; margin: 0; padding: 6px; max-height: 62vh; overflow-y: auto; }
.playlist-items li a {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 11px; border-radius: var(--radius-sm); color: inherit;
}
.playlist-items li a:hover { background: var(--surface-2); text-decoration: none; }
.playlist-items li.active a { background: var(--brand-soft); }
.pl-idx { flex: none; width: 26px; height: 26px; border-radius: 7px; background: var(--surface-2);
    display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--muted); }
.playlist-items li.active .pl-idx { background: var(--brand); color: #fff; }
.pl-main { min-width: 0; }
.pl-title { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.playlist-items li.active .pl-title { color: var(--brand-ink); }
.pl-date { font-size: 12px; color: var(--muted); }
.pl-now { flex: none; margin-left: auto; color: var(--brand); }
.pl-now svg { width: 16px; height: 16px; }

/* ---------- Empty state ---------- */
.empty {
    text-align: center; color: var(--muted); padding: 56px 20px;
    background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty svg { width: 44px; height: 44px; color: var(--muted-2); margin-bottom: 10px; }

/* ---------- Login ---------- */
.login-card {
    max-width: 380px; margin: 40px auto; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 32px 28px; box-shadow: var(--shadow-sm);
}
.login-card h1 { margin: 0 0 4px; }
.login-sub { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.login-error {
    background: #fdf3f0; color: var(--danger); border: 1px solid #f0c9bf;
    padding: 10px 12px; border-radius: 8px; font-size: 14px; margin-bottom: 16px;
}
.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
    width: 100%; font-size: 15px; font-family: inherit; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}
.field input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.btn-primary {
    width: 100%; background: var(--brand); color: #fff; border: none;
    font-size: 15px; font-weight: 600; font-family: inherit; padding: 11px; border-radius: 8px;
    cursor: pointer; transition: background .15s; margin-top: 4px;
}
.btn-primary:hover { background: var(--brand-ink); }

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

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .watch { grid-template-columns: 1fr; }
    .playlist { position: static; }
    .playlist-items { max-height: none; }
}
@media (max-width: 520px) {
    .page-head h1, .course-hero h1 { font-size: 20px; }
    .course-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
}
