/* ХЗ-Пампасы — стили */
:root {
  color-scheme: light;
  --bg: #f4f3ee;
  --surface: #fcfcfb;
  --surface-2: #efeee8;
  --border: #dddbd2;
  --text: #1b1b18;
  --text-2: #52514e;
  --muted: #7a7973;
  --brand: #4d5a26;
  --brand-ink: #ffffff;
  --brand-soft: #e6ead6;
  --accent: #8a6d00;
  --win-bg: #fff4cf;
  --win-border: #e0b93a;
  --win-ink: #6b4f00;
  --link: #2f5d9e;
  --danger: #b3261e;
  --ok: #1f6f3d;
  --grid: #e7e5de;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948;
  --seq-1: #cde2fb; --seq-2: #86b6ef; --seq-3: #3987e5; --seq-4: #1c5cab;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #34342f;
    --text: #f2f1ea; --text-2: #c3c2b7; --muted: #8f8e86;
    --brand: #8fa24a; --brand-ink: #11130a; --brand-soft: #2a3017;
    --accent: #e0b93a; --win-bg: #3a2f0a; --win-border: #a9831b; --win-ink: #f5d77a;
    --link: #7fb0f0; --danger: #ff8a80; --ok: #7fd49a; --grid: #2c2c29;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --seq-1: #1c3350; --seq-2: #184f95; --seq-3: #2a78d6; --seq-4: #86b6ef;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #34342f;
  --text: #f2f1ea; --text-2: #c3c2b7; --muted: #8f8e86;
  --brand: #8fa24a; --brand-ink: #11130a; --brand-soft: #2a3017;
  --accent: #e0b93a; --win-bg: #3a2f0a; --win-border: #a9831b; --win-ink: #f5d77a;
  --link: #7fb0f0; --danger: #ff8a80; --ok: #7fd49a; --grid: #2c2c29;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --seq-1: #1c3350; --seq-2: #184f95; --seq-3: #2a78d6; --seq-4: #86b6ef;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.7rem; margin: .2em 0 .4em; line-height: 1.2; }
h2 { font-size: 1.2rem; margin: 1.6em 0 .6em; }
h3 { font-size: 1.02rem; margin: 1em 0 .4em; }
small, .muted { color: var(--muted); }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 40px; min-height: 70vh; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* header */
.site-header { background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 20; }
.header-row { display: flex; align-items: center; gap: 18px; min-height: 58px; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; font-weight: 700; font-size: 1.15rem; letter-spacing: .01em; }
.brand:hover { text-decoration: none; }
.brand small { display: block; font-weight: 400; font-size: .72rem; opacity: .8; color: inherit; }
.brand-mark { width: 30px; height: 30px; flex: none; }
.main-nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.main-nav a { color: inherit; opacity: .85; padding: 6px 10px; border-radius: 6px; font-size: .93rem; }
.main-nav a:hover { opacity: 1; background: rgba(255,255,255,.12); text-decoration: none; }
.main-nav a.active { opacity: 1; background: rgba(255,255,255,.2); font-weight: 600; }
.header-tools { display: flex; align-items: center; gap: 8px; }
.theme-btn, .nav-toggle { background: transparent; border: 1px solid rgba(255,255,255,.35); color: inherit; border-radius: 6px; padding: 4px 9px; cursor: pointer; font-size: 1rem; }
.admin-link { color: inherit; font-size: .9rem; white-space: nowrap; }
.admin-link.muted { opacity: .8; color: inherit; }
.nav-toggle { display: none; }
@media (max-width: 900px) {
  .nav-toggle { display: block; margin-left: auto; }
  .main-nav { display: none; order: 5; flex-basis: 100%; flex-direction: column; padding-bottom: 10px; }
  body.nav-open .main-nav { display: flex; }
  .header-row { flex-wrap: wrap; }
  .brand small { display: none; }
}

.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; padding: 18px 0 28px; }
.site-footer .wrap { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font-size: 1.9rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--text-2); font-size: .88rem; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.page-head p { margin: 0; color: var(--text-2); }
.crumbs { font-size: .88rem; color: var(--muted); margin-bottom: 4px; }

/* tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.data th, table.data td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { font-weight: 600; color: var(--text-2); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); position: sticky; top: 0; }
table.data th a { color: inherit; }
table.data th.sorted { color: var(--text); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; }
table.data tr.win-row { background: var(--win-bg); }
table.data tr.win-row:hover { background: var(--win-bg); filter: brightness(.98); }
table.data tr.dim td { color: var(--muted); }
.rank { color: var(--muted); width: 2.5em; }

/* badges & pills */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: .86rem; white-space: nowrap; color: var(--text); }
a.pill:hover { text-decoration: none; border-color: var(--text-2); }
.pill.win { background: var(--win-bg); border-color: var(--win-border); color: var(--win-ink); font-weight: 600; }
.pill.unknown { border-style: dashed; color: var(--muted); }
.badge { display: inline-block; font-size: .72rem; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); vertical-align: middle; font-weight: 600; letter-spacing: .02em; }
.badge.cmd { background: var(--brand-soft); color: var(--text); border-color: var(--brand); }
.badge.org { background: transparent; }
.badge.win { background: var(--win-bg); color: var(--win-ink); border-color: var(--win-border); }
.trophy { font-style: normal; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }

/* bar in table */
.bar { position: relative; height: 8px; background: var(--surface-2); border-radius: 4px; min-width: 80px; overflow: hidden; }
.bar > span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--series-1); border-radius: 4px; }
.pct-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.pct-cell .bar { width: 90px; }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin: 10px 0 16px; }
.filters label { display: flex; flex-direction: column; font-size: .8rem; color: var(--text-2); gap: 3px; }
input, select, textarea, button, .btn { font: inherit; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 7px; padding: 7px 10px; min-height: 36px;
}
textarea { width: 100%; min-height: 110px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--series-1); outline-offset: 0; border-color: transparent; }
.btn, button.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--brand); color: var(--brand-ink); border: 1px solid var(--brand); border-radius: 7px; padding: 7px 14px; cursor: pointer; min-height: 36px; font-weight: 600; }
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); font-weight: 500; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); font-weight: 500; }
.btn.small { padding: 3px 9px; min-height: 28px; font-size: .85rem; }
.btn-link { background: none; border: none; color: var(--link); cursor: pointer; padding: 0; }
.btn-link.danger { color: var(--danger); }

/* games list */
.game-list { display: flex; flex-direction: column; gap: 10px; }
.game-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; display: grid; grid-template-columns: 76px 1fr; gap: 14px; }
.game-no { font-size: 1.6rem; font-weight: 800; color: var(--brand); line-height: 1; font-variant-numeric: tabular-nums; }
.game-no small { display: block; font-size: .72rem; font-weight: 500; color: var(--muted); margin-top: 4px; }
.game-title { font-weight: 600; margin-bottom: 6px; }
.game-title .muted { font-weight: 400; }
.game-teams { display: flex; flex-wrap: wrap; gap: 6px; }
details.roster summary { cursor: pointer; color: var(--text-2); font-size: .86rem; margin-top: 8px; }
.roster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-top: 8px; }
.roster-box { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: .9rem; }
.roster-box.win { border-color: var(--win-border); background: var(--win-bg); }
.roster-box h4 { margin: 0 0 4px; font-size: .92rem; }
.roster-box ul { list-style: none; margin: 0; padding: 0; }
.roster-box li { padding: 1px 0; }

/* team cards on game page */
.team-cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.team-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.team-col.win { border: 2px solid var(--win-border); background: linear-gradient(var(--win-bg), var(--surface) 90px); }
.team-col h3 { margin: 0 0 2px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.team-col ol { margin: 8px 0 0; padding-left: 1.4em; }
.team-col li { padding: 2px 0; }

.chart-box { position: relative; height: 320px; }
.chart-box.tall { height: 420px; }
.chart-note { font-size: .82rem; color: var(--muted); margin-top: 6px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--border); background: var(--surface); }
.flash-ok { border-color: var(--ok); }
.flash-error { border-color: var(--danger); color: var(--danger); }
.note { background: var(--surface-2); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 4px; font-size: .92rem; }

/* matrix */
.matrix { border-collapse: separate; border-spacing: 2px; font-size: .75rem; }
.matrix th { font-weight: 500; color: var(--muted); padding: 0 2px; }
.matrix th.team { text-align: right; white-space: nowrap; padding-right: 8px; color: var(--text); font-size: .82rem; position: sticky; left: 0; background: var(--bg); }
.matrix td { width: 16px; height: 16px; border-radius: 3px; background: var(--surface-2); padding: 0; }
.matrix td.p { background: var(--seq-2); }
.matrix td.w { background: var(--win-border); box-shadow: inset 0 0 0 2px var(--win-ink); }
.matrix td a { display: block; width: 100%; height: 100%; }
.matrix .vhead { writing-mode: vertical-rl; transform: rotate(180deg); height: 30px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--text-2); align-items: center; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; }

.search-row { display: flex; gap: 8px; }
.two-col { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .two-col { grid-template-columns: minmax(0, 1fr); } }

/* admin */
.admin-nav { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.admin-nav a { padding: 6px 12px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.admin-nav a.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.form-grid label, .form-row label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--text-2); }
.form-row { margin: 12px 0; }
.form-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
.inline-form { display: inline; }
.login-box { max-width: 380px; margin: 40px auto; }
.login-box label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: .9rem; }
.login-box input { width: 100%; }
.help { font-size: .82rem; color: var(--muted); }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin: 0 0 12px; }
legend { padding: 0 6px; color: var(--text-2); font-size: .88rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.part-row { display: grid; grid-template-columns: minmax(80px, 1.2fr) 92px minmax(80px, 1fr) minmax(60px, .8fr) auto auto; gap: 4px; align-items: center; padding: 3px 0; border-bottom: 1px dashed var(--border); }
.part-row select, .part-row input { min-height: 28px; padding: 2px 5px; font-size: .82rem; min-width: 0; }
.part-nick { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.kpi { display: block; color: inherit; }
a.kpi:hover { text-decoration: none; border-color: var(--brand); }
.team-cols .team-col textarea { margin-bottom: 6px; }
.team-cols.wide { grid-template-columns: repeat(auto-fill, minmax(min(460px, 100%), 1fr)); }
.two-col, .grid { align-items: start; }
