/* Giao diện chung của web phụ huynh Hina.
   Chỉnh màu sắc ở khối :root ngay dưới đây; các phần còn lại dùng lại các biến này. */
:root {
  --brand: #4a5bd4;
  --brand-dark: #3a49b8;
  --brand-soft: #eef0fb;
  --brand-soft-hover: #e1e5fa;
  --bg: #f5f6fb;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #5b6479;
  --line: #e3e6f1;
  --ok: #1c6b34;
  --ok-bg: #d5f2dc;
  --warn: #8a5300;
  --warn-bg: #fff0d6;
  --bad: #b3261e;
  --bad-bg: #fde8e6;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 70, .06), 0 6px 18px rgba(20, 30, 70, .07);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--brand); }
.hidden { display: none !important; }

/* ---------- Đầu trang ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(135deg, var(--brand), #6a55d8);
  color: #fff;
  box-shadow: 0 2px 10px rgba(40, 50, 120, .25);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { width: 36px; height: 36px; border-radius: 10px; background: #fff; flex: none; }
.app-header h1 { margin: 0; font-size: 19px; font-weight: 700; line-height: 1.2; }
.app-header h1 span { display: block; font-size: 12px; font-weight: 500; opacity: .85; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Bố cục ---------- */
main {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 14px calc(32px + env(safe-area-inset-bottom));
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
h2 {
  display: flex;
  align-items: center;
  font-size: 18px;
  line-height: 1.3;
  margin: 0 0 12px;
}
h2::before {
  content: "";
  flex: none;
  width: 4px;
  height: 1.05em;
  margin-right: 10px;
  border-radius: 2px;
  background: var(--brand);
}
.hint { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 6px 0; }
.err { color: var(--bad); font-size: 14px; margin-top: 8px; min-height: 18px; }

/* ---------- Nút ---------- */
button, .btnlink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  color: #fff;
  background: var(--brand);
  border: 0;
  border-radius: 12px;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease, transform .05s ease;
}
button:hover, .btnlink:hover { background: var(--brand-dark); }
button:active, .btnlink:active { transform: translateY(1px); }
button.secondary { background: var(--brand-soft); color: #2a3490; }
button.secondary:hover { background: var(--brand-soft-hover); }
button.danger { background: var(--bad-bg); color: var(--bad); }
button.danger:hover { background: #fbd5d1; }
button:disabled { opacity: .5; cursor: default; transform: none; }
:focus-visible { outline: 3px solid rgba(74, 91, 212, .45); outline-offset: 2px; }

/* Nút trên nền xanh của đầu trang */
.app-header .btnlink,
.app-header button {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 14px;
  color: #fff;
  background: rgba(255, 255, 255, .18);
}
.app-header .btnlink:hover,
.app-header button:hover { background: rgba(255, 255, 255, .3); }

.row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

/* ---------- Biểu mẫu ---------- */
label { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; }
input, select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1.5px solid #c8cedd;
  border-radius: 12px;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(74, 91, 212, .18);
}
input[type="checkbox"] { width: auto; min-height: 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; margin: 0; }
.check input { width: 18px; height: 18px; }

/* Ô mật khẩu có nút mắt (do ui.js thêm vào) */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 54px; }
.pw-eye {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  min-height: 40px;
  height: 40px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border-radius: 10px;
}
.pw-eye:hover { color: var(--brand); background: var(--brand-soft); }
.pw-eye:active { transform: translateY(-50%); }

/* ---------- Đăng nhập ---------- */
.auth-card { max-width: 440px; margin: 20px auto; padding: 22px 20px; }
.auth-intro { text-align: center; margin-bottom: 4px; }
.auth-logo { width: 72px; height: 72px; border-radius: 20px; background: #fff; box-shadow: var(--shadow); }
.auth-intro h2 { justify-content: center; margin: 10px 0 4px; font-size: 22px; }
.auth-intro h2::before { display: none; }

/* ---------- Hồ sơ bé ---------- */
.child { border-top: 1px solid var(--line); padding: 14px 0; }
.child:first-child { border-top: 0; padding-top: 0; }
.child strong { font-size: 17px; }
.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  vertical-align: middle;
  border-radius: 999px;
  background: var(--brand-soft);
  color: #2a3490;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.code {
  display: inline-block;
  margin: 10px 0 0;
  padding: 8px 16px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 8px;
  background: var(--brand-soft);
  border-radius: 12px;
}

details { margin-top: 10px; }
summary {
  cursor: pointer;
  padding: 8px 0;
  font-size: 15px;
  font-weight: 600;
  color: #2a3490;
}
details[open] > summary { margin-bottom: 4px; }

/* ---------- Lịch sử trò chuyện ---------- */
/* (.filters, .stats, .stat được giữ lại vì nơi khác có thể còn dùng) */
.filters { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin: 8px 0; }
.filters > div { flex: 1; min-width: 150px; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.stat { font-size: 13px; padding: 4px 12px; border-radius: 999px; background: var(--brand-soft); color: #2a3490; }
.stat.worry { background: var(--bad-bg); color: var(--bad); font-weight: 600; }
.stat.sens { background: var(--warn-bg); color: var(--warn); }
.day { text-align: center; font-size: 12px; color: var(--muted); margin: 18px 0 6px; }
.msg { display: flex; margin: 8px 0; scroll-margin-top: 96px; }
.msg.kid { justify-content: flex-end; }
.bubble {
  max-width: 85%;
  padding: 9px 13px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  border-radius: 16px;
}
.kid .bubble { background: #dfe4ff; border-bottom-right-radius: 4px; }
.hina .bubble { background: #eef0f6; border-bottom-left-radius: 4px; }
.bubble.worry { border: 2px solid #d93025; background: var(--bad-bg); }
.bubble.sensitive { border: 2px solid #f0a020; background: #fff6e5; }
.meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.tag { font-weight: 700; }
.tag.worry { color: var(--bad); }
.tag.sensitive { color: var(--warn); }

/* ---------- Màn hình trò chuyện: bố cục mới ---------- */
.chat-main > .fold-body { padding: 4px 14px 16px; }

/* Khung danh sách tin có thanh cuộn riêng: cuộn trong khung là xem lịch sử, cuộn ngoài khung là xem các mục khác */
.chat-scroll {
  position: relative;               /* để chat.js tính vị trí tin khi nhảy tới tin đó */
  max-height: 68vh;
  max-height: min(68vh, 640px);
  overflow-y: auto;
  overscroll-behavior: contain;     /* cuộn tới cuối khung thì không kéo theo cả trang */
  -webkit-overflow-scrolling: touch;
  padding: 2px 10px 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  scrollbar-width: thin;
  scrollbar-color: #b5bde8 transparent;
}
.chat-scroll::-webkit-scrollbar { width: 10px; }
.chat-scroll::-webkit-scrollbar-track { background: transparent; }
.chat-scroll::-webkit-scrollbar-thumb { background: #c3c9ee; border: 2px solid #fff; border-radius: 999px; }
.chat-scroll::-webkit-scrollbar-thumb:hover { background: #a9b2e6; }
/* Nhãn ngày dính ở đầu khung khi cuộn, để biết đang xem ngày nào */
.chat-scroll .day {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 0 6px;
  padding: 8px 0 4px;
  background: rgba(255, 255, 255, .94);
}

/* Mục thu gọn được: thẻ <details class="fold"> với thanh tiêu đề bấm để mở */
details.fold { margin-top: 0; }
details.card.fold { padding: 0; overflow: hidden; }
details.fold > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 14px 18px;
  margin: 0;
  list-style: none;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after {
  content: "";
  flex: none;
  width: 9px;
  height: 9px;
  margin: 0 4px 3px auto;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform .2s ease;
}
details.fold[open] > summary::after { transform: rotate(-135deg); margin-bottom: 0; margin-top: 4px; }
details.fold[open] > summary { margin-bottom: 0; }
details.fold > summary:hover { background: #fafbff; }
.fold-head { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fold-title {
  display: flex;
  align-items: center;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}
.fold-title::before {
  content: "";
  flex: none;
  width: 4px;
  height: 1.05em;
  margin-right: 10px;
  border-radius: 2px;
  background: var(--brand);
}
.fold-sub { margin-left: 14px; font-size: 13px; font-weight: 500; line-height: 1.4; color: var(--muted); }
.fold-sub.alert { color: var(--bad); font-weight: 700; }
.fold-body { padding: 4px 18px 18px; }
details.danger-fold .fold-title::before { background: var(--bad); }

/* Bộ lọc nằm trong thẻ Cuộc trò chuyện: viền nhẹ, nền hơi tối hơn */
details.fold-inline {
  margin: 0 0 12px;
  background: #fafbff;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
details.fold-inline > summary { min-height: 54px; padding: 10px 14px; }
details.fold-inline .fold-title { font-size: 16px; }
details.fold-inline .fold-body { padding: 2px 14px 14px; }

/* Nút lọc */
.filter-group + .filter-group { margin-top: 12px; }
.filter-label { margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
button.fchip {
  min-height: 40px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 600;
  color: #2a3490;
  background: var(--brand-soft);
  border: 1.5px solid transparent;
  border-radius: 999px;
}
button.fchip:hover { background: var(--brand-soft-hover); }
button.fchip.on { color: #fff; background: var(--brand); border-color: var(--brand); }
button.fchip.on:hover { background: var(--brand-dark); }
button.fchip.worry { color: var(--bad); background: var(--bad-bg); }
button.fchip.worry:hover { background: #fbd5d1; }
button.fchip.worry.on { color: #fff; background: var(--bad); border-color: var(--bad); }
button.fchip.worry.on:hover { background: #9c1f19; }
button.fchip.sens { color: var(--warn); background: var(--warn-bg); }
button.fchip.sens:hover { background: #ffe6b8; }
button.fchip.sens.on { color: #fff; background: #c77700; border-color: #c77700; }
button.fchip.sens.on:hover { background: #a86300; }
.fcount {
  display: inline-block;
  min-width: 22px;
  padding: 0 7px;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, .7);
  color: inherit;
}
button.fchip.on .fcount { background: rgba(255, 255, 255, .25); }

/* Dòng trạng thái ngay trên danh sách: đang xem gì, bao nhiêu tin, nút bỏ lọc */
.result-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin-bottom: 6px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: var(--brand-soft);
  border: 1px solid transparent;
  border-radius: 12px;
}
.result-bar.filtered { color: #2a3490; background: #e6e9fb; border-color: #c9d0f5; }
.result-bar button { min-height: 34px; padding: 4px 14px; font-size: 13px; }
.chat-empty { padding: 26px 8px; text-align: center; }
.chat-empty .hint { margin-bottom: 12px; }

/* Nút "Xem cả đoạn chat" trong tin đã lọc, và hiệu ứng nháy khi nhảy tới tin đó */
button.ctx-btn {
  min-height: 32px;
  margin-top: 8px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #2a3490;
  background: rgba(255, 255, 255, .85);
  border: 1px solid var(--line);
  border-radius: 8px;
}
button.ctx-btn:hover { background: #fff; }
.msg.flash .bubble { animation: msg-flash 2.2s ease; }
@keyframes msg-flash {
  0%, 65% { box-shadow: 0 0 0 4px rgba(74, 91, 212, .5); }
  100% { box-shadow: 0 0 0 0 rgba(74, 91, 212, 0); }
}

/* ---------- Danh sách video của phụ huynh ---------- */
/* Khung có thanh cuộn riêng: cuộn trong khung để xem các video, cuộn ngoài khung để tới các nút và bộ khác */
.vlist {
  max-height: 340px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  margin: 6px 0;
  padding: 2px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  scrollbar-width: thin;
  scrollbar-color: #b5bde8 transparent;
}
.vlist::-webkit-scrollbar { width: 10px; }
.vlist::-webkit-scrollbar-track { background: transparent; }
.vlist::-webkit-scrollbar-thumb { background: #c3c9ee; border: 2px solid #fff; border-radius: 999px; }
.vlist::-webkit-scrollbar-thumb:hover { background: #a9b2e6; }
.vrow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.vrow:last-child { border-bottom: 0; }
/* Số video đang chọn so với mức tối đa của một bộ */
.vcount { margin: 8px 0 4px; font-size: 14px; font-weight: 700; }
.vcount.ok { color: var(--ok); }
.vcount.over { color: var(--bad); }

/* ---------- Chân trang ---------- */
.site-footer { text-align: center; font-size: 14px; color: var(--muted); padding: 10px 0 4px; }
.site-footer a { margin: 0 4px; }

/* ---------- Màn hình hẹp ---------- */
@media (max-width: 520px) {
  .card { padding: 16px; }
  .row > button { flex: 1 1 140px; }
  .code { font-size: 28px; letter-spacing: 6px; }
  .chat-main > .fold-body { padding: 4px 12px 14px; }
  .chat-scroll { max-height: 62vh; max-height: 62dvh; padding: 2px 6px 8px; }
  .vlist { max-height: 52vh; max-height: 52dvh; padding: 2px 8px; }
  details.fold > summary { padding: 12px 14px; }
  .fold-body { padding: 4px 14px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  button, .btnlink { transition: none; }
  details.fold > summary::after { transition: none; }
  .msg.flash .bubble { animation: none; }
}
/* ---------- Thời gian biểu ---------- */
.sched-item {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin: 8px 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.sched-item.off { opacity: .55; }
.sched-info { flex: 1 1 180px; min-width: 0; }
.sched-time { font-size: 20px; font-weight: 700; }
.sched-sub { font-size: 14px; color: var(--muted); }
.sched-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.sched-actions button { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.sched-form { margin-top: 12px; padding-top: 6px; border-top: 1px dashed var(--line); }
.sched-templates { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.sched-templates button { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.sched-days { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  flex: 1 1 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 8px 0;
  color: #2a3490;
  background: var(--brand-soft);
}
.chip:hover { background: var(--brand-soft-hover); }
.chip.on { color: #fff; background: var(--brand); }
.chip.on:hover { background: var(--brand-dark); }
/* ---------- Bảng thời gian biểu (cột là thứ, hàng là buổi) ---------- */
.sched-table-wrap { overflow-x: auto; margin: 8px 0; border: 1px solid var(--line); border-radius: 12px; }
.sched-table { border-collapse: collapse; width: 100%; min-width: 600px; table-layout: fixed; font-size: 13px; }
.sched-table th, .sched-table td { border: 1px solid var(--line); padding: 4px; vertical-align: top; }
.sched-table thead th { background: var(--brand-soft); color: #2a3490; font-weight: 700; padding: 8px 4px; text-align: center; }
.sched-table .sched-corner { width: 72px; }
.sched-table .sched-rowhead { background: var(--brand-soft); text-align: left; font-weight: 700; padding: 8px 6px; }
.sched-range { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
.sched-table td { height: 64px; background: #fff; }
.sched-table th.today { background: var(--brand); color: #fff; }
.sched-today-tag { display: block; font-size: 10px; font-weight: 600; opacity: .9; }
.sched-table td.today { background: #e8ecff; border-left: 2px solid var(--brand); border-right: 2px solid var(--brand); }
.sched-table tbody tr:last-child td.today { border-bottom: 2px solid var(--brand); }
.sched-chip {
  display: block; width: 100%; min-height: 0; margin: 2px 0; padding: 4px 6px;
  text-align: left; font-size: 12px; font-weight: 500; line-height: 1.3;
  color: var(--text); background: #fff; border: 1.5px solid var(--brand); border-radius: 8px;
}
.sched-chip:hover { background: var(--brand-soft); }
.sched-chip.end { border-color: #d98a00; }
.sched-chip.off { opacity: .45; }
.sched-chip-time { display: block; font-weight: 700; }
.sched-chip-label { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }