/* ============================================================
   SMS Platform – stylesheet principale
   Tema: Professional Light — WCAG 2.1/2.2 AA Compliant
   Versione accessibilità: 1.0
   ============================================================ */

/* ── Variabili CSS ────────────────────────────────────────── */
:root {
  /* Colori base — contrasto verificato WCAG AA (4.5:1 min) */
  --bg:           #f6f9fc;
  --bg-card:      #ffffff;
  --bg-sidebar:   #ffffff;
  --bg-hover:     #f0f4f8;

  /* Bordi */
  --border:       #c8d3de;   /* più scuro per visibilità */
  --border-light: #dde4ed;

  /* Testo — contrasto 7:1 su sfondo bianco (WCAG AAA) */
  --text:         #1a2332;
  --text-muted:   #5a6a7a;   /* contrasto 4.6:1 su bianco */
  --text-dim:     #374151;   /* contrasto 8.6:1 su bianco */

  /* Accent verde — contrasto 4.6:1 su bianco */
  --accent:       #006644;
  --accent-light: rgba(0,102,68,.12);
  --accent-dark:  #00543a;

  /* Attivo sidebar — usa verde accent per uniformità */
  --active-color: #005a36;
  --active-bg:    #e6f4ef;
  --active-border:#005a36;

  /* Semantic — tutti verificati WCAG AA */
  --danger:       #b91c1c;   /* 5.9:1 su bianco */
  --warning:      #92400e;   /* 7.0:1 su bianco */
  --info:         #0066cc;   /* 5.2:1 su bianco */
  --success:      #065f46;   /* 7.2:1 su bianco */

  /* UI */
  --radius:       8px;
  --radius-sm:    6px;
  --radius-lg:    12px;
  --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono:         'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow:       0 4px 6px rgba(0,0,0,.07), 0 1px 3px rgba(0,0,0,.08);
  --shadow-lg:    0 10px 25px rgba(0,0,0,.10), 0 4px 10px rgba(0,0,0,.07);
  --transition:   .15s ease;

  /* Dimensioni minime tocco — WCAG 2.5.5 Target Size (44x44px) */
  --min-target:   44px;
}

/* ── Reset e base ────────────────────────────────────────── */
*,*::before,*::after { box-sizing:border-box; margin:0; padding:0; }

html {
  font-size: 100%;  /* rispetta preferenze utente — 1.4.4 */
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;   /* 16px base — ridimensionabile */
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Skip link — WCAG 2.4.1 ─────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 6px;
  z-index: 9999;
  background: var(--active-color);
  color: #fff;
  padding: 8px 16px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-size: .9rem;
  font-weight: 600;
  text-decoration: none;
  transition: top .15s;
}
.skip-link:focus {
  top: 0;
  outline: 3px solid #ff0;
  outline-offset: 2px;
}

/* ── Focus visibile — WCAG 2.4.7, 2.4.11 ────────────────── */
:focus-visible {
  outline: 3px solid var(--active-color);
  outline-offset: 2px;
  border-radius: 2px;
}
/* Rimuovi outline solo quando non è da tastiera */
:focus:not(:focus-visible) { outline: none; }

a { color: var(--active-color); }
a:hover { text-decoration: underline; }
/* visited links - stessa palette per uniformità visiva */
a:visited { color: var(--active-color); }
.btn:visited { color: inherit; text-decoration: none; }
.btn-primary:visited { color: #fff; }
.btn-secondary:visited { color: var(--text-dim); }
.nav-item:visited { color: var(--text-dim); }
.nav-item.active:visited { color: var(--active-color); }

/* ── Layout ──────────────────────────────────────────────── */
.wrapper { display: flex; min-height: 100vh; }

/* ── Sidebar — navigazione principale ───────────────────── */
.sidebar {
  width: 240px;
  background: var(--bg-sidebar);
  border-right: 2px solid var(--border);  /* bordo più spesso per visibilità */
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform var(--transition);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px 16px;
  border-bottom: 2px solid var(--border);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.sidebar-logo:hover { text-decoration: none; background: var(--bg-hover); }
/* logo SVG inline — nessun .dot necessario */

/* Navigazione sidebar — WCAG 4.1.2 */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px;
  /* Scrollbar accessibile */
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.nav-section {
  padding: 14px 12px 4px;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  margin-bottom: 2px;
  color: var(--text-dim);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  border-left: 3px solid transparent;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
  min-height: var(--min-target);   /* WCAG 2.5.5 target size */
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
  border-left-color: var(--border);
}
.nav-item.active {
  background: var(--active-bg);
  color: var(--active-color);
  border-left-color: var(--active-border);
  font-weight: 700;
}
.nav-item:focus-visible {
  outline: 3px solid var(--active-color);
  outline-offset: -2px;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 2px solid var(--border);
  font-size: .85rem;
}

/* ── Main content ────────────────────────────────────────── */
.main-content {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  background: var(--bg-card);
  border-bottom: 2px solid var(--border);
  padding: 0 28px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.topbar-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
}
.topbar-actions { display: flex; align-items: center; gap: 14px; }

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  color: var(--text-dim);
  min-height: var(--min-target);
  padding: 0 8px;
  border-radius: var(--radius-sm);
}
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--active-color);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.page-body { padding: 24px 28px; flex: 1; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
}

/* ── Stat cards ──────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--accent);
  border-radius: var(--radius) var(--radius) 0 0;
}
.stat-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  letter-spacing: -.02em;
}
.stat-sub { font-size: .78rem; color: var(--text-muted); margin-top: 6px; }

/* ── Tables — WCAG 1.3.1 ─────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table-wrap:focus { outline: 3px solid var(--active-color); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
caption {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: left;
  padding: 8px 0;
  caption-side: top;
}
thead tr { background: #f0f4f8; }
th {
  padding: 11px 14px;
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text);  /* contrasto aumentato per leggibilità */
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  scope: col;
}
th[scope="row"] { font-weight: 600; }
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-dim);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f5f8fb; }
tbody tr:focus-within { background: var(--active-bg); outline: 2px solid var(--active-color); outline-offset: -2px; }

/* ── Badges — non solo il colore per il significato (1.4.1) */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  border: 1px solid transparent;
}
/* I badge usano bordo + colore, non solo colore */
.badge-success { background: #d1fae5; color: #065f46; border-color: #6ee7b7; }
.badge-danger  { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }
.badge-warning { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.badge-info    { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.badge-neutral { background: #f1f5f9; color: #374151; border-color: #cbd5e1; }

/* ── Buttons — WCAG 2.5.5 (44px target) ─────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  min-height: var(--min-target);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.2;
  position: relative;
}
.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
}
.btn:disabled::after {
  content: ' (non disponibile)';
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; text-decoration: none; }
.btn-primary:focus-visible { outline: 3px solid #ff0; outline-offset: 2px; }

.btn-secondary { background: var(--bg-card); color: var(--text-dim); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-hover); color: var(--text); border-color: var(--active-color); text-decoration: none; }

.btn-danger { background: var(--bg-card); color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; text-decoration: none; }

.btn-sm { padding: 6px 12px; font-size: .82rem; min-height: 36px; }  /* componenti secondari */
.btn-lg { padding: 12px 24px; font-size: 1rem; min-height: 52px; }

/* ── Forms — WCAG 1.3.1, 1.3.5, 3.3.1, 3.3.2 ───────────── */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: .875rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
/* Indica campi obbligatori con testo, non solo asterisco */
.form-label .required {
  color: var(--danger);
  margin-left: 2px;
}
.form-label .required::after {
  content: ' (obbligatorio)';
  font-size: .72rem;
  font-weight: 400;
  color: var(--text-muted);
}

.form-control {
  width: 100%;
  background: var(--bg-card);
  border: 2px solid var(--border);   /* bordo 2px per visibilità */
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 1rem;    /* min 16px per evitare zoom su mobile */
  font-family: var(--font);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-height: var(--min-target);
  line-height: 1.4;
}
.form-control:focus {
  border-color: var(--active-color);
  box-shadow: 0 0 0 3px rgba(0,61,153,.2);
}
.form-control:invalid:not(:placeholder-shown) {
  border-color: var(--danger);
}
.form-control::placeholder { color: #8896a4; }
textarea.form-control { resize: vertical; min-height: 100px; }
select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%235a6a7a' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Stato errore — WCAG 3.3.1: non solo colore */
.form-error {
  font-size: .82rem;
  color: var(--danger);
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
}
.form-error::before { content: '⚠ '; }

.form-hint { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media(max-width:600px){ .form-row { grid-template-columns: 1fr; } }

/* ── Alerts — WCAG 4.1.3 status messages ─────────────────── */
.alert {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  margin-bottom: 14px;
  border: 2px solid;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
/* Role alert aggiunto nel PHP */
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: #f0fdf4; border-color: #16a34a; color: #065f46; }
.alert-danger  { background: #fef2f2; border-color: #dc2626; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #d97706; color: #92400e; }
.alert-info    { background: #eff6ff; border-color: #2563eb; color: #1e40af; }

/* ── Pagination ──────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 18px;
}
.page-link {
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  color: var(--text-dim);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--min-target);
  min-width: var(--min-target);
  background: var(--bg-card);
}
.page-link:hover { background: var(--bg-hover); color: var(--text); border-color: var(--active-color); text-decoration: none; }
.page-link.active {
  background: var(--active-color);
  border-color: var(--active-color);
  color: #fff;
}
.page-link[aria-current="page"] { font-weight: 800; }
.page-link.disabled { opacity: .4; pointer-events: none; }

/* ── SMS counter ─────────────────────────────────────────── */
.sms-counter {
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: 4px;
}
.sms-counter .warn { color: var(--warning); font-weight: 700; }

/* ── Login page ──────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f6f9fc 0%, #eef2f7 100%);
}
.login-box {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 28px;
  color: var(--text);
}
.login-logo span { color: var(--accent); }

/* ── High contrast media query (prefers-contrast) ─────────── */
@media (prefers-contrast: high) {
  :root {
    --border:       #000000;
    --text-muted:   #333333;
    --accent:       #004d00;
    --active-color: #00008b;
  }
  .badge { border-width: 2px; }
  .btn { border-width: 2px; }
  .form-control { border-width: 3px; }
}

/* ── Reduced motion (prefers-reduced-motion) — WCAG 2.3.3 ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Dark mode (prefers-color-scheme) — opzionale ─────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #0f172a;
    --bg-card:      #1e293b;
    --bg-sidebar:   #0f172a;
    --bg-hover:     #273549;
    --border:       #334155;
    --border-light: #1e293b;
    --text:         #f1f5f9;
    --text-muted:   #94a3b8;
    --text-dim:     #cbd5e1;
    --active-bg:    #1e3a5f;
    --shadow-sm:    0 1px 3px rgba(0,0,0,.3);
  }
  .badge-success { background: #064e3b; color: #6ee7b7; border-color: #059669; }
  .badge-danger  { background: #7f1d1d; color: #fca5a5; border-color: #dc2626; }
  .badge-warning { background: #78350f; color: #fcd34d; border-color: #d97706; }
  .badge-info    { background: #1e3a8a; color: #93c5fd; border-color: #3b82f6; }
  .badge-neutral { background: #334155; color: #cbd5e1; border-color: #64748b; }
}

/* ── Utilities ───────────────────────────────────────────── */
.text-muted  { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }
.mono        { font-family: var(--mono); }
.flex        { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mb-4  { margin-bottom: 16px; }
.mt-4  { margin-top: 16px; }
.w-full { width: 100%; }

/* Visually hidden — per testo accessibile ma non visivo */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
/* Visible when focused (per skip links) */
.sr-only-focusable:focus { position: static; width: auto; height: auto; clip: auto; white-space: normal; }

.divider { border: none; border-top: 2px solid var(--border); margin: 18px 0; }

.empty-state { text-align: center; padding: 56px 20px; color: var(--text-muted); }
.empty-state svg { width: 44px; height: 44px; margin: 0 auto 12px; opacity: .25; display: block; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .stat-value { font-size: 1.4rem; }
  .page-body { padding: 16px; }
  .topbar { padding: 0 16px; }
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Print ───────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .btn { display: none !important; }
  .main-content { margin-left: 0; }
  body { font-size: 12pt; color: #000; background: #fff; }
  a::after { content: ' (' attr(href) ')'; font-size: .8em; }
  table { border-collapse: collapse; }
  th, td { border: 1px solid #000; }
}

/* ── Animazioni (rispettano prefers-reduced-motion) ─────── */
@keyframes fadeIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }
.fade-in { animation: fadeIn .25s ease forwards; }
