/* Shared layout and typography guardrails for all HOCTAP pages. */
:root {
  --app-text-size: 15px;
  --app-line-height: 1.5;
  --app-content-gutter: clamp(12px, 2vw, 24px);
}

html {
  font-size: 100%;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-size: var(--app-text-size);
  line-height: var(--app-line-height);
}

:where(main, section, article, aside, nav, header, footer, [role="main"], .layout, .page, .page-shell, .workspace, .main-area, .main-content, .content-shell, .panel, .card) {
  min-width: 0;
}

:where(input, select, textarea, button) {
  max-width: 100%;
  font-family: inherit;
}

:where(img, video, canvas, iframe) {
  max-width: 100%;
}

:where(pre, .table-responsive, .table-wrap, .table-container, .data-table-wrap, .table-scroll, .table-scroll-wrap) {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

:where(.dialog-window, [role="dialog"], dialog) {
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  overscroll-behavior: contain;
}

:where(.topbar-pills, .toolbar-group, .form-actions, .hero-actions, .class-toolbar, .page-header, .support-strip, .dialog-footer) {
  min-width: 0;
  flex-wrap: wrap;
}

@media (max-width: 960px) {
  :where(.topbar, .topbar-inner) {
    min-height: 0;
  }

  :where(.page-shell, .page-container, .content-shell) {
    max-width: 100%;
    min-width: 0;
  }
}

@media (max-width: 760px) {
  :where(.page-shell, .page-container, .content-shell) {
    padding-left: var(--app-content-gutter);
    padding-right: var(--app-content-gutter);
  }

  :where(.topbar) {
    min-height: 0 !important;
    padding: 10px 12px !important;
  }

  :where(.topbar-inner) {
    gap: 8px !important;
    padding: 8px 10px !important;
  }

  :where(.nav-horizontal-container .sidebar-link, .nav-link, .nav-sub-card-label, .nav-sub-column-label) {
    font-size: 12px;
    line-height: 1.35;
  }

  :where(.topbar .workspace-pill, .topbar-pills .pill span) {
    font-size: 12px;
  }

  :where(.page-header, .support-strip, .dialog-header) {
    align-items: flex-start;
    gap: 10px;
  }

  :where(.dialog-window, [role="dialog"], dialog) {
    max-width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    max-height: calc(100dvh - 20px);
  }

  :where(.dialog-header, .dialog-body, .dialog-footer) {
    padding-left: 14px;
    padding-right: 14px;
  }

  :where(.form-actions, .hero-actions, .class-toolbar) > button,
  :where(.form-actions, .hero-actions, .class-toolbar) > .btn {
    max-width: 100%;
  }
}

@media (max-width: 420px) {
  :where(.page-shell, .page-container, .content-shell) {
    --app-content-gutter: 12px;
  }

  :where(.page-header h1, .page-header h2) {
    overflow-wrap: anywhere;
  }
}

/* Hộp thoại "Tạo danh sách tài khoản": gọn, hai cột, thanh tab sáng. */
.dialog-window[aria-label="Tạo danh sách tài khoản"] {
  width: min(660px, 100%);
  max-width: 660px;
  border-radius: 16px;
}
.dialog-window[aria-label="Tạo danh sách tài khoản"] .dialog-header {
  padding: 12px 18px;
  align-items: center;
}
.dialog-window[aria-label="Tạo danh sách tài khoản"] .dialog-header h3 { font-size: 17px; }
.dialog-window[aria-label="Tạo danh sách tài khoản"] .dialog-header p { margin: 2px 0 0; font-size: 12.5px; }
.dialog-window[aria-label="Tạo danh sách tài khoản"] .dialog-close { width: 30px; height: 30px; font-size: 18px; border-radius: 9px; }
.dialog-window[aria-label="Tạo danh sách tài khoản"] .dialog-body { padding: 12px 18px 6px; gap: 10px; }
.dialog-window[aria-label="Tạo danh sách tài khoản"] .dialog-footer { padding: 10px 18px; gap: 8px; align-items: center; }
.dialog-window[aria-label="Tạo danh sách tài khoản"] .dialog-footer .btn { min-height: 34px; padding: 4px 16px; font-size: 13.5px; }
.dialog-window[aria-label="Tạo danh sách tài khoản"] .tab-bar {
  background: #eaf0fb;
  padding: 4px;
  gap: 4px;
  width: 100%;
  box-sizing: border-box;
}
.dialog-window[aria-label="Tạo danh sách tài khoản"] .tab-bar .tab-btn {
  flex: 1 1 0;
  padding: 6px 10px;
  font-size: 13px;
  color: #475569;
  text-align: center;
}
.dialog-window[aria-label="Tạo danh sách tài khoản"] .tab-bar .tab-btn.is-active {
  background: #fff !important;
  border: 1px solid #bfdbfe;
  color: #1d4ed8 !important;
  box-shadow: 0 2px 8px #3b82f622;
}
.dialog-window[aria-label="Tạo danh sách tài khoản"] .note-box {
  padding: 8px 12px;
  font-size: 13px;
  gap: 2px;
  box-shadow: none;
}
.dialog-window[aria-label="Tạo danh sách tài khoản"] .note-box strong { font-size: 13px; }
.dialog-window[aria-label="Tạo danh sách tài khoản"] .stack { gap: 10px; }
.dialog-window[aria-label="Tạo danh sách tài khoản"] .form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}
.dialog-window[aria-label="Tạo danh sách tài khoản"] .form-grid .label { font-size: 13px; margin-bottom: 3px; display: block; }
.dialog-window[aria-label="Tạo danh sách tài khoản"] .form-grid .input,
.dialog-window[aria-label="Tạo danh sách tài khoản"] .form-grid .select {
  min-height: 36px;
  height: 36px;
  padding-block: 4px;
  font-size: 13.5px;
  width: 100%;
  box-sizing: border-box;
}
.dialog-window[aria-label="Tạo danh sách tài khoản"] .helper { font-size: 12px; }
@media (max-width: 560px) {
  .dialog-window[aria-label="Tạo danh sách tài khoản"] .form-grid { grid-template-columns: 1fr; }
}

/* Hộp thoại "Xuất danh sách tài khoản": cùng kiểu gọn. */
.dialog-window[aria-label="Xuất danh sách tài khoản"] {
  width: min(660px, 100%);
  max-width: 660px;
  border-radius: 16px;
}
.dialog-window[aria-label="Xuất danh sách tài khoản"] .dialog-header {
  padding: 12px 18px;
  align-items: center;
}
.dialog-window[aria-label="Xuất danh sách tài khoản"] .dialog-header h3 { font-size: 17px; }
.dialog-window[aria-label="Xuất danh sách tài khoản"] .dialog-header p { margin: 2px 0 0; font-size: 12.5px; }
.dialog-window[aria-label="Xuất danh sách tài khoản"] .dialog-close { width: 30px; height: 30px; font-size: 18px; border-radius: 9px; }
.dialog-window[aria-label="Xuất danh sách tài khoản"] .dialog-body { padding: 12px 18px 6px; gap: 10px; }
.dialog-window[aria-label="Xuất danh sách tài khoản"] .dialog-footer { padding: 10px 18px; gap: 8px; align-items: center; }
.dialog-window[aria-label="Xuất danh sách tài khoản"] .dialog-footer .btn { min-height: 34px; padding: 4px 16px; font-size: 13.5px; }
.dialog-window[aria-label="Xuất danh sách tài khoản"] .tab-bar {
  background: #eaf0fb;
  padding: 4px;
  gap: 4px;
  width: 100%;
  box-sizing: border-box;
}
.dialog-window[aria-label="Xuất danh sách tài khoản"] .tab-bar .tab-btn {
  flex: 1 1 0;
  padding: 6px 10px;
  font-size: 13px;
  color: #475569;
  text-align: center;
}
.dialog-window[aria-label="Xuất danh sách tài khoản"] .tab-bar .tab-btn.is-active {
  background: #fff !important;
  border: 1px solid #bfdbfe;
  color: #1d4ed8 !important;
  box-shadow: 0 2px 8px #3b82f622;
}
.dialog-window[aria-label="Xuất danh sách tài khoản"] .note-box {
  padding: 8px 12px;
  font-size: 13px;
  gap: 2px;
  box-shadow: none;
}
.dialog-window[aria-label="Xuất danh sách tài khoản"] .note-box strong { font-size: 13px; }
.dialog-window[aria-label="Xuất danh sách tài khoản"] .stack { gap: 10px; }
.dialog-window[aria-label="Xuất danh sách tài khoản"] .form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}
.dialog-window[aria-label="Xuất danh sách tài khoản"] .form-grid .label { font-size: 13px; margin-bottom: 3px; display: block; }
.dialog-window[aria-label="Xuất danh sách tài khoản"] .form-grid .input,
.dialog-window[aria-label="Xuất danh sách tài khoản"] .form-grid .select {
  min-height: 36px;
  height: 36px;
  padding-block: 4px;
  font-size: 13.5px;
  width: 100%;
  box-sizing: border-box;
}
.dialog-window[aria-label="Xuất danh sách tài khoản"] .helper { font-size: 12px; }
@media (max-width: 560px) {
  .dialog-window[aria-label="Xuất danh sách tài khoản"] .form-grid { grid-template-columns: 1fr; }
}

/* Xuất danh sách: ô tóm tắt phạm vi + lưới lọc. */
.export-summary {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 4px 12px;
  padding: 10px 14px;
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  background: linear-gradient(135deg, #f5f9ff, #e8f1ff);
}
.export-summary-icon {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #2563eb;
  color: #fff;
  font-size: 18px;
  font-weight: 800;
}
.export-summary-label { font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: #5b7bb5; }
.export-summary strong { display: block; font-size: 14.5px; color: #17336d; line-height: 1.35; overflow-wrap: anywhere; }
.export-summary-hint { grid-column: 2; font-size: 12px; color: #64748b; }
.export-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}
.export-grid .label { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 700; color: #334155; }
.export-grid .select { width: 100%; box-sizing: border-box; min-height: 38px; height: 38px; padding-block: 4px; font-size: 13.5px; }
.export-grid .export-wide { grid-column: 1 / -1; }
@media (max-width: 560px) { .export-grid { grid-template-columns: 1fr; } }

/* Quản trị hoạt động hệ thống: hai bảng xếp dọc, mỗi bảng cuộn riêng. */
.activity-card .activity-scroll { max-height: 40vh; overflow: auto; border-radius: 10px; }
.activity-card .data-table th { position: sticky; top: 0; z-index: 1; }
.activity-card .data-table td, .activity-card .data-table th { padding: 6px 10px; font-size: 13px; }
.activity-card .activity-ua { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #64748b; }
.activity-card .activity-filters { margin-bottom: 8px; }
.activity-ok, .activity-fail { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.activity-ok { background: #dcfce7; color: #166534; }
.activity-fail { background: #fee2e2; color: #991b1b; }

/* Tạo / xuất danh sách tài khoản: hiện ngay trong phần nội dung, không phủ lên trang. */
.stack.is-function-view > :not(.dialog-backdrop) { display: none !important; }
.stack.is-function-view > .dialog-backdrop {
  position: static;
  inset: auto;
  display: block;
  padding: 0;
  background: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  z-index: auto;
}
.stack.is-function-view > .dialog-backdrop .dialog-window {
  width: 100%;
  max-width: 880px;
  max-height: none;
  margin: 0;
  overflow: visible;
  box-shadow: 0 8px 24px rgba(31, 62, 116, .08);
}
body:has(.stack.is-function-view) { overflow: auto !important; }

/* Cấu trúc bài học: các trang của bài đang soạn nằm ngay dưới bài trong cây. */
.lesson-node { display: grid; gap: 2px; }
.lesson-pages {
  display: grid;
  gap: 2px;
  margin: 2px 0 6px 14px;
  padding-left: 8px;
  border-left: 2px solid #d9e4f6;
}
.lesson-page-item {
  display: block;
  width: 100%;
  padding: 5px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #3b4960;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.lesson-page-item:hover { background: #f1f5fb; color: #1d4ed8; }
.lesson-page-item.active { background: #e4edff; color: #1d4ed8; font-weight: 800; }
.lesson-page-add { color: #2563eb; font-weight: 700; }

/* Thanh lưu trang dưới trình soạn bài giảng. */
.page-save-bar {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #dbe5f5;
  border-radius: 12px;
  background: #f5f8ff;
}
.page-save-bar .helper { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.page-save-bar .page-save-msg { color: #15803d; font-weight: 600; }
.page-save-bar .btn { flex: none; }

/* Trang trong cây: gọn, kèm nút đổi thứ tự. */
.lesson-pages { gap: 2px !important; }
.lesson-page-row { display: flex; align-items: center; gap: 4px; border-radius: 8px; }
.lesson-page-row.active { background: #e4edff; }
.lesson-pages .lesson-page-item {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0 !important;
  padding: 5px 10px !important;
  border: 0 !important;
  border-radius: 8px !important;
  background: transparent !important;
  box-shadow: none !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  color: #3b4960 !important;
  text-align: left !important;
}
.lesson-pages .lesson-page-item.active { background: transparent !important; color: #1d4ed8 !important; font-weight: 800 !important; }
.lesson-pages .lesson-page-item:hover { background: #f1f5fb !important; }
.lesson-pages .lesson-page-add { color: #2563eb !important; }
.lesson-page-move { display: inline-flex; gap: 2px; flex: none; padding-right: 4px; }
.lesson-pages .lesson-page-move-btn {
  width: 24px;
  height: 24px;
  min-height: 0 !important;
  padding: 0 !important;
  border: 1px solid #c8d6ef !important;
  border-radius: 6px !important;
  background: #fff !important;
  box-shadow: none !important;
  color: #1d4ed8 !important;
  font-size: 13px !important;
  line-height: 1 !important;
  cursor: pointer;
}
.lesson-pages .lesson-page-move-btn:hover:not(:disabled) { background: #eef4ff !important; }
.lesson-pages .lesson-page-move-btn:disabled { opacity: .35; cursor: not-allowed; }

/* Trạng thái soạn trang nằm trên đầu phần nội dung; thanh dưới chỉ còn nút lưu. */
.page-status-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px;
  margin: 0 0 10px;
  padding: 8px 12px;
  border: 1px solid #dbe5f5;
  border-radius: 10px;
  background: #f5f8ff;
  color: #475569;
  font-size: 14px;
}
.page-status-line strong { color: #17336d; }
.page-status-line .page-save-msg { color: #15803d; font-weight: 700; }
.page-save-bar { justify-content: flex-end !important; }

/* Các bước làm trong trang: bước rà soát cần rộng hơn. */
.stack.is-function-view > .dialog-backdrop .dialog-window.dialog-xl { max-width: 1200px; }
.stack.is-function-view > .dialog-backdrop .dialog-window.dialog-lg { max-width: 1000px; }

/* Tổ chức thi: cây các đề thi của giáo viên (Môn › Khối › Đề). */
.exam-tree { display: grid; gap: 8px; margin-top: 8px; }
.exam-tree-node { border: 1px solid #dbe5f5; border-radius: 12px; background: #fff; }
.exam-tree-node > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  list-style: none;
  color: #17336d;
}
.exam-tree-node > summary::-webkit-details-marker { display: none; }
.exam-tree-node > summary::before { content: "▸"; margin-right: 8px; color: #5b7bb5; transition: transform .15s; }
.exam-tree-node[open] > summary::before { transform: rotate(90deg); }
.exam-tree-node > summary strong, .exam-tree-node > summary { flex-wrap: wrap; }
.exam-tree-node > summary .badge { margin-left: auto; }
.exam-tree-grade { margin: 0 12px 10px; background: #fbfdff; }
.exam-tree-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 12px 8px;
  padding: 8px 12px;
  border: 1px solid #e5ecf8;
  border-radius: 10px;
  background: #fff;
}
.exam-tree-main { display: grid; gap: 2px; min-width: 0; }
.exam-tree-main strong { overflow-wrap: anywhere; }
.exam-tree-actions { display: flex; gap: 6px; flex: none; }

/* Tổ chức thi: cây thư mục các đề thi bên trái, danh sách chi tiết bên phải. */
.exam-library-layout {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.exam-pane { position: sticky; top: 12px; max-height: calc(100vh - 40px); overflow: auto; align-content: start; }
.exam-pane-root, .exam-pane-folder > summary, .exam-pane-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
  padding: 7px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #3b4960;
  font: inherit;
  font-size: 13.5px;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
  list-style: none;
}
.exam-pane-folder > summary::-webkit-details-marker { display: none; }
.exam-pane-root:hover, .exam-pane-folder > summary:hover, .exam-pane-item:hover { background: #f1f5fb; color: #1d4ed8; }
.exam-pane-root.active, .exam-pane-folder > summary.active { background: #e4edff; color: #1d4ed8; font-weight: 800; }
.exam-pane-tree { display: grid; gap: 2px; margin-top: 6px; }
.exam-pane-folder { border-radius: 9px; }
.exam-pane-folder[open] > summary { font-weight: 800; }
.exam-pane-folder > .exam-pane-item, .exam-pane-folder > .exam-pane-empty { margin-left: 18px; width: calc(100% - 18px); }
.exam-pane-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.exam-pane-meta { flex: none; font-size: 11px; font-weight: 600; color: #64748b; }
.exam-pane-icon { flex: none; color: #f97316; }
.exam-pane-empty { padding: 4px 10px; }
@media (max-width: 900px) {
  .exam-library-layout { grid-template-columns: 1fr; }
  .exam-pane { position: static; max-height: none; }
}

/* Học sinh không có menu bên: thuộc tính hidden của menu phải thắng các quy tắc display của khung chung. */
#hoctap-horizontal-nav[hidden], #hoctap-top-menu[hidden] { display: none !important; }

/* Học sinh trên điện thoại: khung chỉ có một cột (không có menu bên), tránh bị ép vào cột 68px. */
@media (max-width: 700px) {
  .layout[data-horizontal-nav='1'][data-hoctap-role='student'] { grid-template-columns: minmax(0, 1fr) !important; }
  .layout[data-horizontal-nav='1'][data-hoctap-role='student'] > .main-area,
  .layout[data-horizontal-nav='1'][data-hoctap-role='student'] #hoctap-top-menu { grid-column: 1 !important; width: auto !important; min-width: 0 !important; }
}
