:root {
  --navy: #1e3a8a;
  --navy-dark: #172554;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;
  --green: #15803d;
  --green-bg: #dcfce7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --amber-bg: #fef3c7;
  --amber: #92400e;
  --msc: #1d4ed8;
  --hsc: #dc2626;
  --ca1: #f97316;
  --ca2: #2563eb;
  --ca3: #7c3aed;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 12px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 18px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Thanh trên ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--navy); color: #fff;
}
.topbar-title { font-weight: 700; font-size: 19px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-back {
  background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 10px;
  padding: 8px 14px; font-weight: 600; font-size: 17px; min-height: 44px;
}

.app { max-width: 760px; margin: 0 auto; padding: 16px 16px 120px; }
.app.wide { max-width: 1180px; }
.loading { text-align: center; padding: 60px 0; color: var(--muted); }

h1 { font-size: 26px; margin: 4px 0 12px; line-height: 1.25; }
h2 { font-size: 21px; margin: 24px 0 10px; }
h3 { font-size: 18px; margin: 0 0 6px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.center { text-align: center; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 12px 20px; border-radius: 12px; border: 2px solid transparent;
  font-weight: 700; font-size: 18px; text-decoration: none; text-align: center;
  background: var(--navy); color: #fff;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-block { display: flex; width: 100%; }
.btn-light { background: #fff; color: var(--navy); border-color: var(--navy); }
.btn-green { background: var(--green); }
.btn-red { background: #fff; color: var(--red); border-color: var(--red); }
.btn-ghost { background: transparent; color: var(--navy); border-color: transparent; }
.btn-sm { white-space: nowrap; flex: none; min-height: 40px; padding: 6px 12px; font-size: 16px; border-radius: 10px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }

/* ---------- Form ---------- */
.field { margin-bottom: 16px; }
.field label, .label { display: block; font-weight: 700; margin-bottom: 6px; }
.field .hint { font-size: 15px; color: var(--muted); margin-top: 4px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 54px; padding: 12px 14px; font-size: 20px;
  border: 2px solid #94a3b8; border-radius: 12px; background: #fff;
}
.input:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(30,58,138,.2); }
.input-search { font-size: 18px; }
.input-big::placeholder { color: #cbd5e1; font-weight: 500; }
.input-big { font-size: 28px; letter-spacing: 4px; text-align: center; font-weight: 700; }
.choice-row { display: flex; gap: 10px; }
.choice {
  flex: 1; min-height: 56px; border-radius: 12px; border: 2px solid #94a3b8; background: #fff;
  font-weight: 700; font-size: 19px;
}
.choice.on { border-color: var(--navy); background: var(--navy); color: #fff; }
.choice.on.msc { border-color: var(--msc); background: var(--msc); }
.choice.on.hsc { border-color: var(--hsc); background: var(--hsc); }

.alert { border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; font-size: 17px; }
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid #fca5a5; }
.alert-ok { background: var(--green-bg); color: var(--green); border: 1px solid #86efac; }
.alert-warn { background: var(--amber-bg); color: var(--amber); border: 1px solid #fcd34d; }
.alert-info { background: #e0e7ff; color: var(--navy-dark); border: 1px solid #a5b4fc; }

/* ---------- Đăng nhập ---------- */
.login-wrap { max-width: 440px; margin: 0 auto; padding-top: 24px; }
.login-logo { width: 88px; height: 88px; display: block; margin: 0 auto 12px; border-radius: 22px; box-shadow: var(--shadow); }
.login-title { text-align: center; font-size: 26px; color: var(--navy); margin-bottom: 4px; }

/* ---------- Trang chính ---------- */
.hello { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.hello-name { font-size: 22px; font-weight: 800; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 14px; font-weight: 700;
  background: #e2e8f0; color: var(--muted); vertical-align: middle;
}
.badge-1 { background: #fae8ff; color: #86198f; }
.badge-2 { background: #e0e7ff; color: var(--navy); }
.badge-3 { background: #dcfce7; color: var(--green); }
.badge-open { background: var(--green-bg); color: var(--green); }
.badge-closed { background: #e2e8f0; color: var(--muted); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  background: #fff; border: 0; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; text-align: left; min-height: 110px; font-weight: 700; font-size: 17px; color: var(--text);
}
.tile .ico { font-size: 30px; line-height: 1; }
.tile small { font-weight: 400; color: var(--muted); font-size: 14px; }

.month-card { border-left: 6px solid var(--navy); }
.month-card.done { border-left-color: var(--green); }

/* ---------- Đăng ký ---------- */
.steps { display: flex; gap: 6px; margin-bottom: 14px; }
.steps span { flex: 1; height: 6px; border-radius: 3px; background: #cbd5e1; }
.steps span.on { background: var(--navy); }
.step-label { font-size: 15px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.shift-legend { display: grid; gap: 6px; font-size: 15px; }
.shift-legend div { display: flex; gap: 8px; align-items: center; }
.shift-legend b { white-space: nowrap; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.dot-1 { background: var(--ca1); } .dot-2 { background: var(--ca2); } .dot-3 { background: var(--ca3); }

.day {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; margin-bottom: 10px;
}
.day-head { font-weight: 800; font-size: 18px; margin-bottom: 8px; }
.day-head .muted { font-weight: 500; }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.slot {
  border: 2px solid var(--line); background: #f8fafc; border-radius: 12px; padding: 8px 4px;
  min-height: 78px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 15px; line-height: 1.2;
}
.slot b { font-size: 17px; }
.slot .free { font-weight: 700; color: var(--green); }
.slot.s1 { border-top: 5px solid var(--ca1); }
.slot.s2 { border-top: 5px solid var(--ca2); }
.slot.s3 { border-top: 5px solid var(--ca3); }
.slot:disabled { opacity: .5; background: #f1f5f9; }
.slot:disabled .free { color: var(--muted); }
.slot.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.slot.on .free { color: #fff; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(15,23,42,.08);
  padding: 12px 16px; padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.bottom-bar-inner { max-width: 760px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.bottom-bar-inner .info { flex: 1; font-weight: 700; font-size: 16px; }

.reg-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.reg-item:last-child { border-bottom: 0; }
.reg-date {
  flex: none; width: 64px; text-align: center; border-radius: 12px; padding: 6px 0; color: #fff; font-weight: 800;
  background: var(--navy);
}
.reg-date.HSC { background: var(--hsc); }
.reg-date.MSC { background: var(--msc); }
.reg-date .d { font-size: 24px; line-height: 1.1; }
.reg-date .m { font-size: 13px; }
.reg-body { flex: 1; min-width: 0; }
.reg-body .t { font-weight: 800; }
.reg-actions { flex: none; }

.success-ico {
  width: 88px; height: 88px; border-radius: 50%; background: var(--green); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 52px; margin: 12px auto;
}

/* ---------- Lịch tổng hợp ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.sched-tools .label { margin: 14px 0 6px; }
.month-step { display: flex; align-items: center; gap: 10px; }
.month-step .btn { flex: none; width: 56px; padding: 0; font-size: 30px; line-height: 1; }
.month-now { flex: 1; min-width: 0; text-align: center; background: #f8fafc; border: 2px solid #94a3b8; border-radius: 12px; padding: 6px 4px; }
.month-now:active, .month-now:focus-visible { border-color: var(--navy); background: #eef2ff; }
.month-now .caret { font-size: 16px; color: var(--navy); vertical-align: 2px; }
.month-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.month-grid .choice { min-height: 60px; font-size: 17px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.month-grid .open-dot { font-size: 12px; font-weight: 700; color: var(--green); }
.month-grid .choice.on .open-dot { color: #bbf7d0; }
.month-now .t { font-size: 20px; font-weight: 800; white-space: nowrap; }
.seg { display: grid; gap: 8px; }
.seg-2 { grid-template-columns: 1fr 1fr; }
.seg-3 { grid-template-columns: 1fr 1fr 1fr; }
.seg .choice { min-height: 50px; font-size: 18px; }
.check-row { display: flex; align-items: center; gap: 12px; margin-top: 14px; font-weight: 600; font-size: 17px; cursor: pointer; }
.check-row input { width: 26px; height: 26px; flex: none; accent-color: var(--navy); }
.tool-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 6px; }
.tool-actions .btn { width: 100%; }
.chip {
  flex: none; border: 2px solid #94a3b8; background: #fff; border-radius: 999px; padding: 6px 14px;
  font-weight: 700; font-size: 16px; min-height: 42px;
}
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.person {
  display: inline-flex; align-items: center; gap: 4px; border: 0; border-radius: 999px; padding: 6px 12px;
  background: #eef2ff; color: var(--navy-dark); font-weight: 700; font-size: 16px; margin: 2px 4px 2px 0;
  min-height: 38px; text-align: left;
}
.person.g3 { background: #fff7ed; color: #9a3412; }
.add-person {
  border: 2px dashed #94a3b8; background: transparent; color: var(--muted); border-radius: 999px;
  padding: 4px 12px; font-weight: 700; font-size: 15px; min-height: 38px;
}
.sched-day { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; overflow: hidden; }
.sched-day-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-weight: 800; background: #f8fafc; border-bottom: 1px solid var(--line); }
.camp { font-weight: 800; }
.camp.HSC { color: var(--hsc); } .camp.MSC { color: var(--msc); }
.sched-row { display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.sched-row:last-child { border-bottom: 0; }
.sched-row .ca { flex: none; width: 76px; font-weight: 800; font-size: 15px; line-height: 1.2; padding-top: 6px; }
.sched-row .ca small { display: block; font-weight: 500; color: var(--muted); }
.sched-row .ca.s1 { color: var(--ca1); } .sched-row .ca.s2 { color: var(--ca2); } .sched-row .ca.s3 { color: var(--ca3); }
.sched-row .who { flex: 1; min-width: 0; }
.legend-line { font-size: 14px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.legend-line span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.legend-line .lg2::before { background: #c7d2fe; } .legend-line .lg3::before { background: #fed7aa; }

/* Bảng dạng poster (giống mẫu tháng 11) */
.poster { background: #fff; padding: 24px; border-radius: 16px; width: 1100px; font-size: 18px; color: var(--text); }
.poster-title { text-align: center; font-size: 34px; font-weight: 900; color: var(--navy-dark); margin: 0 0 18px; }
.poster table { width: 100%; border-collapse: separate; border-spacing: 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.poster th { color: #fff; padding: 12px 8px; font-size: 20px; }
.poster th small { display: block; font-size: 15px; font-weight: 600; opacity: .95; }
.poster th.h-day { background: var(--navy-dark); width: 14%; }
.poster th.h-camp { background: #15803d; width: 12%; }
.poster th.h1, .poster th.h2, .poster th.h3 { width: 24.66%; }
.poster th.h1 { background: var(--ca1); } .poster th.h2 { background: var(--ca2); } .poster th.h3 { background: var(--ca3); }
.poster td { padding: 12px 8px; border-top: 1px solid var(--line); text-align: center; font-weight: 700; font-size: 19px; vertical-align: middle; }
.poster td + td { border-left: 1px solid var(--line); }
.poster tr.MSC td.names { color: var(--msc); } .poster tr.HSC td.names { color: #ea580c; }
.poster td.camp-cell.MSC { color: var(--msc); } .poster td.camp-cell.HSC { color: var(--hsc); }
.poster .note { margin-top: 16px; display: flex; gap: 24px; justify-content: center; flex-wrap: wrap; font-size: 16px; font-weight: 600; color: var(--muted); }
.poster-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px 8px; }
.poster-wrap-hidden { position: fixed; left: -10000px; top: 0; }
.poster .camp-mini { display: none; }
.poster .add-cell {
  display: block; margin: 6px auto 0; border: 2px dashed #94a3b8; background: transparent; color: var(--muted);
  border-radius: 999px; padding: 2px 12px; font-weight: 700; font-size: 15px; min-height: 34px;
}
.poster .add-cell:hover { border-color: var(--navy); color: var(--navy); }

/* Bảng trên điện thoại: vừa khung màn hình, không phải kéo ngang */
@media screen and (max-width: 760px) {
  .poster-scroll { overflow: visible; margin: 0 -8px; padding: 0; }
  .poster.fit { width: 100%; padding: 12px 6px; border-radius: 12px; font-size: 14px; }
  .poster.fit .poster-title { font-size: 18px; margin-bottom: 10px; }
  .poster.fit table { table-layout: fixed; overflow: visible; border-radius: 0; }
  .poster.fit th { position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 2; padding: 6px 2px; font-size: 14px; }
  .poster.fit th small { font-size: 12px; }
  .poster.fit th.h-day { width: 22%; }
  .poster.fit th.h-camp { display: none; }
  .poster.fit th.h1, .poster.fit th.h2, .poster.fit th.h3 { width: 26%; }
  .poster.fit td { padding: 6px 3px; font-size: 14px; line-height: 1.25; word-break: break-word; }
  .poster.fit td.camp-cell { display: none; }
  .poster.fit td.day-cell { font-size: 15px; }
  .poster.fit td.day-cell .small { font-size: 12px; }
  .poster.fit .camp-mini { display: inline-block; margin-top: 2px; padding: 0 6px; border-radius: 6px; font-size: 12px; color: #fff; }
  .poster.fit .camp-mini.MSC { background: var(--msc); }
  .poster.fit .camp-mini.HSC { background: var(--hsc); }
  .poster.fit .sep { display: none; }
  .poster.fit .pname { display: block; padding: 2px 0; }
  .poster.fit .pname + .pname { border-top: 1px dashed var(--line); }
  .poster.fit .add-cell { font-size: 13px; padding: 2px 6px; min-height: 32px; width: 100%; max-width: 76px; }
  .poster.fit .note { flex-direction: column; gap: 2px; font-size: 12px; margin-top: 10px; align-items: flex-start; }
}

/* ---------- Danh sách ---------- */
.list-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: #fff; border: 0; border-bottom: 1px solid var(--line); padding: 14px 16px; min-height: 64px;
}
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .t { font-weight: 800; }
.list-item .chev { color: #94a3b8; font-size: 26px; }
.list { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 14px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 700; word-break: break-word; }
.audit-item { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.audit-item:last-child { border-bottom: 0; }
.audit-meta { font-size: 14px; color: var(--muted); }
.act { display: inline-block; font-size: 13px; font-weight: 800; padding: 2px 8px; border-radius: 6px; margin-right: 6px; }
.act-create { background: var(--green-bg); color: var(--green); }
.act-update { background: var(--amber-bg); color: var(--amber); }
.act-delete { background: var(--red-bg); color: var(--red); }
.act-other { background: #e0e7ff; color: var(--navy); }
.diff { font-size: 15px; margin-top: 4px; }
.diff del { color: var(--red); } .diff ins { color: var(--green); text-decoration: none; font-weight: 700; }

.switch-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: 0; }
.switch-row .grow { flex: 1; }
.switch { position: relative; width: 64px; height: 36px; flex: none; border: 0; border-radius: 999px; background: #cbd5e1; }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch.on { background: var(--green); }
.switch.on::after { left: 32px; }

/* ---------- Hộp thoại ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 42, .55);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 20px 16px; padding-bottom: calc(20px + env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 20px; }
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h2 { margin-top: 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--text); color: #fff; padding: 12px 20px; border-radius: 12px; font-weight: 600;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.error { background: var(--red); }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

@media (min-width: 700px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
}

@media print {
  .topbar, .toolbar, .no-print, .bottom-bar { display: none !important; }
  body { background: #fff; }
  .app { padding: 0; max-width: none; }
  .poster-scroll { overflow: visible; margin: 0; padding: 0; }
  .poster { width: 100%; box-shadow: none; padding: 0; }
  .print-only { display: block !important; }
  .screen-only { display: none !important; }
}
.print-only { display: none; }
