/* ==========================================================================
   Nodo Riunioni — stile (CSS puro, mobile-first, dark mode automatica)
   ========================================================================== */

:root {
  --bg:            #f5f6fa;
  --surface:       #ffffff;
  --surface-2:     #eef0f6;
  --border:        #dfe2ec;
  --text:          #1a1c25;
  --text-muted:    #6b7180;
  --accent:        #2b3f6b;   /* navy del brand No.Do. */
  --accent-ink:    #ffffff;
  --danger:        #dc2626;
  --danger-soft:   #fee2e2;
  --ok:            #16a34a;
  --shadow:        0 6px 24px rgba(20, 22, 40, .10);
  --shadow-sm:     0 2px 8px rgba(20, 22, 40, .08);
  --radius:        16px;
  --radius-sm:     10px;
  --grid-hour-h:   56px;      /* altezza di un'ora nella griglia */

  /* Palette sale (accessibile) — assegnata per ordine */
  --room-0: #4f46e5;
  --room-1: #0891b2;
  --room-2: #ca8a04;
  --room-3: #db2777;
  --room-4: #059669;
  --room-5: #7c3aed;
  --room-6: #ea580c;
  --room-7: #2563eb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #0f1220;
    --surface:     #191d2e;
    --surface-2:   #232840;
    --border:      #2c3350;
    --text:        #eef0f7;
    --text-muted:  #9aa1bb;
    --accent:      #7d97cc;   /* navy schiarito per contrasto in dark */
    --accent-ink:  #0f1220;
    --brand-navy:  #223458;
    --danger:      #f87171;
    --danger-soft: #3a1e24;
    --ok:          #4ade80;
    --shadow:      0 8px 28px rgba(0, 0, 0, .45);
    --shadow-sm:   0 2px 10px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.view { min-height: 100dvh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
.muted { color: var(--text-muted); }

/* ---------- Bottoni ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .06s ease, background .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:active { background: var(--surface-2); }

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

/* ---------- Spinner ---------- */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.btn-secondary .spinner, .btn-ghost .spinner { border-color: rgba(0,0,0,.2); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Login
   ========================================================================== */
.login { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 26px;
  box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 26px; }
.brand-logo { display: inline-block; margin: 0 auto 16px; }
.brand-logo img { display: block; width: 240px; max-width: 78%; height: auto; margin: 0 auto; }
.app-name { margin: 0 0 3px; font-size: 15px; font-weight: 600; color: var(--text); }
.brand .muted { margin: 0; font-size: 13.5px; }
/* In dark mode il logo navy va posato su una targhetta chiara per leggibilità */
@media (prefers-color-scheme: dark) {
  .brand-logo {
    background: #ffffff;
    padding: 16px 20px 12px;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
  }
}

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.field input, .field select, .field textarea {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}
.form-error {
  background: var(--danger-soft);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin: 0 0 14px;
}

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
}
.topbar-row { display: flex; align-items: center; gap: 8px; }
.topbar-row.secondary { margin-top: 6px; justify-content: space-between; }
.topbar-title { font-weight: 700; flex: 1; text-align: center; }
.date-display {
  flex: 1;
  background: transparent; border: none; color: var(--text);
  font-size: 17px; font-weight: 700; cursor: pointer;
  padding: 6px; border-radius: var(--radius-sm);
  text-transform: capitalize;
}
.date-display:active { background: var(--surface-2); }
.date-native { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg-btn {
  border: none; background: transparent; color: var(--text-muted);
  padding: 6px 14px; border-radius: 999px; font-weight: 600; font-size: 14px; cursor: pointer;
}
.seg-btn.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ==========================================================================
   Calendario
   ========================================================================== */
.calendar-wrap { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; }
.calendar { position: relative; }

/* header colonne sale */
.cal-head {
  position: sticky; top: 0; z-index: 10;
  display: grid;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.cal-head .corner { border-right: 1px solid var(--border); }
.cal-col-head {
  padding: 8px 6px; text-align: center;
  font-size: 12px; font-weight: 700;
  border-right: 1px solid var(--border);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-col-head small { display: block; font-weight: 500; color: var(--text-muted); }
.cal-col-head .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }

/* corpo griglia */
.cal-body { display: grid; position: relative; }
.cal-times { border-right: 1px solid var(--border); }
.cal-time-cell {
  height: var(--grid-hour-h);
  font-size: 11px; color: var(--text-muted);
  text-align: right; padding: 2px 6px 0 0;
  position: relative;
}
.cal-lane { position: relative; border-right: 1px solid var(--border); }
.cal-lane .hour-line {
  height: var(--grid-hour-h);
  border-bottom: 1px solid var(--border);
}
.cal-lane .hour-line.half::after {
  content: ""; position: absolute; left: 0; right: 0;
  border-top: 1px dashed var(--border); opacity: .5;
  transform: translateY(calc(var(--grid-hour-h) / 2));
}

/* blocco prenotazione */
.booking {
  position: absolute; left: 3px; right: 3px;
  border-radius: 8px;
  padding: 3px 8px;
  color: #fff;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  min-height: 16px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 1px;
  line-height: 1.25;
}
.booking .b-title {
  font-size: 12px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.booking .b-meta {
  font-size: 11px; opacity: .92;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* slot brevi: contenuto centrato, una sola riga (orario + titolo) */
.booking.compact { justify-content: center; padding-top: 1px; padding-bottom: 1px; }
.booking.compact .b-title { font-weight: 600; }
/* prenotazione in attesa di autorizzazione */
.booking.pending { outline: 2px dashed rgba(255,255,255,.85); outline-offset: -3px; }
.booking.is-new { animation: pop .9s ease; outline: 2px solid #fff; outline-offset: 1px; }
@keyframes pop { 0% { transform: scale(.97); } 40% { transform: scale(1.03); } 100% { transform: scale(1); } }

.cal-empty {
  padding: 48px 24px; text-align: center; color: var(--text-muted);
}

/* ==========================================================================
   FAB
   ========================================================================== */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 30;
  border: none;
  background: var(--accent); color: #fff;
  border-radius: 999px;
  padding: 14px 20px;
  font-weight: 700; font-size: 15px;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.fab:active { transform: scale(.97); }
.fab-plus { font-size: 20px; line-height: 1; }

/* ==========================================================================
   Modale (bottom sheet su mobile)
   ========================================================================== */
.modal-root { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); animation: fade .2s ease; }
.modal-sheet {
  position: relative;
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
  animation: slideup .25s cubic-bezier(.2,.8,.2,1);
}
@keyframes fade { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(100%); } }

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.sheet-close { background: var(--surface-2); border: none; color: var(--text); width: 32px; height: 32px; border-radius: 50%; font-size: 18px; cursor: pointer; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.presets { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.preset { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.preset.is-active { background: var(--accent); color: #fff; border-color: transparent; }

/* suggerimenti */
.suggest-box { margin-top: 8px; }
.suggest-title { font-size: 13px; font-weight: 700; color: var(--text-muted); margin: 14px 0 8px; text-transform: uppercase; letter-spacing: .03em; }
.room-option {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
}
.room-option.is-selected { border-color: var(--accent); outline: 1px solid var(--accent); }
.room-option .r-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.room-option .r-info { flex: 1; min-width: 0; }
.room-option .r-name { font-weight: 700; }
.room-option .r-sub { font-size: 12.5px; color: var(--text-muted); }
.room-option .r-badge { font-size: 11px; font-weight: 700; color: var(--accent); }
.room-option .r-approval,
.admin-room .ar-approval { font-size: 11.5px; font-weight: 600; color: var(--danger); margin-top: 3px; }

/* campo checkbox */
.checkbox-field {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.checkbox-field input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

.fallback-slot {
  display: flex; justify-content: space-between; align-items: center;
  border: 1px dashed var(--border); border-radius: var(--radius-sm);
  padding: 10px 14px; margin-bottom: 8px;
}
.fallback-slot button { font-size: 13px; padding: 6px 12px; }

.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 14px; }
.notice.warn { background: var(--danger-soft); color: var(--danger); }

/* dettaglio */
.detail-grid { display: grid; grid-template-columns: 22px 1fr; gap: 10px 12px; margin: 8px 0 18px; align-items: start; }
.detail-grid .ico { text-align: center; }
.detail-grid .val { font-weight: 600; }

/* admin */
.admin-main { padding: 16px; max-width: 640px; width: 100%; margin: 0 auto; }
.admin-rooms { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.admin-room {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.admin-room.inactive { opacity: .55; }
.admin-room .ar-info { flex: 1; min-width: 0; }
.admin-room .ar-name { font-weight: 700; }
.admin-room .ar-sub { font-size: 12.5px; color: var(--text-muted); }
.sep { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* menu impostazioni */
.menu-list { display: flex; flex-direction: column; gap: 2px; }
.menu-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  background: transparent; border: none; color: var(--text);
  padding: 14px 8px; font: inherit; font-weight: 600; cursor: pointer;
  border-radius: var(--radius-sm);
}
.menu-item:active { background: var(--surface-2); }
.menu-item .mi-ico { width: 24px; text-align: center; }

/* ==========================================================================
   Toast
   ========================================================================== */
.toast-container {
  position: fixed; left: 0; right: 0;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 200;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  background: #1f2333; color: #fff;
  padding: 11px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow);
  animation: toastin .25s ease;
  max-width: 90%;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
@keyframes toastin { from { transform: translateY(12px); opacity: 0; } }

/* ==========================================================================
   Offline banner
   ========================================================================== */
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 300;
  background: #b45309; color: #fff;
  text-align: center; font-size: 13px; font-weight: 600;
  padding: 6px 12px;
}

/* ==========================================================================
   Desktop
   ========================================================================== */
@media (min-width: 720px) {
  .fab { padding: 16px 24px; }
  .modal-root { align-items: center; justify-content: center; }
  .modal-sheet {
    max-width: 520px; border-radius: 20px;
    animation: pop-in .2s ease;
  }
  @keyframes pop-in { from { transform: scale(.96); opacity: 0; } }
  .login-card { box-shadow: var(--shadow); }
}
