:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f6f3f8;
  color: #24212b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

button,
input,
select,
textarea {
  border-radius: 8px;
  font: inherit;
}

button {
  background: #e45c3d;
  border: 1px solid #c84b31;
  color: #fff;
  cursor: pointer;
  font-weight: 750;
  min-height: 42px;
  padding: 9px 14px;
}

button.secondary,
.icon-button {
  background: #f3eef7;
  border-color: #ddd3e6;
  color: #31263e;
}

button.danger {
  background: #9f332b;
  border-color: #852821;
}

button.whatsapp-button {
  background: #168c48;
  border-color: #11723a;
}

button:disabled {
  cursor: not-allowed;
  opacity: .58;
}

button.saving {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  justify-content: center;
}

button.saving::before {
  animation: saving-spin .75s linear infinite;
  border: 2px solid rgba(255, 255, 255, .45);
  border-radius: 50%;
  border-top-color: #fff;
  content: "";
  height: 16px;
  width: 16px;
}

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

.hidden {
  display: none !important;
}

.app-header {
  align-items: center;
  background: #31263e;
  color: #fff;
  display: grid;
  gap: 12px;
  grid-template-columns: 44px 1fr 44px;
  padding: max(14px, env(safe-area-inset-top)) 14px 14px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-header h1,
.month-bar h2,
.list-header h2,
.sheet-title h2,
.menu-section h3 {
  margin: 0;
}

.app-header h1 {
  font-size: 22px;
}

.app-title-row {
  align-items: center;
  display: flex;
  gap: 8px;
}

.app-version {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  color: #f5edf9;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  white-space: nowrap;
}

.app-header p {
  color: #ded4e8;
  font-size: 12px;
  margin: 2px 0 0;
}

.icon-button {
  align-items: center;
  display: inline-flex;
  font-size: 22px;
  justify-content: center;
  min-height: 42px;
  min-width: 42px;
  padding: 0;
}

.view-tabs {
  background: #fff;
  border-bottom: 1px solid #ded8e6;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 8px;
  position: sticky;
  top: 72px;
  z-index: 18;
}

.rota-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.rota-header small {
  color: #736d7a;
}

.rota-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.rota-filters {
  align-items: end;
  background: #fff;
  border: 1px solid #ded8e6;
  border-radius: 10px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) auto;
  margin-bottom: 12px;
  padding: 12px;
}

.rota-table-wrap {
  background: #fff;
  border: 1px solid #ded8e6;
  border-radius: 10px;
  overflow-x: auto;
}

.rota-table {
  border-collapse: collapse;
  min-width: 760px;
  width: 100%;
}

.rota-table th,
.rota-table td {
  border: 1px solid #24212b;
  padding: 9px;
  text-align: left;
  vertical-align: top;
}

.rota-table th {
  background: #fff;
  color: #403748;
  font-size: 12px;
  text-transform: uppercase;
}

.rota-table thead th {
  border-bottom-width: 2px;
}

.rota-table .rota-date { min-width: 112px; }
.rota-table .rota-event { min-width: 190px; }
.rota-table .rota-times { min-width: 120px; }
.rota-table .rota-guests-tickets { min-width: 165px; }

.rota-event-link {
  background: transparent;
  border: 0;
  box-shadow: none;
  color: #4f2f72;
  font: inherit;
  font-weight: 800;
  min-height: 0;
  padding: 0;
  text-align: left;
  text-decoration: underline;
}

.rota-setup-table tr > :nth-child(4) {
  text-align: center;
}

.rota-event-link:hover {
  color: #e45c3d;
}

.rota-staff-heading {
  min-width: 48px;
  padding: 8px 5px !important;
  text-align: center !important;
  vertical-align: bottom !important;
  width: 48px;
}

.rota-staff-heading span {
  display: inline-block;
  line-height: 1;
  transform: rotate(180deg);
  white-space: nowrap;
  writing-mode: vertical-rl;
}

.rota-staff-cell {
  font-size: 22px !important;
  font-weight: 900;
  min-width: 48px;
  padding: 5px !important;
  text-align: center !important;
}

.rota-staff-cell.allocated {
  background: #fff500;
  color: #24212b;
}

.rota-staff-cell.unavailable {
  background: #ece9ef;
  color: #9f332b;
}

.rota-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 0 4px 12px;
}

.rota-legend span {
  align-items: center;
  display: inline-flex;
  font-size: 13px;
  gap: 6px;
}

.rota-legend strong {
  align-items: center;
  border: 1px solid #24212b;
  display: inline-flex;
  font-size: 18px;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.legend-tick { background: #fff500; }
.legend-cross { background: #ece9ef; color: #9f332b; }

.rota-status-button {
  background: #fff;
  border: 0;
  border-radius: 0;
  color: #24212b;
  font-size: 22px;
  height: 100%;
  min-height: 38px;
  padding: 0;
  width: 100%;
}

.rota-status-button.on_rota { background: #fff500; }
.rota-status-button.unavailable { background: #ece9ef; color: #9f332b; }
.rota-status-button.cell-saving { cursor: progress; opacity: .55; }
.rota-setup-table .rota-staff-cell { padding: 0 !important; }

.rota-setup-wrap {
  max-height: calc(100vh - 245px);
  overflow: auto;
}

.rota-setup-table thead th {
  position: sticky;
  top: 0;
  z-index: 4;
}

.rota-setup-table thead .rota-date {
  left: 0;
  z-index: 6;
}

.rota-setup-table tbody tr:not(.rota-month-row) > td:first-child {
  background: #fff;
  left: 0;
  position: sticky;
  z-index: 2;
}

.rota-month-row th {
  background: #31263e;
  color: #fff;
  font-size: 14px;
  letter-spacing: .04em;
  padding: 8px 10px;
  text-align: left;
}

.rota-no-staff .rota-date,
.rota-no-staff .rota-event,
.rota-no-staff .rota-times {
  background: #fff1ef;
}

.rota-table td {
  font-size: 14px;
}

@media print {
  .app-header, .view-tabs, .fab, #calendarView, #listView, #rotaView, .rota-actions, .rota-filters, .rota-legend { display: none !important; }
  main { max-width: none; padding: 0; }
  #rotaSetupView { display: block !important; }
  .rota-table-wrap { border: 0; }
  .rota-table { font-size: 8pt; min-width: 0; }
  .rota-table th, .rota-table td { padding: 4px; }
  .rota-staff-heading, .rota-staff-cell { min-width: 28px; width: 28px; }
  .rota-status-button { border: 0; }
  @page { margin: 15mm; }
}

@media (max-width: 560px) {
  .rota-filters { grid-template-columns: 1fr 1fr; }
  #clearRotaFilterButton { grid-column: 1 / -1; }
}

.view-tabs button {
  background: transparent;
  border: 0;
  color: #31263e;
}

.view-tabs button.active {
  background: #31263e;
  color: #fff;
}

main {
  margin: 0 auto;
  max-width: 980px;
  padding: 12px 10px 96px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.month-bar {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: 44px 1fr 44px;
  margin-bottom: 10px;
  text-align: center;
}

.month-bar h2 {
  font-size: 20px;
}

.month-bar span {
  color: #736d7a;
  font-size: 13px;
}

.calendar-grid {
  background: #fff;
  border: 1px solid #ded8e6;
  border-radius: 10px;
  overflow: hidden;
}

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

.calendar-weekdays {
  background: #f0ebf5;
}

.calendar-weekdays span {
  color: #6d6177;
  font-size: 11px;
  font-weight: 800;
  padding: 8px 2px;
  text-align: center;
  text-transform: uppercase;
}

.calendar-day {
  background: #fffdfb;
  border-right: 1px solid #e6e0eb;
  border-top: 1px solid #e6e0eb;
  min-height: 104px;
  min-width: 0;
  padding: 5px;
}

.calendar-day:nth-child(7n) {
  border-right: 0;
}

.calendar-day.muted {
  background: #f1eef4;
}

.calendar-day.today {
  box-shadow: inset 0 0 0 2px #e45c3d;
}

.calendar-day strong {
  color: #403748;
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
}

.calendar-events {
  display: grid;
  gap: 4px;
}

.calendar-event {
  background: #fff;
  border: 1px solid #ded8e6;
  color: #24212b;
  display: grid;
  font-size: 11px;
  font-weight: 700;
  min-height: 0;
  overflow: hidden;
  padding: 4px;
  text-align: left;
}

.calendar-event span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-event small {
  color: #736d7a;
  font-size: 10px;
  margin-top: 1px;
}

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

.events-list,
.type-list {
  display: grid;
  gap: 10px;
}

.event-list-item {
  background: #fff;
  border: 1px solid #ded8e6;
  border-left: 5px solid #e45c3d;
  box-shadow: 0 8px 22px rgba(49, 38, 62, .08);
  color: #24212b;
  display: grid;
  gap: 7px;
  padding: 14px;
  text-align: left;
}

.event-list-item.ticketed {
  border-left-color: #6c4aa0;
}

.event-list-item.private {
  border-left-color: #e45c3d;
}

.event-list-heading {
  align-items: baseline;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.event-list-heading > div {
  align-items: baseline;
  display: flex;
  gap: 9px;
}

.event-list-heading strong {
  font-size: 17px;
}

.event-list-heading span {
  color: #e45c3d;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.event-list-heading .event-kind-badge {
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  letter-spacing: .03em;
  padding: 5px 9px;
  text-transform: uppercase;
}

.ticketed .event-kind-badge {
  background: #6c4aa0;
}

.private .event-kind-badge {
  background: #e45c3d;
}

.event-list-name {
  font-size: 15px;
  font-weight: 800;
}

.event-list-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.event-list-item .event-list-meta span {
  background: #f3eef7;
  border: 1px solid #e3dbe9;
  border-radius: 999px;
  color: #4d4356;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
}

.event-list-finish {
  border-top: 1px solid #eee8f1;
  padding-top: 7px;
}

.event-list-item span,
.event-list-item small,
.empty-state {
  color: #736d7a;
  font-size: 13px;
}

.empty-state {
  background: #fff;
  border: 1px solid #ded8e6;
  border-radius: 10px;
  padding: 18px;
}

.fab {
  border-radius: 999px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 10px 30px rgba(49, 38, 62, .24);
  font-size: 34px;
  height: 64px;
  line-height: 1;
  padding: 0;
  position: fixed;
  right: 18px;
  width: 64px;
  z-index: 30;
}

.sheet,
.drawer {
  background: rgba(36, 33, 43, .46);
  inset: 0;
  position: fixed;
  z-index: 40;
}

.sheet-panel,
.drawer-panel {
  background: #fff;
  box-shadow: 0 -12px 40px rgba(49, 38, 62, .24);
  max-height: 92vh;
  overflow-y: auto;
}

.sheet-panel {
  border-radius: 18px 18px 0 0;
  bottom: 0;
  left: 0;
  padding: 18px;
  position: absolute;
  right: 0;
}

.drawer-panel {
  bottom: 0;
  max-width: 420px;
  padding: 18px;
  position: absolute;
  right: 0;
  top: 0;
  width: min(92vw, 420px);
}

.sheet-title {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
}

.event-form,
.type-form,
.menu-section {
  display: grid;
  gap: 12px;
}

.menu-navigation {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.menu-navigation button.active {
  background: #31263e;
  border-color: #31263e;
  color: #fff;
}

.menu-section {
  border-top: 1px solid #e6e0eb;
  padding: 16px 0;
}

.field-row {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.field-row.deposit-row {
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
}

label {
  color: #655d6d;
  display: grid;
  font-size: 13px;
  gap: 6px;
}

.checkbox-field {
  align-items: center;
  display: flex;
  gap: 10px;
}

.checkbox-field input {
  min-height: 20px;
  width: 20px;
}

input,
select,
textarea {
  background: #fffdfb;
  border: 1px solid #d8d0e0;
  color: #24212b;
  min-height: 44px;
  padding: 9px 10px;
  width: 100%;
}

textarea {
  resize: vertical;
}

.details-section {
  border: 1px solid #ded8e6;
  border-radius: 10px;
  display: grid;
  gap: 12px;
  margin: 4px 0;
  padding: 14px;
}

.collapsible-section {
  background: #fff;
  border: 1px solid #ded8e6;
  border-radius: 10px;
  overflow: hidden;
}

.collapsible-section summary {
  background: #f3eef7;
  color: #31263e;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  list-style: none;
  padding: 14px 42px 14px 14px;
  position: relative;
}

.collapsible-section summary::-webkit-details-marker {
  display: none;
}

.collapsible-section summary::after {
  content: "+";
  font-size: 22px;
  line-height: 1;
  position: absolute;
  right: 15px;
  top: 11px;
}

.collapsible-section[open] summary::after {
  content: "−";
}

.collapsible-section[open] summary {
  border-bottom: 1px solid #ded8e6;
}

.details-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.sheet-actions {
  background: #fff;
  border-top: 1px solid #e6e0eb;
  bottom: -18px;
  box-shadow: 0 -8px 18px rgba(49, 38, 62, .08);
  padding: 12px 0 18px;
  position: sticky;
  z-index: 3;
}

.details-section legend {
  color: #31263e;
  font-weight: 800;
  padding: 0 6px;
}

.field-help {
  color: #736d7a;
}

.event-staff-assignments {
  border: 1px solid #ded8e6;
  border-radius: 8px;
  display: grid;
  overflow: hidden;
}

.event-staff-row {
  align-items: center;
  background: #fff;
  border-bottom: 1px solid #e6e0eb;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 110px;
  padding: 8px 10px;
}

.event-staff-row:last-child {
  border-bottom: 0;
}

.event-staff-row span {
  color: #403748;
  font-weight: 700;
}

.event-staff-status {
  background: #fff;
  border-color: #d8d0e0;
  color: #403748;
  min-height: 38px;
  padding: 5px 8px;
}

.event-staff-status.on_rota {
  background: #fff500;
  border-color: #24212b;
  color: #24212b;
}

.event-staff-status.unavailable {
  background: #ece9ef;
  border-color: #9f332b;
  color: #9f332b;
}

.sheet-actions,
.cleanup-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.sheet-actions {
  grid-template-columns: repeat(4, 1fr);
}

.type-form {
  align-items: center;
  grid-template-columns: 1fr auto auto;
}

.type-row {
  align-items: center;
  border: 1px solid #e6e0eb;
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr auto;
  padding: 10px;
}

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

.type-delete {
  min-height: 34px;
  padding: 6px 10px;
}

.type-row label {
  align-items: center;
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.type-row input[type="checkbox"] {
  min-height: 18px;
  width: 18px;
}

.cleanup-summary {
  background: #f8f5fb;
  border: 1px solid #ded8e6;
  border-radius: 8px;
  color: #403748;
  font-size: 13px;
  line-height: 1.45;
  padding: 12px;
}

#toast {
  background: #24212b;
  border-radius: 10px;
  bottom: calc(92px + env(safe-area-inset-bottom));
  color: #fff;
  left: 50%;
  max-width: min(92vw, 560px);
  opacity: 0;
  padding: 12px 14px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 12px);
  transition: opacity .18s ease, transform .18s ease;
  z-index: 60;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 760px) {
  .calendar-day {
    min-height: 132px;
    padding: 8px;
  }

  .calendar-event {
    font-size: 12px;
    padding: 5px;
  }

  .sheet-panel {
    border-radius: 18px;
    bottom: auto;
    left: 50%;
    max-width: 620px;
    right: auto;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 620px);
  }
}

@media (max-width: 430px) {
  .calendar-day {
    min-height: 88px;
    padding: 4px;
  }

  .calendar-event small {
    display: none;
  }

  .field-row,
  .sheet-actions,
  .cleanup-actions,
  .type-form {
    grid-template-columns: 1fr;
  }

  .field-row.date-time-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .field-row.deposit-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .deposit-row > label:last-child {
    grid-column: 1 / -1;
  }

  .date-time-row label,
  .date-time-row input {
    min-width: 0;
  }
}
