/* ===========================================================================
 * Pickleball Scheduler — mobile-first stylesheet
 * ========================================================================= */

:root {
  --color-bg: #f5f6f4;
  --color-surface: #ffffff;
  --color-text: #1b1f1c;
  --color-text-muted: #5d6a61;
  --color-border: #dde2dc;
  --color-accent: #0f7d3a;          /* pickleball green */
  --color-accent-dark: #0a5b2a;
  --color-accent-soft: #d9efdf;
  --color-warn: #c2410c;
  --color-warn-soft: #ffe9d6;
  --color-danger: #b91c1c;
  --color-info: #1e4ed8;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 6px 18px rgba(0,0,0,0.08);

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; }

a { color: var(--color-accent-dark); }

/* ---------- App bar ------------------------------------------------------ */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--color-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  padding-top: max(0.7rem, env(safe-area-inset-top));
  box-shadow: var(--shadow-sm);
}
.app-bar__title { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; font-size: 1.05rem; }
.app-bar__logo { font-size: 1.3rem; }
.app-bar__user { display: flex; align-items: center; gap: 0.6rem; }
.app-bar__userName { font-size: 0.9rem; opacity: 0.95; }

/* ---------- Layout ------------------------------------------------------- */
.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: 4rem;
}

/* ---------- Buttons ------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--color-accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  min-height: 44px;
}
.btn:hover { background: var(--color-accent-dark); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn--secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn--secondary:hover { background: #f0f3ef; }

.btn--ghost {
  background: transparent;
  color: inherit;
  border-color: rgba(255,255,255,0.4);
}
.btn--ghost:hover { background: rgba(255,255,255,0.15); }

.btn--danger { background: var(--color-danger); }
.btn--danger:hover { background: #8c1414; }

.btn--sm { padding: 0.45rem 0.8rem; min-height: 36px; font-size: 0.85rem; }
.btn--block { width: 100%; }

/* ---------- Forms -------------------------------------------------------- */
.form { display: flex; flex-direction: column; gap: 0.85rem; }
.form__group { display: flex; flex-direction: column; gap: 0.3rem; }
.form__group label { font-size: 0.85rem; color: var(--color-text-muted); font-weight: 600; }
.form__group input,
.form__group select {
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}
.form__group input:focus,
.form__group select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

.form__error { color: var(--color-danger); font-size: 0.9rem; min-height: 1.2em; }
.form__row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

/* ---------- Cards -------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
}

/* ---------- Auth view ---------------------------------------------------- */
.auth-card {
  max-width: 380px;
  margin: 2rem auto 0;
}
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--color-border);
}
.auth-tab {
  flex: 1;
  padding: 0.7rem;
  background: none;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.auth-tab.is-active { color: var(--color-accent-dark); border-bottom-color: var(--color-accent); }

.auth-hint {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  background: var(--color-accent-soft);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-md);
  margin-top: 1rem;
}

/* ---------- Calendar header --------------------------------------------- */
.calendar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 0.75rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}
.calendar__nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.calendar__title { font-weight: 600; }
.calendar__btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  width: 36px;
  height: 36px;
  cursor: pointer;
  color: var(--color-text-muted);
  border-radius: 50%;
}
.calendar__btn:hover { background: #f0f3ef; }

.calendar__weekdays,
.calendar__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  text-align: center;
}
.calendar__weekdays div {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  font-weight: 600;
  padding: 0.25rem 0;
}
.calendar__day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  background: transparent;
  border: none;
  color: var(--color-text);
  position: relative;
}
.calendar__day:hover { background: var(--color-accent-soft); }
.calendar__day.is-empty { cursor: default; visibility: hidden; }
.calendar__day.is-other-month { color: var(--color-text-muted); opacity: 0.4; }
.calendar__day.is-today {
  font-weight: 700;
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}
.calendar__day.is-selected { background: var(--color-accent); color: #fff; }
.calendar__day.is-selected:hover { background: var(--color-accent-dark); }
.calendar__day .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-accent);
  position: absolute;
  bottom: 4px;
}
.calendar__day.is-selected .dot { background: #fff; }

/* ---------- Events list ------------------------------------------------- */
.section-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin: 0.5rem 0;
  font-weight: 700;
}

.event-list { display: flex; flex-direction: column; gap: 0.75rem; }

.event-card {
  display: block;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 0.9rem 1rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.05s, box-shadow 0.15s;
  text-decoration: none;
  color: inherit;
}
.event-card:hover { box-shadow: var(--shadow-md); }
.event-card:active { transform: scale(0.995); }
.event-card__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.event-card__title { font-weight: 600; font-size: 1.05rem; }
.event-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.9rem;
  font-size: 0.88rem;
  color: var(--color-text-muted);
  margin-top: 0.3rem;
}
.event-card__time { color: var(--color-text); font-weight: 600; font-variant-numeric: tabular-nums; }
.event-card__chips { display: flex; gap: 0.35rem; margin-top: 0.55rem; flex-wrap: wrap; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--color-accent-soft);
  color: var(--color-accent-dark);
}
.chip--neutral { background: #eef0ed; color: var(--color-text-muted); }
.chip--warn { background: var(--color-warn-soft); color: var(--color-warn); }
.chip--info { background: #e0e8ff; color: var(--color-info); }

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

/* ---------- Floating action button -------------------------------------- */
.fab {
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #fff;
  border: none;
  font-size: 1.8rem;
  line-height: 0;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  z-index: 30;
}
.fab:hover { background: var(--color-accent-dark); }

/* ---------- Event detail ------------------------------------------------ */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  margin: 0 0 1rem -0.5rem;
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  border-radius: var(--radius-md);
}
.back-link:hover { background: #eef0ed; color: var(--color-text); }

.event-detail h1 { margin: 0 0 0.4rem; font-size: 1.3rem; }
.event-detail__meta {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  margin-bottom: 0.85rem;
}
.event-detail__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.5rem 0 1.2rem;
}

.signup-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.4rem;
}
.signup-list li {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.4rem 0.7rem;
  font-size: 0.9rem;
}

/* ---------- Rounds & games --------------------------------------------- */
.round {
  margin-top: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.round__head {
  background: var(--color-accent-soft);
  color: var(--color-accent-dark);
  padding: 0.6rem 1rem;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.round__head time { font-weight: 500; opacity: 0.8; font-size: 0.85rem; }
.round__games {
  display: grid;
  gap: 0.6rem;
  padding: 0.8rem;
}
@media (min-width: 540px) {
  .round__games { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}
.game {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.8rem;
}
.game__court {
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  font-weight: 700;
  margin-bottom: 0.3rem;
}
.game__players {
  margin: 0;
  padding-left: 1rem;
  font-size: 0.95rem;
}
.game__players li.is-me { font-weight: 700; color: var(--color-accent-dark); }

.waiting {
  padding: 0.6rem 1rem 1rem;
  border-top: 1px dashed var(--color-border);
}
.waiting__title { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; color: var(--color-warn); margin-bottom: 0.4rem; }
.waiting__list { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.waiting__list .chip { background: var(--color-warn-soft); color: var(--color-warn); }

/* ---------- Modal ------------------------------------------------------- */
.modal-host {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 16, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0.5rem;
}
@media (min-width: 540px) {
  .modal-host { align-items: center; padding: 1.5rem; }
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 460px;
  padding: 1.2rem;
  box-shadow: var(--shadow-md);
  max-height: 90vh;
  overflow: auto;
}
.modal h2 { margin: 0 0 1rem; font-size: 1.15rem; }
.modal__actions { display: flex; gap: 0.5rem; margin-top: 1.2rem; justify-content: flex-end; }

/* ---------- Toast ------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1b1f1c;
  color: #fff;
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  max-width: calc(100% - 2rem);
  box-shadow: var(--shadow-md);
}
.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.is-error { background: #7f1d1d; }

/* ---------- Loading spinner -------------------------------------------- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 0;
  color: var(--color-text-muted);
}
.loading::before {
  content: "";
  width: 22px;
  height: 22px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 0.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
