/* Pannello admin Bar Viscuso — pensato prima di tutto per il telefono del titolare.
   Stessa palette di menu e landing (basalto e arancio), tenuta più sobria: qui si lavora. */
:root {
  --bg: #edf1f2;
  --surface: #ffffff;
  --text: #14191c;
  --muted: #55616a;
  --line: #d5dee1;
  --accent: #9a5a14;
  --accent-contrast: #f7fafb;
  --danger: #b42318;
  --ok: #2f7d45;
  --radius: 12px;
  --gutter: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f12;
    --surface: #111a1f;
    --text: #e9f2f4;
    --muted: #93a8b0;
    --line: #27373f;
    --accent: #c98a3c;
    --accent-contrast: #0a0f12;
    --danger: #f97066;
    --ok: #6fcf87;
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1,
h2 {
  line-height: 1.2;
}

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

[hidden] {
  display: none !important;
}

/* Bottoni */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 18px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

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

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

.btn-ghost {
  background: transparent;
}

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

.btn-small {
  padding: 6px 9px;
  min-height: 44px;
  font-size: 0.8rem;
}

.icon-btn {
  font: inherit;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Form */
.input {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
}

textarea.input {
  resize: vertical;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > span,
.field > label {
  font-weight: 600;
  font-size: 0.9rem;
}

.password-wrap {
  display: flex;
  gap: 8px;
}

.pair {
  display: grid;
  gap: 14px;
}

@media (min-width: 640px) {
  .pair {
    grid-template-columns: 1fr 1fr;
  }
}

.fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px 12px;
  margin: 0;
}

.fieldset legend {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0 4px;
}

.checks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 0 10px;
}

.checks.days {
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  cursor: pointer;
}

.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.form-grid {
  display: grid;
  gap: 16px;
}

.form-error {
  color: var(--danger);
  font-weight: 600;
  margin: 0;
}

/* Login */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--gutter);
}

.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 24px;
  display: grid;
  gap: 16px;
}

.login-card h1 {
  margin: 0;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
}

.login-card p {
  margin: 0;
}

/* Layout app */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px var(--gutter);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  gap: 4px;
  flex: none;
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 10px var(--gutter);
  max-width: 960px;
  margin: 0 auto;
}

.tabs button {
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 999px;
  min-height: 44px;
  cursor: pointer;
}

.tabs button[aria-selected="true"] {
  background: var(--text);
  color: var(--bg);
}

.view {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 var(--gutter) 48px;
  outline: none;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 8px 0 12px;
}

.section-head h1 {
  margin: 0;
  font-size: 1.5rem;
}

.intro {
  margin-top: 0;
  max-width: 60ch;
}

.filters {
  margin-bottom: 8px;
}

.group {
  margin-top: 20px;
}

.group-title {
  font-size: 1.05rem;
  margin: 0 0 8px;
}

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

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

.empty {
  text-align: center;
  padding: 40px 16px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* Righe lista */
.rows {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas:
    "thumb main switch"
    "actions actions actions";
  align-items: center;
  gap: 10px 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.row:not(:has(.thumb)) {
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "main main"
    "actions actions";
}

.row:last-child {
  border-bottom: 0;
}

.row.is-off .row-main,
.row.is-off .thumb {
  opacity: 0.5;
}

.thumb {
  grid-area: thumb;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg);
}

.thumb-empty {
  display: grid;
  place-items: center;
  font-size: 1.4rem;
}

.row-main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.row-main strong {
  overflow-wrap: anywhere;
}

.row-main .muted {
  font-size: 0.875rem;
}

.switch-label {
  grid-area: switch;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
}

.row-actions {
  grid-area: actions;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

/* Elimina staccato dalle azioni innocue; su una sola riga anche a 360px */
.row-actions .btn-danger {
  margin-left: auto;
}

.move {
  display: inline-flex;
  gap: 4px;
  margin-right: 2px;
}

@media (min-width: 760px) {
  .row {
    grid-template-columns: auto 1fr auto auto;
    grid-template-areas: "thumb main actions switch";
  }

  .row:not(:has(.thumb)) {
    grid-template-columns: 1fr auto;
    grid-template-areas: "main actions";
  }
}

/* Interruttore disponibile/esaurito */
.switch {
  appearance: none;
  width: 46px;
  height: 28px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  cursor: pointer;
  margin: 0;
  transition: background 0.15s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
  transition: transform 0.15s;
}

.switch:checked {
  background: var(--ok);
}

.switch:checked::after {
  transform: translateX(18px);
}

/* Editor */
.editor {
  width: min(680px, calc(100% - 16px));
  max-height: calc(100dvh - 16px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
}

.editor::backdrop {
  background: rgb(0 0 0 / 0.45);
}

.editor form {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 18px);
}

.editor-head,
.editor-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  flex: none;
}

.editor-head {
  border-bottom: 1px solid var(--line);
}

.editor-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.editor-foot {
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}

.editor-body {
  padding: 16px;
  overflow-y: auto;
  display: grid;
  gap: 14px;
}

.editor .form-error {
  padding: 0 16px;
}

.photo-preview {
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
}

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

/* QR */
.qr-layout {
  display: grid;
  gap: 20px;
}

@media (min-width: 700px) {
  .qr-layout {
    grid-template-columns: 260px 1fr;
    align-items: start;
  }
}

.qr-preview {
  background: #fff;
  border-radius: var(--radius);
  padding: 8px;
  max-width: 260px;
}

.qr-preview svg {
  display: block;
  width: 100%;
  height: auto;
}

.qr-url {
  overflow-wrap: anywhere;
}

.qr-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  z-index: 50;
  max-width: calc(100% - 32px);
}

.toast.is-error {
  background: var(--danger);
  color: #fff;
}

.badge {
  align-self: flex-start;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}

.row-main .badge {
  margin-top: 4px;
}

.date-pick {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 8px;
}

.fieldset > .pair {
  margin-top: 8px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Registro allergeni: a schermo si scorre di lato, su carta esce in A4 orizzontale */
.register-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 16px;
}

.register-actions p {
  margin: 0;
  max-width: 60ch;
}

.register-head h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
}

.register-head p {
  margin: 0 0 4px;
}

.register-scroll {
  overflow-x: auto;
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.register-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

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

.register-table thead th {
  vertical-align: bottom;
  font-weight: 600;
}

/* Nomi degli allergeni in verticale: 14 colonne strette restano leggibili */
.register-table .allergen-col {
  width: 2.2em;
  padding: 8px 4px;
  border-left: 1px solid var(--line);
}

.register-table .allergen-col span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
}

.register-table tbody th {
  font-weight: 600;
  min-width: 12em;
}

.register-table .mark {
  text-align: center;
  border-left: 1px solid var(--line);
  color: var(--accent);
  font-size: 1rem;
}

.register-table .notes {
  min-width: 10em;
  color: var(--muted);
}

.register-table .group th {
  background: var(--bg);
  font-size: 0.8rem;
  color: var(--text);
}

.register-foot .sign {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 32px;
  margin-top: 24px;
}

@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 10pt;
  }

  .topbar,
  .tabs,
  .toast,
  .no-print {
    display: none !important;
  }

  .view {
    max-width: none;
    padding: 0;
  }

  .register-scroll {
    overflow: visible;
    border: 0;
    margin: 8px 0;
  }

  .register-table {
    font-size: 8.5pt;
  }

  .register-table th,
  .register-table td {
    border-color: #999;
    padding: 3px 5px;
  }

  .register-table .mark {
    color: #000;
    font-size: 8pt;
    line-height: 1;
  }

  .register-table .notes {
    color: #333;
  }

  .register-table .group th {
    background: #eee;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .register-table tr {
    break-inside: avoid;
  }
}
