/* Stile condiviso da tutti i pannelli admin: tema chiaro, stesso aspetto
   della cassa (Impostazioni di Mac/iPhone) e stessi colori e font del sito
   (verde #3c8f62, Cinzel per i titoli). Un solo file: una modifica qui vale
   ovunque. Pensato per computer e smartphone. */

:root {
  --admin-accent: #3c8f62;       /* stesso verde del sito pubblico */
  --admin-accent-hover: #2f7550;
  --admin-accent-soft: #e3f1e9;
  --admin-danger: #c0392b;
  --admin-danger-bg: #fbe9e7;
  --admin-warn: #b7791f;
  --admin-warn-bg: #fdf3e1;
  --admin-bg: #f4f1ea;
  --admin-card-bg: #ffffff;
  --admin-border: #e4ded2;
  --admin-line: #ece8df;
  --admin-ink: #1f1e1b;
  --admin-muted: #6f6a60;
  --admin-field: #ffffff;
  --admin-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --admin-display: 'Cinzel', Georgia, serif;
  --admin-shadow: 0 1px 2px rgba(31, 30, 27, .05), 0 4px 14px rgba(31, 30, 27, .05);
}

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body.fdm-admin {
  color-scheme: light;
  margin: 0;
  background: var(--admin-bg);
  color: var(--admin-ink);
  font-family: var(--admin-sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body.fdm-admin a { color: var(--admin-accent-hover); }
body.fdm-admin img { max-width: 100%; }
body.fdm-admin * { box-sizing: border-box; }
body.fdm-admin h1, body.fdm-admin h2, body.fdm-admin h3 { font-family: var(--admin-display); color: var(--admin-ink); }

/* ============ BARRA IN ALTO ============ */
.fdm-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 8px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 24px 12px;
  background: rgba(255, 255, 255, .92);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--admin-border);
}
.fdm-topbar h1 {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .4px;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.fdm-topbar > div { flex-shrink: 0; display: flex; align-items: center; gap: 8px; }
.fdm-topbar .btn2 {
  background: #fff;
  border: 1px solid var(--admin-border);
  color: var(--admin-ink);
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--admin-sans);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  vertical-align: middle;
}
.fdm-topbar .btn2:hover { border-color: #cfc6b5; }

/* Home: solo l'icona, senza il box del pulsante. */
.fdm-home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  color: var(--admin-ink);
  text-decoration: none;
  vertical-align: middle;
}
body.fdm-admin .fdm-home-link { color: var(--admin-ink); }
.fdm-home-link:hover { background: rgba(31, 30, 27, .06); }

/* ============ LAYOUT ============ */
.fdm-panel {
  padding: 24px 24px 60px;
  max-width: 1100px;
  margin: 0 auto;
}
.fdm-notice {
  max-width: 1052px;
  margin: 16px auto 0;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
}
.fdm-notice.ok { background: var(--admin-accent-soft); color: var(--admin-accent-hover); border: 1px solid #bfe0cc; }
.fdm-notice.error { background: var(--admin-danger-bg); color: #9b2c20; border: 1px solid #efc9c3; }

.fdm-card {
  border: 1px solid var(--admin-border);
  border-radius: 14px;
  background: var(--admin-card-bg);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--admin-shadow);
}
.fdm-card.edit { border-color: var(--admin-accent); }

body.fdm-admin h2 { font-size: 19px; font-weight: 700; letter-spacing: .4px; margin: 0 0 12px; }
body.fdm-admin h3 { letter-spacing: .3px; }

.fdm-hint {
  font-size: 13px;
  color: var(--admin-muted);
  margin-top: -4px;
  margin-bottom: 14px;
}

/* ============ CAMPI ============ */
label.fdm-field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--admin-muted);
  margin-bottom: 5px;
}
input[type=text], input[type=number], input[type=url], input[type=password],
input[type=email], input[type=tel], input[type=date], input[type=time], input[type=search], textarea, select {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: 10px;
  border: 1px solid var(--admin-border);
  background: var(--admin-field);
  color: var(--admin-ink);
  font-family: var(--admin-sans);
  font-size: 15px;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--admin-accent) !important;
  box-shadow: 0 0 0 3px rgba(60, 143, 98, .15);
}
input::placeholder, textarea::placeholder { color: #a39d91; }
textarea { min-height: 70px; resize: vertical; }

input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.fdm-preview-img {
  display: block;
  margin: 0 auto 20px;
  max-width: 320px;
  width: 100%;
  border-radius: 12px;
}
.fdm-upload-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.fdm-upload-row input[type=file] { flex: 1 1 220px; margin-bottom: 0; }
.fdm-upload-row button { flex-shrink: 0; }

input[type=file] {
  width: 100%;
  margin-bottom: 10px;
  color: var(--admin-muted);
  font-family: var(--admin-sans);
  font-size: 13px;
}
input[type=file]::file-selector-button,
input[type=file]::-webkit-file-upload-button {
  background: #fff;
  color: var(--admin-ink);
  border: 1px solid var(--admin-border);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--admin-sans);
  margin-right: 10px;
  transition: border-color .15s ease;
}
input[type=file]::file-selector-button:hover,
input[type=file]::-webkit-file-upload-button:hover { border-color: var(--admin-accent); }

input[type=checkbox], input[type=radio] {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  min-width: 22px;
  border: 2px solid #cfc8ba;
  border-radius: 6px;
  background: #fff;
  position: relative;
  cursor: pointer;
  margin: 0;
  transition: background .15s ease, border-color .15s ease;
}
input[type=radio] { border-radius: 50%; }
input[type=checkbox]:hover, input[type=radio]:hover { border-color: var(--admin-accent); }
input[type=checkbox]:checked, input[type=radio]:checked { background-color: var(--admin-accent); border-color: var(--admin-accent); }
/* Spunta disegnata come immagine centrata: resta al centro a qualunque
   dimensione della casella (anche dove una pagina la fa più grande). */
input[type=checkbox]:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.4l3 3 6-6.6' fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 78%;
}
input[type=radio]:checked::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  background: #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
.fdm-checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  margin-bottom: 14px;
  cursor: pointer;
}

/* ============ PULSANTI ============ */
button, input[type=submit], .fdm-btn {
  background: var(--admin-accent);
  color: #fff;
  border: 1px solid var(--admin-accent);
  padding: 10px 18px;
  min-height: 42px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  font-family: var(--admin-sans);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .15s ease, border-color .15s ease, transform .06s;
}
button:active, .fdm-btn:active { transform: scale(.98); }
button:hover, input[type=submit]:hover, .fdm-btn:hover { background: var(--admin-accent-hover); border-color: var(--admin-accent-hover); }
body.fdm-admin a.fdm-btn { color: #fff; }
button.secondary, .fdm-btn.secondary {
  background: #fff;
  color: var(--admin-ink);
  border-color: var(--admin-border);
}
body.fdm-admin a.fdm-btn.secondary { color: var(--admin-ink); }
button.secondary:hover, .fdm-btn.secondary:hover { background: #fff; border-color: #cfc6b5; }
button.danger, .fdm-btn.danger {
  background: #fff;
  color: var(--admin-danger);
  border: 1px solid #efc9c3;
}
button.danger:hover, .fdm-btn.danger:hover { background: var(--admin-danger-bg); border-color: #e7b3ab; }
button:disabled { opacity: .45; cursor: default; transform: none; }

.fdm-btn-mini {
  font-size: 12.5px;
  font-weight: 600;
  font-family: var(--admin-sans);
  padding: 6px 11px;
  min-height: 0;
  border-radius: 8px;
  background: #efebe3;
  color: var(--admin-ink);
  text-decoration: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
body.fdm-admin a.fdm-btn-mini { color: var(--admin-ink); }
.fdm-btn-mini:hover { background: #e6e1d6; }
.fdm-btn-mini.danger, body.fdm-admin a.fdm-btn-mini.danger { background: var(--admin-danger-bg); color: var(--admin-danger); }
.fdm-btn-mini.secondary { background: #efebe3; color: var(--admin-ink); border: none; }

/* ============ GRIGLIA / VARIE ============ */
.fdm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.fdm-inline-form { display: inline; }
.fdm-product-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }

/* Tabelle: righe pulite come le liste di Impostazioni. */
body.fdm-admin table { border-collapse: collapse; }
body.fdm-admin th { color: var(--admin-muted); font-weight: 600; }
body.fdm-admin td, body.fdm-admin th { border-color: var(--admin-line); }

/* ============ MODALE ============ */
.fdm-add-btn {
  background: var(--admin-accent);
  border: 1px solid var(--admin-accent);
  color: #fff;
  height: 38px;
  min-width: 38px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 600;
  font-family: var(--admin-sans);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  vertical-align: middle;
}
.fdm-add-btn:hover { background: var(--admin-accent-hover); }

.fdm-modal {
  display: none;
  position: fixed;
  inset: 0;
  height: 100%;
  background: rgba(31, 30, 27, .45);
  z-index: 9999;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.fdm-modal.open { display: flex; animation: fdmFade .12s; }
@keyframes fdmFade { from { opacity: 0; } }
.fdm-modal-inner {
  background: #fff;
  border-radius: 20px;
  padding: 26px;
  max-width: 640px;
  width: 100%;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.fdm-modal-inner h2 { margin-top: 0; padding-right: 44px; }
.fdm-modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: #f1ede5;
  border: none;
  color: var(--admin-ink);
  width: 36px;
  height: 36px;
  min-height: 0;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.fdm-modal-close:hover { background: #e6e1d6; }

@media screen and (max-width: 700px) {
  /* Foglio dal basso che scorre tutto (anche i pulsanti in fondo). */
  /* Scorre solo il foglio bianco: il contenitore non ha barra propria,
     così il foglio occupa sempre tutta la larghezza dello schermo. */
  .fdm-modal { padding: 40px 0 0; flex-direction: column; align-items: stretch; overflow: hidden; }
  .fdm-modal-inner { max-width: none !important; max-height: 100%; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; margin-top: auto; border-radius: 20px 20px 0 0; padding: 22px 18px calc(28px + env(safe-area-inset-bottom, 0px)); }
}

/* ============ INTERRUTTORE (stile iPhone) ============ */
.fdm-switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.fdm-switch input[type=checkbox] { display: none; }
.fdm-switch .fdm-switch-track {
  width: 51px; height: 31px;
  background: #e3dfd6;
  border-radius: 999px;
  position: relative;
  transition: .2s;
  flex-shrink: 0;
}
.fdm-switch .fdm-switch-track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 27px; height: 27px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
  transition: .2s;
}
.fdm-switch input:checked + .fdm-switch-track { background: #34c759; }
.fdm-switch input:checked + .fdm-switch-track::after { transform: translateX(20px); }
.fdm-switch .fdm-switch-label { font-size: 14px; min-width: 76px; color: var(--admin-muted); }

/* ============ ICONE AZIONE (tabelle) ============ */
.fdm-icon-btn {
  width: 34px; height: 34px;
  min-height: 0;
  padding: 0;
  background: none;
  color: var(--admin-warn);
  border: none;
  border-radius: 8px;
  outline: none;
  box-shadow: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.fdm-icon-btn:hover { background: rgba(31, 30, 27, .06); }
.fdm-icon-btn:focus, .fdm-icon-btn:focus-visible { outline: none; box-shadow: none; }
.fdm-icon-btn.danger { color: var(--admin-danger); background: none; border: none; }
.fdm-icon-btn.danger:hover { background: var(--admin-danger-bg); }
.fdm-icon-btn.accent { color: var(--admin-accent); }

/* ============ TABELLA ORDINABILE ============ */
.fdm-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.fdm-sortable:hover { color: var(--admin-ink); }
.fdm-sortable .fdm-sort-arrow { display: inline-block; width: 10px; opacity: .5; }

/* ============ TASTIERINO NUMERICO ============ */
.numpad-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(31, 30, 27, .45);
  z-index: 10000;
  align-items: center; justify-content: center;
  padding: 20px;
}
.numpad-overlay.open { display: flex; }
.numpad-box {
  position: relative;
  background: #fff;
  border-radius: 22px;
  padding: 22px;
  width: 100%;
  max-width: 300px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.numpad-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: #f1ede5;
  border: none;
  color: var(--admin-ink);
  width: 34px;
  height: 34px;
  min-height: 0;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.numpad-close:hover { background: #e6e1d6; }
.numpad-display {
  font-family: var(--admin-sans);
  font-weight: 700;
  font-size: 36px;
  text-align: center;
  padding: 10px 0 18px;
  color: var(--admin-ink);
  font-variant-numeric: tabular-nums;
}
.numpad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.numpad-key {
  background: #f6f3ec;
  border: 1px solid var(--admin-border);
  color: var(--admin-ink);
  border-radius: 14px;
  font-family: var(--admin-sans);
  font-weight: 600;
  font-size: 22px;
  padding: 16px 0;
  cursor: pointer;
}
.numpad-key:hover { background: #efebe3; border-color: var(--admin-border); }
.numpad-key.numpad-clear { color: var(--admin-danger); }
.numpad-key.numpad-back { font-size: 18px; }
.numpad-ok { width: 100%; margin-top: 14px; padding: 14px 0; font-size: 15px; }

/* ============ SOTTOSEZIONI (pillole) ============ */
.fdm-tabs {
  display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin-bottom: 22px; padding-bottom: 2px; scrollbar-width: none;
}
.fdm-tabs::-webkit-scrollbar { display: none; }
.fdm-tabs a {
  display: inline-flex; align-items: center; padding: 9px 16px; border-radius: 999px;
  background: #fff; border: 1px solid var(--admin-border);
  color: var(--admin-ink); text-decoration: none; font-size: 14px; font-weight: 600;
  white-space: nowrap; flex: 0 0 auto;
}
body.fdm-admin .fdm-tabs a { color: var(--admin-ink); }
.fdm-tabs a:hover { border-color: #cfc6b5; }
body.fdm-admin .fdm-tabs a.active { background: var(--admin-accent); border-color: var(--admin-accent); color: #fff; }

.fdm-tab-section { display: none; }
.fdm-tab-section.active { display: block; }

/* Secondo livello: controllo segmentato stile iPhone. */
.fdm-tabs-sub { margin-bottom: 18px; background: #e6e2d9; border-radius: 10px; padding: 3px; display: inline-flex; gap: 2px; max-width: 100%; }
.fdm-tabs-sub a { padding: 6px 14px; font-size: 13px; background: transparent; border: none; border-radius: 8px; }
body.fdm-admin .fdm-tabs-sub a.active { background: #fff; color: var(--admin-ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

/* ============ SMARTPHONE ============ */
@media screen and (max-width: 700px) {
  .fdm-topbar { padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px; }
  .fdm-topbar h1 { font-size: 16px; }
  .fdm-topbar .btn2 { padding: 0 10px; }
  .fdm-topbar .btn2-label { display: none; }
  .fdm-tab-label { display: none; }
  .fdm-panel { padding: 14px 14px 50px; }
  .fdm-notice { margin: 12px 14px 0; }
  .fdm-card { padding: 16px; border-radius: 12px; }
  .fdm-product-row { flex-direction: column; }
  .fdm-product-row > div { width: 100% !important; min-width: 0 !important; }
  .fdm-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  input[type=text], input[type=number], input[type=url], input[type=password],
  input[type=email], input[type=tel], input[type=date], input[type=search], textarea, select {
    font-size: 16px; /* evita lo zoom automatico di iOS al tocco */
  }
  button, .fdm-btn { min-height: 44px; }
}

/* Pulsante bianco con testo verde: azione importante ma non "definitiva". */
button.tinted, .fdm-btn.tinted { background: #fff; color: var(--admin-accent-hover); border-color: var(--admin-border); }
button.tinted:hover, .fdm-btn.tinted:hover { background: var(--admin-accent-soft); border-color: #bfe0cc; }

/* ============ IMPAGINAZIONE "STILE IMPOSTAZIONI" ============
   admin-tabs.js sposta il contenuto in .fdm-main e aggiunge le icone:
   su computer colonna a sinistra + contenuto a destra, su telefono pillole. */
.fdm-tabs .fdm-ico { display: none; }
.fdm-main-title { display: none; }
@media screen and (min-width: 960px) {
  .fdm-panel.fdm-split { display: flex; align-items: flex-start; gap: 32px; max-width: 1280px; }
  .fdm-panel.fdm-split > .fdm-side {
    position: sticky; top: 86px; flex: 0 0 250px; flex-direction: column; align-items: stretch; gap: 2px;
    background: #ebe7de; border-radius: 16px; padding: 10px; margin: 0; overflow: visible;
  }
  body.fdm-admin .fdm-panel.fdm-split > .fdm-side a {
    background: none; border: none; border-radius: 10px; padding: 7px 10px; gap: 11px; font-size: 14.5px; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--admin-ink);
  }
  body.fdm-admin .fdm-panel.fdm-split > .fdm-side a:hover { background: rgba(31, 30, 27, .05); }
  body.fdm-admin .fdm-panel.fdm-split > .fdm-side a.active { background: var(--admin-accent); color: #fff; }
  .fdm-side .fdm-ico { display: inline-flex; width: 28px; height: 28px; border-radius: 8px; background: var(--ic); color: #fff; align-items: center; justify-content: center; flex-shrink: 0; box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .12); }
  .fdm-side .fdm-ico svg { width: 16px; height: 16px; }
  .fdm-panel.fdm-split > .fdm-main { flex: 1; min-width: 0; }
  body.fdm-admin .fdm-main-title { display: block; font-family: var(--admin-sans); font-size: 28px; font-weight: 700; letter-spacing: -.3px; margin: 2px 0 18px; }
}
@media screen and (min-width: 960px) {
  /* Il titolo della sezione è già in alto: niente doppioni. */
  .fdm-main > .fdm-main-title + h2,
  .fdm-main > .fdm-main-title + .fdm-notice + h2,
  .fdm-main .fdm-tab-section > h2:first-child { display: none; }
}

/* Barra laterale a tutta altezza, attaccata al bordo (come le Impostazioni
   della cassa); contenuto centrato a destra. */
@media screen and (min-width: 960px) {
  .fdm-panel.fdm-split { max-width: none; margin: 0; padding: 0; gap: 0; min-height: calc(100vh - 63px); align-items: stretch; }
  .fdm-panel.fdm-split > .fdm-side {
    position: sticky; top: 63px; align-self: flex-start; height: calc(100vh - 63px); flex: 0 0 240px;
    border-radius: 0; padding: 14px 10px; border-right: 1px solid var(--admin-border); overflow-y: auto;
  }
  .fdm-panel.fdm-split > .fdm-main { padding: 30px 40px 70px; max-width: 1000px; margin: 0 auto; }
}
