/* ===== Design System ===== */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-hover: #15803d;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-hover: #b45309;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fee2e2;
  --info: #0891b2;
  --info-light: #cffafe;
  --tech: #7c3aed;
  --tech-light: #ede9fe;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --radius: 8px;
  --radius-sm: 6px;
  --transition: 150ms ease;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 0.875em;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
}

img { max-width: 100%; height: auto; }

/* ===== Layout ===== */
.container { max-width: 1320px; margin: 0 auto; padding: 20px; }

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.header-left { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.header-right { display: flex; align-items: center; gap: 12px; }

.panel {
  background: var(--surface);
  padding: 20px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.panel-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  border-bottom: 2px solid var(--primary);
  padding-bottom: 10px;
  margin-bottom: 16px;
  margin-top: 0;
}

/* ===== Grid ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-full { grid-column: 1 / -1; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}

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

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.card-title { font-weight: 600; font-size: 0.95rem; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

tr:not(.no-hover):hover { background: #f8fafc; }
tr.selected { background: var(--primary-light) !important; }

/* ===== Forms ===== */
.form-group {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.form-group label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 4px;
  width: 100%;
}

input, select, textarea {
  font-family: inherit;
  font-size: 0.875rem;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

input::placeholder { color: var(--text-muted); }

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  flex: none;
}

input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.form-inline {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.form-inline label { font-size: 0.8125rem; font-weight: 600; color: var(--text-secondary); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
  white-space: nowrap;
  line-height: 1.4;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); text-decoration: none; }

.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: var(--success-hover); text-decoration: none; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); text-decoration: none; }

.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover:not(:disabled) { background: var(--warning-hover); text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); }

.btn-sm { padding: 4px 10px; font-size: 0.75rem; }
.btn-lg { padding: 12px 24px; font-size: 0.9375rem; }
.btn-block { width: 100%; }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-primary { background: var(--primary-light); color: var(--primary); }
.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-info { background: var(--info-light); color: var(--info); }
.badge-tech { background: var(--tech-light); color: var(--tech); }
.badge-muted { background: var(--bg); color: var(--text-secondary); }
.badge-need { background: var(--bg); color: var(--text-muted); }

/* ===== Navigator / Tabs ===== */
.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  background: var(--surface);
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.tab-btn {
  padding: 7px 16px;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.tab-btn:hover { background: #e2e8f0; }
.tab-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.tab-btn .count {
  background: var(--primary);
  color: white;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.6875rem;
  margin-left: 6px;
}

.tab-btn.active .count { background: rgba(255, 255, 255, 0.25); }

/* ===== Back link ===== */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 16px;
  font-weight: 600;
  font-size: 0.875rem;
}

/* ===== Logout button ===== */
.btn-logout {
  background: var(--danger);
  color: white;
}
.btn-logout:hover { background: var(--danger-hover); }

/* ===== Alerts / Messages ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 16px;
}

.alert-error { background: var(--danger-light); color: var(--danger); }
.alert-success { background: var(--success-light); color: var(--success); }
.alert-info { background: var(--info-light); color: var(--info); }
.alert-warning { background: var(--warning-light); color: var(--warning); }

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}

/* ===== Stepper (для matches.html) ===== */
.stepper-wrap { display: flex; align-items: center; gap: 6px; }
.stepper-label { font-size: 0.75rem; color: var(--text-secondary); min-width: 48px; }
.stepper-label.guest { text-align: right; }

.step-btn {
  width: 36px; height: 36px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: background var(--transition);
}
.step-btn:hover { background: #e2e8f0; }
.step-btn:active { background: #cbd5e1; }
.step-btn:disabled { color: var(--text-muted); cursor: not-allowed; background: #fafafa; }

.score-input {
  width: 60px; height: 36px;
  padding: 0 4px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  background: var(--surface);
  -moz-appearance: textfield;
}
.score-input::-webkit-outer-spin-button,
.score-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.score-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
.score-input.tb { background: var(--warning-light); border-color: #fde68a; color: #92400e; }

.score-form-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.score-form-row > label { min-width: 50px; font-weight: 600; color: var(--text-secondary); font-size: 0.8125rem; }
.set-group { display: flex; gap: 4px; align-items: center; }
.set-group .sep { font-weight: bold; color: var(--text-muted); margin: 0 4px; }

/* ===== Match cards (admin_games) ===== */
.override-form { display: none; padding: 16px; background: var(--warning-light); border: 1px solid #fde68a; border-radius: var(--radius-sm); margin: 10px 0; }
.override-form.open { display: block; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.875rem;
  z-index: 9999;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.3s ease;
  max-width: 400px;
}

.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== Spinner ===== */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Filters bar ===== */
.filters-bar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filter-group { display: flex; flex-direction: column; gap: 3px; }
.filter-group label { font-size: 0.75rem; font-weight: 600; color: var(--text-secondary); }

/* ===== Utilities ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.font-bold { font-weight: 700; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: 8px; }
.mb-2 { margin-bottom: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .container { padding: 12px; }
  .header { flex-direction: column; gap: 12px; align-items: flex-start; }
  .header-right { width: 100%; }
  .header-right form { width: 100%; }
  .header-right .btn { width: 100%; }
  .form-group { flex-direction: column; }
  .form-inline { flex-direction: column; align-items: flex-start; }
  .filters-bar { flex-direction: column; align-items: stretch; }
  th, td { padding: 8px 10px; }
}
