/* ============================================================
   FOODBASE — Foglio di stile principale
   Tema: Syrve brand colors
   #00062b  (blu notte — brand primario)
   #00c0c2  (ciano — accent)
   #dad8dd  (grigio perla — superfici)
   #000000  #ffffff
   ============================================================ */

:root {
  --brand:       #00c0c2;
  --brand-dark:  #009496;
  --brand-light: #e6f9f9;
  --navy:        #00062b;
  --navy-2:      #0a1240;
  --navy-3:      #1e2a5e;
  --ink:         #000000;
  --ink-2:       #1a1a2e;
  --ink-3:       #6b6a7a;
  --surface:     #ffffff;
  --surface-2:   #f4f4f7;
  --surface-3:   #dad8dd;
  --border:      #dad8dd;
  --white:       #ffffff;
  --success:     #0e7a4a;
  --success-bg:  #e6f4ee;
  --danger:      #c0001a;
  --danger-bg:   #fdedf0;
  --warning:     #7a5200;
  --warning-bg:  #fff8e6;
  --sidebar-w:   220px;
  --radius:      10px;
  --radius-lg:   16px;
  --shadow:      0 1px 3px rgba(0,6,43,.07), 0 4px 12px rgba(0,6,43,.05);
  --shadow-lg:   0 8px 32px rgba(0,6,43,.13);
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body:    'Nunito Sans', 'NunitoSans', system-ui, sans-serif;
  --transition:  0.18s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  background: var(--surface-2);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── APP SHELL ── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  object-fit: cover;
  mix-blend-mode: screen;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 20px;
  color: #fff;
  letter-spacing: 0.01em;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,.5);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 400;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
}

.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .7; }

.nav-item:hover {
  background: rgba(0,192,194,.12);
  color: var(--brand);
}
.nav-item:hover svg { opacity: 1; }

.nav-item.active {
  background: var(--brand);
  color: var(--navy);
  font-weight: 500;
}
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.db-status {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: rgba(255,255,255,.35);
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%; background: #555;
  flex-shrink: 0; transition: background 0.4s;
}
.status-dot.connected { background: var(--brand); }
.status-dot.error     { background: #f87171; }

/* ── MAIN CONTENT ── */
.main { flex: 1; overflow-y: auto; overflow-x: hidden; }
.page { display: none; }
.page.active { display: block; }

/* ── PAGE HEADER ── */
.page-header {
  padding: 32px 36px 20px;
  display: flex; align-items: flex-end;
  justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}

.page-title {
  font-family: var(--font-display);
  font-size: 30px; color: var(--navy); line-height: 1.1;
}

.page-subtitle { font-size: 13px; color: var(--ink-3); margin-top: 3px; }

/* ── PAGE BODY ── */
.page-body { padding: 0 36px 40px; }

/* ── STATS CARDS ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px; margin-bottom: 32px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  border-top: 3px solid var(--border);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-top-color var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-top-color: var(--brand);
}

.stat-label {
  font-size: 12px; font-weight: 500;
  color: var(--ink-3); text-transform: uppercase;
  letter-spacing: .06em; margin-bottom: 8px;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 38px; color: var(--navy); line-height: 1;
}

.stat-sub { font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.stat-card.accent .stat-value { color: var(--brand-dark); }

/* ── TABLE ── */
.table-wrap {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.table-toolbar {
  padding: 16px 20px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}

.search-wrap { flex: 1; min-width: 200px; position: relative; }

.search-wrap svg {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px;
  color: var(--ink-3); pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--border);
  border-radius: 8px; font-size: 13.5px;
  font-family: var(--font-body);
  background: var(--surface-2); color: var(--ink);
  transition: border-color var(--transition); outline: none;
}

.search-input:focus { border-color: var(--brand); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

thead th {
  background: var(--surface-2); padding: 10px 16px;
  text-align: left; font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--surface-2);
  transition: background var(--transition);
}

tbody tr:hover { background: var(--brand-light); }
tbody tr:last-child { border-bottom: none; }

tbody td { padding: 11px 16px; color: var(--ink-2); vertical-align: middle; }
tbody td.td-primary { color: var(--ink); font-weight: 500; }

.table-empty {
  text-align: center; padding: 52px 20px;
  color: var(--ink-3); font-size: 13px;
}

.table-empty svg {
  width: 40px; height: 40px;
  margin-bottom: 12px; opacity: .25;
  display: block; margin-inline: auto;
}

/* ── PAGINATION ── */
.pagination {
  padding: 12px 20px;
  display: flex; align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  font-size: 13px; color: var(--ink-3);
  flex-wrap: wrap; gap: 8px;
}

.pagination-btns { display: flex; gap: 4px; }

.page-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px; background: var(--white);
  color: var(--ink-2); cursor: pointer;
  font-size: 13px; transition: all var(--transition);
}

.page-btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand-dark); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 22px; border-radius: 8px;
  font-size: 13.5px; font-family: var(--font-body);
  font-weight: 500; cursor: pointer; border: none;
  transition: all var(--transition);
  white-space: nowrap; text-decoration: none;
}

.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary { background: var(--brand); color: var(--navy); }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }

.btn-secondary {
  background: #e6e5e8; color: var(--navy);
  border: none;
}
.btn-secondary:hover { background: #d5d3d8; }

.btn-ghost { background: transparent; color: var(--ink-3); padding: 6px 8px; }
.btn-ghost:hover { background: var(--surface-2); color: var(--navy); }

.btn-ghost.btn-delete { color: var(--ink-3); }
.btn-ghost.btn-delete:hover { background: var(--danger-bg); color: var(--danger); }

.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #f5b8bf; }
.btn-danger:hover { background: #fbd5da; }

.btn-sm { padding: 5px 11px; font-size: 12.5px; }

/* ── BADGES ── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
}

.badge-kg     { background: #e6f9f9; color: #005f61; }
.badge-lt     { background: #e6eeff; color: #002db3; }
.badge-dish   { background: #e6f9f9; color: #004f50; }
.badge-semi   { background: #eeebff; color: #3d00b8; }
.badge-goods  { background: var(--surface-2); color: var(--ink-3); }
.badge-mod    { background: #fff0f9; color: #8c0055; }
.badge-global { background: var(--success-bg); color: var(--success); }
.badge-tenant { background: var(--warning-bg); color: var(--warning); }

/* ── FORM ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: span 3; }

label { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.required::after { content: ' *'; color: var(--brand-dark); }

input, select, textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px; font-size: 13.5px;
  font-family: var(--font-body);
  color: var(--ink); background: var(--white);
  transition: border-color var(--transition);
  outline: none; width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(0,192,194,.12);
}

textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11.5px; color: var(--ink-3); }

.form-section {
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border);
}

.form-section-title {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); margin-bottom: 14px;
}

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,6,43,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 640px; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modal-in .18s ease;
}

.modal.modal-lg { max-width: 860px; }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  padding: 20px 24px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 3px solid var(--brand);
  flex-shrink: 0;
}

.modal-header h3 {
  font-family: var(--font-display);
  font-size: 20px; color: var(--navy);
}

.modal-close {
  width: 30px; height: 30px;
  border-radius: 6px; border: none;
  background: var(--surface-2); color: var(--ink-3);
  font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}

.modal-close:hover { background: var(--surface-3); color: var(--navy); }

.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }

.modal-footer {
  padding: 14px 24px;
  display: flex; justify-content: flex-end; gap: 10px;
  border-top: 1px solid var(--border); flex-shrink: 0;
}

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--navy); color: #fff;
  padding: 12px 20px; border-radius: 10px;
  font-size: 13.5px; box-shadow: var(--shadow-lg);
  z-index: 200; max-width: 320px;
  animation: toast-in .2s ease;
  border-left: 4px solid var(--brand);
}

.toast.hidden { display: none; }
.toast.success { background: var(--navy); border-left-color: var(--brand); }
.toast.error   { background: var(--danger); border-left-color: #ff8888; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── RECIPE LINES TABLE ── */
.lines-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }

.lines-table th {
  background: var(--surface-2); padding: 7px 10px;
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3);
}

.lines-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--surface-2);
  vertical-align: middle;
}

.lines-table input, .lines-table select { padding: 5px 8px; font-size: 12.5px; }

/* ── EXPORT CARDS ── */
.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.export-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-top: 3px solid var(--brand);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

.export-card-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--brand-light);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}

.export-card-icon svg { width: 22px; height: 22px; color: var(--brand-dark); }

.export-card h3 {
  font-family: var(--font-display);
  font-size: 17px; color: var(--navy); margin-bottom: 6px;
}

.export-card p { font-size: 13px; color: var(--ink-3); margin-bottom: 16px; line-height: 1.5; }

/* ── LOADER ── */
.loader {
  display: flex; align-items: center; justify-content: center;
  padding: 40px; color: var(--ink-3); font-size: 13px; gap: 10px;
}

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── MISC ── */
.section-title {
  font-family: var(--font-display);
  font-size: 18px; color: var(--navy); margin-bottom: 16px;
}

.alert {
  padding: 12px 16px; border-radius: 8px;
  font-size: 13px; margin-bottom: 16px; border-left: 3px solid;
}

.alert-info    { background: #e6f9f9; color: #004f50; border-color: var(--brand); }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #6dcfa0; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #f5c842; }
.alert-danger  { background: var(--danger-bg);  color: var(--danger);  border-color: #f5a0aa; }

.text-muted { color: var(--ink-3); }
.text-brand { color: var(--brand-dark); }
.fw-500     { font-weight: 500; }
.mt-16      { margin-top: 16px; }
.mt-24      { margin-top: 24px; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .brand-name, .nav-item span, .sidebar-footer { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .page-header { padding: 20px 20px 12px; }
  .page-body { padding: 0 20px 32px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-group.span-2 { grid-column: span 1; }
}

/* ── IMPOSTAZIONI TABS ── */
.imp-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}

.imp-tab {
  padding: 9px 20px;
  border: none;
  background: transparent;
  color: var(--ink-3);
  font-size: 13.5px;
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: 6px 6px 0 0;
  transition: all var(--transition);
}

.imp-tab:hover { color: var(--navy); background: var(--surface-2); }

.imp-tab.active {
  color: var(--navy);
  border-bottom-color: var(--brand);
  background: transparent;
}

.imp-section { }

.imp-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.imp-section-title {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--navy);
  margin-bottom: 4px;
}

.imp-section-sub {
  font-size: 13px;
  color: var(--ink-3);
  max-width: 520px;
  line-height: 1.5;
}

/* ── LOGIN PAGE ── */
#login-page {
  min-height: 100vh;
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-wrap {
  width: 100%;
  max-width: 400px;
}

.login-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: 0 20px 60px rgba(0,6,43,.4);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo-img {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: var(--navy);
  object-fit: cover;
  margin-bottom: 10px;
}

.login-title {
  font-family: var(--font-display);
  font-size: 26px;
  color: var(--navy);
  line-height: 1.1;
}

.login-sub {
  font-size: 13px;
  color: var(--ink-3);
  margin-top: 4px;
}

/* ── USER BAR ── */
.user-info {
  margin-bottom: 8px;
}

.user-name {
  font-size: 12px;
  color: rgba(255,255,255,.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.user-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.user-tenant {
  font-size: 11.5px;
  color: rgba(255,255,255,.4);
}

#user-bar .btn-ghost {
  color: rgba(255,255,255,.4);
  width: 100%;
  justify-content: center;
  font-size: 12.5px;
  padding: 6px 8px;
  margin-top: 2px;
}

#user-bar .btn-ghost:hover {
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.8);
}

/* ── USER INFO + LOGOUT ── */
.user-info {
  padding: 10px 0 8px;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11px;
  color: var(--brand);
  margin-top: 2px;
  font-weight: 500;
}

.sidebar-footer-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  border-top: 1px solid rgba(255,255,255,.08);
  padding-top: 10px;
}

.btn-logout {
  background: transparent;
  border: none;
  color: rgba(255,255,255,.35);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: all .18s;
}

.btn-logout:hover {
  background: rgba(192,0,26,.2);
  color: #f87171;
}

/* ── ADMIN SUBTABS ── */
.admin-subtabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.admin-subtab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  color: var(--ink-3);
  font-size: 13.5px;
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.admin-subtab:hover {
  border-color: var(--brand);
  color: var(--navy);
}

.admin-subtab.active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

.admin-subtab.active svg {
  stroke: var(--brand);
}

/* ── PER PAGE SELECTOR ── */
.per-page-select {
  width: auto;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--ink-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
}

/* ── CATEGORY CHIPS (navigazione ingredienti) ── */
.cat-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--white);
  color: var(--ink-2);
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
}

.cat-chip:hover {
  border-color: var(--brand);
  color: var(--brand-dark);
  background: var(--brand-light);
}

.cat-chip-active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.cat-chip-active:hover {
  background: var(--navy-2);
  color: #fff;
  border-color: var(--navy-2);
}

/* ── ALBERO CATEGORIE (pannello laterale ingredienti) ── */
.cat-tree-panel {
  width: 220px;
  flex-shrink: 0;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  position: sticky;
  top: 20px;
}

.cat-tree-header {
  padding: 12px 14px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-3);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
}

.tree-node {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-2);
  border-radius: 0;
  transition: background var(--transition);
  border-bottom: 1px solid var(--surface-2);
}

.tree-node:hover { background: var(--brand-light); color: var(--navy); }

.tree-node-active {
  background: var(--navy) !important;
  color: #fff !important;
  font-weight: 500;
}

.tree-arrow {
  font-size: 9px;
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--ink-3);
  transition: transform var(--transition);
  cursor: pointer;
  border-radius: 3px;
}

.tree-arrow:hover { background: var(--surface-3); }
.tree-arrow-open { transform: rotate(90deg); }
.tree-arrow-hidden { visibility: hidden; }

.tree-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12.5px;
}

.tree-node-active .tree-arrow { color: rgba(255,255,255,.6); }
.tree-node-active .tree-arrow:hover { background: rgba(255,255,255,.15); }

/* ── ALBERO CATEGORIE (impostazioni) ── */
.cat-tree-list {
  padding: 8px 0;
}

.cat-tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 7px;
  padding-bottom: 7px;
  padding-right: 12px;
  border-bottom: 1px solid var(--surface-2);
  transition: background var(--transition);
  min-height: 38px;
}

.cat-tree-row:hover { background: var(--brand-light); }

.cat-tree-toggle {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--ink-3);
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 4px;
  transition: background var(--transition);
}

.cat-tree-toggle:hover { background: var(--surface-3); color: var(--navy); }
.cat-tree-toggle-hidden { visibility: hidden; cursor: default; }

.cat-tree-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


/* ============================================================
   DARK MODE — attivo automaticamente dalle 18:00
   Aggiunto dalla classe .dark-mode sul <body>
   ============================================================ */

body.dark-mode {
  --surface:     #0f1117;
  --surface-2:   #1a1d27;
  --surface-3:   #252836;
  --border:      #2e3248;
  --white:       #1a1d27;
  --ink:         #e8e9f0;
  --ink-2:       #b8bbd0;
  --ink-3:       #6b6e8a;
  --navy:        #00c0c2;
  --navy-2:      #00a8aa;
  --navy-3:      #008f91;
  --brand-light: #001f20;
  --success-bg:  #0a1f14;
  --warning-bg:  #1a1400;
  --danger-bg:   #1f0a0d;
  --shadow:      0 1px 3px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.5);

  background: #0b0d14;
  color: var(--ink);
}

/* Sidebar in dark mode — diventa ancora più scura */
body.dark-mode .sidebar {
  background: #070910;
  border-right: 1px solid var(--border);
}

body.dark-mode .sidebar-brand {
  border-bottom-color: rgba(255,255,255,.05);
}

body.dark-mode .sidebar-footer {
  border-top-color: rgba(255,255,255,.05);
}

/* Nav item attivo: testo scuro leggibile su sfondo ciano */
body.dark-mode .nav-item.active {
  background: var(--brand);
  color: #0b0d14;
}

/* Stat card hover: bordo bianco in dark mode */
body.dark-mode .stat-card:hover {
  border-top-color: #ffffff;
}

/* Header pagine */
body.dark-mode .page-title {
  color: var(--brand);
}

body.dark-mode .page-title span {
  color: #e8e9f0 !important;
}

/* Tabelle */
body.dark-mode thead th {
  background: var(--surface-3);
  color: var(--ink-3);
  border-bottom-color: var(--border);
}

body.dark-mode tbody tr:hover {
  background: rgba(0,192,194,.06);
}

body.dark-mode tbody tr {
  border-bottom-color: var(--border);
}

/* Input e form */
body.dark-mode input,
body.dark-mode select,
body.dark-mode textarea {
  background: var(--surface-3);
  border-color: var(--border);
  color: var(--ink);
}

body.dark-mode input:focus,
body.dark-mode select:focus,
body.dark-mode textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(0,192,194,.15);
}

body.dark-mode input[readonly],
body.dark-mode input:disabled {
  background: var(--surface-2);
  color: var(--ink-3);
}

/* Pulsanti */
body.dark-mode .btn-secondary {
  background: var(--surface-3);
  border-color: var(--border);
  color: var(--ink-2);
}

body.dark-mode .btn-secondary:hover {
  background: #2e3248;
}

body.dark-mode .btn-ghost:hover {
  background: var(--surface-3);
  color: var(--brand);
}

body.dark-mode .btn-ghost.btn-delete:hover {
  background: var(--danger-bg);
  color: #f87171;
}

/* Modal */
body.dark-mode .modal {
  background: var(--surface-2);
  border: 1px solid var(--border);
}

body.dark-mode .modal-header {
  border-bottom-color: var(--brand);
}

body.dark-mode .modal-header h3 {
  color: var(--brand);
}

body.dark-mode .modal-footer {
  border-top-color: var(--border);
}

body.dark-mode .modal-close {
  background: var(--surface-3);
  color: var(--ink-3);
}

body.dark-mode .modal-close:hover {
  background: var(--border);
  color: var(--ink);
}

body.dark-mode .modal-overlay {
  background: rgba(0,0,0,.7);
}

/* Stat cards */
body.dark-mode .stat-card {
  background: var(--surface-2);
  border-color: var(--border);
}

/* Export cards */
body.dark-mode .export-card {
  background: var(--surface-2);
  border-color: var(--border);
}

body.dark-mode .export-card-icon {
  background: var(--brand-light);
}

/* Tabs impostazioni */
body.dark-mode .imp-tab:hover {
  background: var(--surface-3);
  color: var(--ink);
}

body.dark-mode .imp-tab.active {
  color: var(--brand);
}

body.dark-mode .imp-tabs {
  border-bottom-color: var(--border);
}

/* Alert */
body.dark-mode .alert-info    { background: #001a1b; color: #00c0c2; border-color: #005f61; }
body.dark-mode .alert-success { background: var(--success-bg); color: #4caf82; border-color: #1a5c38; }
body.dark-mode .alert-warning { background: var(--warning-bg); color: #c8a030; border-color: #5a3e00; }
body.dark-mode .alert-danger  { background: var(--danger-bg);  color: #f87171; border-color: #6b1a22; }

/* Badge */
body.dark-mode .badge-goods  { background: var(--surface-3); color: var(--ink-3); }
body.dark-mode .badge-global { background: #0a1f14; color: #4caf82; }
body.dark-mode .badge-tenant { background: #1a1400; color: #c8a030; }
body.dark-mode .badge-dish   { background: #001a1b; color: #00c0c2; }
body.dark-mode .badge-semi   { background: #130a2a; color: #a97df5; }
body.dark-mode .badge-mod    { background: #1f0018; color: #e066b3; }

/* Paginazione */
body.dark-mode .page-btn {
  background: var(--surface-3);
  border-color: var(--border);
  color: var(--ink-2);
}

body.dark-mode .page-btn.active {
  background: var(--brand);
  color: var(--surface);
  border-color: var(--brand);
}

/* Scrollbar */
body.dark-mode ::-webkit-scrollbar { width: 6px; height: 6px; }
body.dark-mode ::-webkit-scrollbar-track { background: var(--surface-2); }
body.dark-mode ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
body.dark-mode ::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

/* Separatori e bordi vari */
body.dark-mode .form-section { border-top-color: var(--border); }
body.dark-mode .table-toolbar { border-bottom-color: var(--border); }
body.dark-mode .pagination { border-top-color: var(--border); }
body.dark-mode .search-input { background: var(--surface-3); }

/* Transizione morbida al cambio tema */
body, body * {
  transition-property: background-color, border-color, color, box-shadow;
  transition-duration: 0.3s;
  transition-timing-function: ease;
}

/* ── DARK MODE FIX — testo su sfondo ciano ── */

/* btn-primary: testo sempre scuro su sfondo ciano */
body.dark-mode .btn-primary {
  color: #0b0d14;
}
body.dark-mode .btn-primary:hover {
  color: #ffffff;
}

/* btn-ghost hover: non usare navy come colore testo */
body.dark-mode .btn-ghost:hover {
  color: var(--brand);
}

/* Tab impostazioni attivo */
body.dark-mode .imp-tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

/* Sub-tab admin (Ristoranti / Utenti / Rivenditori) attivi */
body.dark-mode .admin-sub-btn.active,
body.dark-mode [class*="sub-tab"].active,
body.dark-mode button.active {
  color: #0b0d14;
}

/* Qualsiasi elemento con color:var(--navy) inline nel JS
   — li sovrascriviamo con il brand chiaro */
body.dark-mode .imp-section-title,
body.dark-mode .section-title {
  color: var(--brand);
}

/* Page title span (nome utente nel saluto) — già gestito,
   ma forziamo anche il colore navy inline nei titoli sezione */
body.dark-mode [style*="color:var(--navy)"],
body.dark-mode [style*="color: var(--navy)"] {
  color: var(--brand) !important;
}

/* Eccezione: testo su sfondo ciano deve restare scuro */
body.dark-mode .btn-primary [style*="color:var(--navy)"],
body.dark-mode .btn-primary [style*="color: var(--navy)"],
body.dark-mode .nav-item.active {
  color: #0b0d14 !important;
}

/* ── DARK MODE — override globale navy→brand per testi ──
   Cattura tutti i casi dove --navy viene usato come colore testo
   in elementi non-interattivi */
body.dark-mode td.td-primary,
body.dark-mode .td-primary {
  color: var(--ink);
}

body.dark-mode code {
  background: var(--surface-3);
  color: var(--brand);
}

/* Forza il testo nei titoli sezione dei modal */
body.dark-mode .form-section-title {
  color: var(--ink-3);
}

/* Sub-tab Amministrazione: Ristoranti / Utenti / Rivenditori */
body.dark-mode .btn-sm.active,
body.dark-mode button[style*="background:var(--navy)"],
body.dark-mode button[style*="background: var(--navy)"] {
  background: var(--brand) !important;
  color: #0b0d14 !important;
}

/* ── DARK MODE — fix admin subtab e cat-tree ── */

/* Admin subtab attivo: sfondo navy→scuro, testo bianco */
body.dark-mode .admin-subtab.active {
  background: var(--surface-3);
  border-color: var(--brand);
  color: var(--brand);
}

body.dark-mode .admin-subtab.active svg {
  stroke: var(--brand);
}

body.dark-mode .admin-subtab:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--surface-3);
}

body.dark-mode .admin-subtab {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--ink-3);
}

/* Cat tree nodi: il colore navy inline viene catturato dalla regola
   [style*="color:var(--navy)"] già presente, ma forziamo anche qui */
body.dark-mode .cat-tree-name {
  color: var(--ink) !important;
}

body.dark-mode .cat-tree-row:hover .cat-tree-name {
  color: var(--brand) !important;
}

/* ── PULSANTI MODAL PRODOTTO ── */
.btn-modale-chiudi {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 22px; border-radius: 8px;
  font-size: 13.5px; font-family: var(--font-body);
  font-weight: 500; cursor: pointer; border: none;
  transition: all var(--transition); white-space: nowrap;
  background: #e6e5e8; color: var(--navy);
}
.btn-modale-chiudi:hover { background: #d5d3d8; }

.btn-salva {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 22px; border-radius: 8px;
  font-size: 13.5px; font-family: var(--font-body);
  font-weight: 500; cursor: pointer; border: none;
  transition: all var(--transition); white-space: nowrap;
  background: #cfe9ed; color: var(--navy);
}
.btn-salva:hover { background: #b8dde3; }
.btn-salva:disabled { opacity: .45; cursor: not-allowed; }

.btn-duplica {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 22px; border-radius: 8px;
  font-size: 13.5px; font-family: var(--font-body);
  font-weight: 500; cursor: pointer; border: none;
  transition: all var(--transition); white-space: nowrap;
  background: #cfe9ed; color: var(--navy);
}
.btn-duplica:hover:not(:disabled) { background: #b8dde3; }
.btn-duplica:disabled { opacity: .45; cursor: not-allowed; }

.btn-add-new {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; flex-shrink: 0;
  border-radius: 50%; border: none; cursor: pointer;
  background: var(--brand); transition: background var(--transition);
  padding: 0;
}
.btn-add-new:hover { background: var(--brand-dark); }

/* ── TOGGLE IVA ── */
.iva-toggle {
  position: relative; display: inline-block;
  width: 48px; height: 26px; flex-shrink: 0;
}
.iva-toggle input { opacity: 0; width: 0; height: 0; }
.iva-toggle-slider {
  position: absolute; cursor: pointer;
  inset: 0; border-radius: 26px;
  background: var(--surface-3);
  transition: background .2s;
}
.iva-toggle-slider::before {
  content: ''; position: absolute;
  width: 20px; height: 20px; border-radius: 50%;
  left: 3px; top: 3px;
  background: white;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.iva-toggle input:checked + .iva-toggle-slider { background: var(--brand); }
.iva-toggle input:checked + .iva-toggle-slider::before { transform: translateX(22px); }

/* ── CAMPO RIEPILOGO QUANTITÀ (sola lettura) ── */
#np-riepilogo {
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--navy);
  font-family: monospace;
  letter-spacing: 0.02em;
}

/* ── RIGHE TABELLA PRODOTTI FORNITORE ── */
/* Item aggiunto + abbinato: default (nessun colore speciale) */
/* Item aggiunto senza abbinamento: arancio tenue */
.prod-row-no-match {
  background: rgba(122,82,0,.07) !important;
  border-left: 3px solid var(--warning) !important;
}
/* Item in attesa (buffer): ciano tenue */
.prod-row-buffer {
  background: rgba(0,192,194,.10) !important;
  border-left: 3px solid var(--brand) !important;
}

body.dark-mode .prod-row-no-match {
  background: rgba(245,200,66,.08) !important;
}
body.dark-mode .prod-row-buffer {
  background: rgba(0,192,194,.12) !important;
}
