/* =========================================================
   app.css — Design token e stili base di rHR
   I token (variabili CSS) sono il punto unico di verità per colori,
   tipografia e spaziature: i moduli li riusano senza ridefinirli.
   ========================================================= */
:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #1f2733;
  --ink-soft: #5b6675;

  --primary: #2563eb;
  --ok: #16a34a;
  --ko: #dc2626;

  --radius-lg: 14px;
  --shadow-card: 0 8px 30px rgba(20, 30, 50, 0.08);
}

* { box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  margin: 0;
}

/* ---- Layout centrato (health, login) ---- */
body.health,
body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 32px 36px;
  max-width: 440px;
  width: 100%;
}

.card h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: -0.5px; }
.subtitle { margin: 0 0 24px; color: var(--ink-soft); }

.checks { list-style: none; margin: 0 0 20px; padding: 0; }
.checks li { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.checks .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.checks .ok .dot { background: var(--ok); }
.checks .ko .dot { background: var(--ko); }
.checks .ko { color: var(--ko); font-weight: 600; }

.env { margin: 0 0 4px; color: var(--ink-soft); }
.hint { margin: 0; font-size: 13px; color: var(--ink-soft); }

/* ---- Form ---- */
.field { display: block; margin: 0 0 16px; }
.field span { display: block; margin: 0 0 6px; font-size: 14px; color: var(--ink-soft); }
.field input {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid #d5dbe4;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn {
  display: inline-block;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.btn-primary { width: 100%; background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(0.95); }
.btn-ghost { background: transparent; color: var(--ink-soft); padding: 6px 10px; }
.btn-ghost:hover { color: var(--ink); }

.alert { padding: 10px 14px; border-radius: 8px; margin: 0 0 18px; font-size: 14px; }
.alert-ko { background: #fdecea; color: var(--ko); }
.alert-ok { background: #eaf7ef; color: var(--ok); }

/* ---- Account (badge di stato + azioni) ---- */
.badge-ok    { background: #eaf7ef; color: var(--ok); }
.badge-ko    { background: #fdecea; color: var(--ko); }
.badge-muted { background: #eef1f5; color: var(--ink-soft); }
.badge-warn  { background: #fef3e2; color: #b45309; }
.account-actions { display: grid; gap: 16px; margin-top: 6px; }
.account-action { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.account-action .field { flex: 1; min-width: 200px; margin: 0; }
.account-action .field select,
.account-action .field input {
  width: 100%; padding: 10px 12px; font-size: 15px;
  border: 1px solid #d5dbe4; border-radius: 8px; background: #fff; color: var(--ink);
}
.account-action .btn { width: auto; }
.account-note { color: var(--ink-soft); font-size: 13px; margin: 6px 0 0; }

/* ---- Cronologia (timeline audit) ---- */
.timeline { list-style: none; margin: 6px 0 0; padding: 0; }
.timeline > li { padding: 12px 0; border-bottom: 1px solid #f2f4f7; }
.timeline > li:last-child { border-bottom: 0; }
.tl-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.tl-action { font-weight: 600; }
.tl-when { color: var(--ink-soft); font-size: 13px; white-space: nowrap; }
.tl-meta { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.tl-changes { list-style: none; margin: 6px 0 0; padding: 0; font-size: 13px; }
.tl-changes li { padding: 2px 0; color: var(--ink); }

/* ---- Presenze ---- */
.btn-danger { background: var(--ko); color: #fff; }
.btn-danger:hover { filter: brightness(0.95); }
.punch-card { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.punch-status { display: flex; flex-direction: column; gap: 4px; }
.punch-status .badge { align-self: flex-start; font-size: 14px; }
.punch-since { color: var(--ink-soft); font-size: 14px; }
.punch-form { margin: 0; }
.btn-punch { width: auto; font-size: 16px; padding: 14px 22px; }
.punch-list { list-style: none; margin: 6px 0 0; padding: 0; }
.punch-list li { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid #f2f4f7; }
.punch-list li:last-child { border-bottom: 0; }
.punch-time { font-weight: 600; font-variant-numeric: tabular-nums; }
.inline-delete { display: flex; gap: 8px; margin: 0; }
.inline-delete input { padding: 6px 10px; font-size: 13px; border: 1px solid #d5dbe4; border-radius: 6px; }
.inline-delete .btn { width: auto; padding: 6px 12px; font-size: 13px; }

/* ---- Ferie: azioni di decisione ---- */
.decide-actions { display: flex; flex-direction: column; gap: 8px; }
.decide-actions form { display: flex; gap: 6px; margin: 0; }
.decide-actions input { padding: 6px 10px; font-size: 13px; border: 1px solid #d5dbe4; border-radius: 6px; min-width: 160px; }
.decide-actions .btn { width: auto; padding: 6px 12px; font-size: 13px; }

/* ---- Ferie: calendario assenze ---- */
.cal-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; }
.cal-month { font-weight: 700; font-size: 16px; text-transform: capitalize; }
.cal-legend { display: flex; gap: 18px; margin: 0 0 16px; font-size: 13px; color: var(--ink-soft); }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cal-swatch { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.cal-scroll { overflow-x: auto; }
.cal-table { border-collapse: collapse; font-size: 12px; }
.cal-table th, .cal-table td { border: 1px solid #eef1f5; text-align: center; }
.cal-name { text-align: left !important; padding: 6px 10px; white-space: nowrap; position: sticky; left: 0; background: var(--surface); z-index: 1; font-weight: 600; }
.cal-day { width: 26px; padding: 4px 0; color: var(--ink-soft); }
.cal-dnum { display: block; font-weight: 600; color: var(--ink); }
.cal-dwd { display: block; font-size: 10px; }
.cal-cell { width: 26px; height: 30px; font-weight: 700; color: #fff; }
.cal-weekend { background: #f4f6f9; }
.cal-ferie { background: var(--primary); }
.cal-permesso { background: #b45309; }
.cal-ferie.cal-swatch, .cal-permesso.cal-swatch { color: transparent; }
.cal-pending { background: repeating-linear-gradient(45deg, #cbd5e1, #cbd5e1 4px, #e2e8f0 4px, #e2e8f0 8px); color: var(--ink-soft); }

/* ---- Dashboard widget ---- */
.dash-date { color: var(--ink-soft); font-size: 14px; margin: 0 0 14px; }
.dash-stats { display: flex; flex-wrap: wrap; gap: 14px; margin: 4px 0 12px; }
.dash-stats .stat { flex: 1; min-width: 120px; background: #f8fafc; border: 1px solid #eef1f5; border-radius: 10px; padding: 12px 14px; }
.stat-n { display: block; font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }
.stat-n.stat-warn { color: #b45309; }
.stat-l { display: block; font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.widget-sub { font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
.widget-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 0; }
.widget-tag { white-space: nowrap; }
.chip { display: inline-block; font-size: 13px; padding: 3px 10px; border-radius: 999px; background: #eef2ff; color: var(--primary); margin: 2px 0; }
.chip-warn { background: #fef3e2; color: #b45309; }

/* ---- Layout con sidebar ---- */
.layout { display: flex; align-items: stretch; min-height: 100vh; }
.sidebar {
  flex: 0 0 232px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px 14px;
  background: var(--surface);
  box-shadow: 1px 0 0 rgba(20, 30, 50, 0.06);
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand { font-weight: 700; font-size: 20px; padding: 6px 10px 12px; text-decoration: none; color: var(--ink); }
.sidenav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-group-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink); margin: 22px 10px 8px; font-weight: 800;
  padding-bottom: 6px; border-bottom: 1px solid #e7ebf1;
}
.nav-group-title:first-child { margin-top: 4px; }
.nav-item {
  display: block; padding: 9px 12px; border-radius: 8px;
  color: var(--ink-soft); text-decoration: none; font-size: 14px; font-weight: 600;
}
.nav-item:hover { background: #f1f5f9; color: var(--ink); }
.nav-item.active { background: var(--primary); color: #fff; }
.sidebar-foot {
  border-top: 1px solid #eef1f5; margin-top: 10px; padding-top: 12px;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
}
.side-user { display: flex; flex-direction: column; gap: 4px; }
.user-name { color: var(--ink); font-size: 14px; font-weight: 600; }
.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary);
}
form.inline { margin: 0; }
.content { flex: 1; min-width: 0; max-width: 1000px; margin: 32px auto; padding: 0 28px; }
.card-wide { max-width: none; }

/* Sidebar responsive: su schermi stretti diventa una barra orizzontale sopra. */
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar {
    flex: none; width: auto; height: auto; position: static;
    flex-direction: row; align-items: center; flex-wrap: wrap; gap: 6px;
    box-shadow: 0 1px 0 rgba(20, 30, 50, 0.06);
  }
  .sidebar .brand { padding: 6px 10px; }
  .sidenav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .nav-group-title { display: none; }
  .sidebar-foot { border-top: 0; margin: 0 0 0 auto; padding: 0; flex-direction: row; align-items: center; gap: 10px; }
  .side-user { flex-direction: row; align-items: center; gap: 8px; }
  .content { margin: 20px auto; padding: 0 18px; }
}
/* Spaziatura verticale tra card impilate nell'area app (non tocca le
   pagine centrate login/health, che usano body.centered). */
.content .card { margin-bottom: 24px; }
.content .card:last-child { margin-bottom: 0; }

/* ---- Elenco / tabelle ---- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 18px; }
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -0.4px; }

.toolbar { display: flex; gap: 10px; margin: 0 0 18px; }
.toolbar input[type="search"] {
  flex: 1;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid #d5dbe4;
  border-radius: 8px;
}
.toolbar input[type="search"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.toolbar .btn-primary { width: auto; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #eef1f5; }
.table th { color: var(--ink-soft); font-weight: 600; font-size: 13px; }
.table tbody tr:hover { background: #f8fafc; }
.table .empty { text-align: center; color: var(--ink-soft); padding: 22px; }
.table a { color: var(--primary); text-decoration: none; font-weight: 600; }
.table a:hover { text-decoration: underline; }

.page-head-actions { display: flex; gap: 10px; }

/* ---- Form multi-sezione ---- */
.form-section { border: 0; border-top: 1px solid #eef1f5; margin: 0; padding: 18px 0 4px; }
.form-section:first-of-type { border-top: 0; padding-top: 0; }
.form-section legend { font-weight: 600; color: var(--ink-soft); padding: 0; margin: 0 0 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.form-grid .field select,
.form-grid .field input {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid #d5dbe4;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
.form-grid .field input:disabled { background: #f4f6f9; color: var(--ink-soft); }
.field-error { display: block; margin-top: 4px; font-size: 13px; color: var(--ko); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---- Dettaglio ---- */
.detail-title { font-size: 15px; color: var(--ink-soft); margin: 22px 0 10px; }
.detail-title:first-of-type { margin-top: 4px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; margin: 0; }
.detail-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid #f2f4f7; }
.detail-row dt { color: var(--ink-soft); margin: 0; }
.detail-row dd { margin: 0; font-weight: 500; text-align: right; }

@media (max-width: 640px) {
  .form-grid, .detail-grid { grid-template-columns: 1fr; }
}
