@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;650&display=swap');

:root {
  --ink: #16171a;
  --paper: #faf9f7;
  --rule: #dcd9d2;
  --iron: #b73c22;
  --iron-dark: #8f2e19;
  --moss: #2f6b4f;
  --amber: #a4700e;
  --muted: #6b6d70;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.45;
}

h1, h2, h3 { font-weight: 650; letter-spacing: -0.01em; margin: 0; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 2px solid var(--ink);
}

.topbar .brand {
  font-size: 1.15rem;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  height: 32px;
  width: auto;
  display: block;
}

.topbar .brand span {
  color: var(--iron);
}

button, .btn {
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

button:hover, .btn:hover { background: var(--ink); color: var(--paper); }

button.primary {
  background: var(--iron);
  border-color: var(--iron);
  color: #fff;
}

button.primary:hover { background: var(--iron-dark); border-color: var(--iron-dark); }

button.ghost {
  border-color: var(--rule);
  color: var(--muted);
}

button.ghost:hover { background: var(--rule); color: var(--ink); }

button:disabled { opacity: 0.45; cursor: default; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  font-size: 0.78rem;
  font-weight: 500;
  border: 1px solid currentColor;
}

.badge.ok { color: #15803d; } /* verde netto: attivo */
.badge.expired { color: #dc2626; } /* rosso netto: scaduto */

input, select, textarea {
  font-family: inherit;
  /* 16px minimo: sotto questa soglia Safari su iPhone zooma automaticamente
     la pagina quando l'utente tocca un campo. Su Android non serve, ma non dà fastidio. */
  font-size: 1rem;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  background: #fff;
  color: var(--ink);
}

input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--iron);
  outline-offset: 1px;
}

.layout {
  display: flex;
  min-height: calc(100vh - 61px);
}

nav.rail {
  width: 200px;
  border-right: 1px solid var(--rule);
  padding: 24px 0;
  flex-shrink: 0;
}

nav.rail a {
  display: block;
  padding: 10px 24px;
  color: var(--ink);
  text-decoration: none;
  border-left: 3px solid transparent;
  font-size: 0.95rem;
}

nav.rail a.active { border-left-color: var(--iron); font-weight: 650; }
nav.rail a:hover { background: #f1efe9; }

main {
  flex: 1;
  padding: 32px;
  max-width: 1180px;
  min-width: 0;
}

.panel {
  border: 1px solid var(--rule);
  padding: 24px;
  margin-bottom: 28px;
}

.panel h2 { margin-bottom: 18px; font-size: 1.05rem; }

table { width: 100%; border-collapse: collapse; }
/* Tabella tesserati */
/* TABELLA TESSERATI */
.tesserati-table-wrap {
  width: 100%;
  overflow-x: auto;
}

#view-tesserati table {
  width: 100%;
  min-width: 940px;
  max-width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

#view-tesserati th:nth-child(1),
#view-tesserati td:nth-child(1) { width: 19%; }   /* Nome */
#view-tesserati th:nth-child(2),
#view-tesserati td:nth-child(2) { width: 8%; }    /* Stato */
#view-tesserati th:nth-child(3),
#view-tesserati td:nth-child(3) { width: 14%; }   /* Scadenza mese */
#view-tesserati th:nth-child(4),
#view-tesserati td:nth-child(4) { width: 14%; }   /* Scadenza certificato */
#view-tesserati th:nth-child(5),
#view-tesserati td:nth-child(5) { width: 15%; }   /* Scheda PDF */
#view-tesserati th:nth-child(6),
#view-tesserati td:nth-child(6) { width: 18%; }   /* Interruttore */
#view-tesserati th:nth-child(7),
#view-tesserati td:nth-child(7) { width: 12%; }   /* Salva */

#view-tesserati th,
#view-tesserati td {
  box-sizing: border-box;
  vertical-align: middle;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}

#view-tesserati th {
  padding: 6px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--ink);
}

#view-tesserati td {
  padding: 8px;
  border-bottom: 1px solid var(--rule);
  font-size: 0.85rem;
}

#view-tesserati td input[type="text"],
#view-tesserati td input:not([type]) {
  width: 100%;
  max-width: 150px;
  min-width: 0;
  box-sizing: border-box;
}

#view-tesserati td input[type="date"] {
  width: 100% !important;
  max-width: 120px;
  min-width: 0 !important;
  box-sizing: border-box;
  font-size: 0.78rem;
  padding: 6px;
}

#view-tesserati .pdf-status {
  display: block;
  margin-top: 4px;
  white-space: nowrap;
  font-size: 0.72rem;
  font-weight: 600;
}

#view-tesserati .pdf-status.present {
  color: var(--moss);
}

#view-tesserati .pdf-status.empty {
  color: var(--muted);
}

#view-tesserati td input[type="file"] {
  width: 115px;
  max-width: 100%;
  box-sizing: border-box;
  font-size: 0.7rem;
}

#view-tesserati .save-btn {
  width: 100%;
  max-width: 90px;
  box-sizing: border-box;
  padding: 7px 8px;
  font-size: 0.78rem;
  white-space: nowrap;
}

#view-tesserati td > *,
#view-tesserati th > * {
  max-width: 100%;
  box-sizing: border-box;
}

.hint { color: var(--muted); font-size: 0.85rem; margin-top: 6px; }

.error-box {
  border: 1px solid var(--iron);
  color: var(--iron-dark);
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-bottom: 16px;
  display: none;
}

.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  border: 1px solid var(--rule);
  padding: 40px;
  width: 340px;
}

.login-card h1 { font-size: 1.4rem; margin-bottom: 4px; }
.login-card p.sub { color: var(--muted); font-size: 0.9rem; margin: 0 0 24px 0; }

.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 0.82rem; color: var(--muted); }
.field input { width: 100%; }

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

.folder-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 22px 10px;
  border: 1px solid var(--rule);
  background: #fff;
  font-family: inherit;
}

.folder-tile:hover { background: #f1efe9; }
.folder-icon { font-size: 1.9rem; line-height: 1; }
.folder-name { font-weight: 600; font-size: 0.92rem; }
.folder-count { font-size: 0.76rem; color: var(--muted); }

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

.video-card { border: 1px solid var(--rule); }
.video-card .frame { position: relative; padding-top: 56.25%; background: #000; }
.video-card iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-card .info { padding: 12px 14px; }
.video-card .info h3 { font-size: 0.95rem; }
.video-card .info .cat { color: var(--muted); font-size: 0.78rem; margin: 2px 0 6px 0; }
.video-card .info p { font-size: 0.85rem; margin: 0; }

.empty-state {
  border: 1px dashed var(--rule);
  padding: 32px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  nav.rail { width: 100%; display: flex; padding: 8px 0; border-right: none; border-bottom: 1px solid var(--rule); }
  nav.rail a { padding: 8px 16px; border-left: none; border-bottom: 3px solid transparent; }
  nav.rail a.active { border-bottom-color: var(--iron); }
  main { padding: 20px; }
}

.row-inline input[type="file"] {
  width: 105px;
  font-size: 0;
  color: transparent;
}

.row-inline input[type="file"]::file-selector-button {
  font-size: 0.8rem;
}

.expiry-table .expiry-value select {
  font-size: 0.8rem;
}

/* FIX DEFINITIVO TABELLA TESSERATI */
@media (max-width: 760px) {
  #view-tesserati {
    overflow-x: auto;
  }

  #view-tesserati table {
    display: table;
    width: max-content;
    min-width: 1100px;
    table-layout: auto;
  }

  #view-tesserati thead {
    display: table-header-group;
  }

  #view-tesserati tbody {
    display: table-row-group;
  }

  #view-tesserati tr {
    display: table-row;
  }

  #view-tesserati th,
  #view-tesserati td {
    display: table-cell;
    white-space: nowrap;
    vertical-align: middle;
  }

  #view-tesserati td input[type="date"] {
    width: 150px !important;
    min-width: 150px !important;
    font-size: 16px !important; /* evita lo zoom automatico di Safari su iPhone */
  }

  #view-tesserati td input[type="text"],
  #view-tesserati td input:not([type]) {
    font-size: 16px !important;
  }
}
/* TABELLA SCADENZE - STILE DEFINITIVO */
.expiry-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #c8c8c8;
}

.expiry-table td {
  border: 1px solid #c8c8c8;
}

.expiry-table .badge.ok {
  color: #15803d;
}

.expiry-table .badge.expired {
  color: #dc2626;
}

/* TABELLA TESSERATI - LAYOUT DEFINITIVO */


/* SCADENZE SU MOBILE: etichetta sopra, badge sotto, piena larghezza.
   Così la data non viene mai tagliata, qualunque sia la sua lunghezza
   o la larghezza dello schermo (Android o iPhone, non fa differenza). */
@media (max-width: 760px) {
  .expiry-table, .expiry-table tbody, .expiry-table tr,
  .expiry-table td { display: block; width: 100%; }

  .expiry-table tr {
    padding: 10px 0;
    border-bottom: 1px solid #c8c8c8;
  }
  .expiry-table tr:last-child { border-bottom: none; }

  .expiry-table td { border: none; padding: 2px 0; }

  .expiry-table .expiry-label {
    font-size: 0.82rem;
    color: var(--muted);
  }

  .expiry-table .expiry-value { padding-top: 4px; }

  .expiry-table .badge.ok,
  .expiry-table .badge.expired {
    display: inline-block;
    width: auto;
    max-width: 100%;
    white-space: normal;
    word-break: break-word;
    font-size: 0.85rem;
    border-width: 2px;
  }
}

/* INTERRUTTORE ACCESSO CONTENUTI (admin): verde = attivo, grigio = disattivo */
.access-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 108px;
  max-width: 100%;
  justify-content: flex-start;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  border: 1px solid #c8c8c8;
  background: #e5e7eb;
  color: #4b5563;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
.access-toggle .access-knob {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.access-toggle.off,
.access-toggle.off:hover {
  background: #e5e7eb;
  border-color: #9ca3af;
  color: #374151;
}
.access-toggle.on,
.access-toggle.on:hover {
  background: #15803d;
  border-color: #15803d;
  color: #fff;
  flex-direction: row-reverse;
  padding: 6px 6px 6px 12px;
}
.access-toggle:hover { filter: brightness(0.96); }
.access-toggle:disabled { opacity: 0.55; cursor: default; }

/* SCELTA SORGENTE VIDEO (admin): YouTube oppure dal telefono/PC */
.source-switch { display: flex; gap: 8px; flex-wrap: wrap; }
.source-tab {
  padding: 8px 14px;
  border: 1px solid var(--rule);
  background: #fff;
  color: var(--ink);
  font-weight: 500;
}
.source-tab:hover { background: #f1efe9; color: var(--ink); }
.source-tab.active,
.source-tab.active:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

/* VIDEO CARICATI DAL DISPOSITIVO (lato tesserato) */
.video-card video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
  object-fit: contain;
}
.video-card .video-missing {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.85rem;
}
