@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-strong: #edf4f7;
  --ink: #101828;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #d9e2ea;
  --line-soft: #e8eef3;
  --nav: #0f172a;
  --nav-soft: #1e293b;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --blue: #2563eb;
  --green: #059669;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 8px 22px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Be Vietnam Pro", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

button:hover { border-color: #b7c5d1; background: #f8fbfd; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.16);
  border-color: var(--blue);
}

input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
}

textarea { min-height: 92px; padding: 10px 12px; resize: vertical; }
select { appearance: auto; }

.hidden { display: none !important; }
.readonly .admin-only { display: none !important; }
.primary { background: var(--teal) !important; border-color: var(--teal) !important; color: #ffffff !important; }
.primary:hover { background: var(--teal-dark) !important; border-color: var(--teal-dark) !important; }
.danger { background: #fff1f2 !important; border-color: #fecdd3 !important; color: #be123c !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #eef6fb 0%, #f7fafc 52%, #edf7f4 100%);
}

.login-panel {
  width: min(430px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-mark, .side-brand span {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #0f766e;
  color: #ffffff;
  font-weight: 800;
  letter-spacing: 0;
}

.login-panel h1 { margin: 16px 0 6px; font-size: 28px; line-height: 1.18; }
.login-panel p { margin: 0 0 20px; color: var(--muted); }
.login-panel label, .modal-form label, .club-builder label { display: grid; gap: 6px; font-weight: 700; color: var(--ink); }
.login-panel label { margin-top: 12px; }
.login-panel button { width: 100%; margin-top: 18px; }
.login-panel small, .modal-form label small, .club-builder small, .data-table small { color: var(--muted); font-size: 12px; font-weight: 500; line-height: 1.4; }
.error { margin-top: 10px; color: var(--red); font-weight: 700; }

.app { min-height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 20px;
  background: var(--nav);
  color: #dbeafe;
}

.side-brand { display: flex; align-items: center; gap: 12px; }
.side-brand strong { color: #ffffff; font-size: 18px; font-weight: 800; }
nav { display: grid; gap: 6px; }

.nav {
  height: 42px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #b6c5d6;
  text-align: left;
  padding: 0 12px;
  font-weight: 700;
}

.nav:hover { background: rgba(255, 255, 255, 0.08); color: #ffffff; }
.nav.active { background: #ffffff; color: var(--nav); box-shadow: 0 10px 22px rgba(0, 0, 0, 0.16); }

.side-note {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.side-note span { color: #cbd5e1; font-size: 13px; }
.side-note button { background: var(--nav-soft); border-color: rgba(255, 255, 255, 0.1); color: #ffffff; }

main { min-width: 0; padding: 24px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 20px;
}

.topbar h1 { margin: 0; font-size: 30px; line-height: 1.18; font-weight: 800; }
.topbar p { max-width: 760px; margin: 7px 0 0; color: var(--muted); }
.toolbar { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.toolbar select { width: min(300px, 100%); }

.view { display: none; }
.view.active { display: block; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.metric {
  position: relative;
  overflow: hidden;
  min-height: 112px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  padding: 18px;
}

.metric::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--blue); }
.metric.live::before, .metric.running::before { background: var(--amber); }
.metric.active::before, .metric.published::before { background: var(--green); }
.metric span { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.metric strong { display: block; margin-top: 10px; color: var(--ink); font-size: 32px; line-height: 1; font-weight: 800; }

.grid.two { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr); gap: 14px; }
.panel {
  margin-bottom: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  padding: 16px;
}

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel h2 { margin: 0; font-size: 18px; line-height: 1.25; font-weight: 800; }
.panel h3 { margin: 18px 0 10px; font-size: 15px; font-weight: 800; }
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: #e7f5f2;
  color: var(--teal-dark);
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.pill.live { background: #fff4e5; color: #b45309; }

.empty { border: 1px dashed #cbd5e1; border-radius: 8px; background: var(--surface-soft); color: var(--muted); padding: 18px; }

.match-list { display: grid; gap: 10px; }
.match-card {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}
.match-card.pro { background: #fbfdff; }
.match-top, .match-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; }
.match-top { margin-bottom: 10px; }
.match-meta { margin-top: 10px; }
.versus { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 12px; }
.player-side { display: flex; align-items: center; gap: 9px; min-width: 0; }
.player-side.right { justify-content: flex-end; text-align: right; }
.player-side b, .rank-row b, .member-card h3, .player-card h3 { overflow-wrap: anywhere; }
.player-side small { display: block; color: var(--muted); font-size: 12px; }
.player-side.serving b::after { content: " · giao"; color: var(--amber); font-size: 12px; font-weight: 800; }
.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
}
.score {
  min-width: 88px;
  border-color: #cdddea !important;
  background: #ffffff !important;
  color: var(--ink) !important;
  font-size: 18px;
  font-weight: 800;
}

.ranking-list { display: grid; gap: 10px; }
.rank-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 10px 12px;
}
.rank-row > strong:first-child { color: var(--muted); }
.rank-row > div { display: flex; align-items: center; gap: 9px; min-width: 0; }
.rank-row small { display: block; color: var(--muted); font-size: 12px; }

.table-wrap { width: 100%; overflow: auto; border-radius: 8px; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 720px; }
.data-table th, .data-table td { border-bottom: 1px solid var(--line-soft); padding: 11px 12px; text-align: left; vertical-align: middle; }
.data-table th { position: sticky; top: 0; z-index: 1; background: #f3f7fa; color: var(--ink-soft); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.data-table td { background: #ffffff; }
.data-table tr:hover td { background: #fbfdff; }
.data-table button { min-height: 32px; padding: 0 10px; }

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: #edf2f7;
  color: var(--ink-soft);
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.status.live, .status.running { background: #fff4e5; color: #b45309; }
.status.finished, .status.completed, .status.confirmed, .status.active { background: #e7f7ef; color: #047857; }
.status.cancelled, .status.inactive { background: #fff1f2; color: #be123c; }
.status.scheduled, .status.waitlist { background: #eff6ff; color: #1d4ed8; }

.player-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.player-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  padding: 14px;
}
.player-card-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.player-card h3, .member-card h3 { margin: 0; font-size: 15px; line-height: 1.3; }
.player-card p, .member-card p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.stat-line { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); }
.stat-line b { color: var(--ink); }
.progress { height: 7px; overflow: hidden; border-radius: 999px; background: #edf2f7; }
.progress i { display: block; height: 100%; background: var(--teal); }
.card-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.detail-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}
.detail-actions span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.detail-actions > div:last-child { display: flex; gap: 8px; flex-wrap: wrap; }
.tournament-detail.muted { color: var(--muted); }
.config-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr); gap: 14px; }
.rules-box { min-height: 118px; border: 1px solid var(--line-soft); border-radius: 8px; background: var(--surface-soft); padding: 12px; color: var(--ink-soft); white-space: pre-wrap; }

.member-card {
  display: grid;
  grid-template-columns: auto 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  padding: 12px;
  cursor: pointer;
}
.member-card:hover { border-color: #b8c8d6; }
.member-card input, .checkline input { width: 18px; height: 18px; accent-color: var(--teal); }
.member-card small { color: var(--muted); font-size: 12px; }
.club-builder { display: grid; gap: 12px; }
.club-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.checkline { display: flex !important; align-items: center; gap: 8px; font-weight: 700; }
.checkline input { flex: 0 0 auto; }

.scoreboard { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.score-player {
  min-height: 154px !important;
  display: grid !important;
  place-items: center !important;
  border: 0 !important;
  border-radius: 8px !important;
  background: var(--nav) !important;
  color: #ffffff !important;
  padding: 14px !important;
  text-align: center;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.score-player.right { background: var(--teal-dark) !important; }
.score-player strong { display: block; font-size: 64px; line-height: 1; font-weight: 800; }
.score-player span { display: block; font-weight: 800; }
.score-player small { color: rgba(255, 255, 255, 0.76); }
.score-player.serving { outline: 4px solid #f59e0b; outline-offset: -4px; }
.score-title { border: 1px solid var(--line-soft); border-radius: 7px; background: var(--surface-soft); padding: 10px 12px; font-weight: 800; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid label { min-width: 0; }

dialog {
  width: min(520px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 0;
}
dialog::backdrop { background: rgba(15, 23, 42, 0.42); }
dialog:has(.wide) { width: min(780px, calc(100vw - 28px)); }
.modal-form { display: grid; gap: 12px; padding: 18px; }
.modal-form h3 { margin: 0 0 2px; font-size: 19px; line-height: 1.25; }
.modal-form menu { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin: 8px 0 0; padding: 0; }
.modal-form input[type="color"] { padding: 4px; }

@media (max-width: 1100px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .config-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; gap: 14px; }
  nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-note { margin-top: 0; }
  .topbar { flex-direction: column; }
  .toolbar { justify-content: flex-start; width: 100%; }
  .toolbar select { flex: 1 1 240px; }
}

@media (max-width: 560px) {
  body { font-size: 13px; }
  main { padding: 14px; }
  .sidebar { padding: 14px; }
  nav { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 24px; }
  .metrics { grid-template-columns: 1fr; }
  .panel { padding: 13px; }
  .panel-head, .detail-actions { align-items: flex-start; flex-direction: column; }
  .versus { grid-template-columns: 1fr; gap: 8px; }
  .player-side.right { justify-content: flex-start; text-align: left; flex-direction: row-reverse; }
  .score { width: 100%; text-align: center; }
  .match-top, .match-meta { align-items: flex-start; flex-direction: column; }
  .rank-row { grid-template-columns: 36px minmax(0, 1fr); }
  .rank-row > strong:last-child { grid-column: 2; justify-self: start; }
  .form-grid, .scoreboard { grid-template-columns: 1fr; }
  .score-player { min-height: 132px !important; }
  .score-player strong { font-size: 52px; }
  .member-card { grid-template-columns: auto 34px minmax(0, 1fr); }
  .member-card button { grid-column: 2 / 4; justify-self: start; }
  .modal-form menu button { flex: 1 1 120px; }
}
