/* WA Checker — stile base, tema chiaro/scuro */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #dde1e6;
  --text: #1c2128;
  --muted: #5d6673;
  --primary: #128c5e;
  --primary-contrast: #ffffff;
  --primary-hover: #0e7149;
  --danger-bg: #fdecec;
  --danger-text: #a12222;
  --warning-bg: #fff6e0;
  --warning-border: #f0c75e;
  --warning-text: #6b4e00;
  --info-bg: #e8f1fd;
  --info-text: #1d4f91;
  --ok: #1f9d55;
  --warn: #d49b00;
  --off: #9aa4b0;
  --danger: #c62828;
  --radius: 10px;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.06), 0 4px 12px rgb(0 0 0 / 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #111418;
    --surface: #1a1e24;
    --border: #2d333b;
    --text: #e6e8eb;
    --muted: #9aa4b0;
    --primary: #2bb67d;
    --primary-contrast: #06110c;
    --primary-hover: #39c98d;
    --danger-bg: #3a1a1a;
    --danger-text: #ff9b9b;
    --warning-bg: #332a12;
    --warning-border: #7a6220;
    --warning-text: #f3d48a;
    --shadow: none;
    --info-bg: #16263d;
    --info-text: #9cc3f5;
    --danger: #ef6b6b;
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #111418;
  --surface: #1a1e24;
  --border: #2d333b;
  --text: #e6e8eb;
  --muted: #9aa4b0;
  --primary: #2bb67d;
  --primary-contrast: #06110c;
  --primary-hover: #39c98d;
  --danger-bg: #3a1a1a;
  --danger-text: #ff9b9b;
  --warning-bg: #332a12;
  --warning-border: #7a6220;
  --warning-text: #f3d48a;
  --shadow: none;
  --info-bg: #16263d;
  --info-text: #9cc3f5;
  --danger: #ef6b6b;
  color-scheme: dark;
}

[x-cloak] { display: none !important; }

* { box-sizing: border-box; }

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

h1, h2, h3 { line-height: 1.2; }
h2 { margin: 0 0 1rem; font-size: 1.4rem; }

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

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

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

/* --- Pulsanti e form --- */
.btn {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
}
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn-primary { background: var(--primary); color: var(--primary-contrast); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }

label { display: block; margin-bottom: 1rem; font-weight: 500; }
input[type='text'], input[type='password'] {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
input:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.alert { border-radius: 8px; padding: 0.75rem 1rem; margin: 0 0 1rem; }
.alert-error { background: var(--danger-bg); color: var(--danger-text); }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border); }

/* --- Login --- */
.login-page { min-height: 100vh; display: grid; grid-template-rows: 1fr auto; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brand { margin: 0; color: var(--primary); }
.login-card .btn { width: 100%; }

/* --- Layout applicazione --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { font-weight: 700; color: var(--primary); text-decoration: none; font-size: 1.1rem; }
.nav { display: flex; gap: 0.25rem; flex: 1; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
}
.nav a:hover { color: var(--text); background: var(--bg); }
.nav a.active { color: var(--text); background: var(--bg); font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }
.menu-toggle { display: none; }

.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; }
  .menu-toggle { display: inline-block; order: 2; }
  .topbar-actions { order: 1; margin-left: auto; }
  .topbar-actions .user { display: none; }
  .nav { order: 3; flex-basis: 100%; flex-direction: column; display: none; }
  .nav.open { display: flex; }
}

.alert-info { background: var(--info-bg); color: var(--info-text); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }

.btn-danger { background: var(--danger); color: #fff; font-weight: 600; }
.btn-danger-ghost { background: transparent; border-color: var(--danger); color: var(--danger); }

/* --- Connessione WhatsApp --- */
.wa-card { display: grid; gap: 1rem; }
.wa-card .alert { margin: 0; }
.wa-status { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--border);
}
.badge-connesso { color: var(--ok); border-color: var(--ok); }
.badge-qr, .badge-in_connessione { color: var(--warn); border-color: var(--warn); }
.badge-disconnesso { color: var(--muted); }
.live { font-size: 0.85rem; }

.qr-box { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: center; }
.qr-box img {
  width: 280px;
  max-width: 100%;
  height: auto;
  background: #fff; /* il QR deve restare leggibile anche col tema scuro */
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.qr-box ol { margin: 0; padding-left: 1.2rem; max-width: 420px; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.confirm { border: 1px solid var(--danger); border-radius: 8px; padding: 0.75rem 1rem; }
.confirm p { margin-top: 0; }
.confirm .btn { margin-right: 0.5rem; }

.wa-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); display: inline-block; }
.wa-dot.dot-connesso { background: var(--ok); }
.wa-dot.dot-qr, .wa-dot.dot-in_connessione { background: var(--warn); }
.wa-dot.dot-bloccato { background: var(--danger); }

/* --- Nuova verifica --- */
.stack { display: grid; gap: 1rem; }
h3 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.small { font-size: 0.85rem; font-weight: normal; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2.5rem 1rem;
  margin: 0;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  font-weight: normal;
}
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: var(--bg); }
.dropzone.disabled { cursor: progress; }
.dropzone:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }
.dropzone progress { width: min(320px, 100%); }

.file-info { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: baseline; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.form-grid label { margin-bottom: 0.5rem; }
select {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.5rem 0.6rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.checkbox { display: flex; align-items: center; gap: 0.5rem; font-weight: normal; margin: 0; }

.table-wrap { overflow-x: auto; }
.table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.table th, .table td { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.table th { color: var(--muted); font-weight: 600; }
.table .sel { background: color-mix(in srgb, var(--primary) 10%, transparent); }
.table td.ok { color: var(--ok); }
.table td.ko { color: var(--danger); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; }
.stat { background: var(--bg); border-radius: 8px; padding: 0.75rem 1rem; display: flex; flex-direction: column; }
.stat-n { font-size: 1.6rem; font-weight: 700; }

/* --- Storico --- */
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem 1rem; margin-bottom: 1rem; }
.section-head h2 { margin: 0; }
.jobs { display: grid; gap: 1rem; }
.job { display: grid; gap: 0.75rem; }
.job .alert { margin: 0; }
.job-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.job-head h3 { margin: 0 0 0.2rem; word-break: break-word; }
.job-progress-line { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.25rem 1rem; }
.progress { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.progress span { display: block; height: 100%; background: var(--primary); transition: width 0.4s ease; }
.job-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.5rem; margin: 0; }
.job-stats div { background: var(--bg); border-radius: 8px; padding: 0.5rem 0.75rem; }
.job-stats dt { font-size: 0.8rem; color: var(--muted); }
.job-stats dd { margin: 0; font-size: 1.25rem; font-weight: 700; }
.ok { color: var(--ok); }
.ko { color: var(--danger); }
.badge-job-in_corso { color: var(--ok); border-color: var(--ok); }
.badge-job-in_coda, .badge-job-in_pausa { color: var(--warn); border-color: var(--warn); }
.badge-job-completato { color: var(--primary); border-color: var(--primary); }
.badge-job-annullato, .badge-job-errore { color: var(--danger); border-color: var(--danger); }
input[type='number'] {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
a.btn { text-decoration: none; display: inline-block; }

/* --- Risultati --- */
.btn-primary-ghost { background: transparent; border-color: var(--primary); color: var(--primary); text-decoration: none; }
.tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tab {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.35rem 0.75rem; border: 1px solid var(--border); border-radius: 999px;
  background: transparent; color: inherit; font: inherit; font-size: 0.9rem; cursor: pointer;
}
.tab.active { border-color: var(--primary); color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); }
.tab-n { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.85em; }
.tab.active .tab-n { color: inherit; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.toolbar input[type="search"] { flex: 1 1 16rem; min-width: 0; }
label.inline { display: inline-flex; align-items: center; gap: 0.5rem; }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.5rem; }
.table.results td { font-variant-numeric: tabular-nums; }
.esito { font-weight: 600; }
.esito-SI { color: var(--ok); }
.esito-NO { color: var(--muted); }
.esito-NON_VALIDO { color: var(--warn); }
.esito-ERRORE { color: var(--danger); }
.esito-NON_VERIFICATO { color: var(--muted); font-weight: 400; font-style: italic; }

/* --- Logo e firma --- */
.brand { display: inline-flex; align-items: center; gap: 0.5rem; }
.brand .logo { display: block; border-radius: 7px; box-shadow: 0 1px 4px rgb(18 140 94 / 0.35); }
.login-card .brand .logo { border-radius: 9px; }

.app-page { min-height: 100vh; display: flex; flex-direction: column; }
.app-page > main { flex: 1; width: 100%; }

.site-footer { text-align: center; padding: 1.5rem 1rem 1.75rem; font-size: 0.85rem; color: var(--muted); }
.credit {
  display: inline-flex; align-items: center; gap: 0.4em;
  padding: 0.4rem 1rem; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow);
  transition: border-color 0.2s, transform 0.2s;
}
.credit:hover { border-color: color-mix(in srgb, #e5484d 45%, var(--border)); transform: translateY(-1px); }
.credit strong {
  font-weight: 700; letter-spacing: 0.02em;
  background: linear-gradient(90deg, var(--primary), #2f7fe0);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.heart { width: 1.05em; height: 1.05em; color: #e5484d; transform-origin: center; animation: battito 1.8s ease-in-out infinite; }
.credit:hover .heart { animation-duration: 0.9s; }
@keyframes battito {
  0%, 45%, 100% { transform: scale(1); }
  12%, 32% { transform: scale(1.22); }
  22% { transform: scale(1.04); }
}
@media (prefers-reduced-motion: reduce) {
  .heart { animation: none; }
  .credit, .credit:hover { transition: none; transform: none; }
}

/* --- Sfondo animato (pioggia di caratteri) --- */
.matrix-bg {
  position: fixed; inset: 0; width: 100vw; height: 100vh;
  z-index: -1; pointer-events: none;
  opacity: 0.22;
}
:root[data-theme='dark'] .matrix-bg { opacity: 0.3; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .matrix-bg { opacity: 0.3; }
}
/* Titoli e testi posati direttamente sullo sfondo: un alone li tiene leggibili */
.container > section > h2, .section-head, .container > section > .muted, .container > section > a {
  text-shadow: 0 0 6px var(--bg), 0 0 12px var(--bg);
}
@media (prefers-reduced-motion: reduce) {
  .matrix-bg { display: none; }
}
