:root {
  --bg-body: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-alt: #0f172a;
  --bg-elevated: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent-indigo: #6366f1;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.16);
  --yellow: #eab308;
  --yellow-bg: rgba(234, 179, 8, 0.18);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.18);
  --purple: #a855f7;
  --purple-bg: rgba(168, 85, 247, 0.18);
  --blue-bg: rgba(59, 130, 246, 0.16);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
  --radius: 12px;
}

body.light-mode {
  --bg-body: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-surface-alt: #f8fafc;
  --bg-elevated: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #cbd5e1;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --yellow: #ca8a04;
  --yellow-bg: #fef9c3;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --purple: #9333ea;
  --purple-bg: #f3e8ff;
  --blue-bg: #dbeafe;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-box {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  border: 2px solid var(--primary);
  background: #fff;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0;
}

.header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Inputs & Buttons */
select, input[type="text"], input[type="password"], input[type="email"], input[type="date"], input[type="time"], input[type="number"], textarea {
  background: var(--bg-surface-alt);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-success {
  background: var(--green);
  color: #ffffff;
}
.btn-success:hover {
  filter: brightness(1.08);
}

.btn-warning {
  background: #f59e0b;
  color: #ffffff;
}

.btn-danger {
  background: var(--red);
  color: #ffffff;
}

.btn-outline {
  background: var(--bg-surface-alt);
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-outline:hover {
  background: var(--bg-elevated);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.78rem;
  border-radius: 6px;
}

.btn-mf-active {
  background: var(--green-bg);
  color: var(--green);
  border-color: var(--green);
}

/* Main Navigation Tabs */
.nav-tabs-bar {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  border-top: 1px solid var(--border-color);
}

.nav-tab {
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-bottom: 3px solid transparent;
  padding: 11px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}

.nav-tab:hover {
  color: var(--text-main);
}

.nav-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Container */
.main-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px 16px 64px;
}

/* Team Selector Pills */
/* Team Selector: Category + Team Pills */
.team-selector-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.category-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 10px;
}

.category-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}

.category-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-main);
}

.category-btn.active {
  background: var(--primary);
  color: #fff;
}

.team-pills-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.team-pill {
  background: var(--bg-surface-alt);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.team-pill:hover {
  border-color: var(--primary);
  background: var(--bg-elevated);
}

.team-pill.active {
  background: var(--blue-bg);
  color: var(--primary);
  border-color: var(--primary);
  font-weight: 800;
}

.team-pill-badge {
  font-size: 0.70rem;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-elevated);
}

/* View Switcher (Segmented Control) */
.view-switch-bar {
  display: inline-flex;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 16px;
}

.view-switch-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 7px;
  padding: 8px 16px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.view-switch-btn:hover {
  color: var(--text-main);
}

.view-switch-btn.active {
  background: var(--bg-surface);
  color: var(--text-main);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

body.light-mode .view-switch-btn.active {
  background: #ffffff;
  color: var(--primary);
}

/* Sub-Team Section in Ersatzspieler-Finder */
.sub-team-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  margin-bottom: 14px;
  overflow: hidden;
}

.sub-team-header {
  background: var(--bg-surface-alt);
  padding: 10px 14px;
  font-weight: 800;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

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

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

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Rotation / Fairness Grid */
.rotation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.rotation-player-card {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rotation-player-card.is-me {
  border: 2px solid var(--primary);
  background: var(--blue-bg);
}

.rotation-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.rotation-name {
  font-weight: 700;
  font-size: 0.9rem;
}

.rotation-ttr {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 600;
}

.rotation-bar-track {
  height: 7px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
}

.rotation-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--green));
  border-radius: 999px;
  transition: width 0.25s ease;
}

.rotation-stats-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* Availability Matrix Table */
.matrix-scroll-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-surface);
}

.matrix-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.84rem;
}

.matrix-table th, .matrix-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  text-align: center;
}

.matrix-table th {
  background: var(--bg-surface-alt);
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 10;
}

.matrix-table th.sticky-col,
.matrix-table td.sticky-col {
  position: sticky;
  left: 0;
  z-index: 12;
  background: var(--bg-surface);
  text-align: left;
  min-width: 220px;
  max-width: 260px;
  border-right: 2px solid var(--border-color);
}

.matrix-table th.sticky-col {
  z-index: 15;
  background: var(--bg-surface-alt);
}

.matrix-col-me {
  background: var(--blue-bg) !important;
}

.avail-cell {
  cursor: pointer;
  user-select: none;
  min-width: 82px;
  transition: transform 0.1s, background-color 0.15s;
  position: relative;
}

.avail-cell.is-editable {
  cursor: pointer;
}

.avail-cell.is-editable:hover {
  filter: brightness(1.15);
  transform: scale(1.03);
  z-index: 2;
}

.avail-cell.is-locked {
  cursor: not-allowed;
  opacity: 0.92;
}

.avail-cell.is-locked:hover {
  filter: brightness(0.97);
}

.avail-YES {
  background: var(--green-bg);
  color: var(--green);
  font-weight: 700;
}

.avail-EMERGENCY {
  background: var(--yellow-bg);
  color: var(--yellow);
  font-weight: 700;
}

.avail-NO {
  background: var(--red-bg);
  color: var(--red);
  font-weight: 700;
}

.avail-UNSET {
  color: var(--text-muted);
}

.cell-lineup-badge {
  display: inline-block;
  margin-top: 3px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 800;
  background: var(--primary);
  color: #fff;
}

.cell-pulled-badge {
  display: inline-block;
  margin-top: 3px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 800;
  background: var(--purple);
  color: #fff;
}

/* Matchday Lineup Cards Grid */
.matchdays-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
}

.matchday-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
}

.matchday-card.status-short {
  border-left: 5px solid var(--red);
}

.matchday-card.status-ok {
  border-left: 5px solid var(--green);
}

.matchday-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.ha-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.74rem;
  font-weight: 800;
}

.ha-H {
  background: var(--blue-bg);
  color: var(--primary);
}

.ha-A {
  background: var(--yellow-bg);
  color: var(--yellow);
}

.lineup-slots {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lineup-slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.85rem;
}

.lineup-slot.slot-empty {
  border-style: dashed;
  color: var(--red);
  background: var(--red-bg);
}

.lineup-slot.slot-pulled {
  background: var(--purple-bg);
  border-color: var(--purple);
  color: var(--purple);
}

.slot-pos {
  font-weight: 800;
  color: var(--primary);
  min-width: 48px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
}

.badge-sub {
  background: var(--blue-bg);
  color: var(--primary);
}

.badge-spv {
  background: var(--red-bg);
  color: var(--red);
}

.badge-pulled {
  background: var(--purple-bg);
  color: var(--purple);
}

.badge-ok {
  background: var(--green-bg);
  color: var(--green);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.76);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 100%;
  max-width: 780px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Substitute candidate row */
.sub-candidate-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  margin-bottom: 8px;
}

.sub-candidate-row.cat-FREE_YES {
  border-left: 4px solid var(--green);
}
.sub-candidate-row.cat-PULLABLE_LOWER {
  border-left: 4px solid var(--primary);
}
.sub-candidate-row.cat-EMERGENCY {
  border-left: 4px solid var(--yellow);
}
.sub-candidate-row.cat-BLOCKED_HIGHER,
.sub-candidate-row.cat-ABSENT {
  opacity: 0.58;
  border-left: 4px solid var(--red);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast-msg {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--primary);
  border-left: 5px solid var(--primary);
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  font-weight: 600;
  max-width: 380px;
}

@media (max-width: 768px) {
  .matchdays-grid {
    grid-template-columns: 1fr;
  }
  .matrix-table th.sticky-col,
  .matrix-table td.sticky-col {
    min-width: 155px;
    max-width: 175px;
  }
}
