:root {
    --navy: #032b52;
    --navy-2: #064875;
    --cyan: #00c8e8;
    --orange: #ff8a1f;
    --lime: #d8ef00;
    --ink: #0f172a;
    --muted: #526174;
    --line: #cbd5e1;
    --soft: #edf5fa;
    --paper: #fff;
    --good: #17663a;
    --good-bg: #dcfce7;
    --bad: #9f1d2c;
    --bad-bg: #fee2e2;
    --warn: #854d0e;
    --warn-bg: #fef3c7;
    --radius: 18px;
    color-scheme: light;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Multi-category events reuse the established tournament colors and components. */
.event-fields { border: 0; padding: 0; margin: 0; min-width: 0; }
.event-fields > section, .event-categories { margin-bottom: 20px; }
.event-fields fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-width: 0; }
.event-fields legend { color: var(--navy); font-weight: 800; }
.event-fields .event-check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 6px 0; }
.event-check input, [data-event-select], [data-slot-enabled] { width: 22px; height: 22px; min-height: 22px; accent-color: var(--navy); }
.event-category { margin: 12px 0; }
.event-category .grid + .grid, #event-create-form .card > .grid + .grid, #event-settings-form .grid + .grid { margin-top: 14px; }
.event-category-table { min-width: 760px; }
.event-schedule { min-width: 880px; }
.event-schedule td:first-child { min-width: 250px; }
.event-schedule input[type="number"] { width: 78px; }
.event-schedule input[type="datetime-local"] { min-width: 215px; }
.event-athlete-list { display: grid; gap: 12px; }
.event-athlete-row { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); padding: 10px 0; }
.event-athlete-row input { width: 22px; height: 22px; }
.event-athlete-row span { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 650px) {
    .event-fields .grid.three, .event-fields .grid.two, #event-settings-form .grid { grid-template-columns: minmax(0,1fr); }
    .event-category { padding: 15px; }
    .event-fields .toolbar { align-items: start; }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #e7f0f6; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: linear-gradient(155deg, #f7fbfd 0%, #e3eef5 100%); }
button, input, select, textarea { font: inherit; }
button, .button { min-height: 48px; border: 0; border-radius: 12px; padding: 10px 18px; font-weight: 850; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 4px solid #fbbf24; outline-offset: 2px; }
button:disabled { opacity: .52; cursor: not-allowed; }
a { color: #005f8f; font-weight: 750; }
h1, h2, h3 { color: var(--navy); line-height: 1.1; }
h1 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.6rem); }
h2 { margin: 0 0 16px; font-size: clamp(1.35rem, 3vw, 1.9rem); }
h3 { margin: 12px 0; }
p { line-height: 1.5; }

.app-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 76px; padding: 10px max(16px, calc((100vw - 1200px)/2)); color: #fff; background: var(--navy); border-bottom: 5px solid var(--cyan); box-shadow: 0 6px 20px #032b5230; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { width: 52px; height: 52px; object-fit: contain; border-radius: 12px; background: #fff; }
.brand strong { display: block; font-size: 1.18rem; white-space: nowrap; }
.brand small { display: block; color: #d6eef7; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-actions button { min-height: 42px; padding: 8px 12px; background: #ffffff16; color: #fff; border: 1px solid #ffffff55; }
.connection { display: inline-flex; align-items: center; gap: 7px; font-size: .88rem; font-weight: 800; }
.connection::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px #4ade8033; }
.connection.offline::before { background: #f59e0b; box-shadow: 0 0 0 3px #f59e0b33; }

.page { width: min(1200px, 100%); margin: 0 auto; padding: 26px 16px 64px; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 50% 0, #0b6291 0, var(--navy) 46%, #01172e 100%); }
.login-card { width: min(480px, 100%); padding: 30px; border-radius: 24px; background: #fff; box-shadow: 0 28px 80px #0008; }
.login-logo { display: block; width: min(240px, 70%); max-height: 210px; object-fit: contain; margin: 0 auto 18px; }
.lead { color: var(--muted); font-size: 1.05rem; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: 0 8px 24px #0f172a10; }
.card + .card { margin-top: 16px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.primary { background: var(--navy); color: #fff; }
.accent { background: var(--orange); color: #142033; }
.secondary { color: var(--navy); background: #e2edf4; border: 1px solid #a8c4d5; }
.danger { color: #fff; background: var(--bad); }
.ghost { color: var(--navy); background: transparent; border: 1px solid var(--line); }
.small { min-height: 38px; padding: 6px 11px; font-size: .9rem; }
.full { width: 100%; }
label { display: grid; gap: 6px; color: #25364b; font-weight: 780; }
.team-notes-row .participating-teams-field[hidden] { display: none; }
input, select, textarea { width: 100%; min-height: 48px; padding: 10px 12px; color: var(--ink); background: #fff; border: 1px solid #91a5b8; border-radius: 11px; }
input:disabled, select:disabled, textarea:disabled { color: #526174; background: #eef2f6; }
textarea { min-height: 96px; resize: vertical; }
.hint { color: var(--muted); font-size: .88rem; font-weight: 500; }
.required::after { content: " *"; color: var(--bad); }
.notice { padding: 13px 15px; border-left: 5px solid var(--cyan); border-radius: 8px; background: #e9fbff; }
.warning { padding: 13px 15px; color: var(--warn); border-left: 5px solid #f59e0b; border-radius: 8px; background: var(--warn-bg); }
.error { padding: 11px 13px; color: var(--bad); border-radius: 8px; background: var(--bad-bg); font-weight: 780; }
.success { padding: 11px 13px; color: var(--good); border-radius: 8px; background: var(--good-bg); font-weight: 780; }
.status { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 10px; background: #e2e8f0; color: #334155; font-size: .82rem; font-weight: 900; }
.status.running { color: #075985; background: #dbeafe; }
.status.finalized { color: var(--good); background: var(--good-bg); }
.status.dirty { color: var(--warn); background: var(--warn-bg); }
.status.synced { color: var(--good); background: var(--good-bg); }
.metric { padding: 14px; border-radius: 14px; background: var(--soft); }
.metric strong { display: block; color: var(--navy); font-size: 1.5rem; }
.metric span { color: var(--muted); font-size: .88rem; }
.tournament-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(285px, 1fr)); gap: 16px; }
.tournament-card { display: grid; gap: 10px; align-content: start; }
.tournament-card h3 { margin: 0; }
.tournament-card dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 10px; margin: 0; }
.tournament-card dt { color: var(--muted); font-weight: 700; }
.tournament-card dd { margin: 0; font-weight: 750; }

.tabs { display: flex; gap: 7px; overflow-x: auto; margin: 18px 0; padding: 3px 1px 9px; scrollbar-width: thin; }
.tabs button { flex: 0 0 auto; min-height: 42px; color: var(--navy); background: #fff; border: 1px solid var(--line); }
.tabs button.active { color: #fff; background: var(--navy-2); border-color: var(--navy-2); }
.progress { display: flex; align-items: center; gap: 12px; }
.progress meter { width: min(320px, 50vw); height: 20px; }
.participant { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid #e2e8f0; }
.participant:last-child { border-bottom: 0; }
.participant small { display: block; color: var(--muted); }
.participant .number { display: inline-grid; place-items: center; width: 34px; height: 34px; margin-right: 9px; border-radius: 50%; color: #fff; background: var(--navy-2); font-weight: 900; }
.team-row { display: grid; grid-template-columns: auto 1fr auto 1fr minmax(120px, .6fr); gap: 10px; align-items: end; padding: 13px 0; border-bottom: 1px solid #e2e8f0; }
.team-row > strong { align-self: center; white-space: nowrap; }
.versus { align-self: center; color: var(--muted); font-weight: 900; }
.match-section { margin-top: 22px; }
.match-card { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 12px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.match-card + .match-card { margin-top: 10px; }
.side { font-weight: 800; }
.side:last-child { text-align: right; }
.score-box { display: grid; grid-template-columns: 68px auto 68px; align-items: center; gap: 6px; }
.score-box input { min-height: 44px; padding: 8px; text-align: center; font-size: 1.15rem; font-weight: 900; }
.score-box span { font-weight: 900; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; }
table { width: 100%; min-width: 620px; border-collapse: collapse; background: #fff; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #dbe3ea; }
th { color: #fff; background: var(--navy); }
tr:last-child td { border-bottom: 0; }
tr:nth-child(even) td { background: #f6f9fb; }
.place { font-size: 1.15rem; font-weight: 950; color: var(--navy); }
.coupon-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(275px, 1fr)); gap: 16px; }
.coupon { text-align: center; }
.coupon .qr { display: block; width: min(232px, 100%); height: auto; margin: 10px auto; border: 1px solid #d5dde5; }
.coupon .percent { font-size: 2rem; color: var(--navy); font-weight: 950; }
.location-code { letter-spacing: .13em; font-family: ui-monospace, Consolas, monospace; font-size: 1.35rem; font-weight: 950; }
.install-banner { display: none; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.install-banner.visible { display: flex; }
.empty { padding: 32px 18px; text-align: center; color: var(--muted); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid #fff7; border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
    .app-header { position: static; align-items: flex-start; }
    .brand small, .header-actions .username { display: none; }
    .page { padding: 18px 11px 48px; }
    .grid.two, .grid.three { grid-template-columns: 1fr; }
    .card { padding: 17px; }
    .team-row { grid-template-columns: 1fr; align-items: stretch; }
    .team-row > strong { padding-top: 8px; }
    .versus { text-align: center; }
    .match-card { grid-template-columns: 1fr; text-align: center; }
    .side, .side:last-child { text-align: center; }
    .score-box { justify-content: center; }
    .connection span { display: none; }
}

@media print {
    .app-header, .tabs, .actions, button, .install-banner { display: none !important; }
    body { background: #fff; }
    .page { width: 100%; padding: 0; }
    .card { break-inside: avoid; box-shadow: none; }
}
.registration-settings{border:1px solid #d8e2ec;border-radius:14px;padding:18px;margin-top:20px;min-width:0}.registration-settings legend{font-weight:750;padding:0 8px}.registration-settings [hidden]{display:none!important}.registration-settings label{margin-bottom:14px}.registration-settings .hint{display:block;margin-top:5px}

.tournament-code[hidden]{display:none}.tournament-code{font-size:1rem;overflow-wrap:anywhere}.tournament-notes p{margin:6px 0}.tournament-invites form{max-width:600px}

.tournament-invites [hidden]{display:none!important}
