:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --text: #1d2a24;
  --muted: #5f6f67;
  --border: #dde3de;
  --primary: #2f6b4f;
  --primary-hover: #245640;
  --primary-soft: #e3efe8;
  --warn: #a35a12;
  --warn-soft: #fbeedd;
  --danger: #b3261e;
  --danger-soft: #fbe4e2;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a17;
    --surface: #1d2521;
    --text: #e6ece8;
    --muted: #9aaba2;
    --border: #2e3934;
    --primary: #5fb08a;
    --primary-hover: #74c39d;
    --primary-soft: #23382e;
    --warn: #e9a35c;
    --warn-soft: #3a2c1c;
    --danger: #f2867e;
    --danger-soft: #3b2120;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--primary);
}

h1 {
  font-size: 1.75rem;
  margin: 0 0 1rem;
}

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

h3 {
  font-size: 1rem;
  margin: 0 0 0.5rem;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
}

.main {
  padding-top: 24px;
  padding-bottom: 48px;
}

.muted {
  color: var(--muted);
}

.error-text {
  color: var(--danger);
  margin: 0.5rem 0;
}

form.inline {
  display: inline;
  margin: 0;
}

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin: 0 0 20px;
  font-weight: 500;
}

.flash-ok {
  background: var(--primary-soft);
  color: var(--primary);
}

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

/* Barra superiore */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
  flex-wrap: wrap;
}

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

.nav {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.nav a {
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
}

.nav a.active {
  color: var(--text);
}

.nav a.btn-primary {
  color: #fff;
}

/* Pulsanti */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn.disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover:not(.disabled) {
  background: var(--primary-soft);
}

.btn-small {
  padding: 4px 12px;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--border);
  color: var(--text);
}

.badge-ok {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

/* Elenco gite */
.hero {
  margin-bottom: 16px;
}

.hero p {
  margin: -0.5rem 0 0;
  color: var(--muted);
}

.filters {
  display: grid;
  grid-template-columns: 2fr repeat(4, 1fr) auto;
  gap: 8px;
  margin-bottom: 24px;
}

.filters input,
.filters select,
.form input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

/* Card gita */
.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-past > :not(dialog) {
  opacity: 0.75;
}

.card-photo-link {
  position: relative;
  display: block;
  text-decoration: none;
}

.trip-photo {
  display: block;
  width: 100%;
  height: 170px;
  object-fit: cover;
}

.trip-photo-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.5rem;
  background: linear-gradient(160deg, #8fb8a2, #2f6b4f);
}

.cat-escursionismo-invernale {
  background: linear-gradient(160deg, #cfe2f3, #5b86b0);
}

.cat-via-ferrata {
  background: linear-gradient(160deg, #d9c3a5, #8a5a2f);
}

.cat-sci-alpinismo {
  background: linear-gradient(160deg, #e6eef5, #7896b5);
}

.cat-mountain-bike {
  background: linear-gradient(160deg, #e2c98f, #a0782a);
}

.card-category {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.55);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
}

.card-body {
  padding: 16px 16px 8px;
  flex: 1;
}

.card-date {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.card-date::first-letter {
  text-transform: uppercase;
}

.card-title {
  margin: 2px 0 0;
  font-size: 1.15rem;
}

.card-valley {
  margin: 0 0 8px;
  color: var(--muted);
}

.card-stats {
  list-style: none;
  padding: 0;
  margin: 0 0 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 0.9rem;
}

.card-stats .difficulty {
  font-weight: 700;
  color: var(--primary);
}

.card-desc {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px 16px;
}

.participate {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.spots {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 4px;
}

.spots p {
  margin: 4px 0 0;
}

.spots-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.spots-bar span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin: 24px 0;
}

/* Popup e pagina di dettaglio */
.modal {
  padding: 0;
  border: none;
  border-radius: var(--radius);
  width: min(720px, calc(100% - 32px));
  max-height: calc(100% - 64px);
  background: var(--surface);
  color: var(--text);
}

.modal::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.modal .trip-photo,
.trip-page .trip-photo {
  height: 220px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgb(0 0 0 / 0.55);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
}

.modal-body {
  padding: 20px 24px 24px;
}

.trip-title {
  margin: 2px 0 0;
  font-size: 1.5rem;
}

.trip-desc {
  white-space: pre-line;
}

.details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin: 16px 0;
}

.details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
  font-size: 0.95rem;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
}

.modal-body .participate {
  margin-top: 16px;
}

.trip-page {
  padding: 0;
  overflow: hidden;
}

/* Form */
.auth-box {
  max-width: 420px;
  margin: 24px auto;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 500;
}

.form label small {
  font-weight: 400;
  color: var(--muted);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form .btn {
  align-self: flex-start;
}

.auth-box .form .btn {
  align-self: stretch;
}

.oauth {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.divider {
  text-align: center;
  color: var(--muted);
  margin: 0;
}

.btn-oauth {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.btn-facebook {
  background: #1877f2;
  border-color: #1877f2;
  color: #fff;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 24px;
}

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

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

.table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.9rem;
}

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

  .filters input {
    grid-column: 1 / -1;
  }

  .details-grid,
  .form-row {
    grid-template-columns: 1fr;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
  }

  .panel {
    padding: 16px;
  }

  .table th:nth-child(3),
  .table td:nth-child(3) {
    white-space: nowrap;
  }
}

/* Gestione e amministrazione */
.card-group {
  margin: -6px 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.page-head h1 {
  margin-bottom: 0.25rem;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 8px 0 20px;
}

.tabs a {
  padding: 8px 14px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tabs a.active {
  color: var(--text);
  border-bottom-color: var(--primary);
}

.list {
  display: grid;
  gap: 12px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  text-decoration: none;
  color: var(--text);
  margin: 0;
}

.list-item:hover {
  outline: 2px solid var(--primary-soft);
}

.table-wrap {
  padding: 8px 16px;
  overflow-x: auto;
}

.table .nowrap {
  white-space: nowrap;
}

.table .actions {
  text-align: right;
  white-space: nowrap;
}

.table .actions > * + * {
  margin-left: 4px;
}

.row-muted td {
  color: var(--muted);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  filter: brightness(0.9);
}

.form select,
.form textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.form h2 {
  margin: 12px 0 0;
}

.form h2:first-of-type {
  margin-top: 0;
}

.form-row-3 {
  grid-template-columns: repeat(3, 1fr);
}

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

.form label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 400;
}

.form label.check input {
  width: auto;
}

.form-actions {
  display: flex;
  gap: 8px;
}

.inline-form {
  margin-top: 12px;
  flex-direction: row;
  align-items: flex-end;
  flex-wrap: wrap;
}

.inline-form label {
  flex: 1;
  min-width: 220px;
}

.filters-simple {
  grid-template-columns: 1fr auto;
}

.danger-zone {
  border: 1px solid var(--danger-soft);
}

@media (max-width: 720px) {
  .form-row-3,
  .form-row-4 {
    grid-template-columns: 1fr;
  }

  .filters-simple {
    grid-template-columns: 1fr auto;
  }

  .filters-simple input {
    grid-column: auto;
  }
}

/* Gite annullate e avvisi */
.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.card-cancelled .card-title {
  text-decoration: line-through;
  text-decoration-color: var(--danger);
}

.card-ribbon {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.cancelled-note {
  margin: 8px 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
}

.notice {
  border: 1px solid var(--warn-soft);
}

.notice p {
  margin-top: 0;
}

.resend {
  margin-top: 12px;
}

/* Filtri: ricerca a tutta larghezza, menu a tendina sotto. */
.filters {
  display: flex;
  flex-wrap: wrap;
}

.filters input {
  flex: 1 1 100%;
}

.filters select {
  flex: 1 1 170px;
  width: auto;
  min-width: 0; /* altrimenti la larghezza minima è quella dell'opzione più lunga */
}

.filters .btn {
  flex: 0 0 auto;
}

.filters-simple input {
  flex: 1 1 200px;
}

/* Selettore di date (datepicker.js) */
.datepicker {
  position: relative;
  display: block;
}

.dp-field {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.dp-field::first-letter {
  text-transform: uppercase;
}

.dp-field.dp-placeholder {
  color: var(--muted);
}

.dp-field:focus-visible,
.dp-popup button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.dp-popup {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 20;
  width: 300px;
  max-width: calc(100vw - 32px);
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.15);
  font-weight: 400;
}

.dp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.dp-title {
  font-weight: 600;
}

.dp-title::first-letter {
  text-transform: uppercase;
}

.dp-head button,
.dp-foot button {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.dp-head button {
  width: 34px;
  height: 34px;
  font-size: 1.2rem;
  line-height: 1;
}

.dp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.dp-weekday {
  padding: 4px 0;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.dp-day {
  aspect-ratio: 1;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.dp-day:hover:not(:disabled) {
  background: var(--primary-soft);
}

.dp-day[aria-current="date"] {
  font-weight: 700;
  color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.dp-day[aria-selected="true"] {
  background: var(--primary);
  color: #fff;
}

.dp-day:disabled {
  color: var(--border);
  cursor: default;
}

.dp-foot {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.dp-foot button {
  padding: 4px 12px;
}

.dp-error {
  display: block;
  margin-top: 4px;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 400;
}
