/* FindFields — portale centri · base condivisa
   Eredita i token di design da ../../css/styles.css (:root). Qui solo il layout
   del portale (shell, sidebar, topbar) e i componenti riusati nelle tab. */

:root {
  --portal-sidebar: 248px;
  --portal-topbar: 64px;
  --portal-gap: 1.25rem;
  --danger: #ff453a;
  --danger-soft: rgba(255, 69, 58, 0.12);
  --confirmed-soft: rgba(52, 199, 89, 0.14);
  --proposed-soft: rgba(255, 159, 10, 0.14);
  --topbar-bg: rgba(10, 10, 11, 0.72);
  --tabbar-bg: rgba(10, 10, 11, 0.86);
  --card-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

/* ---------- Tema chiaro ---------- */
html[data-theme="light"] {
  --bg: #f5f5f7;
  --bg-elev: #ffffff;
  --surface: #ececed;
  --border: #dcdce1;
  --text: #1d1d1f;
  --text-dim: #56565e;
  --text-faint: #8a8a90;
  --accent: #007aff;
  --accent-dim: #0064d2;
  --accent-soft: rgba(0, 122, 255, 0.1);
  --accent-line: rgba(0, 122, 255, 0.28);
  --danger: #ff3b30;
  --danger-soft: rgba(255, 59, 48, 0.1);
  --confirmed-soft: rgba(52, 199, 89, 0.16);
  --proposed-soft: rgba(255, 159, 10, 0.16);
  --topbar-bg: rgba(255, 255, 255, 0.72);
  --tabbar-bg: rgba(255, 255, 255, 0.88);
  --card-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
}

/* ---------- Form controls ---------- */

.input {
  width: 100%;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.72rem 0.95rem;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.input::placeholder { color: var(--text-faint); }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select.input {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  padding-right: 2.4rem;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 16 16' fill='none' stroke='%238a8a90' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'><path d='M4 6l4 4 4-4'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 14px;
}

.btn--block { width: 100%; }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: #e23b31; color: #fff; }
.btn--subtle {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn--subtle:hover { border-color: var(--accent-line); color: var(--text); }
.btn--sm { padding: 0.5rem 0.85rem; font-size: 0.85rem; }
.btn[disabled] { opacity: 0.55; pointer-events: none; }

/* ---------- App shell ---------- */

.app-body {
  min-height: 100vh;
  background: var(--bg);
}

.shell {
  display: grid;
  grid-template-columns: var(--portal-sidebar) 1fr;
  min-height: 100vh;
}

/* Sidebar (desktop) */
.sidebar {
  position: sticky;
  top: 0;
  z-index: 30; /* il menu dello switcher deve stare sopra la topbar (z 20) */
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1.25rem 0.85rem;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
}
.sidebar__center { margin: 0 0 0.9rem; }
.sidebar__brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.03em;
  color: var(--text);
  padding: 0.4rem 0.65rem 1.25rem;
}
.sidebar__brand img { width: 30px; height: 30px; border-radius: 8px; }
.sidebar__brand span span { color: var(--accent); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.72rem 0.8rem;
  border-radius: 11px;
  color: var(--text-dim);
  font-size: 0.94rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  position: relative;
}
.nav-item:hover { color: var(--text); background: var(--surface); }
.nav-item.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
.nav-item svg { flex-shrink: 0; }
.nav-item__badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-item__badge[hidden] { display: none; }

.sidebar__spacer { flex: 1; }
.sidebar__user {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  font-family: inherit;
  text-align: left;
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  border-radius: 0;
  padding: 0.75rem 0.8rem 0.35rem;
  cursor: pointer;
}
.sidebar__user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.16s ease;
}
.sidebar__user:hover .sidebar__user-name { color: var(--text); }
.sidebar__user-mail {
  font-size: 0.74rem;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main column */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--portal-topbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.5rem;
  background: var(--topbar-bg);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar__lead {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}
.topbar__title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__center { display: none; } /* lo switcher compatto appare solo su mobile */
.topbar__right { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.topbar__actions { display: flex; align-items: center; gap: 0.6rem; }

/* ---------- Theme toggle (sole ↔ luna) ---------- */
.theme-toggle {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.16s ease, color 0.16s ease, background 0.16s ease;
}
.theme-toggle:hover { border-color: var(--accent-line); color: var(--accent); }
.tt { display: block; overflow: visible; }
.tt-core, .tt-moon, .tt-rays {
  transform-box: fill-box;
  transform-origin: center;
}
.tt-moon { transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1); }
.tt-rays { transition: opacity 0.35s ease, transform 0.5s cubic-bezier(0.4, 0, 0.2, 1); }

/* Sole (chiaro): cutout fuori → cerchio pieno, raggi visibili */
html[data-theme="light"] .tt-moon { transform: translateX(16px); }
html[data-theme="light"] .tt-rays { opacity: 1; transform: scale(1) rotate(0deg); }

/* Luna (scuro): cutout morde → falce, raggi nascosti */
html[data-theme="dark"] .tt-moon { transform: translate(6px, -3px); }
html[data-theme="dark"] .tt-rays { opacity: 0; transform: scale(0.4) rotate(45deg); }

.content {
  flex: 1;
  padding: 1.75rem 1.5rem 5rem;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- Cards & shared bits ---------- */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
}
.card__title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.section-head h2 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Status chip (prenotazioni) */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.chip::before {
  content: "";
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
}
.chip.is-confirmed { color: var(--confirmed); border-color: rgba(52,199,89,.35); background: var(--confirmed-soft); }
.chip.is-proposed  { color: var(--proposed);  border-color: rgba(255,159,10,.35); background: var(--proposed-soft); }
.chip.is-draft     { color: var(--accent);    border-color: var(--accent-line); background: var(--accent-soft); }
.chip.is-cancelled { color: var(--text-faint); }

/* States */
.empty-state {
  text-align: center;
  padding: 3.5rem 1.5rem;
  color: var(--text-dim);
}
.empty-state svg { color: var(--text-faint); margin-bottom: 1rem; }
.empty-state h3 { color: var(--text); font-size: 1.05rem; font-weight: 600; margin-bottom: 0.4rem; }

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 3rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.banner-error {
  background: var(--danger-soft);
  border: 1px solid rgba(255, 69, 58, 0.4);
  color: #ff6b61;
  border-radius: 12px;
  padding: 0.85rem 1.1rem;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

/* ---------- Mobile bottom tab bar (stile iPhone/iPad) ---------- */

.tabbar { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding: 1.25rem 1rem calc(5.5rem + env(safe-area-inset-bottom)); }

  /* Topbar mobile: titolo + switcher centro impilati a sinistra */
  .topbar { padding: 0 1rem; }
  .topbar__title { font-size: 1.02rem; }
  .topbar__center { display: block; }

  .tabbar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 40;
    background: var(--tabbar-bg);
    backdrop-filter: saturate(160%) blur(16px);
    -webkit-backdrop-filter: saturate(160%) blur(16px);
    border-top: 1px solid var(--border);
    padding: 0.4rem 0.5rem calc(0.4rem + env(safe-area-inset-bottom));
  }
  .tabbar .nav-item {
    flex-direction: column;
    gap: 0.18rem;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    padding: 0.35rem 0.25rem;
    border: none;
    background: none;
  }
  .tabbar .nav-item.is-active { background: none; color: var(--accent); }
  .tabbar .nav-item__badge {
    position: absolute;
    top: 0.1rem;
    right: calc(50% - 1.4rem);
    margin: 0;
  }
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: modal-fade 0.18s ease;
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%;
  max-width: 440px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.5);
  animation: modal-rise 0.2s ease;
}
@keyframes modal-rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.3rem 0.4rem;
}
.modal__title { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; }
.modal__close {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.2rem;
}
.modal__close:hover { color: var(--text); }
.modal__body { padding: 0.6rem 1.3rem 0.5rem; }
.modal__body .field { display: grid; gap: 0.45rem; margin-bottom: 0.9rem; }
.modal__body .field__label { font-size: 0.85rem; font-weight: 500; color: var(--text-dim); }
.modal__foot {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
  padding: 0.6rem 1.3rem 1.3rem;
}
.modal__foot .btn {
  flex: 1 1 auto;
  min-width: 0;
  justify-content: center;
  white-space: nowrap;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translate(-50%, 1rem);
  z-index: 90;
  padding: 0.75rem 1.15rem;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
  max-width: calc(100vw - 2rem);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast--ok { border-color: rgba(52, 199, 89, 0.5); }
.toast--err { border-color: rgba(255, 69, 58, 0.5); }
@media (max-width: 900px) { .toast { bottom: calc(5rem + env(safe-area-inset-bottom)); } }

/* Utility */
.row { display: flex; align-items: center; gap: 0.6rem; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--portal-gap); }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Selettore centro sportivo (switcher) ---------- */

.cswitch { position: relative; min-width: 0; }
.cswitch__btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  min-width: 0;
  font-family: inherit;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.5rem 0.65rem;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease;
}
.cswitch__btn:hover { border-color: var(--accent-line); }
.cswitch__btn > svg { flex-shrink: 0; margin-left: auto; color: var(--text-faint); }
.cswitch__badge {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.95rem;
}
.cswitch__txt {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.cswitch__name {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cswitch__sub {
  font-size: 0.74rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cswitch__sub:empty { display: none; }

.cswitch__menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  width: max-content;
  min-width: 100%;
  max-width: min(320px, calc(100vw - 2rem));
  max-height: min(60vh, 420px);
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.35rem;
  box-shadow: var(--card-shadow);
  transform-origin: top left;
  animation: cswitch-pop 0.16s cubic-bezier(0.2, 0, 0, 1);
}
@keyframes cswitch-pop {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
}
.cswitch__opt {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  font-family: inherit;
  font-size: 0.9rem;
  text-align: left;
  background: none;
  border: none;
  border-radius: 9px;
  padding: 0.5rem 0.6rem;
  color: var(--text);
  cursor: pointer;
}
.cswitch__opt:hover,
.cswitch__opt:focus-visible { background: var(--surface); }
.cswitch__opt.is-active .cswitch__name { color: var(--accent); }
.cswitch__check {
  width: 16px;
  flex-shrink: 0;
  display: inline-flex;
  color: var(--accent);
}
.cswitch__sep { height: 1px; background: var(--border); margin: 0.35rem 0.3rem; }
.cswitch__new { color: var(--accent); font-weight: 600; font-size: 0.88rem; }
.cswitch__new svg { flex-shrink: 0; }

/* Variante compatta (topbar mobile): solo nome + chevron, hit-area estesa */
.cswitch--compact .cswitch__btn {
  background: transparent;
  border-color: transparent;
  border-radius: 8px;
  padding: 0.1rem 0.4rem;
  gap: 0.3rem;
  margin-left: -0.4rem;
  width: auto;
  max-width: 100%;
}
.cswitch--compact .cswitch__btn::after { content: ""; position: absolute; inset: -8px; }
.cswitch--compact .cswitch__btn:hover { background: var(--surface); }
.cswitch--compact .cswitch__badge { display: none; }
.cswitch--compact .cswitch__sub { display: none; }
.cswitch--compact .cswitch__name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
}
.cswitch--compact .cswitch__btn > svg { width: 12px; height: 12px; }

/* ---------- Skeleton loading ---------- */

.skel {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.skel::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.05), transparent);
  animation: skel-sweep 1.3s ease-in-out infinite;
}
html[data-theme="light"] .skel::after {
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.045), transparent);
}
@keyframes skel-sweep { to { transform: translateX(100%); } }
.skel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--portal-gap);
}
.skel-kpi {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--portal-gap);
}
@media (max-width: 900px) {
  .skel-kpi { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Banner errore con retry ---------- */

.banner-error--retry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.cal .banner-error--retry { border: none; margin: 0; border-radius: 0; }

/* ---------- Focus visibile (tastiera) ---------- */

.btn:focus-visible,
.nav-item:focus-visible,
.theme-toggle:focus-visible,
.cswitch__btn:focus-visible,
.sidebar__user:focus-visible,
.seg__btn:focus-visible,
.day-nav__arrow:focus-visible,
.day-nav__today:focus-visible,
.cal-block:focus-visible,
.modal__close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .modal-overlay,
  .modal,
  .cswitch__menu { animation: none; }
  .skel::after { animation: none; }
  .toast { transition: opacity 0.01s linear; }
  .tt-moon,
  .tt-rays,
  .cal-block,
  .fieldcard,
  .bar__fill { transition: none; }
  .fieldcard:hover,
  .cal-block:hover { transform: none; }
}

/* ---------- Editor orari per giorno ---------- */

.sched { display: grid; gap: 0.4rem; }
.sched-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.35rem 0;
}
.sched-row__day {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.92rem;
  cursor: pointer;
  min-width: 105px;
}
.sched-row__day input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.sched-row__times {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.sched-row__times .input {
  padding: 0.45rem 0.55rem;
  width: auto;
  font-size: 0.88rem;
}
.sched-sep { color: var(--text-faint); }
.sched-row.is-closed .sched-row__day span { color: var(--text-faint); }
.sched-row.is-closed .sched-row__times { opacity: 0.45; }

@media (max-width: 460px) {
  .sched-row { flex-direction: column; align-items: stretch; gap: 0.35rem; }
  .sched-row__times { justify-content: space-between; }
  .sched-row__times .input { flex: 1; }
}
