:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #dde3ea;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #166534;
  --primary-hover: #14532d;
  --primary-soft: #dcfce7;
  --accent: #0369a1;
  --accent-soft: #e0f2fe;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: #0f172a;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid #1e293b;
}

.sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #1e293b;
}

.club-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.club-logo { font-size: 24px; }
.club-logo-img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  background: #ffffff;
  border-radius: 8px;
  padding: 3px;
  flex-shrink: 0;
}
.club-name { font-weight: 700; font-size: 16px; color: #fff; }
.club-sub { font-size: 12px; color: #94a3b8; }

.mode-bar {
  padding: 10px 14px;
  background: #1e293b;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid #334155;
}
.mode-badge {
  font-size: 11.5px;
  font-weight: 600;
  color: #cbd5e1;
}
body.edit-mode .mode-badge {
  color: #86efac;
}
body.admin-mode .mode-badge {
  color: #fde047;
}
body:not(.edit-mode) .edit-only {
  display: none !important;
}
body:not(.admin-mode) .admin-only {
  display: none !important;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.nav-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  font-weight: 600;
  margin: 10px 8px 6px;
}

.nav-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 14px 8px 6px;
}
.nav-section-header .nav-section-title { margin: 0; }

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: none;
  background: transparent;
  color: #cbd5e1;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: #1e293b; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }

.team-group-label {
  font-size: 11px;
  color: #64748b;
  font-weight: 700;
  padding: 8px 10px 2px;
  text-transform: uppercase;
}

.team-nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border: none;
  background: transparent;
  color: #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}
.team-nav-item:hover { background: #1e293b; color: #fff; }
.team-nav-item.active { background: #1e3a2f; color: #86efac; font-weight: 600; border-left: 3px solid #22c55e; }
.team-nav-badge {
  font-size: 11px;
  background: #1e293b;
  color: #94a3b8;
  padding: 1px 6px;
  border-radius: 999px;
}

.team-slot-pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 12.5px;
  font-weight: 600;
  color: #1e293b;
  margin: 2px 4px 2px 0;
}

.team-slot-pill[data-team-id] {
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.team-slot-pill[data-team-id]:hover {
  filter: brightness(0.95);
  text-decoration: underline;
}

.team-slot-pending {
  border-top: 1px dashed #d97706;
  border-right: 1px dashed #d97706;
  border-bottom: 1px dashed #d97706;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid #1e293b;
}

.rgpd-pill {
  font-size: 11px;
  background: #1e293b;
  color: #86efac;
  padding: 8px 10px;
  border-radius: 8px;
  text-align: center;
}

.license-note {
  margin-top: 8px;
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
  line-height: 1.4;
}

.license-note a {
  color: #cbd5e1;
  text-decoration: underline;
}

.license-note a:hover {
  color: #ffffff;
}

/* Main */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.page-title { margin: 0; font-size: 20px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.main-content {
  padding: 20px 24px 48px;
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
}

/* Cards & Controls */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}

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

.card-title { margin: 0; font-size: 17px; font-weight: 700; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.input, .select, .textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid #86efac;
  border-color: var(--primary);
}
.input-sm { padding: 5px 8px; font-size: 13px; }
.w-full { width: 100%; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #075985; }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-alt); border-color: #cbd5e1; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #991b1b; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: 5px; border: none; cursor: pointer; }
.btn-icon { background: transparent; border: none; font-size: 20px; cursor: pointer; color: inherit; padding: 4px 8px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.team-matches-table { width: auto; min-width: 660px; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
th {
  background: var(--surface-alt);
  font-weight: 700;
  color: #334155;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
tr:hover td { background: #f8fafc; }
tr.conflict-row td { background: #fffbeb; }
tr.blocked-row td { background: #fef2f2; }
tr.upcoming-row td:first-child { border-left: 4px solid var(--primary); }
tr.upcoming-row { scroll-margin-top: 80px; }

td.result-win, input.result-win {
  background: #dcfce7 !important;
  color: #14532d !important;
  border-color: #86efac !important;
  font-weight: 700;
}
td.result-loss, input.result-loss {
  background: #fee2e2 !important;
  color: #991b1b !important;
  border-color: #fca5a5 !important;
  font-weight: 700;
}
td.result-draw, input.result-draw {
  background: #fef3c7 !important;
  color: #92400e !important;
  border-color: #fcd34d !important;
  font-weight: 700;
}

.hidden { display: none !important; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-green { background: var(--primary-soft); color: var(--primary); }
.badge-blue { background: var(--accent-soft); color: var(--accent); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-gray { background: #e2e8f0; color: #475569; }

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.form-label { font-size: 12px; font-weight: 600; color: #475569; }

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  margin-bottom: 14px;
  border-left: 4px solid;
}
.alert-info { background: var(--accent-soft); border-color: var(--accent); color: #0c4a6e; }
.alert-warn { background: var(--warn-soft); border-color: var(--warn); color: #78350f; }
.alert-success { background: var(--primary-soft); border-color: var(--primary); color: #14532d; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-backdrop.hidden { display: none; }
.modal-dialog {
  background: var(--surface);
  border-radius: 12px;
  max-width: 780px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  padding: 22px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 16px;
}
.modal-title { margin: 0; font-size: 18px; font-weight: 700; }
.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

/* Monthly Calendar */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}
.cal-header-cell {
  background: var(--surface-alt);
  padding: 7px 6px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: #475569;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.cal-day {
  min-height: 105px;
  padding: 5px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cal-day-muted { background: #f8fafc; }
.cal-day-today { background: #f0fdf4; }
.cal-day-holiday { background: #fefce8; }
.cal-day-pub-holiday { background: #eef2ff; }
.cal-day-clickable { cursor: pointer; }
.cal-day-clickable:hover { background: #f8fafc; }
.cal-day-num {
  font-size: 12px;
  font-weight: 700;
  color: #475569;
}
.cal-day-today .cal-day-num {
  color: var(--primary);
}
.cal-day-items {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.cal-item {
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 11.5px;
  line-height: 1.25;
  color: #1e293b;
  overflow: hidden;
  cursor: pointer;
}
.cal-item-match { cursor: pointer; }
.cal-item-clickable { cursor: pointer; }
.cal-item-time {
  font-size: 10.5px;
  font-weight: 700;
  opacity: 0.85;
}
.cal-item-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-item-pending {
  border-top: 1px dashed #d97706;
  border-right: 1px dashed #d97706;
  border-bottom: 1px dashed #d97706;
}

/* Print-only header hidden on screen */
.print-only { display: none; }

/* Responsive */
.mobile-menu, .mobile-close { display: none; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: -290px;
    top: 0;
    bottom: 0;
    z-index: 50;
    transition: left 0.2s ease;
  }
  .sidebar.open { left: 0; }
  .mobile-menu, .mobile-close { display: inline-flex; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .cal-day { min-height: 75px; padding: 3px; }
  .cal-item { font-size: 10px; padding: 2px 4px; }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .page-title { font-size: 17px; }
  .topbar-actions .btn { padding: 6px 10px; font-size: 12px; }
  .main-content { padding: 12px 10px 36px; }

  .modal-backdrop { padding: 8px; }
  .modal-dialog { padding: 14px; max-height: 94vh; }
  .modal-header {
    position: sticky;
    top: -14px;
    background: var(--surface);
    z-index: 5;
    padding-top: 4px;
  }
  .modal-footer {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 8px;
  }
  .modal-footer .btn {
    width: 100%;
    justify-content: center;
  }

  .mobile-cards { overflow-x: visible; }
  .mobile-cards table,
  .mobile-cards .team-matches-table,
  .mobile-cards thead,
  .mobile-cards tbody,
  .mobile-cards th,
  .mobile-cards td,
  .mobile-cards tr {
    display: block;
    width: 100%;
    min-width: 0 !important;
  }
  .mobile-cards thead { display: none; }
  .mobile-cards tr {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 10px;
    background: var(--surface);
  }
  .mobile-cards td {
    border-bottom: 1px dashed #e2e8f0;
    padding: 6px 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 6px 10px;
    text-align: right !important;
  }
  .mobile-cards td > input,
  .mobile-cards td > select {
    max-width: 195px;
  }
  .mobile-cards .match-opp-club {
    min-width: 0 !important;
  }
  .mobile-cards td:last-child { border-bottom: none; }
  .mobile-cards td::before {
    content: attr(data-label);
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    text-align: left;
    flex-shrink: 0;
  }
}
