/* Quest Teacher v2 — chapters page (index.html). Tokens & components live in ui.css. */

#loginScreen.hidden { display: none !important; }

/* ---------- page ---------- */
#chaptersView { max-width: 1120px; margin: 0 auto; }
body.results-open #chaptersView { display: none; }
.page-head { margin: 0 0 18px; }
#hello { font-size: 22px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- "now" — the chapter running today (or the next one) ---------- */
.now {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 16px;
  padding: 14px 16px; margin-bottom: 16px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line);
}
.now-body { min-width: 0; }
.now-eyebrow { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 500; color: var(--text-2); }
.now-label { font-weight: 600; color: var(--green); }
.now-next .now-label { color: var(--blue); }
.now-note { font-weight: 400; color: var(--muted); }
.now-note::before { content: "·"; margin-right: 7px; color: var(--faint); }
.now-title { font-size: 17px; line-height: 1.3; margin: 2px 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.now-meta .sep { color: var(--faint); }
.now-meta .warn { color: var(--amber); }
.now-bar { margin-top: 10px; height: 3px; max-width: 320px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.now-bar i { display: block; height: 100%; background: var(--ink); }
.now-actions { display: flex; gap: 6px; }

/* ---------- chapter list ---------- */
.list-card { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); overflow: hidden; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 8px 8px 10px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.list-head .seg .cnt { font-size: 11px; color: var(--muted); }
.list-head .seg button.active .cnt { color: var(--text-2); }
.list-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.bulk-mode .list-head .seg { visibility: hidden; }
.bulkBar { display: flex; align-items: center; gap: 6px; padding: 8px 12px 8px 18px; border-bottom: 1px solid var(--line-2); background: var(--surface-2); }
.bulkCount { font-size: 12px; color: var(--text-2); margin-right: auto; }

.table-wrapper { overflow-x: auto; }

/* ---------- chapter rows ---------- */
.chapters-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.chapters-table td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; background: var(--surface); transition: background .12s ease; }
.chapters-table tr:last-child td { border-bottom: 0; }
.chapters-table tr[data-chapter-id] { cursor: pointer; }
.chapters-table tr[data-chapter-id]:hover td { background: var(--row-hover); }
.chapters-table tr[data-chapter-id]:focus-visible { outline: none; }
.chapters-table tr[data-chapter-id]:focus-visible td { background: var(--row-sel); }
.chapters-table tr.chapter-row-reordering td { background: var(--row-sel); }

.c-icon { width: 58px; padding-left: 14px !important; }
.c-icon > * { vertical-align: middle; }
.c-name { min-width: 0; }
.c-dates { width: 1%; white-space: nowrap; }
.c-status { width: 1%; white-space: nowrap; padding-right: 6px !important; }
.c-actions { width: 1%; white-space: nowrap; padding-right: 14px !important; text-align: right; }
.row-more { opacity: .55; }
tr[data-chapter-id]:hover .row-more, .row-more[aria-expanded="true"], .row-more:focus-visible { opacity: 1; }
.row-go { display: inline-flex; width: 22px; justify-content: center; color: var(--faint); vertical-align: middle; transition: transform .15s ease, color .15s ease; }
.row-go .ic { width: 16px; height: 16px; }
tr[data-chapter-id]:hover .row-go { color: var(--ink); transform: translateX(2px); }
.bulk-mode .row-go, .bulk-mode .row-more { visibility: hidden; }

.meta-link { display: inline-flex; align-items: center; gap: 4px; font: inherit; color: inherit; border-radius: 6px; padding: 0 3px; margin: 0 -3px; }
.meta-link:hover { color: var(--ink); background: var(--surface-3); }

.chapter-name { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cellText {
  font-size: 13.5px; font-weight: 500; color: var(--ink); line-height: 1.35;
  max-width: 100%; width: fit-content; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-radius: 6px; outline: none;
}

.cellText.is-editing { white-space: normal; background: var(--surface) !important; box-shadow: 0 0 0 1px var(--focus-line), 0 0 0 5px var(--focus) !important; padding: 0 4px; margin: 0 -4px; }
.chapter-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.chapter-meta .sep { color: var(--faint); }
.chapter-meta .warn { color: var(--amber); }

.dates-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 8px; margin: 0 -8px;
  border-radius: 5px; font-size: 12.5px; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.dates-btn .ic { width: 14px; height: 14px; color: var(--faint); }
button.dates-btn:hover { background: var(--surface-3); color: var(--ink); }
button.dates-btn:hover .ic { color: var(--text-2); }
span.dates-btn { cursor: default; }

.date-edit { display: inline-flex; align-items: center; gap: 6px; }
.date-edit input {
  height: 28px; width: 130px; padding: 0 7px; border: 1px solid var(--line); border-radius: 5px; outline: none;
  font-size: 12.5px; background: var(--surface);
}
.date-edit input:focus { border-color: var(--focus-line); box-shadow: 0 0 0 3px var(--focus); }
.date-edit .dash { color: var(--faint); }

.emptyStateRow td { border: 0 !important; background: transparent !important; }
.emptyStateRow .empty { padding: 64px 20px; }

/* bulk mode */
.bulkSelectWrap { display: none; align-items: center; justify-content: center; width: 26px; margin-right: 8px; }
.bulk-mode .bulkSelectWrap { display: inline-flex; }
.bulkSelectCheckbox { width: 18px; height: 18px; }
.bulk-mode tr[data-chapter-id] { cursor: pointer; }
.bulk-mode tr.bulk-selected td, .bulk-mode tr.bulk-selected:hover td { background: var(--row-sel); }

/* ---------- chapter details drawer ---------- */
.drawer-back { position: fixed; inset: 0; z-index: 140; background: rgba(15, 20, 30, .12); animation: qtFade .16s ease; }
.drawer {
  position: fixed; top: 8px; right: 8px; bottom: 8px; z-index: 150; width: min(360px, calc(100vw - 16px));
  display: flex; flex-direction: column; overflow-y: auto;
  padding: 8px 14px 16px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: 0 16px 48px -16px rgba(16, 24, 40, .3);
  animation: drawerIn .18s ease;
}
@keyframes drawerIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 4px 6px; }
.drawer-title { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.side-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; color: var(--muted); padding: 24px 12px 48px; }
.side-empty p { font-size: 13.5px; color: var(--muted); }
.side-empty small { font-size: 12.5px; color: var(--muted); margin-top: -8px; }
.side-empty small:empty { display: none; }

.side-content { display: flex; flex-direction: column; gap: 14px; }
.side-hero { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 10px 6px 2px; }
.side-hero .qicon { margin-bottom: 10px; }
.side-hero h3 { font-size: 16px; font-weight: 600; letter-spacing: -.015em; color: var(--ink); line-height: 1.3; word-break: break-word; }
.side-hero .side-dates { font-size: 12.5px; color: var(--text-2); }
.side-hero .chip { margin-top: 6px; }
.side-hero .btn { margin-top: 12px; }

.side-section { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.side-section-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 2px 6px; font-size: 13px; font-weight: 600; color: var(--ink); }
.side-section-head .mono { font-size: 12px; color: var(--muted); font-weight: 400; }

.res-list { display: flex; flex-direction: column; gap: 2px; }
.res-empty { padding: 6px 6px 2px; font-size: 13px; color: var(--muted); }
.resRow { display: flex; align-items: center; gap: 10px; padding: 6px 4px 6px 6px; border-radius: 8px; transition: background .12s ease; }
.resRow:hover { background: var(--surface-2); }
.resIcon { width: 28px; height: 28px; flex: 0 0 auto; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; }
.resIcon .ic { width: 17px; height: 17px; }
.resIcon.k-pdf { background: var(--t5-soft); color: var(--t5-ink); }
.resIcon.k-img { background: var(--t4-soft); color: var(--t4-ink); }
.resIcon.k-doc { background: var(--t1-soft); color: var(--t1-ink); }
.resIcon.k-sheet { background: var(--t4-soft); color: var(--t4-ink); }
.resIcon.k-other { background: var(--surface-3); color: var(--text-2); }
.resText { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.resNameBtn { text-align: left; font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.resNameBtn:hover { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }
.resMeta { font-size: 11.5px; color: var(--muted); }
.resTrashBtn { opacity: 0; }
.resRow:hover .resTrashBtn, .resTrashBtn:focus-visible { opacity: 1; }

.dropZone {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 8px 10px;
  border: 1.5px dashed var(--line-strong); border-radius: 8px; color: var(--muted); font-size: 13px; cursor: pointer;
  transition: border-color .14s ease, background .14s ease, color .14s ease;
}
.dropZone u { color: var(--text); text-underline-offset: 2px; }
.dropZone:hover, .dropZone:focus-visible { border-color: var(--focus-line); background: var(--row-sel); color: var(--text-2); outline: none; }
.dropZone.active { border-color: var(--blue); background: var(--sky-soft); color: var(--sky-ink); }
.resStatus { font-size: 12px; color: var(--muted); padding: 0 6px; }
.resStatus:empty { display: none; }
.resStatus.error { color: var(--red); }
.resStatus.ok { color: var(--green); }

/* ---------- copy to class ---------- */
.copy-list { display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow-y: auto; margin: 0 -6px; padding: 2px 6px; }
.copyTarget { display: flex; align-items: center; gap: 12px; height: 46px; padding: 0 12px 0 8px; border-radius: 8px; text-align: left; border: 1px solid transparent; }
.copyTarget:hover { background: var(--surface-2); }
.copyTarget.selected { background: var(--row-sel); border-color: var(--focus-line); }
.copyTargetName { flex: 1; min-width: 0; font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.copyTargetCheck { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--line-strong); display: inline-flex; align-items: center; justify-content: center; color: var(--on-ink); }
.copyTargetCheck .ic { width: 13px; height: 13px; opacity: 0; }
.copyTarget.selected .copyTargetCheck { background: var(--ink); border-color: var(--ink); }
.copyTarget.selected .copyTargetCheck .ic { opacity: 1; }
.copyModalStatus { font-size: 13px; color: var(--text-2); line-height: 1.55; }
.copyModalStatus:empty { display: none; }
.copyModalStatus.ok { color: var(--green); }
.copyModalStatus.error { color: var(--red); }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .c-status { display: none; }
}
@media (max-width: 640px) {
  .now { grid-template-columns: auto minmax(0, 1fr); }
  .now-actions { grid-column: 1 / -1; }
  .now-actions .btn { flex: 1; }
  #addGroup span { display: none; }
  #addGroup { width: 32px; padding: 0; }
  .c-icon { width: 50px; padding-left: 10px !important; }
  .c-dates { display: none; }
  .drawer { top: auto; max-height: 86vh; }
}

/* ---------- v3: fewer boxes ---------- */
.page-head { margin-bottom: 22px; }
#hello { font-size: 24px; font-weight: 500; letter-spacing: -.02em; }
.now { background: var(--surface-2); border: 0; border-radius: 8px; padding: 16px 18px; margin-bottom: 28px; }
.list-card { border: 0; border-radius: 0; overflow: visible; }
.list-head { padding: 0 0 12px; border-bottom: 1px solid var(--line); }
.chapters-table td { padding: 12px 10px; }
.chapters-table tr:last-child td { border-bottom: 1px solid var(--line-2); }
.c-icon { width: 52px; padding-left: 0 !important; }
.c-actions { padding-right: 0 !important; }
.bulkBar { padding: 8px 10px; border-radius: 6px; border-bottom: 0; margin-top: 8px; }

/* fresh */
.now { background: var(--accent-soft); }
.now-label { color: var(--accent-ink); }
.now-next .now-label { color: var(--accent-ink); }
.now-bar { background: rgba(47, 124, 246, .16); }
.now-bar i { background: var(--accent); }
.now .btn-secondary { background: var(--surface); border-color: transparent; }
.chapters-table tr[data-chapter-id]:hover .cellText { color: var(--accent-ink); }

/* ---------- warm & soft ---------- */
#chaptersView { max-width: 1100px; }
.page-head { margin: 8px 0 22px; }
#hello { font-size: 36px; line-height: 1.1; font-weight: 400; }
.page-sub { margin-top: 6px; font-size: 14px; color: var(--muted); }

/* the one gradient: today's chapter */
.now {
  position: relative; overflow: hidden; border: 0; border-radius: 20px;
  padding: 22px 24px; gap: 20px; margin-bottom: 26px;
  background:
    radial-gradient(120% 160% at 100% 0%, #ffe39a 0%, rgba(255, 227, 154, 0) 55%),
    linear-gradient(135deg, #fbf6ea 0%, #fdefc6 100%);
}
.now-art .qicon-fg { border-radius: 14px; box-shadow: 0 6px 16px -8px rgba(90, 60, 10, .35); }
.now-label, .now-next .now-label { color: #8a5a00; font-weight: 600; }
.now-note { color: #9b7d4a; }
.now-note::before { color: #d7bf8f; }
.now-title { font-family: var(--serif); font-weight: 400; font-size: 30px; line-height: 1.15; letter-spacing: -.015em; margin: 4px 0 4px; white-space: normal; }
.now-meta { color: #8a7650; font-size: 13px; }
.now-meta .sep { color: #d7bf8f; }
.now-bar { height: 4px; border-radius: 3px; background: rgba(138, 90, 0, .14); max-width: 360px; margin-top: 14px; }
.now-bar i { background: #1b1916; border-radius: 3px; }
.now .btn-secondary { background: rgba(255, 255, 255, .7); border-color: rgba(255, 255, 255, .9); }
@media (prefers-color-scheme: dark) {
  .now { background: radial-gradient(120% 160% at 100% 0%, rgba(210, 160, 50, .32) 0%, rgba(210, 160, 50, 0) 55%), linear-gradient(135deg, #24211b 0%, #2b2517 100%); }
  .now-label, .now-next .now-label { color: #f0c46a; }
  .now-note, .now-meta { color: #b8a27a; }
  .now-bar { background: rgba(240, 196, 106, .18); }
  .now-bar i { background: #f0c46a; }
  .now .btn-secondary { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .1); }
}

.list-card { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); overflow: hidden; }
.list-head { padding: 12px 12px 12px 16px; border-bottom: 1px solid var(--line-2); }
.chapters-table td { padding: 12px 10px; }
.chapters-table tr:last-child td { border-bottom: 0; }
.c-icon { width: 62px; padding-left: 16px !important; }
.c-actions { padding-right: 14px !important; }
.chapters-table tr[data-chapter-id]:hover .cellText { color: var(--ink); }
.bulkBar { margin: 0; border-radius: 0; border-bottom: 1px solid var(--line-2); }
.drawer { border-radius: 18px; }

/* files button on each row */
.row-files {
  display: inline-flex; align-items: center; gap: 4px; height: 28px; min-width: 28px; padding: 0 7px; margin-right: 2px;
  border-radius: 8px; color: var(--faint); font-size: 12.5px; font-weight: 500; font-variant-numeric: tabular-nums; vertical-align: middle;
  transition: background .12s ease, color .12s ease;
}
.row-files .ic { width: 15px; height: 15px; }
.row-files span:empty { display: none; }
.row-files.has { color: var(--text-2); }
tr[data-chapter-id]:hover .row-files { color: var(--text-2); }
.row-files:hover { background: var(--surface-3); color: var(--ink) !important; }
.bulk-mode .row-files { visibility: hidden; }

/* v1 blue: the "now" card */
.now {
  background:
    radial-gradient(120% 160% at 100% 0%, #cfe4ff 0%, rgba(207, 228, 255, 0) 55%),
    linear-gradient(135deg, #f3f8ff 0%, #e4f0ff 100%);
}
.now-art .qicon-fg { box-shadow: 0 6px 16px -8px rgba(30, 80, 160, .35); }
.now-label, .now-next .now-label { color: var(--accent-ink); }
.now-note, .now-meta { color: #6b7a93; }
.now-note::before, .now-meta .sep { color: #b8c7de; }
.now-bar { background: rgba(75, 157, 255, .18); }
.now-bar i { background: var(--accent); }
@media (prefers-color-scheme: dark) {
  .now { background: radial-gradient(120% 160% at 100% 0%, rgba(75, 157, 255, .28) 0%, rgba(75, 157, 255, 0) 55%), linear-gradient(135deg, #162034 0%, #172642 100%); }
  .now-label, .now-next .now-label { color: #8ec2ff; }
  .now-note, .now-meta { color: #9aa9c2; }
  .now-bar { background: rgba(142, 194, 255, .18); }
  .now-bar i { background: #8ec2ff; }
}


/* current chapter: flat, no gradient */
.now { background: var(--surface); border: 1px solid var(--line); box-shadow: none; padding: 18px 20px; }
.now-art .qicon-fg { box-shadow: none; }
.now-title { font-family: var(--font); font-weight: 600; font-size: 20px; letter-spacing: -.02em; }
#hello { font-family: var(--font); font-weight: 600; font-size: 28px; letter-spacing: -.025em; }
.page-head { margin-bottom: 20px; }
@media (prefers-color-scheme: dark) {
  .now { background: var(--surface); border-color: var(--line); }
}

/* bigger */
#hello { font-size: 31px; }
.page-head { margin-bottom: 24px; }
.now { padding: 20px 24px; gap: 18px; }
.now-eyebrow { font-size: 13px; }
.now-title { font-size: 22px; }
.now-meta { font-size: 14px; }
.list-head { padding: 12px 14px 12px 16px; }
.chapters-table td { padding: 14px 10px; }
.c-icon { width: 70px; }
.cellText { font-size: 15px; }
.chapter-meta { font-size: 13px; }
.dates-btn { font-size: 13.5px; height: 30px; }
.row-files { font-size: 13.5px; height: 32px; }
.row-files .ic { width: 16px; height: 16px; }

/* ====================== new chapter: inline row ====================== */
/* Adding a chapter happens in the table, not in a dialog. The row borrows the
   date editor's vocabulary so it reads as part of the list. */
.nc-row td { background: var(--row-new); padding-top: 18px; padding-bottom: 18px; }
.nc-row .c-icon { vertical-align: middle; }
.nc-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px dashed var(--line-strong); color: var(--faint); background: var(--surface);
}
.nc-icon .ic { width: 16px; height: 16px; }
.nc-input {
  width: 100%; height: 32px; padding: 0 9px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
  font: inherit; font-size: 15px; font-weight: 500; color: var(--ink); outline: none;
}
.nc-input::placeholder { color: var(--faint); font-weight: 400; }
.nc-input:focus { border-color: var(--focus-line); box-shadow: 0 0 0 3px var(--focus); }
.nc-chip { background: var(--green-soft); color: var(--green); }
.nc-row [data-nc="save"] { color: var(--green); }
.nc-row [data-nc="save"]:hover:not(:disabled) { background: var(--green-soft); }
.nc-row.is-saving { opacity: .6; pointer-events: none; }

/* ====================== shift schedule bar ====================== */
/* Moves a chapter and everything after it by N days; sits under the list head
   like the selection bar, and previews the new dates in the table. */
.shiftBar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px 10px 16px; border-bottom: 1px solid var(--line-2); background: var(--surface-2);
}
.shift-step {
  display: inline-flex; align-items: center; gap: 2px; height: 32px; padding: 0 2px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--surface);
}
.shift-step:focus-within { border-color: var(--focus-line); box-shadow: 0 0 0 3px var(--focus); }
.shift-step .iconbtn.sm { width: 26px; height: 26px; }
.shift-days {
  width: 44px; height: 28px; border: 0; background: transparent; outline: none; text-align: right;
  font: inherit; font-size: 14px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums;
  -moz-appearance: textfield; appearance: textfield;
}
.shift-days::-webkit-inner-spin-button, .shift-days::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.shift-unit { min-width: 30px; font-size: 12.5px; color: var(--muted); }
.shift-msg { flex: 1; min-width: 0; font-size: 12.5px; color: var(--muted); }
.shift-msg.is-error { color: var(--red); }
#shiftScheduleBtn.active { background: var(--surface-3); border-color: var(--line-strong); }
.dates-btn.is-shifted, button.dates-btn.is-shifted:hover { background: var(--accent-soft); color: var(--accent-ink); }
.dates-btn.is-shifted .ic { color: var(--accent-ink); }

/* selection mode: the checkbox sits left of the chapter icon, on one line */
.bulk-mode .chapters-table td.c-icon { width: 108px; white-space: nowrap; }
.bulk-mode .bulkSelectWrap { vertical-align: middle; }
.bulk-mode tr[data-chapter-id] .cellText { cursor: pointer; }
