/* ═══════════════════════════════════════════════════════════
   DISMA GESTIONALE — Design System
   Tema: Light · Professionale · Raffinato
   Font: DM Sans (body) + DM Mono (dati/codici)
   Colore primario: #0162b2 (brand originale)
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

/* ─── VARIABILI ─────────────────────────────────────────── */
:root {
  --brand:        #0162b2;
  --brand-dark:   #014a88;
  --brand-light:  #e8f2fc;
  --brand-mid:    #cce0f5;
  --accent:       #0284c7;
  --success:      #16a34a;
  --success-light:#dcfce7;
  --danger:       #dc2626;
  --danger-light: #fee2e2;
  --warning:      #d97706;
  --warning-light:#fef3c7;

  --bg:           #f0f4f9;
  --surface:      #ffffff;
  --surface2:     #f8fafc;
  --border:       #dde5ee;
  --border-strong:#b8c9de;

  --text:         #1a2433;
  --text-secondary:#4a5568;
  --text-muted:   #8795a8;

  --shadow-sm:    0 1px 3px rgba(1,98,178,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:       0 4px 16px rgba(1,98,178,0.10), 0 2px 6px rgba(0,0,0,0.05);
  --shadow-lg:    0 10px 32px rgba(1,98,178,0.14), 0 4px 12px rgba(0,0,0,0.06);

  --radius-sm:    6px;
  --radius:       10px;
  --radius-lg:    16px;
  --radius-xl:    22px;

  --transition:   all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── RESET & BASE ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Sfondo con pattern sottile */
body::before {
  content: '';
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(circle at 20% 20%, rgba(1,98,178,0.04) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(1,98,178,0.03) 0%, transparent 50%);
}

/* ─── TOPBAR ────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

.topbar-brand {
  display: flex; align-items: center; gap: 0.75rem;
  font-weight: 700; font-size: 1.05rem; color: var(--brand);
  text-decoration: none; letter-spacing: -0.01em;
}

.topbar-brand img { height: 32px; width: auto; border-radius: 4px; }

.topbar-brand .brand-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

.topbar-right {
  display: flex; align-items: center; gap: 1rem;
}

.topbar-user {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.875rem; color: var(--text-secondary); font-weight: 500;
}

.topbar-user .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-light);
  border: 2px solid var(--brand-mid);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; color: var(--brand);
}

/* ─── NAVIGAZIONE ───────────────────────────────────────── */
nav {
  background: var(--brand);
  padding: 0 2rem;
  display: flex; align-items: center; gap: 0.25rem;
  height: 48px;
  box-shadow: 0 2px 8px rgba(1,98,178,0.2);
}

nav a {
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  letter-spacing: 0.01em;
}

nav a:hover { color: #fff; background: rgba(255,255,255,0.12); }
nav a.active { color: #fff; background: rgba(255,255,255,0.2); }

/* ─── CONTAINER ─────────────────────────────────────────── */
.container {
  position: relative; z-index: 1;
  width: min(92%, 1300px);
  margin: 2rem auto;
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 2rem 2.5rem;
  border: 1px solid var(--border);
}

/* Header della pagina dentro container */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding-bottom: 1.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap; gap: 1rem;
}

.page-header-left img {
  height: 48px; margin-bottom: 0.75rem;
}

.page-header h1 {
  font-size: 1.6rem; font-weight: 700;
  color: var(--brand); letter-spacing: -0.02em; line-height: 1.2;
}

.page-header h2 {
  font-size: 0.95rem; font-weight: 400;
  color: var(--text-muted); margin-top: 0.25rem;
}

/* ─── TITOLI ────────────────────────────────────────────── */
h1 { font-size: 1.6rem; font-weight: 700; color: var(--brand); letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; font-weight: 600; color: var(--brand); }
h3 { font-size: 1rem; font-weight: 600; color: var(--text); }
h4 { font-size: 0.9rem; font-weight: 500; color: var(--text-secondary); }
h6 { font-size: 1.3rem; font-weight: 700; color: var(--brand); text-align: center; }

/* ─── CARDS GRIGLIA ─────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-top: 1.75rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-align: center;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transform: scaleX(0); transform-origin: left;
  transition: transform 0.3s ease;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--brand-mid);
}

.card:hover::before { transform: scaleX(1); }

.card h2 {
  font-size: 1rem; font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.card p {
  font-size: 0.85rem; color: var(--text-muted);
  margin-bottom: 1.25rem; line-height: 1.5;
}

/* Emoji nelle card */
.card h2 { display: flex; align-items: center; justify-content: center; gap: 0.5rem; }

/* ─── PULSANTI ──────────────────────────────────────────── */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.55rem 1.2rem;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
  width: auto;
  margin-top: 0;
}

button:hover, .btn:hover {
  background: var(--brand-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(1,98,178,0.25);
}

button:active, .btn:active { transform: translateY(0); }

/* Varianti */
.btn-success, button.btn-success {
  background: var(--success);
}
.btn-success:hover { background: #15803d; box-shadow: 0 4px 12px rgba(22,163,74,0.3); }

.btn-danger, button.btn-danger {
  background: var(--danger);
}
.btn-danger:hover { background: #b91c1c; box-shadow: 0 4px 12px rgba(220,38,38,0.3); }

.btn-outline, button.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border-strong);
  color: var(--text-secondary);
}
.btn-outline:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-light);
  box-shadow: none;
  transform: none;
}

.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 1.75rem; font-size: 1rem; }
.btn-full { width: 100%; }

/* Pulsanti entrata/uscita timbratura */
.btn-entrata {
  background: linear-gradient(135deg, #16a34a, #15803d) !important;
  font-size: 0.95rem !important;
  padding: 0.7rem 1.5rem !important;
}
.btn-entrata:hover { background: linear-gradient(135deg, #15803d, #166534) !important; }

.btn-uscita {
  background: linear-gradient(135deg, #dc2626, #b91c1c) !important;
  font-size: 0.95rem !important;
  padding: 0.7rem 1.5rem !important;
}
.btn-uscita:hover { background: linear-gradient(135deg, #b91c1c, #991b1b) !important; }

/* ─── FORM ──────────────────────────────────────────────── */
form { margin-top: 1rem; }

.form-group { margin-bottom: 1rem; }

label, .form-label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

input:not([type="radio"]):not([type="checkbox"]), select, textarea {
  width: 100%;
  padding: 0.6rem 0.9rem;
  margin-top: 0;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  transition: var(--transition);
  box-sizing: border-box;
  appearance: auto;
}

input[type="radio"], input[type="checkbox"] {
  width: auto;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  appearance: auto;
}

input:not([type="radio"]):not([type="checkbox"]):focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(1,98,178,0.1);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }

textarea { min-height: 100px; resize: vertical; }

/* ─── TABELLE ───────────────────────────────────────────── */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-top: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 0.88rem;
  margin-top: 0;
}

thead tr { background: var(--brand); }

table th {
  padding: 0.85rem 1rem;
  text-align: left;
  color: rgba(255,255,255,0.9);
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: none;
}

table td {
  padding: 0.85rem 1rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:nth-child(even) { background: var(--surface2); }

tbody tr:hover { background: var(--brand-light) !important; }

/* Tabella scrollabile */
.tabella-scroll {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tabella-scroll table th {
  position: sticky; top: 0; z-index: 2;
}

/* ─── BADGE / PILLOLE ───────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.65rem;
  border-radius: 20px;
  font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.03em; text-transform: uppercase;
  font-family: 'DM Mono', monospace;
}

.badge-entrata, .badge-success {
  background: var(--success-light); color: var(--success);
  border: 1px solid #bbf7d0;
}
.badge-uscita, .badge-danger {
  background: var(--danger-light); color: var(--danger);
  border: 1px solid #fecaca;
}
.badge-warning {
  background: var(--warning-light); color: var(--warning);
  border: 1px solid #fde68a;
}
.badge-info {
  background: var(--brand-light); color: var(--brand);
  border: 1px solid var(--brand-mid);
}

/* ─── STAT CARDS ────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  position: relative; overflow: hidden;
}

.stat-card::after {
  content: ''; position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.stat-card:nth-child(1)::after { background: var(--brand); }
.stat-card:nth-child(2)::after { background: var(--success); }
.stat-card:nth-child(3)::after { background: var(--danger); }
.stat-card:nth-child(4)::after { background: var(--warning); }

.stat-label {
  font-size: 0.75rem; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.06em; margin-bottom: 0.4rem;
}

.stat-value {
  font-size: 1.9rem; font-weight: 700;
  line-height: 1; color: var(--text);
  font-family: 'DM Mono', monospace;
}

/* ─── TOOLBAR FILTRI ────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center;
  gap: 0.75rem; flex-wrap: wrap;
  padding: 1rem 0;
}

.toolbar-left { display: flex; align-items: center; gap: 0.75rem; flex: 1; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 0.75rem; }

.input-group {
  display: flex; align-items: center;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0 0.75rem; gap: 0.5rem;
  transition: var(--transition);
}

.input-group:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(1,98,178,0.1); }

.input-group svg { color: var(--text-muted); flex-shrink: 0; }

.input-group input, .input-group select {
  background: none; border: none; outline: none; box-shadow: none;
  color: var(--text); font-family: 'DM Mono', monospace;
  font-size: 0.85rem; padding: 0.6rem 0;
  min-width: 150px; width: auto;
}

.filter-btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.45rem 0.9rem;
  border-radius: 20px;
  font-size: 0.8rem; font-weight: 600;
  cursor: pointer; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text-muted);
  transition: var(--transition);
  font-family: 'DM Sans', sans-serif;
  margin-top: 0;
}

.filter-btn.active {
  background: var(--brand-light); border-color: var(--brand-mid);
  color: var(--brand);
}

.filter-btn.active-danger {
  background: var(--danger-light); border-color: #fca5a5; color: var(--danger);
}

.filter-btn:hover { transform: none; box-shadow: none; }

/* ─── PAGINAZIONE ───────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface2);
  font-size: 0.82rem; color: var(--text-muted);
  font-family: 'DM Mono', monospace;
}

.pagination span { color: var(--text); font-weight: 600; }

.pag-btns { display: flex; gap: 0.3rem; }

.page-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  font-family: 'DM Mono', monospace; font-size: 0.8rem;
  cursor: pointer; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text-muted);
  transition: var(--transition); padding: 0; margin: 0;
  width: auto; min-width: 32px; padding: 0 6px;
}

.page-btn:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-light); transform: none; box-shadow: none; }
.page-btn.active { background: var(--brand); border-color: var(--brand); color: white; }

/* ─── CARD ACCESSO ──────────────────────────────────────── */
.card-assenza {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  max-width: 520px; margin: 2rem auto;
}

.card-header-custom {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: white; padding: 2rem 1.5rem; text-align: center;
}

.card-header-custom h2 { color: white; font-size: 1.3rem; }
.card-header-custom p { color: rgba(255,255,255,0.75); font-size: 0.875rem; margin-top: 0.25rem; }

.user-info-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.user-icon { font-size: 2rem; }

/* ─── FEEDBACK GPS ──────────────────────────────────────── */
#feedback-gps {
  font-size: 0.8rem; color: var(--text-muted);
  margin-top: 0.5rem; font-family: 'DM Mono', monospace;
  min-height: 1.2em;
}

/* ─── ALERT / MESSAGI ───────────────────────────────────── */
.alert {
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 500;
  margin-bottom: 1rem;
  display: flex; align-items: flex-start; gap: 0.5rem;
}

.alert-success { background: var(--success-light); color: #15803d; border: 1px solid #bbf7d0; }
.alert-danger   { background: var(--danger-light);  color: #b91c1c; border: 1px solid #fecaca; }
.alert-info     { background: var(--brand-light);   color: var(--brand); border: 1px solid var(--brand-mid); }
.alert-warning  { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }

/* ─── DIVISORE ──────────────────────────────────────────── */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

/* ─── LINK ──────────────────────────────────────────────── */
a { color: var(--brand); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--brand-dark); text-decoration: underline; }

.btn-back {
  color: var(--text-muted); font-size: 0.85rem;
  display: inline-flex; align-items: center; gap: 0.3rem;
}
.btn-back:hover { color: var(--brand); text-decoration: none; }

/* ─── ANIMAZIONI ────────────────────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card { animation: fadeInUp 0.35s ease both; }
.card:nth-child(1) { animation-delay: 0.05s; }
.card:nth-child(2) { animation-delay: 0.10s; }
.card:nth-child(3) { animation-delay: 0.15s; }
.card:nth-child(4) { animation-delay: 0.20s; }
.card:nth-child(5) { animation-delay: 0.25s; }
.card:nth-child(6) { animation-delay: 0.30s; }
.card:nth-child(7) { animation-delay: 0.35s; }
.card:nth-child(8) { animation-delay: 0.40s; }

tbody tr { animation: fadeInUp 0.25s ease both; }

/* ─── RESPONSIVE ────────────────────────────────────────── */
@media (max-width: 1024px) {
  .container { width: 95%; padding: 1.5rem; }
}

@media (max-width: 768px) {
  .container { width: 98%; margin: 1rem auto; padding: 1.25rem; border-radius: var(--radius-lg); }
  .cards { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  nav { padding: 0 1rem; overflow-x: auto; }
}

@media (max-width: 540px) {
  .cards { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-right { width: 100%; }
  table { font-size: 0.8rem; }
  table th, table td { padding: 0.65rem 0.75rem; }
}

/* ─── UTILITY ───────────────────────────────────────────── */
.text-muted   { color: var(--text-muted); }
.text-center  { text-align: center; }
.text-mono    { font-family: 'DM Mono', monospace; font-size: 0.85em; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }


@media (max-width: 900px) {
  .container {
    width: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    padding: 1rem !important;
  }
  
  /* Forza scroll orizzontale su TUTTI i wrapper tabella */
  .table-wrap,
  div[style*="overflow:hidden"] {
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 750px !important;
    font-size: 0.78rem !important;
  }

  table th, table td {
    padding: 0.5rem 0.6rem !important;
    white-space: nowrap;
  }
}