/* Organizing app - its own blue look, deliberately distinct from the green public site. */

:root {
  --bg: #eef4fc;
  --bg-deep: #e2ecf9;
  --surface: #ffffff;
  --surface-soft: #f6f9fe;
  --primary: #1f6fd6;
  --primary-hover: #185bb3;
  --primary-dark: #0f3a75;
  --primary-light: #e3eefc;
  --primary-lighter: #f0f6fe;
  --accent: #4fa3ff;
  --text: #13243b;
  --muted: #5d6f88;
  --border: #d4e2f4;
  --border-strong: #b7cdea;
  --success: #138a5e;
  --success-light: #e1f5ec;
  --warning: #a86a00;
  --warning-light: #fff3d6;
  --danger: #c0392b;
  --danger-light: #fdecea;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --shadow: 0 1px 2px rgba(15, 58, 117, 0.06), 0 6px 20px rgba(15, 58, 117, 0.07);
  --shadow-lg: 0 12px 40px rgba(15, 58, 117, 0.18);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
/* components below set their own display - [hidden] must still win */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-deep) 0, var(--bg) 320px) fixed;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 12px; color: var(--primary-dark); letter-spacing: -0.01em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 10px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Header ---------- */
.org-header {
  position: sticky; top: 0; z-index: 40;
  background: linear-gradient(120deg, #0f3a75 0%, #1f6fd6 70%, #3f8ff0 100%);
  color: #fff;
  box-shadow: 0 4px 18px rgba(15, 58, 117, 0.25);
}
.org-header-inner {
  max-width: 1180px; margin: 0 auto; padding: 12px 16px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
}
.org-brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
.org-logo {
  width: 36px; height: 36px; border-radius: 11px; flex: 0 0 auto;
  background: rgba(255,255,255,0.18); display: grid; place-items: center; font-size: 1.2rem;
}
.org-title { min-width: 0; }
.org-title .kicker { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.8; }
.org-title .name { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.status-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.8rem; font-weight: 600; padding: 4px 10px; border-radius: var(--radius-pill);
  background: rgba(255,255,255,0.16); color: #fff; white-space: nowrap;
}
.status-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: #9fd0ff; }
.status-chip.ok .dot { background: #6ee7b7; }
.status-chip.warn .dot { background: #fcd34d; }
.status-chip.off .dot { background: #fca5a5; }
.org-header .btn-ghost { background: rgba(255,255,255,0.14); color: #fff; }
.org-header .btn-ghost:hover { background: rgba(255,255,255,0.26); }

/* ---------- Tabs ---------- */
.org-tabs {
  max-width: 1180px; margin: 0 auto; padding: 0 16px 10px;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
}
.org-tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; border: none; cursor: pointer; font: inherit; font-weight: 600; font-size: 0.92rem;
  color: rgba(255,255,255,0.86); background: transparent; padding: 7px 14px; border-radius: var(--radius-pill);
  transition: background-color .15s ease, color .15s ease;
}
.tab:hover { background: rgba(255,255,255,0.14); color: #fff; }
.tab.active { background: #fff; color: var(--primary-dark); box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.tab .count { font-size: 0.75rem; opacity: 0.75; margin-left: 4px; }

/* ---------- Layout ---------- */
.org-main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }
.panel[hidden] { display: none; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 16px; border: 1px solid rgba(183, 205, 234, 0.45);
}
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card.soft { background: var(--surface-soft); box-shadow: none; }

.hint {
  font-size: 0.86rem; color: var(--muted); background: var(--primary-lighter);
  border-left: 3px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 8px 12px; margin: 0 0 12px;
}
.hint strong { color: var(--primary-dark); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: var(--radius-pill); padding: 8px 16px;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  background: var(--primary); color: #fff; transition: background-color .15s ease, transform .05s ease, box-shadow .15s ease;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .tab:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn-secondary { background: var(--primary-light); color: var(--primary-dark); }
.btn-secondary:hover { background: #d3e4fa; }
.btn-outline { background: transparent; color: var(--primary); box-shadow: inset 0 0 0 1.5px var(--border-strong); }
.btn-outline:hover { background: var(--primary-lighter); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #a02f23; }
.btn-success { background: var(--success); }
.btn-success:hover { background: #0f704c; }
.btn-sm { padding: 5px 12px; font-size: 0.85rem; }
.btn-icon { padding: 5px 9px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- Forms ---------- */
.field { margin-bottom: 12px; }
.field > label, .label { display: block; font-weight: 600; font-size: 0.86rem; margin-bottom: 4px; color: var(--primary-dark); }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; padding: 8px 11px; font: inherit; color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 111, 214, 0.18); }
.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.inline > .field { margin-bottom: 0; flex: 1 1 150px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.seg { display: inline-flex; background: var(--primary-light); padding: 3px; border-radius: var(--radius-pill); gap: 2px; flex-wrap: wrap; }
.seg button { border: none; background: transparent; font: inherit; font-size: 0.85rem; font-weight: 600; color: var(--primary-dark); padding: 5px 12px; border-radius: var(--radius-pill); cursor: pointer; }
.seg button.active { background: #fff; box-shadow: 0 1px 4px rgba(15,58,117,0.15); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
table.t { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.t th, table.t td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.t th { background: var(--primary-lighter); color: var(--primary-dark); font-weight: 700; font-size: 0.82rem; position: sticky; top: 0; }
table.t th.sortable { cursor: pointer; user-select: none; }
table.t th.sortable:hover { background: var(--primary-light); }
table.t th .arrow { opacity: 0.6; margin-left: 4px; }
table.t tbody tr:last-child td { border-bottom: none; }
table.t tbody tr:hover { background: var(--primary-lighter); }
table.t td.r, table.t th.r { text-align: right; }
tr.is-hidden td { color: var(--muted); }
tr.is-hidden td:first-child { box-shadow: inset 3px 0 0 var(--border-strong); }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: var(--radius-pill);
  background: var(--primary-light); color: var(--primary-dark); vertical-align: middle; white-space: nowrap;
}
.badge.success { background: var(--success-light); color: var(--success); }
.badge.warning { background: var(--warning-light); color: var(--warning); }
.badge.danger { background: var(--danger-light); color: var(--danger); }
.badge.grey { background: #edf0f5; color: var(--muted); }
.gain-pos { color: var(--success); font-weight: 600; }
.gain-neg { color: var(--danger); font-weight: 600; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; border: 1px solid rgba(183,205,234,0.45); }
.stat .v { font-size: 1.5rem; font-weight: 700; color: var(--primary-dark); font-variant-numeric: tabular-nums; }
.stat .l { font-size: 0.8rem; color: var(--muted); }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface-soft); border: 1px solid var(--border);
}
.list-item .title { font-weight: 600; }
.list-item .meta { font-size: 0.84rem; color: var(--muted); }
.list-item.current { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(31,111,214,0.15); }

/* ---------- Matches ---------- */
.match-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.match {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px;
  border: 1px solid rgba(183,205,234,0.45); border-top: 4px solid var(--accent);
  display: flex; flex-direction: column; gap: 10px;
}
.match.played { border-top-color: var(--success); }
.match.editing { border-top-color: var(--warning); }
.match-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--muted); }
.match-players { display: grid; grid-template-columns: 1fr auto auto; gap: 6px 8px; align-items: center; }
.match-players .pname { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match-players .pname small { display: block; font-weight: 400; color: var(--muted); font-size: 0.78rem; }
.match-players input { width: 58px; text-align: center; padding: 6px 4px; font-variant-numeric: tabular-nums; font-weight: 600; }
.match-players .score { width: 58px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.match-players .score.win { color: var(--success); }
.match-sets-head { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.match-sets-head span { width: 58px; text-align: center; }
.match-elo { font-size: 0.8rem; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.match-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.match-error { color: var(--danger); font-size: 0.82rem; }

/* ---------- Club matrix ---------- */
.matrix-wrap { overflow: auto; max-height: 70vh; border-radius: var(--radius-sm); border: 1px solid var(--border); }
table.matrix { border-collapse: separate; border-spacing: 0; font-size: 0.85rem; }
table.matrix th, table.matrix td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 4px; text-align: center; }
table.matrix thead th { position: sticky; top: 0; background: var(--primary-lighter); z-index: 2; color: var(--primary-dark); font-weight: 700; max-width: 120px; white-space: normal; }
table.matrix tbody th { position: sticky; left: 0; background: var(--primary-lighter); z-index: 1; text-align: left; white-space: nowrap; color: var(--primary-dark); }
table.matrix thead th:first-child { left: 0; z-index: 3; }
table.matrix td.off { background: #f3f6fa; }
table.matrix td.diag { background: #fbfdff; }
table.matrix input { width: 64px; padding: 4px; text-align: center; border-radius: 7px; font-variant-numeric: tabular-nums; }
table.matrix input.changed { background: var(--warning-light); border-color: #f0c869; }
table.matrix input.forbidden { background: var(--danger-light); border-color: #f0a9a1; color: var(--danger); font-weight: 700; }
table.matrix input.invalid { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(192,57,43,0.2); }

/* ---------- Modal / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 35, 70, 0.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100; animation: fade .15s ease; }
.modal { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 22px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; animation: pop .18s ease; }
.modal h3 { margin-top: 0; font-size: 1.1rem; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: translateY(8px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--primary-dark); color: #fff; padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-size: 0.9rem; animation: pop .2s ease; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: #8a5a00; }

.offline-banner { background: var(--warning-light); color: var(--warning); text-align: center; font-size: 0.85rem; font-weight: 600; padding: 6px 12px; }
.offline-banner[hidden] { display: none; }

@media (max-width: 640px) {
  .org-main { padding: 14px 12px 40px; }
  .card { padding: 14px; }
  .match-grid { grid-template-columns: 1fr; }
}
