/* LabelRifiuti — UI mobile-first per autisti.
   Obiettivi: bottoni grandi, contrasto alto, pochi click. */

* { box-sizing: border-box; }

:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --primary: #15803d;        /* verde Wastetrax */
  --primary-dark: #0f5c2c;
  --accent: #0b5fff;         /* blu accent */
  --danger: #d32f2f;
  --warning: #f59e0b;
  --success: #15803d;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --radius: 14px;
  --gap: 14px;
}

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 18px;          /* base grande per autisti */
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

header.top {
  background: var(--primary);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
header.top h1 { margin: 0; font-size: 20px; font-weight: 600; }
header.top .right { font-size: 14px; opacity: 0.9; }
header.top a { color: #fff; text-decoration: none; }

header.top .brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.5px;
}
header.top .brand-logo {
  width: 36px;
  height: 36px;
  background: #fff;
  border-radius: 8px;
  padding: 3px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

/* Back button sticky sotto l'header */
.back-bar {
  position: sticky;
  top: 56px;
  z-index: 9;
  background: var(--bg);
  margin: -16px -16px 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.back-bar a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 16px;
  padding: 6px 10px;
  border-radius: 8px;
}
.back-bar a:active { background: #e0e7ff; }

/* Anteprima etichetta SVG */
.label-preview-svg {
  display: block;
  margin: 8px auto;
  background: #fff;
  border: 2px dashed var(--border);
  border-radius: 8px;
  max-width: 100%;
  height: auto;
}

/* Editor template */
.editor-canvas {
  position: relative;
  background: #fff;
  border: 2px solid var(--text);
  margin: 0 auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  touch-action: none;
}
.editor-element {
  position: absolute;
  border: 2px dashed var(--primary);
  background: rgba(11,95,255,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  text-align: center;
  cursor: move;
  user-select: none;
  padding: 2px;
  overflow: hidden;
  border-radius: 3px;
}
.editor-element.selected {
  border-color: var(--danger);
  background: rgba(211,47,47,0.10);
  color: var(--danger);
  z-index: 2;
}
.editor-element.locked {
  border-style: solid;
  cursor: not-allowed;
  opacity: 0.85;
}
.editor-handle {
  position: absolute;
  right: -6px; bottom: -6px;
  width: 14px; height: 14px;
  background: var(--danger);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: nwse-resize;
}
.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}
.editor-toolbar button {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 8px 12px;
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.editor-toolbar button:active { background: #e0e7ff; }
.editor-toolbar button.danger { color: var(--danger); border-color: var(--danger); }
.editor-toolbar button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.editor-props { margin-top: 12px; }
.editor-props label { font-size: 14px; margin-top: 8px; }
.editor-props input, .editor-props select { font-size: 16px; padding: 8px; }

/* =====================================================
   BACKOFFICE — layout desktop con sidebar
   ===================================================== */

.admin-layout {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
}

.admin-sidebar {
  width: 240px;
  background: #0f1f1a;
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
}
.admin-sidebar .brand {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.admin-sidebar .brand img {
  width: 36px; height: 36px;
  background: #fff;
  border-radius: 8px;
  padding: 3px;
}
.admin-sidebar .brand .title { font-weight: 800; font-size: 18px; letter-spacing: 0.5px; }
.admin-sidebar .brand .subtitle { font-size: 11px; opacity: 0.6; }
.admin-sidebar nav { flex: 1; padding: 12px 0; }
.admin-sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 15px;
  border-left: 3px solid transparent;
}
.admin-sidebar nav a:hover { background: rgba(255,255,255,0.05); }
.admin-sidebar nav a.active {
  background: rgba(21,128,61,0.15);
  border-left-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.admin-sidebar nav a .ico { width: 22px; text-align: center; }
.admin-sidebar nav .group-label {
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 1px;
  opacity: 0.5;
  padding: 18px 20px 6px;
}
.admin-sidebar .footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 13px;
}
.admin-sidebar .footer a { color: rgba(255,255,255,0.7); text-decoration: none; }

.admin-main {
  flex: 1;
  padding: 28px 32px;
  min-width: 0;
  max-width: 100%;
}
.admin-main h1 {
  font-size: 26px;
  margin: 0 0 6px;
  font-weight: 700;
}
.admin-main .page-subtitle {
  color: var(--muted);
  margin: 0 0 24px;
}

/* KPI cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 18px 20px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.kpi-card .kpi-label {
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 600;
}
.kpi-card .kpi-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}
.kpi-card .kpi-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
.kpi-card.accent { border-top: 4px solid var(--primary); }
.kpi-card.warn   { border-top: 4px solid var(--warning); }
.kpi-card.danger { border-top: 4px solid var(--danger); }
.kpi-card.accent2{ border-top: 4px solid var(--accent); }

/* Pannelli con titolo */
.panel {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 18px;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.panel-body { padding: 16px 18px; }
.panel-body.flush { padding: 0; }
.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 900px) { .panel-grid { grid-template-columns: 1fr; } }

/* Tabella admin */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.admin-table th {
  text-align: left;
  padding: 12px 14px;
  background: #f9fafb;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table tbody tr:hover { background: #f9fafb; }
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.admin-table .pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.admin-table .pill.ok      { background: #dcfce7; color: #15803d; }
.admin-table .pill.warn    { background: #fef3c7; color: #92400e; }
.admin-table .pill.danger  { background: #fee2e2; color: #991b1b; }
.admin-table .pill.info    { background: #dbeafe; color: #1e3a8a; }

.row-actions a, .row-actions button {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  margin-right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.row-actions a.danger, .row-actions button.danger { color: var(--danger); }

/* Filtri */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  padding: 14px 18px;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
}
.filters .f {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filters .f label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin: 0;
}
.filters input, .filters select {
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.filters .actions { margin-left: auto; display: flex; gap: 8px; align-items: end; }
.filters button {
  min-height: 36px;
  padding: 7px 14px;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}
.filters button.secondary { background: #fff; color: var(--primary); }

/* Paginazione */
.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--muted);
}
.pager .pages { display: flex; gap: 4px; }
.pager .pages button {
  min-width: 32px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
}
.pager .pages button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.form-grid label { font-size: 13px; font-weight: 600; margin: 0 0 4px; display: block; }
.form-grid .field { display: flex; flex-direction: column; }
.form-grid .field.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
  font-size: 15px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.form-grid textarea { min-height: 80px; resize: vertical; }
.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.form-actions .btn { width: auto; min-height: 44px; padding: 10px 20px; }

.btn.compact { min-height: 38px; padding: 8px 14px; font-size: 14px; width: auto; }

/* Hamburger mobile per sidebar */
.admin-hamburger {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 20;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 44px; height: 44px;
  font-size: 22px;
}
@media (max-width: 768px) {
  .admin-sidebar {
    position: fixed;
    top: 0; left: 0;
    transform: translateX(-100%);
    transition: transform 0.2s;
    z-index: 30;
  }
  .admin-sidebar.open { transform: translateX(0); }
  .admin-main { padding: 60px 16px 24px; }
  .admin-hamburger { display: block; }
  .kpi-card .kpi-value { font-size: 26px; }
  .form-grid { grid-template-columns: 1fr; }
}

/* Visualizza lista bidoni / chips piccoli */
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }
.tag-list .tag {
  background: #e0e7ff;
  color: #1e3a8a;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.tag-list .tag.danger { background: #fee2e2; color: #991b1b; }

/* Empty state */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty .ico { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }

main {
  padding: 16px;
  padding-bottom: 100px; /* spazio per status bar */
  max-width: 720px;
  margin: 0 auto;
}

/* Stato connessione */
.status-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  z-index: 5;
}
.status-bar .online  { color: var(--success); }
.status-bar .offline { color: var(--warning); }
.status-bar .pending {
  background: var(--warning); color: #fff;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; margin-left: 6px;
}

/* Card */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: var(--gap);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border: 1px solid var(--border);
}
.card h2 { margin: 0 0 10px; font-size: 18px; }
.card .label { color: var(--muted); font-size: 13px; }

/* Lista (aziende, rifiuti) */
.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.list-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 0.1s;
  min-height: 64px;        /* target touch ampio */
}
.list-item:active { background: #eef2ff; }
.list-item .main { flex: 1; min-width: 0; }
.list-item .title {
  font-weight: 600;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item .sub {
  color: var(--muted);
  font-size: 14px;
  margin-top: 2px;
}
.list-item .badge {
  background: var(--primary);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}
.list-item.pericoloso { border-left: 6px solid var(--danger); }
.list-item.pericoloso .badge { background: var(--danger); }

/* Bottoni grandi */
.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 56px;
  padding: 12px 20px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 18px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  width: 100%;
  margin-bottom: 10px;
}
.btn:active { background: var(--primary-dark); }
.btn[disabled] { background: #9ca3af; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--primary); border: 2px solid var(--primary); }
.btn.danger { background: var(--danger); }
.btn.big { min-height: 72px; font-size: 22px; }

/* Form */
label { display: block; font-weight: 600; margin: 14px 0 6px; }
input[type=text], input[type=number], input[type=password], input[type=search], select {
  width: 100%;
  padding: 14px;
  font-size: 18px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
input:focus { outline: none; border-color: var(--primary); }

/* Search bar */
.search-bar {
  position: relative;
  margin-bottom: var(--gap);
}
.search-bar input { padding-left: 44px; }
.search-bar::before {
  content: "🔍";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  opacity: 0.5;
}

/* Stepper +/- per colli */
.stepper {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}
.stepper button {
  width: 64px;
  font-size: 28px;
  background: #f3f4f6;
  border: none;
  cursor: pointer;
  font-weight: 700;
}
.stepper button:active { background: #e5e7eb; }
.stepper input {
  flex: 1;
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  border: none;
  border-left: 2px solid var(--border);
  border-right: 2px solid var(--border);
  border-radius: 0;
  padding: 8px 0;
}

/* Anteprima loghi */
.loghi-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.loghi-list .logo-chip {
  background: #fee2e2;
  color: #991b1b;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
}

/* Anteprima etichetta */
.etichetta-preview {
  background: #fff;
  border: 2px dashed var(--border);
  padding: 14px;
  border-radius: var(--radius);
  margin: var(--gap) 0;
}
.etichetta-preview .cer-big { font-size: 28px; font-weight: 700; }
.etichetta-preview .collo-big { font-size: 48px; font-weight: 800; text-align: center; margin: 8px 0; }
.etichetta-preview .pericoloso-band {
  background: #000; color: #fff;
  padding: 4px 8px; text-align: center; font-weight: 700;
  margin: 6px 0;
}

/* Login */
.login-box {
  max-width: 360px;
  margin: 60px auto;
  padding: 24px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.login-box h1 { text-align: center; margin: 0 0 20px; }
.login-error {
  background: #fee2e2; color: #991b1b;
  padding: 10px; border-radius: 8px;
  margin-bottom: 12px; text-align: center;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 15px;
  z-index: 100;
  animation: toast-in 0.2s ease-out;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* Spinner inline */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 3px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }
