:root {
  color-scheme: light;
  --green: #1f7a4d;
  --green-dark: #155f3b;
  --ink: #1f2933;
  --muted: #64748b;
  --line: #d8e1dc;
  --paper: #ffffff;
  --soft: #f4f7f5;
  --mine: #dff3e7;
  --event: #fff1cf;
  --busy: #e8eef5;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body { margin: 0; color: var(--ink); background: var(--soft); }
.hidden { display: none !important; }
a { color: var(--green-dark); text-decoration: none; font-weight: 650; }
button, .button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 40px;
  padding: 9px 13px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.primary { background: var(--green); border-color: var(--green); color: #fff; }
.site-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px clamp(16px, 3vw, 34px);
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}
.site-header .brand {
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 850;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: min(260px, 100%);
}
.site-header .brand img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex: 0 0 auto;
}
.site-header .brand .brand-text {
  display: grid;
  gap: 1px;
  min-width: 0;
}
.site-header .brand strong {
  color: var(--ink);
  font-size: 1.08rem;
  line-height: 1.05;
}
.site-header .brand small {
  color: var(--muted);
  font-size: .86rem;
  font-weight: 650;
  line-height: 1.1;
}
nav { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.home-link {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--green-dark);
  min-height: 36px;
  padding: 7px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}
.home-link:hover,
.home-link:focus {
  border-color: var(--green);
  background: #f2faf5;
}
.inline { display: inline; }
.inline button { min-height: 32px; padding: 5px 9px; }
.page { width: min(1180px, 100%); margin: 0 auto; padding: 26px clamp(14px, 3vw, 32px) 48px; }
.calendar-page { padding-top: 12px; padding-bottom: 22px; }
h1 { margin: 0 0 16px; font-size: clamp(1.55rem, 3vw, 2.2rem); }
h2 { font-size: 1.02rem; margin: 0 0 10px; }
.auth, .narrow { max-width: 520px; }
form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
.date-field {
  cursor: pointer;
}
.date-picker-popover {
  position: absolute;
  z-index: 1000;
  width: min(320px, calc(100vw - 20px));
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 16px 42px rgba(31, 41, 51, .16);
}
.date-picker-head {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.date-picker-head button {
  min-height: 38px;
  padding: 0;
  font-size: 1.45rem;
}
.date-picker-head strong {
  text-align: center;
  text-transform: capitalize;
}
.date-picker-weekdays,
.date-picker-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}
.date-picker-weekdays span {
  color: var(--muted);
  text-align: center;
  font-size: .78rem;
  font-weight: 800;
  padding: 4px 0;
}
.date-picker-days button {
  min-height: 38px;
  padding: 0;
  border-color: transparent;
  border-radius: 6px;
  font-weight: 750;
}
.date-picker-days button:hover,
.date-picker-days button:focus {
  border-color: var(--green);
}
.date-picker-days button.muted {
  color: #9aa7b5;
  background: #f8faf9;
}
.date-picker-days button.today {
  border-color: var(--green);
}
.date-picker-days button.selected {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
textarea { min-height: 92px; resize: vertical; }
fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
legend { font-weight: 800; padding: 0 6px; }
.permissions-box { display: grid; gap: 10px; }
.check-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  font-weight: 500;
}
.check-row input { width: auto; margin-top: 4px; }
.check-row span { display: grid; gap: 2px; }
.check-row small { color: var(--muted); }
.reservation-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}
.reservation-form .wide { grid-column: 1 / -1; }
.series-box { display: grid; gap: 12px; }
.danger-zone {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid #f1c5c5;
  border-radius: 8px;
  background: #fff7f7;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.danger-zone h2 {
  flex-basis: 100%;
  margin: 0 0 4px;
  font-size: 1.05rem;
}
.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 6px;
  position: relative;
  z-index: 30;
}
.toolbar > div { display: flex; gap: 8px; flex-wrap: wrap; }
.range, .hint { color: var(--muted); }
.legend { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin: 14px 0; color: var(--muted); }
.legend span { width: 18px; height: 18px; border-radius: 4px; display: inline-block; border: 1px solid var(--line); }
.legend em { font-style: normal; }
.legend .free { background: #fff; border-style: dashed; border-color: var(--green); }
.legend .busy { background: var(--busy); }
.legend .mine { background: var(--mine); }
.legend .event { background: var(--event); }
.calendar { display: grid; gap: 14px; }
.week-calendar {
  --time-col: 46px;
  height: calc(100vh - 260px);
  min-height: 300px;
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: visible;
  margin-bottom: 14px;
}
.mobile-calendar { display: none; }
.week-head {
  display: grid;
  grid-template-columns: var(--time-col) repeat(7, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: #eef5f0;
}
.time-head { border-right: 1px solid var(--line); }
.day-head {
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--line);
  font-size: clamp(.72rem, .9vw, .94rem);
  font-weight: 800;
  white-space: nowrap;
}
.day-head:last-child { border-right: 0; }
.week-body {
  min-height: 0;
  display: grid;
  grid-template-columns: var(--time-col) repeat(7, minmax(0, 1fr));
}
.time-axis {
  position: relative;
  align-self: start;
  height: calc(100% - 22px);
  margin-top: 22px;
  border-right: 1px solid var(--line);
  background: #fbfdfc;
  overflow: visible;
  z-index: 5;
}
.time-axis span {
  position: absolute;
  right: 6px;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: clamp(.58rem, .75vw, .76rem);
  line-height: 1;
}
.time-axis span.first { transform: translateY(-50%); }
.time-axis span.last { transform: translateY(-50%); }
.day-column {
  min-width: 0;
  border-right: 1px solid var(--line);
}
.day-column:last-child { border-right: 0; }
.mobile-day-title { display: none; }
.court-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  height: 100%;
}
.court-lane {
  min-width: 0;
  display: grid;
  grid-template-rows: 22px minmax(0, 1fr);
  border-right: 1px solid var(--line);
}
.court-lane:last-child { border-right: 0; }
.court-lane .court-title {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  border-bottom: 1px solid var(--line);
  background: #f8fbf9;
  color: var(--muted);
  font-size: clamp(.55rem, .72vw, .72rem);
  white-space: nowrap;
}
.lane-body {
  position: relative;
  min-height: 0;
  overflow: hidden;
}
.hour-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid #edf2ef;
  pointer-events: none;
}
.hour-line.hour { border-top-color: #d7e1dc; border-top-width: 1px; }
.hour-line.half { border-top-color: #f1f5f2; border-top-style: dashed; }
.slot-free-grid {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 1;
  border: 0;
  border-radius: 0;
  min-height: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}
.slot-free-grid:hover {
  background: rgba(31, 122, 77, .08);
  outline: 1px dashed var(--green);
  outline-offset: -1px;
}
.day {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.court-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.court {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 140px;
}
.court-title { font-weight: 800; margin-bottom: 8px; }
.slots { display: grid; gap: 6px; }
.slot-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
}
.slot-time {
  color: var(--muted);
  font-size: .86rem;
  padding-top: 8px;
  white-space: nowrap;
}
.slot-content { min-width: 0; }
.slot-free {
  display: flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--green);
  border-radius: 6px;
  padding: 7px 9px;
  background: #fff;
  text-align: center;
}
.booking {
  appearance: none;
  width: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 3px;
  margin: 0;
  display: grid;
  grid-template-rows: min-content min-content;
  align-content: start;
  gap: 0;
  text-align: left;
  font: inherit;
  color: var(--ink);
}
.lane-body > .booking {
  position: absolute;
  left: 2px;
  right: 2px;
  z-index: 3;
  min-height: 0;
  overflow: hidden;
  cursor: pointer;
}
.mobile-lane-body > .booking {
  position: absolute;
  left: 2px;
  right: 2px;
  z-index: 3;
  min-height: 0;
  overflow: hidden;
  cursor: pointer;
}
.booking strong,
.booking span {
  min-width: 0;
  overflow: hidden;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.08;
  font-size: clamp(.5rem, .68vw, .74rem);
}
.booking strong {
  font-weight: 850;
}
.booking span {
  font-size: clamp(.48rem, .62vw, .68rem);
}
.booking.mine { background: var(--mine); }
.booking.event { background: var(--event); }
.booking.busy { background: var(--busy); }
.booking span, .booking p { color: var(--muted); margin: 0; }
.booking-dialog {
  width: min(420px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--ink);
  background: #fff;
}
.booking-dialog::backdrop { background: rgba(15, 23, 42, .28); }
.reservation-modal {
  width: min(760px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--ink);
  background: #fff;
}
.reservation-modal::backdrop { background: rgba(15, 23, 42, .35); }
.reservation-modal-body {
  display: grid;
  gap: 12px;
}
.reservation-modal h1 {
  margin-right: 42px;
}
.reservation-modal .reservation-form {
  border: 0;
  padding: 0;
}
.booking-dialog h2 { margin-right: 32px; }
.dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  min-height: 34px;
  padding: 0;
}
.dialog-time { font-weight: 800; }
.dialog-details {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px 12px;
  margin: 12px 0 0;
}
.dialog-details dt { font-weight: 800; color: var(--muted); }
.dialog-details dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.dialog-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 14px;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.actions form { display: inline; }
.actions button { min-height: 30px; padding: 4px 8px; }
.empty { color: var(--muted); margin: 10px 0 0; }
.alert {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid #f2b8a2;
  background: #fff0ea;
  margin-bottom: 16px;
}
table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: #eef5f0; }

@media (max-width: 760px) {
  .site-header { align-items: flex-start; flex-direction: column; }
  .site-header .brand img { width: 38px; height: 38px; }
  .site-header .brand strong { font-size: 1rem; }
  .site-header .brand small { font-size: .78rem; }
  nav {
    width: 100%;
    gap: 8px;
  }
  .home-link {
    min-height: 34px;
    padding: 6px 10px;
  }
  .calendar-page {
    padding: 14px 12px calc(96px + env(safe-area-inset-bottom));
  }
  .calendar-page .toolbar {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr) 56px;
    grid-template-rows: auto auto;
    align-items: center;
    gap: 10px;
  }
  .calendar-page .toolbar h1 { display: none; }
  .calendar-page .toolbar > div {
    display: contents;
  }
  .calendar-page .toolbar .button {
    min-width: 0;
    padding: 10px;
  }
  .calendar-page .toolbar .week-prev {
    grid-column: 1;
    grid-row: 2;
    font-size: 0;
  }
  .calendar-page .toolbar .week-prev::before { content: "<"; font-size: 1.35rem; }
  .calendar-page .toolbar .week-next {
    grid-column: 3;
    grid-row: 2;
    font-size: 0;
  }
  .calendar-page .toolbar .week-next::before { content: ">"; font-size: 1.35rem; }
  .calendar-page .toolbar .week-today {
    grid-column: 2;
    grid-row: 2;
  }
  .calendar-page .toolbar .primary { display: none; }
  .range {
    grid-column: 1 / -1;
    grid-row: 1;
    text-align: center;
    font-size: 1.35rem;
    font-weight: 800;
    margin: 2px 0 4px;
  }
  .legend {
    display: flex;
    flex-wrap: nowrap;
    gap: 5px;
    align-items: center;
    overflow: hidden;
    white-space: nowrap;
    font-size: .72rem;
    margin: 8px 0 10px;
  }
  .legend span {
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
    border-radius: 4px;
  }
  .legend em {
    flex: 0 1 auto;
    min-width: 0;
    font-size: 0;
  }
  .legend em::after {
    content: attr(data-short);
    font-size: .72rem;
  }
  .week-calendar { display: none; }
  .mobile-calendar {
    display: block;
    position: relative;
  }
  .mobile-view-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: min(360px, 100%);
    margin: 0 auto 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
  }
  .mobile-view-toggle button {
    border: 0;
    border-radius: 0;
    min-height: 44px;
    background: #fff;
  }
  .mobile-view-toggle button.active {
    background: var(--green);
    color: #fff;
  }
  .mobile-week-view,
  .mobile-day-view {
    display: grid;
    gap: 14px;
    padding-bottom: 88px;
  }
  .mobile-court-section {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: visible;
  }
  .mobile-court-section h2,
  .mobile-court-section h3 {
    margin: 0;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    font-size: 1.05rem;
  }
  .mobile-week-head {
    display: grid;
    grid-template-columns: 52px repeat(7, minmax(0, 1fr));
    border-bottom: 1px solid var(--line);
    background: #f8fbf9;
  }
  .mobile-week-head > div {
    min-width: 0;
    padding: 6px 2px;
    text-align: center;
    border-right: 1px solid var(--line);
    color: var(--green-dark);
  }
  .mobile-week-head > div:last-child { border-right: 0; }
  .mobile-week-head strong,
  .mobile-week-head span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.1;
  }
  .mobile-week-head strong { font-size: .82rem; }
  .mobile-week-head span { font-size: .72rem; font-weight: 800; }
  .mobile-week-grid {
    display: grid;
    grid-template-columns: 52px repeat(7, minmax(0, 1fr));
    height: 430px;
  }
  .mobile-day-grid {
    grid-template-columns: 52px minmax(0, 1fr);
    height: 560px;
  }
  .mobile-time-axis {
    position: relative;
    border-right: 1px solid var(--line);
    background: #fbfdfc;
    overflow: visible;
    z-index: 5;
  }
  .mobile-time-axis span {
    position: absolute;
    right: 5px;
    transform: translateY(-50%);
    color: var(--green-dark);
    font-size: .72rem;
    line-height: 1;
  }
  .mobile-time-axis span.first { transform: translateY(-50%); }
  .mobile-time-axis span.last { transform: translateY(-50%); }
  .mobile-day-lane {
    min-width: 0;
    border-right: 1px solid var(--line);
  }
  .mobile-day-lane:last-child { border-right: 0; }
  .mobile-lane-body {
    position: relative;
    height: 100%;
    overflow: hidden;
  }
  .mobile-lane-body .hour-line.hour { border-top-color: #d7e1dc; }
  .mobile-lane-body .hour-line.half { border-top-color: #eef3f0; }
  .mobile-lane-body .slot-free-grid:hover,
  .mobile-lane-body .slot-free-grid:focus {
    background: rgba(31, 122, 77, .08);
    outline: 1px dashed var(--green);
    outline-offset: -1px;
  }
  .mobile-lane-body > .booking {
    padding: 3px 4px;
    border-radius: 5px;
  }
  .mobile-lane-body > .booking strong,
  .mobile-lane-body > .booking span {
    font-size: clamp(.58rem, 2.35vw, .76rem);
    line-height: 1.08;
    white-space: normal;
  }
  .mobile-day-grid .booking strong,
  .mobile-day-grid .booking span {
    font-size: .86rem;
  }
  .mobile-calendar .booking > span {
    display: none;
  }
  .mobile-day-picker {
    display: grid;
    gap: 6px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
  }
  .mobile-day-panel {
    display: grid;
    gap: 12px;
  }
  .mobile-day-panel > h2 {
    margin: 0;
    font-size: 1.1rem;
  }
  .mobile-calendar-help {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 16px;
    padding-bottom: 12px;
  }
  .mobile-calendar-help > div {
    display: grid;
    grid-template-columns: 34px 1fr;
    gap: 2px 10px;
    align-items: start;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
  }
  .mobile-calendar-help p {
    grid-column: 2;
    margin: 0;
    color: var(--muted);
  }
  .legend-icon {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    border: 1px solid var(--line);
    grid-row: span 2;
  }
  .legend-icon.free {
    border-style: dashed;
    border-color: var(--green);
  }
  .legend-icon.event { background: var(--event); }
  .mobile-fab {
    position: fixed;
    right: 18px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    z-index: 20;
    width: 58px;
    height: 58px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--green);
    color: #fff;
    font-size: 2rem;
    line-height: 1;
    box-shadow: 0 12px 26px rgba(21, 95, 59, .25);
  }
  .court-grid, .reservation-form { grid-template-columns: 1fr; }
  .slot-row { grid-template-columns: 48px minmax(0, 1fr); }
  table { display: block; overflow-x: auto; }
}

@media (max-width: 430px) {
  .mobile-week-grid {
    grid-template-columns: 44px repeat(7, minmax(0, 1fr));
    height: 390px;
  }
  .mobile-week-head { grid-template-columns: 44px repeat(7, minmax(0, 1fr)); }
  .mobile-day-grid { grid-template-columns: 44px minmax(0, 1fr); }
  .mobile-time-axis span { font-size: .64rem; right: 3px; }
  .mobile-lane-body > .booking { left: 1px; right: 1px; padding: 2px; }
}

[hidden],
.dialog-actions[hidden],
#dialog-edit[hidden],
#dialog-delete-form[hidden] {
  display: none !important;
}
