:root {
  --bg: #f4f7fb;
  --ink: #152038;
  --muted: #64748b;
  --surface: #ffffff;
  --line: #d9e2ef;
  --side: #0f172a;
  --side-muted: #94a3b8;
  --brand: #0ea5e9;
  --good: #16a34a;
  --warn: #f59e0b;
  --bad: #ef4444;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Inter", "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 85% 0%, #deefff 0%, var(--bg) 40%);
}

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

.sidebar {
  background: linear-gradient(180deg, #0b1220, #0f172a 45%, #111b33);
  color: #fff;
  padding: 22px 16px;
  border-right: 1px solid #1f2d4a;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 18px;
}

.menu {
  display: grid;
  gap: 6px;
}

.menu a {
  color: var(--side-muted);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 600;
}

.menu a.active,
.menu a:hover {
  background: rgba(14, 165, 233, 0.15);
  color: #e0f2fe;
}

.reset-form {
  margin-top: 20px;
}

.content {
  padding: 22px;
}

.site-footer {
  margin-top: 22px;
  padding: 16px 0 4px;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.top {
  margin-bottom: 14px;
}

.top-tools {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
  padding-right: 4px;
}

.notif-bell-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  color: #0f172a;
  text-decoration: none;
}

.notif-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.notif-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  color: #0f172a;
  font-weight: 600;
}

.back-link .back-arrow {
  font-size: 18px;
  line-height: 1;
  font-weight: 700;
}

.page-title {
  margin: 0;
  font-size: 1.7rem;
}

.page-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 12px;
}

.kpi {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.two {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 8px 26px rgba(14, 30, 63, 0.06);
}

.card h2,
.card h3 {
  margin: 0 0 10px;
}

.kpi .card p {
  margin: 0;
  color: var(--muted);
}

.kpi .card h2 {
  margin: 4px 0 0;
  font-size: 1.8rem;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 9px 8px;
  font-size: 0.93rem;
}

th {
  font-size: 0.75rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

a {
  color: #0c4dc5;
  text-decoration: none;
}

.status,
.prio {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}

.status.nuovo { background: #e0f2fe; color: #0b79ad; }
.status.da_lavorare { background: #ffedd5; color: #9a3412; }
.status.assegnato { background: #ede9fe; color: #5b21b6; }
.status.in_lavorazione { background: #fff4d6; color: #9a6700; }
.status.in_attesa { background: #fef3c7; color: #92400e; }
.status.in_ritardo { background: #fee2e2; color: #991b1b; }
.status.chiuso { background: #dcfce7; color: #166534; }

.prio.bassa { background: #ecfeff; color: #155e75; }
.prio.media { background: #eef2ff; color: #3730a3; }
.prio.alta { background: #ffedd5; color: #9a3412; }
.prio.urgente { background: #fee2e2; color: #991b1b; }

.form-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.form-grid .full {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.86rem;
  color: #334155;
  font-weight: 600;
}

input,
select,
textarea,
button {
  width: 100%;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
}

.btn {
  width: auto;
  border: none;
  color: #fff;
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  padding: 9px 14px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
}

.btn.ghost {
  background: #e2e8f0;
  color: #0f172a;
}

.btn.danger {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
  margin-left: 8px;
}

.preview-thumb-btn {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.notes article {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px;
  background: #f8fbff;
}

small {
  color: var(--muted);
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .menu {
    grid-template-columns: repeat(3, minmax(90px, 1fr));
  }
}

.user-box {
  margin-top: 16px;
  padding: 12px;
  border: 1px solid #243554;
  border-radius: 12px;
  background: rgba(148, 163, 184, 0.08);
}

.user-box p {
  margin: 0;
  color: #e2e8f0;
  font-weight: 700;
}

.user-box small {
  display: block;
  color: #94a3b8;
}

.user-admin-links {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(148, 163, 184, 0.25);
  display: grid;
  gap: 6px;
}

.user-admin-links a {
  color: #94a3b8;
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
  font-weight: 600;
}

.user-admin-links a.active,
.user-admin-links a:hover {
  background: rgba(14, 165, 233, 0.15);
  color: #e0f2fe;
}

.logout-link {
  margin-top: 10px;
  display: inline-block;
}

.login-page {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 20%, #dbeafe, #eff6ff 45%, #f8fafc 100%);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px 0;
}

.login-wrap {
  width: min(460px, 92%);
}

.login-card {
  background: #ffffff;
  border: 1px solid #d9e2ef;
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 15px 35px rgba(15, 30, 63, 0.12);
}

.login-card h1 {
  margin: 0 0 8px;
}

.login-card p {
  margin: 0 0 12px;
  color: #64748b;
}

.login-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
  font-weight: 700;
}

.login-help {
  margin-top: 14px;
}

.login-help p {
  margin: 0 0 4px;
  font-size: 0.9rem;
}

.login-footer {
  padding-bottom: 0;
}

.toolbar {
  padding: 12px;
}

.users-maintenance-head {
  display: grid;
  gap: 12px;
  grid-template-columns: 1.5fr 1fr;
  align-items: start;
}

.users-maintenance-head h2 {
  margin: 0 0 6px;
}

.users-maintenance-head p {
  margin: 0;
  color: var(--muted);
}

.users-filter-form {
  display: grid;
  gap: 8px;
}

.users-maintenance-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 320px 1fr;
  margin-top: 12px;
}

.users-card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.users-card-title h3 {
  margin: 0;
}

.badge {
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #bae6fd;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 700;
}

.users-sectors-list {
  display: grid;
  gap: 8px;
}

.sector-chip {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fbff;
  padding: 10px;
  cursor: pointer;
}

.sector-chip b {
  display: block;
  margin-bottom: 4px;
}

.sector-chip:hover {
  border-color: #8cc9ff;
  background: #eef7ff;
}

.readonly-note {
  margin: 10px 0 0;
  color: #0f172a;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 10px;
  padding: 10px;
  font-size: 0.85rem;
}

.search-form {
  display: grid;
  grid-template-columns: 1fr 170px auto;
  gap: 8px;
}

.dashboard-search-form {
  grid-template-columns: minmax(260px, 1fr) 170px 220px auto;
}

.priority-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(80px, 1fr));
  gap: 8px;
  background: #eef2f7;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  margin-top: 6px;
}

.chip-priority input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.chip-priority {
  position: relative;
}

.chip-priority span {
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 10px;
  height: 38px;
  background: transparent;
  color: #475569;
  font-weight: 700;
  cursor: pointer;
}

.chip-priority input:checked + span {
  background: #ffffff;
  color: #137fec;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.09);
}

.close-box {
  border: 1px solid #b7ddff;
  background: linear-gradient(180deg, #f0f8ff 0%, #f9fcff 100%);
}

tr.row-overdue td {
  background: #fff1f2;
}

.overdue-pill {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #b91c1c;
  background: #fee2e2;
  border: 1px solid #fecaca;
}

#client-search-hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: -2px;
}

.client-preview {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  max-height: 240px;
  overflow-y: auto;
}

.client-preview[hidden] {
  display: none;
}

.client-preview-list {
  display: grid;
}

.client-preview-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid #e5e7eb;
  border-radius: 0;
  padding: 9px 10px;
  cursor: pointer;
  color: #1e293b;
}

.client-preview-item:hover {
  background: #f8fafc;
}

.client-preview-item:last-child {
  border-bottom: none;
}

.client-preview-empty,
.client-preview-more {
  padding: 9px 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.intervention-focus-title,
.intervention-focus-description {
  border: 1px solid #dbeafe;
  border-radius: 12px;
  padding: 12px 14px;
  margin: 10px 0;
  background: linear-gradient(180deg, #eff6ff 0%, #f8fbff 100%);
}

.intervention-focus-title small,
.intervention-focus-description small {
  display: block;
  color: #475569;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}

.intervention-focus-title h1 {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.25;
  color: #0f172a;
}

.intervention-focus-description p {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.5;
  color: #0f172a;
  font-weight: 700;
  white-space: pre-wrap;
}

.client-anagrafica-grid {
  display: grid;
  gap: 8px 14px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.client-anagrafica-grid p {
  margin: 0;
}

.trend-chart {
  margin-bottom: 10px;
  display: grid;
  gap: 7px;
}

.trend-row {
  display: grid;
  grid-template-columns: minmax(88px, 130px) 1fr 40px;
  gap: 8px;
  align-items: center;
}

.trend-label {
  font-size: 0.78rem;
  color: #334155;
}

.trend-bar-wrap {
  height: 12px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.trend-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #38bdf8, #2563eb);
}

.trend-value {
  text-align: right;
  font-weight: 700;
  font-size: 0.78rem;
  color: #0f172a;
}

.trend-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 760px) {
  .users-maintenance-head {
    grid-template-columns: 1fr;
  }

  .users-maintenance-grid {
    grid-template-columns: 1fr;
  }

  .search-form {
    grid-template-columns: 1fr;
  }

  .dashboard-search-form {
    grid-template-columns: 1fr;
  }

  .priority-grid {
    grid-template-columns: repeat(2, minmax(90px, 1fr));
  }

  .trend-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .trend-value {
    text-align: left;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 12mm 12mm 14mm 12mm;
  }

  body {
    background: #ffffff !important;
  }

  .sidebar,
  .site-footer,
  .toolbar,
  .no-print,
  .top {
    display: none !important;
  }

  .layout {
    display: block;
  }

  .content {
    padding: 0;
    padding-bottom: 24mm;
  }

  .card {
    border: none;
    box-shadow: none;
    padding: 0;
  }

  .print-focus {
    display: block !important;
  }

  .print-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 4mm 12mm;
    border-top: 1px solid #cbd5e1;
    background: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 10px;
    color: #334155;
  }

  .print-page-num::after {
    content: counter(page);
  }

  .print-page-total::after {
    content: counter(pages);
  }

  a {
    color: #000;
    text-decoration: none;
  }
}

.print-footer {
  display: none;
}
