:root {
  --navy: #0b1f33;
  --navy-2: #13304d;
  --blue: #1d5fd6;
  --blue-50: #eef4ff;
  --blue-100: #d9e6ff;
  --red: #d62839;
  --green: #0f8a5f;
  --amber: #b45309;
  --amber-50: #fff7e6;
  --bg: #f3f5f9;
  --surface: #fff;
  --text: #0f172a;
  --muted: #5b6577;
  --faint: #98a2b3;
  --line: #e4e8ef;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --sidebar: 240px;
  --sidebar-mini: 72px;
  --nav-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--blue); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.ic {
  width: 20px; height: 20px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ================= LAYOUT ================= */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { flex: 1; padding: 24px; width: 100%; max-width: 1320px; margin: 0 auto; }

/* ================= SIDEBAR ================= */
.sidebar {
  width: var(--sidebar);
  background: var(--navy);
  color: #cbd5e1;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  transition: width .25s ease;
  flex-shrink: 0;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: #fff; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; white-space: nowrap; }
.brand-text strong { color: #fff; font-size: 15px; font-weight: 700; }
.brand-text span { font-size: 12.5px; color: #8ea3bd; }

.nav { display: flex; flex-direction: column; gap: 4px; padding: 16px 12px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: #cbd5e1; text-decoration: none; font-weight: 500;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.active { background: var(--blue); color: #fff; }
.sidebar-footer { padding: 16px; font-size: 12px; color: #6b7f99; white-space: nowrap; border-top: 1px solid rgba(255,255,255,.08); }

.sidebar.mini { width: var(--sidebar-mini); }
.sidebar.mini .brand { justify-content: center; padding: 20px 0; }
.sidebar.mini .brand-text,
.sidebar.mini .nav-link span,
.sidebar.mini .sidebar-footer { display: none; }
.sidebar.mini .nav-link { justify-content: center; }

/* ================= TOPBAR ================= */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 19px; font-weight: 700; line-height: 1.25; color: var(--navy); }
.topbar-sub { font-size: 12.5px; color: var(--muted); }
.topbar-logo { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.icon-btn {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; color: var(--navy);
}
.icon-btn:hover { background: var(--bg); }
.only-mobile { display: none; }

/* ================= CARD ================= */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }

/* ================= FORM ================= */
.register-layout { display: grid; grid-template-columns: minmax(0, 640px) minmax(240px, 340px); gap: 20px; justify-content: center; align-items: start; }
.form-card { display: flex; flex-direction: column; gap: 18px; padding: 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13.5px; font-weight: 600; color: var(--navy-2); }
.input-wrap { position: relative; }
.input-wrap .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; width: 18px; height: 18px; }
.input-wrap input {
  width: 100%; height: 46px;
  padding: 0 12px 0 40px;
  border: 1px solid #d3d9e3; border-radius: 10px; background: #fff;
  font-size: 15px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input-wrap input::placeholder { color: #a9b2c0; }
.input-wrap input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29,95,214,.15); }
.input-wrap input:focus + .ic, .input-wrap:focus-within .ic { color: var(--blue); }
.field.invalid input { border-color: var(--red); }
.field.invalid .hint { color: var(--red); }
.hint { font-size: 12.5px; color: var(--muted); }

.note-card h2 { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--navy); margin-bottom: 10px; }
.note-card h2 .ic { color: var(--blue); }
.note-card ul { padding-left: 18px; display: flex; flex-direction: column; gap: 8px; color: var(--muted); font-size: 14px; }
.note-card b { color: var(--text); font-weight: 600; }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; font-size: 14px; font-weight: 500; }
.alert .ic { margin-top: 1px; }
.alert.ok { background: #e9f8f1; color: #065f46; border: 1px solid #a7e3c8; }
.alert.err { background: #fdecee; color: #8a1422; border: 1px solid #f5b5bd; }

/* ================= BUTTONS ================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: 10px;
  font-weight: 600; font-size: 14.5px; cursor: pointer; border: 1px solid transparent;
  transition: background .15s, opacity .15s;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #174fb5; }
.btn-primary:disabled { opacity: .65; cursor: progress; }
.btn-block { width: 100%; height: 50px; font-size: 16px; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--navy); }
.btn-ghost:hover { background: var(--bg); }
.btn.loading .ic { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ================= TOOLBAR & STATS ================= */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search { position: relative; flex: 1 1 260px; }
.search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); width: 18px; height: 18px; }
.search input { width: 100%; height: 42px; padding: 0 12px 0 38px; border: 1px solid #d3d9e3; border-radius: 10px; outline: none; }
.search input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29,95,214,.15); }
.select { height: 42px; padding: 0 12px; border: 1px solid #d3d9e3; border-radius: 10px; background: #fff; font-weight: 500; cursor: pointer; min-width: 140px; }
.segmented { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.segmented button { white-space: nowrap; border: 0; background: transparent; padding: 0 14px; height: 34px; border-radius: 8px; font-weight: 600; font-size: 13.5px; color: var(--muted); cursor: pointer; }
.segmented button.on { background: var(--surface); color: var(--navy); box-shadow: 0 1px 3px rgba(15,23,42,.1); }

.stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 16px; }
.stat { display: flex; align-items: baseline; gap: 8px; padding: 8px 14px; border-radius: 10px; background: var(--blue-50); color: var(--navy-2); font-size: 13px; }
.stat strong { font-size: 18px; color: var(--blue); font-variant-numeric: tabular-nums; }
.stat.warn { background: var(--amber-50); }
.stat.warn strong { color: var(--amber); }

/* ================= TABLE ================= */
.table-wrap { overflow: auto; max-height: calc(100vh - 290px); border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  position: sticky; top: 0; z-index: 2;
  background: #f7f9fc; color: var(--muted);
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  text-align: left; padding: 11px 12px; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfd; }
tr.past td { color: var(--faint); }
tr.past .club, tr.past .date { color: var(--faint); background: transparent; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.c { text-align: center; }
.nowrap { white-space: nowrap; }
.idx { color: var(--faint); width: 44px; }

.club { display: inline-block; font-weight: 600; color: var(--navy); }
.club small { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; }
.date { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.time { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.tag.soon { background: #fdecee; color: var(--red); }
.tag.pending { background: var(--amber-50); color: var(--amber); }
.tag.done { background: #e9f8f1; color: var(--green); }
.qty { font-weight: 700; color: var(--blue); }

.tel { color: var(--green); text-decoration: none; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tel:hover { text-decoration: underline; }
.person { min-width: 130px; font-size: 13px; line-height: 1.35; }
.person b { display: block; font-weight: 600; color: var(--text); }
.person .code { display: block; color: var(--faint); font-size: 11.5px; }
.empty-dash { color: #cfd5de; }

.state { text-align: center; padding: 48px 16px; color: var(--muted); }
.state .ic { width: 28px; height: 28px; color: var(--faint); margin-bottom: 8px; }
.state.loading .ic { animation: spin .8s linear infinite; }
.state.error { color: var(--red); }

/* ================= CARD LIST (mobile) ================= */
.cards { display: none; flex-direction: column; gap: 10px; }
.item { border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--surface); }
.item.past { opacity: .6; }
.item-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
.item-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 13.5px; }
.item-meta span { display: inline-flex; align-items: center; gap: 5px; }
.item-meta .ic { width: 15px; height: 15px; }
.roles { display: grid; grid-template-columns: 1fr; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.role { display: grid; grid-template-columns: 92px 1fr; gap: 8px; font-size: 13.5px; align-items: baseline; }
.role > span { color: var(--muted); font-size: 12.5px; }

/* ================= RESPONSIVE ================= */
@media (max-width: 1024px) {
  .register-layout { grid-template-columns: minmax(0, 640px); }
}

@media (max-width: 768px) {
  body { font-size: 15px; }
  .only-mobile { display: block; }
  .only-desktop { display: none; }
  .hide-sm { display: none; }

  .sidebar {
    position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; top: auto;
    width: 100% !important; height: auto;
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid rgba(255,255,255,.08);
  }
  .brand, .sidebar-footer { display: none !important; }
  .nav { flex-direction: row; padding: 6px; gap: 4px; }
  .nav-link { flex: 1; flex-direction: column; gap: 2px; padding: 8px 4px; font-size: 11.5px; justify-content: center; }
  .nav-link span { display: inline !important; }
  .nav-link.active { background: rgba(29,95,214,.9); }

  .topbar { padding: 10px 16px; }
  .topbar h1 { font-size: 17px; }
  .content { padding: 12px 12px calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); }
  .card { padding: 14px; }
  .form-card { padding: 16px; gap: 16px; }
  .grid-2 { grid-template-columns: 1fr; gap: 16px; }
  .input-wrap input { font-size: 16px; } /* tránh iOS tự zoom */

  .toolbar .search { flex-basis: 100%; }
  .segmented { flex: 0 0 auto; }
  .segmented button { flex: 1; }
  .select { flex: 1; min-width: 0; }
  .stats { margin: 12px 0; }
  .stat { flex: 1; flex-direction: column; gap: 0; padding: 8px 12px; }

  .table-wrap { display: none; }
  .cards { display: flex; }
}

/* ================= CHỐNG VỠ TRÊN MOBILE / iOS SAFARI ================= */
html, body { max-width: 100%; overflow-x: hidden; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.input-wrap { min-width: 0; }
.input-wrap input { min-width: 0; max-width: 100%; display: block; }
/* iOS: ô date/time có độ rộng cố định, chữ căn giữa, cao lệch → ép về như ô thường */
.input-wrap input[type="date"],
.input-wrap input[type="time"] {
  -webkit-appearance: none; appearance: none;
  line-height: 44px; min-height: 46px; text-align: left;
}
.input-wrap input::-webkit-date-and-time-value { text-align: left; margin: 0; }
.input-wrap input::-webkit-datetime-edit { padding: 0; }
.toolbar > * { min-width: 0; }
.item, .item-meta span, .role div, td { overflow-wrap: anywhere; }
.item-head .tag, .item-head .qty { flex-shrink: 0; }

@media (max-width: 768px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .stats { flex-wrap: nowrap; }
  .stat { min-width: 0; }
  .stat span { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .role { grid-template-columns: 84px minmax(0, 1fr); }
  .person { min-width: 0; }
  .nav-link { min-width: 0; }
  .nav-link span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
}
@media (max-width: 360px) {
  .content { padding-left: 8px; padding-right: 8px; }
  .card { padding: 12px; }
  .segmented button { padding: 0 10px; }
  .stat strong { font-size: 16px; }
}

/* v3: toolbar 2 hàng + thống kê dạng lưới trên mobile */
@media (max-width: 768px) {
  .toolbar { gap: 8px; }
  .toolbar .search { order: 0; flex: 1 1 0; }
  .toolbar [data-reload] { order: 1; flex: 0 0 42px; padding: 0; }
  .toolbar .segmented { order: 2; flex: 1 1 0; }
  .toolbar .select { order: 3; flex: 1 1 0; }
  .toolbar .search { flex-basis: 0 !important; }
  .toolbar::after { content: ""; order: 1; flex-basis: 100%; height: 0; }
  .stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; }
  .stat { width: auto; }
  .stat span { white-space: normal; line-height: 1.25; overflow: visible; }
  .topbar > div { min-width: 0; }
  .topbar h1, .topbar-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 768px) {
  .toolbar .segmented { flex: 0 0 auto; }
  .toolbar .segmented button { flex: 0 0 auto; padding: 0 12px; }
  .toolbar .select { flex: 1 1 0; padding: 0 8px; text-overflow: ellipsis; }
}

/* ================= COMBOBOX CHỌN CLB ================= */
.combo { position: relative; scroll-margin-top: 76px; }
.combo .input-wrap input { padding-right: 44px; text-overflow: ellipsis; cursor: pointer; }
.combo.open .input-wrap input { cursor: text; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29,95,214,.15); }
.combo-btn {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 8px;
}
.combo-btn .ic { position: static; transform: none; transition: transform .2s; width: 18px; height: 18px; }
.combo.open .combo-btn .ic { transform: rotate(180deg); color: var(--blue); }
.combo-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 6px);
  max-height: min(320px, 50vh); overflow-y: auto; overscroll-behavior: contain;
  list-style: none; padding: 6px; margin: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(15,23,42,.16);
}
.combo-list li[role=option] {
  display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; column-gap: 10px;
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
}
.combo-list li.active { background: var(--blue-50); }
.combo-list .opt-main { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-list .opt-sub { grid-column: 1; font-size: 12.5px; color: var(--muted); }
.combo-list .opt-check { grid-column: 2; grid-row: 1 / span 2; width: 18px; height: 18px; color: var(--blue); visibility: hidden; }
.combo-list li.selected .opt-check { visibility: visible; }
.combo-list li.selected .opt-main { color: var(--blue); }
.combo-list mark { background: #fff1b8; color: inherit; border-radius: 2px; padding: 0 1px; }
.combo-empty { padding: 14px 10px; color: var(--muted); font-size: 14px; text-align: center; }
@media (max-width: 768px) {
  .combo-list { max-height: 45vh; }
  .combo-list li[role=option] { padding: 11px 10px; }
}

/* ================= TẮT PHÓNG TO ================= */
/* Chặn double-tap zoom; iOS không tự zoom khi ô nhập có cỡ chữ >= 16px */
html, body { touch-action: pan-x pan-y; }
a, button, input, select, label, .nav-link, li[role=option] { touch-action: manipulation; }
@media (max-width: 768px) {
  input, select, textarea,
  .search input, .select, .input-wrap input { font-size: 16px !important; }
}
