:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --text: #111827;
  --muted: #667085;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success-bg: #ecfdf3;
  --success-text: #067647;
  --radius: 18px;
  --shadow: 0 12px 35px rgba(17, 24, 39, .06);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
}
a { color: inherit; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.container { width: min(1120px, calc(100% - 32px)); margin: 0 auto; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(229,231,235,.9);
}
.topbar-inner { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.brand { display: inline-flex; align-items: center; gap: 11px; text-decoration: none; }
.brand-mark { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; color: #fff; background: var(--text); font-size: 20px; font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { color: var(--muted); font-size: 12px; margin-top: -1px; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; }
.inline-form { margin: 0; display: inline-flex; }
.readonly-pill {
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  background: #f2f4f7;
  color: #475467;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.page-shell { min-height: calc(100vh - 150px); padding: 42px 0 64px; }
.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; padding: 24px 0 36px; }

.hero, .course-hero {
  background: linear-gradient(135deg, #111827 0%, #1f2937 100%);
  color: #fff;
  border-radius: 28px;
  padding: 38px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  box-shadow: var(--shadow);
}
.hero h1, .course-hero h1 { font-size: clamp(32px, 5vw, 54px); line-height: 1.03; letter-spacing: -.04em; margin: 8px 0 14px; max-width: 740px; }
.course-hero h1 { font-size: clamp(30px, 4.2vw, 46px); }
.hero p, .course-hero p { color: #d1d5db; margin: 0; max-width: 720px; font-size: 16px; }
.eyebrow { display: inline-block; color: #93c5fd; font-weight: 800; font-size: 11px; letter-spacing: .16em; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.course-hero .button-ghost { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.18); color: #fff; }

.button {
  border: 0;
  border-radius: 11px;
  min-height: 42px;
  padding: 10px 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-decoration: none;
  font-weight: 750;
  font-size: 14px;
  transition: .18s ease;
  white-space: nowrap;
}
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-dark); }
.button-dark { background: #111827; color: #fff; }
.button-ghost { background: #fff; border: 1px solid var(--line); color: #344054; }
.button-danger { background: var(--danger); color: #fff; }
.button-danger-link { background: transparent; color: var(--danger); padding-left: 7px; padding-right: 7px; }
.button-read {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}
.button-read.is-read {
  background: #f8fafc;
  border-color: #d0d5dd;
  color: #475467;
}
.button-small { min-height: 38px; padding: 8px 12px; }
.button.is-disabled,
.button[aria-disabled="true"] {
  opacity: .45;
  pointer-events: none;
  transform: none;
}

.notice { margin: 20px 0; border: 1px solid #d0d5dd; background: #fff; color: #344054; padding: 12px 15px; border-radius: 11px; font-size: 14px; }
.notice.success { background: var(--success-bg); border-color: #abefc6; color: var(--success-text); }
.notice.error { background: #fef3f2; border-color: #fecdca; color: #b42318; }

.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 22px 0 36px; max-width: 440px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: 15px; padding: 17px 19px; display: flex; flex-direction: column; box-shadow: 0 5px 18px rgba(17,24,39,.03); }
.stat-card strong { font-size: 27px; line-height: 1.1; }
.stat-card span { font-size: 13px; color: var(--muted); margin-top: 5px; }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin: 32px 0 16px; }
.section-heading h2 { margin: 0; font-size: 25px; letter-spacing: -.025em; }
.section-heading p { margin: 4px 0 0; color: var(--muted); }
.course-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.course-card {
  position: relative;
  min-height: 215px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 23px;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  box-shadow: 0 5px 20px rgba(17,24,39,.035);
  transition: .18s ease;
  overflow: hidden;
}
.course-card:hover { transform: translateY(-3px); border-color: #c7d2fe; box-shadow: var(--shadow); }
.course-number { color: var(--primary); font-weight: 850; letter-spacing: .06em; font-size: 12px; }
.course-body { padding-right: 34px; }
.course-body h3 { font-size: 21px; margin: 12px 0 8px; letter-spacing: -.025em; }
.course-body p { color: var(--muted); margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.course-meta { margin-top: auto; padding-top: 22px; display: flex; align-items: center; gap: 13px; color: var(--muted); font-size: 12px; }
.course-meta span + span::before { content: '•'; margin-right: 13px; color: #c4c9d4; }
.course-arrow { position: absolute; right: 22px; top: 22px; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: #f2f4f7; font-size: 19px; }

.back-row { margin-bottom: 18px; }
.back-row a { text-decoration: none; color: #475467; font-size: 14px; font-weight: 700; }
.form-card { background: #fff; border: 1px solid var(--line); border-radius: 24px; padding: 30px; box-shadow: var(--shadow); }
.narrow { max-width: 760px; margin: 0 auto; }
.auth-card { max-width: 520px; }
.form-heading { margin-bottom: 26px; }
.form-heading h1 { font-size: 32px; letter-spacing: -.035em; margin: 7px 0 8px; }
.form-heading p { margin: 0; color: var(--muted); }
.stack-form { display: grid; gap: 19px; }
.stack-form label > span { display: block; font-size: 13px; font-weight: 800; margin-bottom: 7px; }
.stack-form label > small { display: block; margin-top: 6px; color: var(--muted); }
input, textarea, select {
  width: 100%;
  border: 1px solid #d0d5dd;
  border-radius: 11px;
  background: #fff;
  color: var(--text);
  padding: 12px 13px;
  outline: none;
  transition: .15s ease;
}
input:focus, textarea:focus { border-color: #84adff; box-shadow: 0 0 0 4px rgba(37,99,235,.09); }
select:focus { border-color: #84adff; box-shadow: 0 0 0 4px rgba(37,99,235,.09); }
textarea { resize: vertical; min-height: 116px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 4px; }

.pagination-bar {
  margin: 18px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 5px 18px rgba(17,24,39,.03);
}
.pagination-bar + .course-grid,
.pagination-bar + .resource-list { margin-top: 16px; }
.pagination-summary {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.pagination-summary strong { color: var(--text); }
.page-size-form label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.page-size-form select {
  width: auto;
  min-width: 86px;
  padding: 8px 10px;
  background: #f8fafc;
}
.pagination-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}
.page-indicator {
  min-width: 52px;
  text-align: center;
  color: #475467;
  font-size: 13px;
  font-weight: 850;
}

.toolbar { display: flex; justify-content: space-between; gap: 15px; align-items: center; margin: 24px 0 15px; }
.search-form { display: flex; align-items: center; gap: 8px; flex: 1; }
.search-form input { max-width: 560px; }
.read-filter-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
}
.read-filter-tab {
  min-height: 34px;
  padding: 7px 9px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #475467;
  text-decoration: none;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}
.read-filter-tab strong {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #f2f4f7;
  color: #667085;
  font-size: 11px;
}
.read-filter-tab.is-active {
  background: #111827;
  color: #fff;
}
.read-filter-tab.is-active strong {
  background: rgba(255,255,255,.16);
  color: #fff;
}
.result-count { color: var(--muted); font-size: 13px; font-weight: 700; white-space: nowrap; }
.resource-list { display: grid; gap: 12px; }
.resource-card {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 15px;
  align-items: start;
  padding: 19px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
}
.resource-index { width: 36px; height: 36px; border-radius: 10px; background: #eff6ff; color: #1d4ed8; display: grid; place-items: center; font-weight: 850; font-size: 13px; }
.resource-main h2 { font-size: 17px; margin: 2px 0 5px; letter-spacing: -.015em; }
.resource-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.read-badge {
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  background: #f2f4f7;
  color: #667085;
  font-size: 11px;
  font-weight: 850;
  white-space: nowrap;
}
.read-badge.is-read {
  background: #dcfce7;
  color: #166534;
}
.resource-main p { margin: 0 0 7px; color: #475467; white-space: pre-line; }
.resource-url { color: #2563eb; font-size: 12px; word-break: break-all; text-decoration: none; }
.resource-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; max-width: 380px; }
.resource-actions form { margin: 0; }

.empty-state { background: #fff; border: 1px dashed #cfd5df; border-radius: 20px; text-align: center; padding: 58px 24px; }
.empty-state.compact { padding: 42px 24px; }
.empty-icon { font-size: 34px; }
.empty-state h1, .empty-state h3 { margin: 10px 0 7px; }
.empty-state p { color: var(--muted); margin: 0 auto 18px; max-width: 560px; }
.danger-zone { margin-top: 38px; padding-top: 24px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.danger-zone p { color: var(--muted); margin: 3px 0 0; font-size: 13px; }
.error-box { text-align: left; background: #111827; color: #f9fafb; padding: 15px; border-radius: 12px; overflow: auto; max-width: 900px; margin: 15px auto; }
.back-to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 50%;
  background: #111827;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 14px 34px rgba(17, 24, 39, .22);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: .18s ease;
}
.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.back-to-top:hover { transform: translateY(-2px); }

@media (max-width: 800px) {
  .page-shell { padding-top: 26px; }
  .hero, .course-hero { padding: 27px; align-items: stretch; flex-direction: column; }
  .hero h1 { font-size: 38px; }
  .course-grid { grid-template-columns: 1fr; }
  .resource-card { grid-template-columns: 38px 1fr; }
  .resource-actions { grid-column: 2; justify-content: flex-start; max-width: none; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .search-form { flex-wrap: wrap; }
  .search-form input { max-width: none; flex-basis: 100%; }
  .read-filter-tabs { width: 100%; overflow-x: auto; }
  .read-filter-tab { flex: 1 0 auto; justify-content: center; }
  .result-count { align-self: flex-start; }
  .pagination-bar { align-items: stretch; flex-direction: column; }
  .pagination-summary, .page-size-form label, .pagination-actions { justify-content: center; }
}

@media (max-width: 520px) {
  .container { width: min(100% - 22px, 1120px); }
  .brand small { display: none; }
  .topbar-inner { min-height: 62px; }
  .brand-mark { width: 34px; height: 34px; }
  .topbar-actions { gap: 6px; }
  .readonly-pill { display: none; }
  .hero, .course-hero, .form-card { border-radius: 18px; padding: 21px; }
  .hero h1 { font-size: 32px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .button { width: 100%; }
  .resource-card { padding: 14px; grid-template-columns: 32px 1fr; gap: 10px; }
  .resource-index { width: 30px; height: 30px; }
  .resource-actions { grid-column: 1 / -1; }
  .resource-actions .button { flex: 1 1 auto; }
  .danger-zone { align-items: stretch; flex-direction: column; }
  .pagination-actions { flex-wrap: wrap; }
  .pagination-actions .button { flex: 1 1 42px; }
  .back-to-top { right: 14px; bottom: 14px; width: 40px; height: 40px; }
}


.toolbar-meta { display: flex; align-items: center; gap: 14px; }
.drag-help { color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
.resource-order-controls { display: flex; align-items: center; gap: 6px; }
.drag-handle {
  width: 22px;
  min-width: 22px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #98a2b3;
  font-weight: 900;
  font-size: 18px;
  line-height: 1;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.drag-handle:hover { background: #f2f4f7; color: #475467; }
.drag-handle:active { cursor: grabbing; }
.resource-card { transition: box-shadow .15s ease, border-color .15s ease, transform .15s ease; }
.resource-card-chosen { border-color: #93c5fd; box-shadow: 0 12px 30px rgba(37, 99, 235, .12); }
.resource-card-ghost { opacity: .35; background: #eff6ff; border: 1px dashed #60a5fa; }
.resource-card-drag { box-shadow: 0 16px 45px rgba(17, 24, 39, .18); }
.sort-status { min-height: 22px; padding-top: 8px; color: var(--muted); font-size: 12px; font-weight: 700; text-align: right; }
.sort-status.saving { color: #475467; }
.sort-status.success { color: var(--success-text); }
.sort-status.error { color: var(--danger); }

@media (max-width: 800px) {
  .toolbar-meta { width: 100%; justify-content: space-between; }
  .resource-card { grid-template-columns: 48px 1fr; }
}

@media (max-width: 520px) {
  .drag-help { font-size: 11px; white-space: normal; }
  .resource-card { grid-template-columns: 43px 1fr; }
  .resource-order-controls { gap: 3px; }
  .drag-handle { width: 18px; min-width: 18px; }
}

/* V1.2 - thao tác sắp xếp dễ hơn */
.resource-card {
  grid-template-columns: 72px minmax(0, 1fr) auto;
}
.resource-order-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}
.drag-handle {
  width: 58px;
  min-width: 58px;
  height: 36px;
  padding: 0 7px;
  border: 1px solid #d0d5dd;
  border-radius: 9px;
  background: #f8fafc;
  color: #475467;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-weight: 850;
  font-size: 15px;
  line-height: 1;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.drag-handle small {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.drag-handle:hover,
.drag-handle:focus-visible {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1d4ed8;
  outline: none;
}
.drag-handle:active { cursor: grabbing; }
.button-move {
  min-height: 38px;
  padding: 8px 11px;
  background: #f8fafc;
  border: 1px solid #d0d5dd;
  color: #344054;
}
.button-move:hover:not(:disabled) {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1d4ed8;
}
.button-move:disabled {
  opacity: .35;
  cursor: not-allowed;
  transform: none;
}
.move-form { margin: 0; }

@media (max-width: 800px) {
  .resource-card { grid-template-columns: 66px 1fr; }
  .resource-actions { grid-column: 2; }
}

@media (max-width: 520px) {
  .resource-card { grid-template-columns: 58px 1fr; }
  .drag-handle { width: 52px; min-width: 52px; height: 34px; padding: 0 5px; }
  .drag-handle small { font-size: 9px; }
  .resource-actions { grid-column: 1 / -1; }
  .button-move { flex: 1 1 80px; }
}
