/* ==========================================================================
   Token di design — modificare qui colori, raggi e font per tutto il progetto
   ========================================================================== */

/* :host = componente <prenota-tavolo> (shadow DOM). Nel componente il tema scuro è attivo solo con theme="auto". */
:root,
:host {
  /* Unità tipografica: 1rem sul sito; il componente la fissa a 16px (css/widget.css) per non dipendere
     dalla dimensione del font della pagina che lo ospita. Usare calc(N * var(--rem)) al posto di Nrem. */
  --rem: 1rem;
  color-scheme: light;
  --bg: #f6f3ee;
  --surface: #fffdf9;
  --surface-2: #f1ece4;
  --line: #e5ddd1;
  --ink: #1f1b16;
  --ink-2: #554d44;
  --muted: #877d72;

  --accent: #2f5d50;
  --accent-hover: #244a3f;
  --accent-ink: #ffffff;
  --accent-soft: #e2ece7;

  --ok: #2e7d4f;
  --ok-soft: #e1f1e7;
  --warn: #a2620a;
  --warn-soft: #fbefd9;
  --danger: #b3261e;
  --danger-soft: #f9e3e1;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(31, 27, 22, 0.04), 0 8px 24px rgba(31, 27, 22, 0.06);
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);

  --font: "Manrope", system-ui, -apple-system, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root,
  :host([theme="auto"]) {
    color-scheme: dark;
    --bg: #141311;
    --surface: #1c1a17;
    --surface-2: #26231f;
    --line: #35312b;
    --ink: #f3eee7;
    --ink-2: #cbc2b6;
    --muted: #978d81;

    --accent: #86bfaa;
    --accent-hover: #9dcdbb;
    --accent-ink: #0f1a16;
    --accent-soft: #1f302a;

    --ok: #82d1a0;
    --ok-soft: #1a2f22;
    --warn: #e6a94f;
    --warn-soft: #382a15;
    --danger: #f08b80;
    --danger-soft: #3a1f1c;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

/* ==========================================================================
   Base
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p,
dl,
dd,
ul {
  margin: 0;
}

h1,
h2 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(calc(1.9 * var(--rem)), 4vw, calc(2.6 * var(--rem)));
  line-height: 1.1;
}

h2 {
  font-size: calc(1.25 * var(--rem));
}

h3 {
  font-size: calc(0.95 * var(--rem));
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85em;
}

/* ==========================================================================
   Layout
   ========================================================================== */

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

main {
  padding: 32px 0 64px;
}

.stack {
  display: grid;
  gap: 16px;
}

.stack-lg {
  display: grid;
  gap: 24px;
}

.grid-2,
.grid-3 {
  display: grid;
  gap: 16px;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.page-head {
  display: grid;
  gap: 8px;
}

.page-head-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.eyebrow {
  font-size: calc(0.75 * var(--rem));
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.lead {
  color: var(--ink-2);
  font-size: calc(1.05 * var(--rem));
}

.hint,
.fine-print {
  color: var(--muted);
  font-size: calc(0.82 * var(--rem));
}

.empty {
  grid-column: 1 / -1;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-align: center;
  font-size: calc(0.9 * var(--rem));
}

.spacer {
  flex: 1;
}

/* ==========================================================================
   Topbar
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

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

.brand {
  display: flex;
  min-width: 0;
  white-space: nowrap;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: calc(1.15 * var(--rem));
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: calc(1 * var(--rem));
}

.nav {
  display: flex;
  gap: 4px;
}

.nav a {
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--ink-2);
  font-weight: 600;
  font-size: calc(0.9 * var(--rem));
  text-decoration: none;
}

.nav a:hover {
  background: var(--surface-2);
}

.nav a[aria-current="page"] {
  background: var(--ink);
  color: var(--bg);
}

/* ==========================================================================
   Form
   ========================================================================== */

.field {
  display: grid;
  gap: 6px;
  align-content: start;
}

.label {
  font-size: calc(0.82 * var(--rem));
  font-weight: 600;
  color: var(--ink-2);
}

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

input:not([type="radio"], [type="checkbox"]),
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:not([type="radio"], [type="checkbox"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus);
}

textarea {
  resize: vertical;
  font: inherit;
  color: inherit;
  line-height: 1.4;
}

input::placeholder {
  color: var(--muted);
}

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  margin: 0;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

/* Bottoni */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 700;
  font-size: calc(0.92 * var(--rem));
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn-sm {
  min-height: 34px;
  padding: 0 14px;
  font-size: calc(0.84 * var(--rem));
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

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

.btn-primary:disabled {
  opacity: 0.45;
}

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

.btn-ghost:hover {
  background: var(--surface-2);
}

.btn-danger-ghost {
  background: transparent;
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
}

.btn-danger-ghost:hover {
  background: var(--danger-soft);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: calc(1.2 * var(--rem));
  line-height: 1;
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface-2);
}

.icon-btn.danger {
  color: var(--danger);
}

.icon-btn:disabled {
  opacity: 0.4;
}

/* Scelte a scheda (radio) — date, servizi, sale, orari */

.choice {
  position: relative;
  display: block;
}

.choice input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.choice input:disabled {
  cursor: not-allowed;
}

.choice-face {
  display: grid;
  place-items: center;
  gap: 2px;
  height: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: center;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s;
}

.choice-face small {
  font-size: calc(0.72 * var(--rem));
  font-weight: 600;
  color: var(--muted);
}

.choice:hover input:not(:disabled) + .choice-face {
  border-color: var(--accent);
}

.choice input:checked + .choice-face {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.choice input:checked + .choice-face small {
  color: inherit;
  opacity: 0.85;
}

.choice input:focus-visible + .choice-face {
  box-shadow: var(--focus);
}

.choice input:disabled + .choice-face {
  opacity: 0.45;
  background: var(--surface-2);
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
}

.segmented .choice-face {
  min-height: 42px;
  padding: 8px 10px;
  font-size: calc(0.9 * var(--rem));
}

.date-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 8px;
  scroll-snap-type: x mandatory;
}

.date-strip .choice {
  flex: 0 0 68px;
  scroll-snap-align: start;
}

.date-strip strong {
  font-size: calc(1.25 * var(--rem));
  line-height: 1.1;
}

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

.time-grid strong {
  font-size: calc(1.05 * var(--rem));
}

.stepper {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}

.stepper button {
  width: 42px;
  height: 40px;
  border: 0;
  background: transparent;
  font-size: calc(1.2 * var(--rem));
}

.stepper button:hover {
  background: var(--surface-2);
}

.stepper input[type="number"] {
  width: 48px;
  min-height: 40px;
  padding: 0;
  border: 0;
  border-radius: 0;
  text-align: center;
  font-weight: 700;
  -moz-appearance: textfield;
}

.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

/* Toni di stato */

.tone-ok {
  color: var(--ok) !important;
}

.tone-warn {
  color: var(--warn) !important;
}

.tone-danger {
  color: var(--danger) !important;
}

.tone-bg-ok {
  background: var(--ok);
}

.tone-bg-warn {
  background: var(--warn);
}

.tone-bg-danger {
  background: var(--danger);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: calc(0.72 * var(--rem));
  font-weight: 700;
  font-family: var(--font);
  vertical-align: middle;
}

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

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

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

/* ==========================================================================
   Dialog e toast
   ========================================================================== */

.dialog {
  width: min(560px, calc(100% - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
}

.dialog::backdrop {
  background: rgba(20, 18, 15, 0.45);
  backdrop-filter: blur(2px);
}

.dialog-head,
.dialog-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-foot {
  justify-content: flex-end;
  padding-top: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  font-size: calc(0.9 * var(--rem));
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast[data-tone="error"] {
  background: var(--danger);
  color: #fff;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Pagina in caricamento: il contenuto appare quando i dati sono pronti. */
.is-loading main {
  visibility: hidden;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 640px) {
  main {
    padding-top: 20px;
  }

  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .nav a {
    padding: 8px 10px;
  }

  /* Intestazione con il solo logo (pagina cliente): centrata */
  .topbar-inner:not(:has(.nav)) {
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
