:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1d2433;
  --subtle: #65708a;
  --line: #d7deeb;
  --primary: #0f766e;
  --primary-dark: #0b5a53;
  --danger-bg: #fdecec;
  --danger-text: #8f2222;
  --success-bg: #e8f8ed;
  --success-text: #1c6432;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.site-nav {
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 10px;
  padding-bottom: 10px;
}

.brand {
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
}

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

.links a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.nav-link-btn {
  border: none;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  padding: 0;
  border-radius: 0;
}

.nav-link-btn:hover {
  background: transparent;
  color: var(--primary);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.narrow {
  max-width: 560px;
}

h1 {
  margin: 0;
  font-size: 2rem;
}

h2 {
  margin: 0;
  font-size: 1.25rem;
}

.subtitle {
  color: var(--subtle);
  margin: 8px 0 18px;
}

.subtitle.compact {
  margin: 6px 0 10px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

label {
  font-weight: 600;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
  background: #fff;
}

button,
.button-link {
  display: inline-block;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.button-link:hover {
  background: var(--primary-dark);
}

.secondary {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.secondary:hover {
  background: #eaf8f5;
}

.small {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.stacked {
  display: grid;
  gap: 10px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.grid-form button {
  width: 100%;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 8px 6px;
  vertical-align: middle;
}

.action-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.avatar,
.mini-avatar {
  object-fit: cover;
  border-radius: 999px;
}

.avatar {
  width: 56px;
  height: 56px;
}

.mini-avatar {
  width: 36px;
  height: 36px;
}

.profile-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.flash {
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

.flash.error {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.flash.success {
  background: var(--success-bg);
  color: var(--success-text);
}

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 700;
}

.pill.pending {
  background: #fef3c7;
  color: #7a5600;
}

.pill.success {
  background: #dcfce7;
  color: #18603a;
}

.calendar-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.calendar-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.calendar-actions-left,
.calendar-actions-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.view-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--subtle);
}

.view-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.view-switch .slider {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: #d1d5db;
  position: relative;
  transition: background 0.2s ease;
}

.view-switch .slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.view-switch input:checked + .slider {
  background: #0f766e;
}

.view-switch input:checked + .slider::after {
  transform: translateX(18px);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.calendar-grid.week-feed {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.weekday {
  font-weight: 700;
  color: var(--subtle);
  text-align: center;
  padding: 6px 0;
}

.day {
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
}

.day.current-week {
  border-color: #0f766e;
  box-shadow: 0 0 0 1px rgba(15, 118, 110, 0.18);
}

.week-feed-day {
  min-height: unset;
}

.week-feed-header {
  font-weight: 700;
  color: var(--subtle);
  margin-bottom: 6px;
}

.week-feed-empty {
  margin-top: 8px;
}

.mobile-week-nav {
  position: fixed;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  display: none;
  gap: 12px;
  z-index: 1200;
  pointer-events: none;
}

.week-float-btn {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: rgba(15, 23, 42, 0.22);
  color: #ffffff;
  backdrop-filter: blur(4px);
  pointer-events: auto;
}

.week-float-btn:hover {
  background: rgba(15, 23, 42, 0.32);
}

.week-float-label {
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.18);
  color: #ffffff;
  backdrop-filter: blur(4px);
  padding: 8px 12px;
  font-size: 0.82rem;
  white-space: nowrap;
}

.day.empty {
  background: #f7f9fc;
  border-style: dashed;
}

.day-number {
  font-weight: 700;
  margin-bottom: 6px;
}

.event {
  margin-bottom: 6px;
  padding: 6px;
  border-radius: 6px;
  background: #f5f5f5;
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  border: 1px solid transparent;
}

.event:focus {
  outline: none;
  border-color: #1d2433;
}

.event small {
  color: #2f3544;
}

.event-orange {
  background: #ffedd5;
  border-color: #fdba74;
}

.event-red {
  background: #fee2e2;
  border-color: #fca5a5;
}

.event-green {
  background: #dcfce7;
  border-color: #86efac;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.modal-content {
  position: relative;
  width: min(560px, calc(100% - 24px));
  margin: 8vh auto 0;
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 16px;
  z-index: 1;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--subtle);
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  background: #f8fafc;
  color: var(--text);
}

#reservationModal .modal-content {
  max-height: 90vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #c5cfdf transparent;
}

#reservationModal .modal-content::-webkit-scrollbar {
  width: 6px;
}

#reservationModal .modal-content::-webkit-scrollbar-track {
  background: transparent;
}

#reservationModal .modal-content::-webkit-scrollbar-thumb {
  background: #c5cfdf;
  border-radius: 999px;
}

.players-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-row input {
  flex: 1;
}

.dual-range-wrap {
  width: 100%;
  display: grid;
  gap: 6px;
}

.dual-range-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: var(--subtle);
  font-size: 0.9rem;
}

.dual-range-box {
  position: relative;
  height: 30px;
}

.dual-range-box input[type="range"] {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  width: 100%;
  margin: 0;
  pointer-events: none;
  background: transparent;
}

.dual-range-box input[type="range"]::-webkit-slider-thumb {
  pointer-events: auto;
}

.dual-range-box input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
}

.search-results,
.selected-players {
  display: grid;
  gap: 6px;
}

.search-result-row,
.selected-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.avatars-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0;
}

.avatars-row.compact {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 4px;
  width: fit-content;
}

.avatar-chip {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #1f2937;
  border: 1px solid #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1;
  overflow: hidden;
  padding: 0;
}

.avatar-chip-link {
  text-decoration: none;
  color: inherit;
}

button.avatar-chip {
  cursor: pointer;
  padding: 0;
  border: 1px solid #cbd5e1;
}

.avatar-chip.small {
  width: 36px;
  height: 36px;
  font-size: 0.8rem;
}

.avatar-chip.empty {
  background: #f8fafc;
  color: #64748b;
  border-style: dashed;
}

.avatar-chip.pending {
  opacity: 0.5;
}

.avatars-row.compact .avatar-chip {
  border: 1px solid #cbd5e1;
  box-shadow: none;
}

.avatars-row.compact .avatar-chip + .avatar-chip {
  margin-left: 0;
}

.avatar-chip-img {
  width: calc(100% + 2px);
  height: calc(100% + 2px);
  margin: -1px;
  object-fit: cover;
  object-position: center;
  display: block;
  border-radius: inherit;
}

.event .avatars-row {
  gap: 4px;
  margin: 4px 0 2px;
}

.event .avatar-chip,
.event .avatar-chip.small {
  width: 52px;
  height: 52px;
  font-size: 0.9rem;
  overflow: hidden;
  border-radius: 999px;
}

.event .avatar-chip-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  border-radius: 999px;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.check-line input {
  width: auto;
}

.segmented-control {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.segmented-control input[type="radio"] {
  display: none;
}

.segmented-control label {
  margin: 0;
  padding: 8px 10px;
  text-align: center;
  font-weight: 600;
  color: var(--subtle);
  background: #fff;
  border-right: 1px solid var(--line);
  cursor: pointer;
}

.segmented-control label:last-of-type {
  border-right: none;
}

.segmented-control input[type="radio"]:checked + label {
  background: #eaf8f5;
  color: var(--primary-dark);
}

#privacyPersonal:checked + label {
  background: #e6f0ff;
  color: #1e40af;
}

#privacyPublic:checked + label {
  background: #e8f8ed;
  color: #166534;
}

#privacyPrivate:checked + label {
  background: #feeceb;
  color: #9f1239;
}

.privacy-help {
  display: grid;
  gap: 4px;
  font-size: 0.82rem;
  color: var(--subtle);
}

.modal-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.incoming-block {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.results-panel {
  display: grid;
  gap: 8px;
}

.result-teams-preview {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
}

.result-team-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  display: grid;
  gap: 6px;
  justify-items: center;
}

.result-team-box.drag-over {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.12);
}

.result-team-title {
  font-weight: 700;
  color: var(--subtle);
  font-size: 0.85rem;
}

.result-vs {
  font-weight: 800;
  color: var(--subtle);
}

.manage-team-preview {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin: 4px 0;
}

.manage-team-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 8px;
  justify-items: center;
}

.manage-team-box.drag-over {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.12);
}

.manage-team-avatar {
  width: 52px;
  height: 52px;
  font-size: 0.9rem;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.manage-team-avatar:active {
  cursor: grabbing;
}

.is-dragging-avatar {
  opacity: 0.2 !important;
}

.drag-touch-ghost {
  position: fixed;
  width: 52px;
  height: 52px;
  border-radius: 999px;
  pointer-events: none;
  opacity: 0.2;
  z-index: 2500;
  transform: translate(-50%, -50%);
}

.result-row-teams {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.result-draggable {
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.result-draggable:active {
  cursor: grabbing;
}

.results-panel .avatar-chip {
  width: 52px;
  height: 52px;
  font-size: 0.9rem;
}

.incoming-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
}

.row-actions {
  display: flex;
  gap: 6px;
}

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

  .calendar-grid {
    gap: 6px;
  }

  .day {
    min-height: 95px;
  }

  .event {
    font-size: 0.75rem;
  }
}

@media (max-width: 640px) {
  .container {
    padding: 12px;
  }

  .nav-inner {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
  }

  .links {
    flex-wrap: wrap;
    gap: 8px;
  }

  .topbar {
    flex-direction: column;
    gap: 10px;
  }

  .card {
    padding: 12px;
    border-radius: 10px;
  }

  .calendar-controls {
    flex-wrap: wrap;
    gap: 8px;
  }

  .calendar-actions {
    flex-wrap: wrap;
  }

  .calendar-actions-left,
  .calendar-actions-right {
    width: 100%;
    justify-content: flex-start;
  }

  .calendar-card {
    overflow-x: hidden;
  }

  .calendar-grid {
    min-width: 700px;
    gap: 4px;
  }

  .calendar-grid.week-feed {
    min-width: 0;
    gap: 8px;
  }

  .calendar-grid.week-feed .day {
    min-height: auto;
    padding: 8px;
  }

  .day {
    min-height: 88px;
    padding: 6px;
  }

  .event {
    font-size: 0.68rem;
    padding: 5px;
  }

  .event .avatar-chip,
  .event .avatar-chip.small {
    width: 36px;
    height: 36px;
    font-size: 0.8rem;
  }

  .modal-content {
    width: calc(100% - 12px);
    margin: 3vh auto 0;
    padding: 12px;
    max-height: 94vh;
    overflow-y: auto;
  }

  .modal-actions {
    flex-wrap: wrap;
  }

  .modal-actions button,
  .modal-actions .button-link {
    flex: 1 1 130px;
  }

  .search-row {
    flex-direction: column;
  }

  .selected-row,
  .search-result-row,
  .incoming-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .row-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .result-teams-preview {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .manage-team-preview {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .result-vs {
    text-align: center;
  }

  .data-table {
    font-size: 0.86rem;
  }

  input {
    font-size: 16px;
  }
}
