/* style.css - Interfaccia semplice e pulita */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green: #25D366;
  --green-dark: #128C7E;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

header {
  background: linear-gradient(135deg, var(--green-dark), var(--green));
  color: white;
  padding: 24px 0;
}
.header-inner h1 { font-size: 28px; font-weight: 700; }
.tagline { opacity: 0.9; font-size: 14px; margin-top: 4px; }

nav {
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.nav-inner {
  display: flex;
  gap: 4px;
  overflow-x: auto;
}
.tab-btn {
  background: none;
  border: none;
  padding: 16px 20px;
  font-size: 15px;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  font-weight: 500;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--green-dark);
  border-bottom-color: var(--green);
}

main { padding: 30px 0; }

.tab-content { display: none; }
.tab-content.active { display: block; }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.section-header h2 { font-size: 22px; }
.header-actions { display: flex; gap: 8px; }

.hint {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 20px;
  background: white;
  padding: 12px 16px;
  border-radius: 8px;
  border-left: 3px solid var(--green);
}

/* BUTTONS */
button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 500;
  transition: all 0.15s;
  border: none;
}
.btn-primary {
  background: var(--green);
  color: white;
}
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #f9fafb; }
.btn-danger {
  background: white;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 6px 12px;
  font-size: 13px;
}
.btn-danger:hover { background: var(--danger); color: white; }
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--muted);
}
.btn-icon:hover { color: var(--text); }

/* CARDS GRID */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.number-card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid var(--border);
}
.number-card h3 {
  font-size: 16px;
  margin-bottom: 6px;
}
.number-card .phone {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 12px;
  font-family: monospace;
}
.number-card .actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.number-card .actions button { padding: 6px 12px; font-size: 13px; }

/* STATUS BADGE */
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}
.status-ready { background: #d1fae5; color: #065f46; }
.status-qr { background: #fef3c7; color: #92400e; }
.status-disconnected, .status-error, .status-auth_failure { background: #fee2e2; color: #991b1b; }
.status-initializing, .status-authenticated { background: #dbeafe; color: #1e40af; }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge.new { background: #dbeafe; color: #1e40af; }
.badge.sent, .badge.first_sent { background: #fef3c7; color: #92400e; }
.badge.followup, .badge.followup_sent { background: #fed7aa; color: #9a3412; }
.badge.responded { background: #d1fae5; color: #065f46; }
.badge.acquired { background: #c7d2fe; color: #3730a3; }

/* TABLES */
.table-wrapper {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th {
  text-align: left;
  padding: 12px 16px;
  background: #f9fafb;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

/* FILTER ROW */
.filter-row {
  margin-bottom: 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.filter-row label {
  font-size: 14px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* FORMS */
.form-card {
  background: white;
  padding: 24px;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 200px; }
.field { margin-bottom: 16px; }
.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
}
input[type="text"], input[type="number"], input[type="datetime-local"],
input[type="file"], textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: white;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}
textarea { resize: vertical; }
code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: monospace;
}

/* MODAL */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal.active { display: flex; }
.modal-content {
  background: white;
  border-radius: 12px;
  padding: 28px;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-content h3 {
  margin-bottom: 16px;
  font-size: 20px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

#qr-container {
  text-align: center;
  margin: 20px 0;
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#qr-container img {
  max-width: 320px;
  border-radius: 8px;
}
.loader {
  color: var(--muted);
  font-size: 14px;
}
.status-text {
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 16px;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

/* HELP */
.help-list {
  background: white;
  padding: 20px 20px 20px 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.help-list li { margin-bottom: 10px; }
.help-list ul { margin: 8px 0 8px 20px; }

#save-status {
  margin-left: 12px;
  font-size: 14px;
  color: var(--green-dark);
}

@media (max-width: 640px) {
  .header-inner h1 { font-size: 22px; }
  .section-header h2 { font-size: 18px; }
  th, td { padding: 10px 8px; font-size: 13px; }
}

/* HEADER right-side */
.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.header-inner .header-actions button,
.header-inner .header-actions a {
  background: rgba(255,255,255,0.2);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
}
.header-inner .header-actions button:hover,
.header-inner .header-actions a:hover {
  background: rgba(255,255,255,0.3);
}

/* LOGIN PAGE */
.login-body {
  background: linear-gradient(135deg, var(--green-dark), var(--green));
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: white;
  padding: 40px;
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.login-card h1 {
  font-size: 26px;
  text-align: center;
  color: var(--green-dark);
}
.login-sub {
  text-align: center;
  color: var(--muted);
  margin-bottom: 24px;
  font-size: 14px;
}
.btn-block {
  width: 100%;
  padding: 12px;
  font-size: 15px;
}
.login-error {
  color: var(--danger);
  text-align: center;
  margin-top: 12px;
  font-size: 14px;
  min-height: 20px;
}

/* readonly inputs */
input[readonly] {
  background: #f9fafb;
  font-family: monospace;
  font-size: 12px;
}

details summary { padding: 8px 0; }

/* Toggle label per checkbox */
.toggle-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px !important;
}
.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
  cursor: pointer;
}

/* iOS-style switch */
.ios-switch {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}
.ios-switch input { opacity: 0; width: 0; height: 0; }
.ios-switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #e5e7eb;
  transition: background-color 0.25s;
  border-radius: 31px;
}
.ios-switch-slider:before {
  position: absolute;
  content: "";
  height: 27px;
  width: 27px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: transform 0.25s;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.ios-switch input:checked + .ios-switch-slider { background-color: #34c759; }
.ios-switch input:checked + .ios-switch-slider:before { transform: translateX(20px); }
.ios-switch input:disabled + .ios-switch-slider { opacity: 0.5; cursor: not-allowed; }

/* Riga con etichetta a sinistra e switch a destra */
.ios-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.ios-toggle-row:last-child { border-bottom: none; }
.ios-toggle-row .label-text {
  flex: 1;
  font-weight: 500;
  color: var(--text);
}
.ios-toggle-row .label-sub {
  display: block;
  font-weight: 400;
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

