/* =========================================================
   Quản lý học viên – giao diện cho người lớn tuổi (SPEC mục 5)
   Chữ nền 20px · nút ≥ 56px · tương phản cao · 1 cột
   ========================================================= */
:root {
  --primary: #0b5394;
  --primary-dark: #073763;
  --primary-soft: #e3eefa;
  --text: #111111;
  --text-2: #333333;
  --bg: #ffffff;
  --bg-2: #f3f5f8;
  --border: #6b7785;
  --line: #c9d1db;
  --danger: #b00020;
  --danger-soft: #fdeaea;
  --success: #1b5e20;
  --success-soft: #e6f4e7;
  --warn: #7a4a00;
  --warn-soft: #fff4d6;
  --radius: 12px;
  --tap: 56px;
  --bottom-nav: 76px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { font-size: 20px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  padding-bottom: calc(var(--bottom-nav) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--primary); text-underline-offset: 3px; }
h1 { font-size: 1.5rem; margin: .4rem 0 1rem; line-height: 1.25; }
h2 { font-size: 1.25rem; margin: 1.5rem 0 .75rem; }
h3 { font-size: 1.1rem; margin: 1.2rem 0 .5rem; }
p { margin: .5rem 0; }
small, .small { font-size: 18px; }
.muted { color: var(--text-2); }
hr { border: 0; border-top: 2px solid var(--line); margin: 1.5rem 0; }

/* ---------- Khung trang ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--primary); color: #fff;
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.topbar a { color: #fff; text-decoration: none; }
.topbar .brand { font-weight: 700; font-size: 1.1rem; flex: 1; }
.topbar .who { font-size: 18px; }
.topbar .back { font-size: 18px; border: 2px solid #fff; border-radius: 10px; padding: 6px 12px; min-height: 44px; display: inline-flex; align-items: center; }
.layout { display: flex; min-height: calc(100vh - 60px); }
.sidenav { display: none; }
main { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 16px; }

/* Thanh dưới cố định 5 mục (điện thoại) */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #fff;
  border-top: 2px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--bottom-nav); color: var(--text); text-decoration: none; font-size: 16px; font-weight: 600;
}
.bottomnav a .ic { font-size: 26px; line-height: 1; }
.bottomnav a.active { color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 4px 0 var(--primary); }

@media (min-width: 900px) {
  body { padding-bottom: 24px; }
  .bottomnav { display: none; }
  .sidenav {
    display: block; width: 260px; flex-shrink: 0; background: var(--bg-2); border-right: 2px solid var(--line);
    padding: 12px 0; position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto;
  }
  .sidenav a { display: flex; gap: 12px; align-items: center; padding: 12px 20px; color: var(--text); text-decoration: none; font-weight: 600; min-height: 52px; }
  .sidenav a.active { background: var(--primary); color: #fff; }
  .sidenav .sep { border-top: 2px solid var(--line); margin: 8px 0; }
  main { padding: 24px 32px; }
}

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 20px; border-radius: var(--radius);
  border: 2px solid var(--primary); background: #fff; color: var(--primary);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; text-align: center;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 4px solid #f9a825; outline-offset: 2px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger.solid { background: var(--danger); color: #fff; }
.btn-success { border-color: var(--success); background: var(--success); color: #fff; }
.btn-plain { border-color: var(--border); color: var(--text); }
.btn-sm { min-height: 48px; padding: 6px 14px; font-size: 18px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-block { display: flex; width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0; }
.actions > .btn { flex: 1 1 auto; }
@media (max-width: 899px) {
  .btn-primary.main, .main-action { width: 100%; display: flex; }
  .actions.stack { flex-direction: column; }
  .actions.stack > .btn { width: 100%; }
}

/* Lưới nút lớn (trang Thêm, Hôm nay) */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 12px 0; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 120px; padding: 14px; border-radius: 16px; border: 2px solid var(--primary);
  background: var(--primary-soft); color: var(--primary-dark); font-weight: 700; text-decoration: none; text-align: center;
}
.tile .ic { font-size: 40px; line-height: 1; }
.tile .num { font-size: 1.6rem; }

/* ---------- Form ---------- */
form { margin: 0; }
.field { margin: 0 0 18px; }
label, .label { display: block; font-weight: 700; margin-bottom: 6px; }
.hint { display: block; font-size: 18px; color: var(--text-2); margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=tel], input[type=date], input[type=time],
input[type=search], input[type=url], input[type=file], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 14px; font: inherit; font-size: 20px; color: var(--text);
  background: #fff; border: 2px solid var(--border); border-radius: var(--radius);
}
textarea { min-height: 140px; resize: vertical; }
input.money { text-align: right; font-variant-numeric: tabular-nums; }
.check {
  display: flex; align-items: center; gap: 14px; min-height: var(--tap); padding: 8px 12px;
  border: 2px solid var(--line); border-radius: var(--radius); margin: 8px 0; font-weight: 600; cursor: pointer; background: #fff;
}
.check input[type=checkbox], .check input[type=radio] { width: 30px; height: 30px; flex-shrink: 0; accent-color: var(--primary); }
.check.on, .check:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.radio-row { display: flex; flex-wrap: wrap; gap: 10px; }
.radio-row .check { flex: 1 1 140px; margin: 0; }
.validation, .field-validation-error, .text-danger { color: var(--danger); font-weight: 600; }
.input-validation-error { border-color: var(--danger) !important; }
.row2 { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 700px) { .row2 { grid-template-columns: 1fr 1fr; } }
fieldset { border: 2px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin: 0 0 18px; }
legend { font-weight: 700; padding: 0 6px; }

/* Ô tìm kiếm to */
.searchbar { display: flex; gap: 10px; margin: 8px 0 16px; }
.searchbar input { flex: 1; font-size: 22px; }

/* ---------- Thẻ & danh sách ---------- */
.card { border: 2px solid var(--line); border-radius: 16px; padding: 14px 16px; margin: 0 0 12px; background: #fff; }
.card h3 { margin-top: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 2px solid var(--line); }
.list > li > a, .list > li > .row {
  display: flex; align-items: center; gap: 12px; padding: 12px 6px; min-height: 64px; color: var(--text); text-decoration: none;
}
.list > li > a:active { background: var(--bg-2); }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 700; display: block; }
.list .sub { font-size: 18px; color: var(--text-2); display: block; }
.chev { font-size: 28px; color: var(--primary); }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 17px; font-weight: 700;
  border: 2px solid currentColor; white-space: nowrap;
}
.badge.ok { color: var(--success); background: var(--success-soft); }
.badge.warn { color: var(--warn); background: var(--warn-soft); }
.badge.bad { color: var(--danger); background: var(--danger-soft); }
.badge.info { color: var(--primary); background: var(--primary-soft); }

.alert { border-radius: var(--radius); padding: 12px 16px; margin: 12px 0; border: 2px solid; font-weight: 600; }
.alert.ok { color: var(--success); background: var(--success-soft); }
.alert.warn { color: var(--warn); background: var(--warn-soft); }
.alert.bad { color: var(--danger); background: var(--danger-soft); }
.alert.info { color: var(--primary-dark); background: var(--primary-soft); }

dl.info { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.info dt { font-weight: 700; color: var(--text-2); }
dl.info dd { margin: 0; }
@media (max-width: 500px) { dl.info { grid-template-columns: 1fr; } dl.info dt { margin-top: 8px; } }

/* Bảng */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 2px solid var(--line); border-radius: var(--radius); margin: 12px 0; }
table { width: 100%; border-collapse: collapse; font-size: 18px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--bg-2); font-weight: 700; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { font-weight: 700; background: var(--bg-2); }
.history td { white-space: nowrap; }

/* Số tiền to */
.money-big { font-size: 2.2rem; font-weight: 800; color: var(--primary-dark); font-variant-numeric: tabular-nums; }
.total-box { border: 3px solid var(--primary); border-radius: 16px; padding: 12px 16px; margin: 16px 0; background: var(--primary-soft); text-align: center; }

/* Bước (luồng Mở lớp mới) */
.steps { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 16px; padding: 0; list-style: none; }
.steps li a, .steps li span {
  display: block; padding: 6px 12px; border-radius: 999px; border: 2px solid var(--line); font-size: 17px; white-space: nowrap;
  text-decoration: none; color: var(--text);
}
.steps li.cur a, .steps li.cur span { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Thông báo (toast) */
.toast-area { position: fixed; left: 12px; right: 12px; top: calc(70px + env(safe-area-inset-top)); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  width: 100%; max-width: 640px; display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  border-radius: 14px; border: 3px solid; font-weight: 700; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.toast.success { background: var(--success-soft); color: var(--success); }
.toast.error { background: var(--danger-soft); color: var(--danger); }
.toast.info { background: var(--primary-soft); color: var(--primary-dark); }
.toast .msg { flex: 1; }
.toast .ic { font-size: 28px; }

/* Hộp thoại tự vẽ */
dialog.modal {
  border: 3px solid var(--primary); border-radius: 18px; padding: 20px; width: min(560px, calc(100vw - 32px));
  font-size: 22px; color: var(--text);
}
dialog.modal::backdrop { background: rgba(0,0,0,.55); }
dialog.modal .msg { font-weight: 700; margin: 0 0 18px; white-space: pre-line; }
dialog.modal .actions { margin: 0; flex-direction: column; }
dialog.modal .actions .btn { width: 100%; }

/* Tài liệu */
.doc-text { font-size: 22px; line-height: 1.7; }
.doc-text img { max-width: 100%; }
.media { width: 100%; max-height: 70vh; background: #000; border-radius: 12px; }
.pdf-frame { width: 100%; height: 75vh; border: 2px solid var(--line); border-radius: 12px; }

/* Tin nhắn */
.msg-preview { font-size: 22px; line-height: 1.6; min-height: 220px; }

/* Lịch sử 11 cấp */
.levels-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.levels-grid .lv { border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; min-height: 88px; }
.levels-grid .lv .n { font-weight: 800; }
.levels-grid .lv.done { border-color: var(--success); background: var(--success-soft); }
.levels-grid .lv.cur { border-color: var(--primary); background: var(--primary-soft); }
.levels-grid .lv.wait { border-color: var(--warn); background: var(--warn-soft); }
.levels-grid .lv .s { font-size: 17px; }

.perm-table td, .perm-table th { text-align: center; }
.perm-table td:first-child, .perm-table th:first-child { text-align: left; }
.perm-table input[type=checkbox] { width: 30px; height: 30px; accent-color: var(--primary); }

.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt0 { margin-top: 0; }
.spacer { flex: 1; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- In ---------- */
@media print {
  html { font-size: 13pt; }
  body { padding: 0; }
  .topbar, .bottomnav, .sidenav, .actions, .no-print, .toast-area, .btn, .steps { display: none !important; }
  main { padding: 0; max-width: none; }
  .table-wrap { border: 0; overflow: visible; }
  table { font-size: 11pt; }
  th, td { border: 1px solid #000; padding: 4px 6px; }
  th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { color: #000; text-decoration: none; }
  .card { border: 1px solid #000; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
