/* ========== Design tokens (tema chiaro) ========== */
:root {
  /* Palette */
  --c-primary: #3498db;
  --c-primary-600: #2c82bd;
  --c-primary-50: #eef6fe;
  --c-primary-100: #dceeff;

  --c-accent: #27ae60;
  --c-accent-600: #219150;

  --c-danger: #f21717;
  --c-danger-600: #cc1414;
  --c-warn: #ff7f50;
  --c-warn-600: #e36f45;

  --c-bg: #f5f7fa;
  --c-surface: #ffffff;
  --c-elevated: #ffffff;

  --c-text: #222222;
  --c-text-muted: #555555;
  --c-border: #e2e6ea;

  /* Shadows */
  --shadow-100: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-200: 0 2px 12px rgba(0,0,0,0.10);

  /* Radii */
  --radius-4: 4px;
  --radius-6: 6px;
  --radius-8: 8px;
  --radius-10: 10px;

  /* Spacing scale */
  --space-0: 0;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  /* Typography */
  --font-base: clamp(16px, 1.6vw, 17px);
  --line-height: 1.55;

  /* Layout */
  --container-max: 1100px;

  /* Motion */
  --t-fast: 120ms;
  --t-normal: 200ms;
  --ease: cubic-bezier(.2,.8,.2,1);

  /* Focus ring */
  --focus-ring: 0 0 0 3px color-mix(in srgb, var(--c-primary) 25%, transparent);
  --focus-border: color-mix(in srgb, var(--c-primary) 55%, var(--c-border));
}

/* Preferenze utente: riduci animazioni */
@media (prefers-reduced-motion: reduce) {
  :root { --t-fast: 0ms; --t-normal: 0ms; }
  * { transition: none !important; animation: none !important; }
}

/* ========== Reset base ========== */
*,
*::before,
*::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: var(--font-base);
  line-height: var(--line-height);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
img, svg, video { max-width: 100%; height: auto; display: block; }

/* Accessibilità focus: mantiene il focus visibile per tastiera */
:where(a, button, input, textarea, select, summary, [tabindex]:not([tabindex="-1"])):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-color: var(--focus-border);
}
:where(button):focus:not(:focus-visible),
:where(a):focus:not(:focus-visible) { outline: none; } /* evita doppi ring per click mouse */

/* ========== Header e Navbar ========== */
header {
  background: var(--c-primary);
  color: #fff;
  padding: var(--space-4) 0;
  text-align: center;
  box-shadow: var(--shadow-100);
}
header h1 { font-size: 24px; margin: 0; }

.navbar {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: color-mix(in srgb, var(--c-primary) 8%, #fff);
  border-bottom: 1px solid var(--c-border);
  flex-wrap: wrap;
}
@supports not (background: color-mix(in srgb, #000 10%, #fff)) {
  .navbar { background: #ffffff; }
}
.navbar a {
  display: inline-block;
  padding: 8px 14px;
  border-radius: var(--radius-6);
  text-decoration: none;
  color: var(--c-text);
  background: #fff;
  box-shadow: var(--shadow-100);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
  will-change: background, color, transform;
}
.navbar a:hover { background: var(--c-primary-50); transform: translateY(-1px); }
.navbar a.active {
  background: var(--c-primary-100);
  border-bottom: 3px solid #0055aa;
}

/* ========== Container principali ========== */
.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-5) var(--space-3);
}
.table-container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-5);
  background: var(--c-surface);
  border-radius: var(--radius-8);
  box-shadow: var(--shadow-200);
}

/* ========== Dashboard e contenuti ========== */
main {
  padding: var(--space-5) var(--space-3);
  display: flex;
  justify-content: center;
}
.dashboard {
  background: var(--c-surface);
  border-radius: var(--radius-10);
  box-shadow: var(--shadow-200);
  max-width: 700px;
  width: 100%;
  padding: var(--space-5);
  text-align: center;
}
.dashboard h2 { font-size: 22px; margin-bottom: var(--space-2); }
.dashboard h3 { margin: var(--space-4) 0 var(--space-2); font-size: 18px; }
.dashboard h4 { margin: var(--space-4) 0 var(--space-2); color: #333; }

.dashboard p a {
  display: inline-block;
  margin: var(--space-2) auto;
  color: #6a1b9a;
  font-weight: 700;
  text-decoration: underline;
  width: fit-content;
  border-left: 5px solid #222;
  padding-left: var(--space-3);
}

/* ========== Tabelle responsive ========== */
.table-wrap {
  background: var(--c-surface);
  border-radius: var(--radius-8);
  box-shadow: var(--shadow-200);
  overflow: hidden;
  margin: var(--space-4) 0;
}
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--c-surface);
}
th, td {
  padding: var(--space-3);
  border: 1px solid var(--c-border);
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}
th { background: #e6f0ff; color: var(--c-text); }
td.actions { min-width: 140px; white-space: nowrap; }

/* Stacked su mobile */
@media (max-width: 768px) {
  table { border: 0; }
  thead { display: none; }
  tbody, tr, td { display: block; width: 100%; }
  tr {
    background: var(--c-surface);
    box-shadow: var(--shadow-100);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-6);
    padding: var(--space-2);
    margin-bottom: var(--space-2);
  }
  td {
    border: 0;
    display: grid;
    grid-template-columns: 42% 58%;
    gap: var(--space-2);
    text-align: left;
    padding: var(--space-1) 0;
    white-space: normal;
  }
  td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--c-text);
    padding-right: var(--space-2);
  }
}

/* ========== Form e input ========== */
select, input, textarea {
  display: block;
  margin: var(--space-2) auto;
  padding: var(--space-3);
  width: 100%;
  max-width: 500px;
  font-size: 16px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-6);
  background: var(--c-surface);
  color: var(--c-text);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
textarea { resize: vertical; }
select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--focus-border);
  box-shadow: var(--focus-ring);
}

/* ========== Pulsanti ========== */
.button, .btn-green, .btn-red, .btn-orange {
  border: none;
  padding: 12px;
  margin: var(--space-2) auto;
  width: 100%;
  max-width: 500px;
  display: block;
  cursor: pointer;
  font-size: 16px;
  border-radius: var(--radius-6);
  text-align: center;
  transition: background var(--t-normal) var(--ease), transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
  box-shadow: var(--shadow-100);
  will-change: transform, background, box-shadow;
}
.button { background: var(--c-primary); color: #fff; }
.button:hover { background: var(--c-primary-600); transform: translateY(-1px); }
.button:active { transform: translateY(0); }

.btn-green { background-color: var(--c-accent); color: #fff; }
.btn-green:hover { background-color: var(--c-accent-600); }

.btn-red { background-color: var(--c-danger); color: #fff; }
.btn-red:hover { background-color: var(--c-danger-600); }

.btn-orange { background-color: var(--c-warn); color: #fff; }
.btn-orange:hover { background-color: var(--c-warn-600); }

/* Pulsanti inline compatti */
.btn-inline {
  width: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  gap: 8px;
}

/* Stato focus pulsanti e link */
:where(.button, .btn-green, .btn-red, .btn-orange, .btn-inline, .navbar a):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ========== Footer ========== */
footer {
  background-color: #eee;
  text-align: center;
  padding: var(--space-4);
  font-size: 14px;
  color: #444;
}

/* ========== Modale ========== */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  inset: 0;
  background-color: rgba(0,0,0,0.45);
  align-items: center;
  justify-content: center;
}
.modal[aria-hidden="false"] { display: flex; }
.modal-content {
  background: var(--c-elevated);
  padding: var(--space-4);
  border-radius: var(--radius-10);
  width: 90%;
  max-width: 420px;
  text-align: center;
  box-shadow: var(--shadow-200);
}
.modal-buttons {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
  margin-top: var(--space-3);
}
.modal-buttons button {
  margin: var(--space-1);
  padding: 10px 20px;
  border: none;
  font-weight: 700;
  border-radius: var(--radius-6);
  cursor: pointer;
}

/* ========== Utility ========== */
.box { background: var(--c-surface); border-radius: var(--radius-8); box-shadow: var(--shadow-100); padding: var(--space-4); margin: var(--space-4) 0; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.mt-2 { margin-top: var(--space-2); }
.mb-2 { margin-bottom: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mb-3 { margin-bottom: var(--space-3); }

/* ========== Piccoli ritocchi mobile ========== */
@media (max-width: 480px) {
  .container { padding: var(--space-4) var(--space-2); }
  .navbar { padding: var(--space-2); gap: var(--space-2); }
  .button, .btn-green, .btn-red, .btn-orange { font-size: 1.05em; min-height: 48px; }
}

/* ========== Progressive enhancement: color-scheme ========== */
:root { color-scheme: light; } /* aiuta UA per modali/scrollbar nel tema chiaro */
