:root {
  --black: #0c0f10;
  --ink: #1a1f21;
  --white: #ffffff;
  --paper: #f6f8f8;
  --line: #e3e8e8;
  --muted: #6b7677;
  --teal: #1cb5a3;
  --teal-dark: #158f81;
  --teal-soft: #e3f7f4;
  --warn: #c2410c;
  --danger: #b91c1c;
  --radius: 14px;
  --font: 'Manrope', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; max-width: 100%; overflow-x: hidden; }
body { font-family: var(--font); color: var(--ink); background: var(--paper); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
body.dark { background: var(--black); color: var(--white); }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1rem; margin-bottom: 1rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; font-size: 0.75rem; }
::selection { background: var(--teal); color: var(--white); }

/* Brand */
.brand { display: inline-flex; align-items: center; gap: 0.6rem; font-weight: 800; letter-spacing: -0.01em; }
.brand-mark { width: 14px; height: 14px; background: var(--teal); border-radius: 4px; display: inline-block; box-shadow: 0 0 0 4px rgba(28, 181, 163, 0.18); }
.brand-mark.lg { width: 28px; height: 28px; border-radius: 8px; margin-bottom: 2rem; }

/* Hero / welcome */
.hero { min-height: 100vh; display: grid; place-items: center; padding: 8vw; background: radial-gradient(1200px 600px at 100% 0%, rgba(28, 181, 163, 0.12), transparent 60%), var(--black); }
.hero-inner { max-width: 760px; animation: rise 0.7s ease both; }
.eyebrow { color: var(--teal); text-transform: uppercase; letter-spacing: 0.2em; font-size: 0.75rem; font-weight: 700; margin: 0 0 1rem; }
.hero h1 { font-size: clamp(2.4rem, 6vw, 4.5rem); line-height: 1.02; margin-bottom: 3rem; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 2rem; background: radial-gradient(900px 500px at 0% 100%, rgba(28, 181, 163, 0.14), transparent 60%), var(--black); }
.auth-card { width: 100%; max-width: 400px; background: var(--white); color: var(--ink); animation: rise 0.5s ease both; }
.auth-card h1 { font-size: 1.75rem; margin: 1.5rem 0 1.25rem; }
.auth-card .brand { color: var(--ink); }

/* Shell */
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; width: 100%; min-width: 0; }
.sidebar { background: var(--black); color: var(--white); padding: 2rem 1.25rem; display: flex; flex-direction: column; gap: 2.5rem; position: sticky; top: 0; height: 100vh; }
.nav { display: flex; flex-direction: column; gap: 0.25rem; }
.nav a { padding: 0.65rem 0.9rem; border-radius: 10px; color: rgba(255, 255, 255, 0.7); font-weight: 600; transition: background-color 0.2s, color 0.2s, transform 0.2s; position: relative; }
.nav a:hover { background: rgba(255, 255, 255, 0.06); color: var(--white); transform: translateX(2px); }
.nav a.active { background: rgba(28, 181, 163, 0.14); color: var(--white); }
.nav a.active::before { content: ''; position: absolute; left: -1.25rem; top: 20%; height: 60%; width: 3px; background: var(--teal); border-radius: 0 3px 3px 0; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 0.75rem; }
.user { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.tag { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--teal); font-weight: 700; }
.main { padding: 2.5rem 3rem 4rem; max-width: 1200px; width: 100%; min-width: 0; animation: fade 0.4s ease both; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 2rem; flex-wrap: wrap; }
.page-title { font-size: clamp(1.6rem, 3vw, 2.25rem); }
.page-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

/* Cards */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; }
.card + .card, .grid-2.top + .card, .panel + .toolbar, .stats + .card, .stats + .panel, .toolbar + .card, .panel + .card, .panel + .grid-2 { margin-top: 1.25rem; }
.panel { border-color: var(--teal); box-shadow: 0 12px 40px -24px rgba(28, 181, 163, 0.6); animation: rise 0.3s ease both; }
.hidden { display: none !important; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; display: flex; flex-direction: column; gap: 0.25rem; }
.stat span { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; }
.stat strong { font-size: 1.5rem; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.teal { color: var(--teal-dark); }
.warn { color: var(--warn); }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.strong { font-weight: 700; }
.link { color: var(--ink); border-bottom: 1px solid transparent; transition: border-color 0.2s, color 0.2s; }
.link:hover { color: var(--teal-dark); border-color: var(--teal-dark); }
.empty { color: var(--muted); text-align: center; padding: 1.5rem; margin: 0; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.field span { font-size: 0.78rem; font-weight: 700; color: var(--muted); }
input, select, textarea { font: inherit; padding: 0.65rem 0.85rem; border: 1px solid var(--line); border-radius: 10px; background: var(--white); color: var(--ink); transition: border-color 0.2s, box-shadow 0.2s; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(28, 181, 163, 0.18); }
input[type='checkbox'] { width: 1.1rem; height: 1.1rem; accent-color: var(--teal); padding: 0; }
.check { display: inline-flex; align-items: center; gap: 0.6rem; cursor: pointer; font-weight: 600; }
.auth-card .check { margin-bottom: 1.25rem; font-weight: 500; font-size: 0.9rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1.25rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 1rem; }
.grid-2.top { align-items: start; gap: 1.25rem; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.inline-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.inline-form input { width: auto; flex: 1 1 140px; }
.inline-form input[type='date'], .inline-form input[type='datetime-local'] { flex: 0 1 220px; }
.inline { display: inline; }
.toolbar { display: flex; align-items: center; gap: 1rem; }
.search { flex: 1; padding: 0.85rem 1.1rem; border-radius: 999px; font-size: 1rem; }
.danger-zone { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px dashed var(--line); }
.section-divider { display: flex; align-items: center; gap: 1rem; margin: 1.25rem 0 1rem; color: var(--muted); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; }
.section-divider::after { content: ''; height: 1px; flex: 1; background: var(--line); }

/* Buttons */
.btn { font: inherit; font-weight: 700; padding: 0.65rem 1.2rem; border-radius: 999px; border: 1px solid transparent; cursor: pointer; display: inline-flex; align-items: center; gap: 0.4rem; transition: background-color 0.2s, color 0.2s, transform 0.15s, box-shadow 0.2s; white-space: nowrap; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-teal { background: var(--teal-dark); color: var(--white); }
.btn-teal:hover { background: #0b625b; box-shadow: 0 8px 24px -10px var(--teal); }
.btn-outline { background: transparent; color: var(--ink); border-color: var(--ink); }
.btn-outline:hover { background: var(--ink); color: var(--white); }
.btn-ghost { background: transparent; color: inherit; border-color: var(--line); }
.btn-ghost:hover { background: rgba(0, 0, 0, 0.05); }
.dark .btn-ghost, .sidebar .btn-ghost { border-color: rgba(255, 255, 255, 0.18); color: rgba(255, 255, 255, 0.85); }
.sidebar .btn-ghost:hover { background: rgba(255, 255, 255, 0.08); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: var(--white); }
.btn-lg { padding: 1rem 2.2rem; font-size: 1.05rem; }
.btn-sm { padding: 0.45rem 0.9rem; font-size: 0.85rem; }
.btn-xs { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-block { width: 100%; justify-content: center; }

/* Tables & lists */
.table-wrap { padding: 0; width: 100%; max-width: 100%; min-width: 0; overflow-x: auto; overscroll-behavior-inline: contain; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); padding: 0.9rem 1.25rem; border-bottom: 1px solid var(--line); }
.table td { padding: 0.9rem 1.25rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color 0.15s; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr:hover { background: var(--paper); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.actions { text-align: right; }
.actions form { display: inline; }
.pill { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.pill-teal { background: var(--teal-soft); color: var(--teal-dark); }
.pill-dark { background: var(--ink); color: var(--white); }
/* --- PILLS (Etichette tabella) --- */
.pill { 
    display: inline-block; 
    padding: 0.15rem 0.6rem; 
    border-radius: 999px; 
    font-size: 0.72rem; 
    font-weight: 700; 
    text-transform: uppercase; 
    letter-spacing: 0.06em; 
}
/* Entrata Contanti (Verde Acqua - originale) */
.pill-teal { background: var(--teal-soft, #e6f6f4); color: var(--teal-dark, #0d7a6e); }

/* Entrata POS (Verde Smeraldo) */
.pill-success { background: #d1fae5; color: #065f46; }

/* Uscita (Rosso) */
.pill-danger { background: #fee2e2; color: #991b1b; }

/* Vecchio stile scuro (nel caso serva altrove) */
.pill-dark { background: var(--ink); color: var(--white); }


/* --- BOX STATISTICHE (Conti) --- */
.stats .stat {
    text-align: center; /* Centra il testo in tutti i box dei totali */
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 0.75rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.lab-row { display: grid; grid-template-columns: 92px minmax(180px, 1fr) minmax(180px, auto) auto; gap: 1.25rem; align-items: center; }
.lab-row.done .lab-desc { text-decoration: line-through; color: var(--muted); }
.lab-row.overdue { box-shadow: inset 3px 0 0 var(--warn); }
.lab-date { display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.lab-date strong { font-size: 1.1rem; }
.lab-date span { color: var(--muted); font-size: 0.72rem; }
.lab-info { display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem; }
.lab-delay { color: var(--warn); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.lab-status-button { min-width: 96px; padding: 0.55rem 0.9rem; border: 1px solid transparent; border-radius: 999px; font: inherit; font-size: 0.78rem; font-weight: 800; cursor: pointer; transition: background-color 0.2s, color 0.2s, transform 0.15s; }
.lab-status-button:hover { transform: translateY(-1px); }
.lab-status-button:disabled { cursor: wait; opacity: 0.65; }
.lab-status-button.is-pending { border-color: #f3c7af; background: #fff7ed; color: var(--warn); }
.lab-status-button.is-arrived { border-color: rgba(28, 181, 163, 0.35); background: var(--teal-soft); color: var(--teal-dark); }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 0.5rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.dl dd { margin: 0; word-break: break-word; }
.section-head { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.section-head h2 { margin: 0; }
.count-badge { min-width: 1.6rem; height: 1.6rem; padding: 0 0.45rem; border-radius: 999px; display: inline-grid; place-items: center; background: var(--teal-soft); color: var(--teal-dark); font-size: 0.75rem; font-weight: 800; }
.intervention-list { display: grid; gap: 0.75rem; }
.intervention { border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }
.intervention-main { display: flex; justify-content: space-between; gap: 1.5rem; align-items: flex-start; }
.intervention-main p { color: var(--muted); margin: 0.2rem 0 0; font-size: 0.85rem; }
.intervention-money { text-align: right; display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.intervention-money span { color: var(--muted); font-size: 0.78rem; }
.progress { height: 5px; border-radius: 999px; background: var(--line); margin: 0.9rem 0; overflow: hidden; }
.progress span { display: block; height: 100%; border-radius: inherit; background: var(--teal); }
.intervention details summary, .audit summary { color: var(--teal-dark); font-size: 0.8rem; font-weight: 700; cursor: pointer; }
.compact-form { display: grid; grid-template-columns: 1.2fr 0.6fr 1.6fr auto; gap: 0.5rem; margin: 0.8rem 0; align-items: center; }
.audit { margin-top: 0.35rem; }
.audit-entry { display: flex; flex-direction: column; margin-top: 0.35rem; padding-left: 0.65rem; border-left: 2px solid var(--teal-soft); font-size: 0.75rem; }
.staff-edit { display: inline-block; margin-right: 0.35rem; text-align: left; }
.staff-edit summary { color: var(--teal-dark); cursor: pointer; font-size: 0.8rem; font-weight: 700; list-style: none; }
.staff-edit summary::-webkit-details-marker { display: none; }
.staff-edit-form { display: grid !important; gap: 0.5rem; min-width: 300px; padding: 0.85rem; margin: 0.6rem 0; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.staff-edit-form .field { margin: 0; }

/* Flash */
.flash { background: var(--teal-soft); color: var(--teal-dark); border: 1px solid rgba(28, 181, 163, 0.35); padding: 0.85rem 1.1rem; border-radius: 10px; margin-bottom: 1.25rem; font-weight: 600; animation: rise 0.3s ease both; }
.flash-error { background: #fff1f0; color: var(--danger); border-color: rgba(185, 28, 28, 0.3); }
.flash ul { margin: 0; padding-left: 1.1rem; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); align-content: start; }
  .sidebar { position: static; height: auto; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: 'brand footer' 'nav nav'; align-items: center; gap: 0.75rem 1rem; padding: 0.85rem 1rem; }
  .sidebar .brand { grid-area: brand; justify-content: flex-start; font-size: 0.9rem; }
  .nav { grid-area: nav; width: 100%; flex-direction: row; gap: 0.25rem; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { flex: 1 0 auto; min-width: 0; padding: 0.55rem 0.65rem; text-align: center; font-size: 0.8rem; white-space: nowrap; }
  .nav a.active::before { display: none; }
  .sidebar-footer { grid-area: footer; width: auto; margin-top: 0; flex-direction: row; align-items: center; gap: 0.5rem; }
  .sidebar-footer .user { font-size: 0.72rem; line-height: 1.2; text-align: right; }
  .sidebar-footer .tag { display: none; }
  .sidebar-footer .btn { min-height: 38px; padding: 0.45rem 0.8rem; }
  .main { padding: 1.25rem 1rem 3rem; }
  .page-head { margin-bottom: 1.25rem; }
  .page-head, .toolbar, .card { min-width: 0; max-width: 100%; }
  .grid-2, .grid-3, .grid-4, .compact-form { grid-template-columns: 1fr; }
  .table { min-width: 680px; }
  .table th, .table td { padding: 0.75rem 0.9rem; }
  .lab-row { grid-template-columns: 72px minmax(0, 1fr) auto; gap: 0.75rem; }
  .lab-row .lab-arrived { grid-column: 2 / -1; grid-row: 2; }
  .intervention-main { flex-direction: column; gap: 0.75rem; }
  .intervention-money { text-align: left; }
  .staff-edit-form { min-width: min(280px, calc(100vw - 4rem)); }
  .dl { grid-template-columns: 1fr; gap: 0 }
  .dl dd { margin-bottom: 0.6rem; }
}

@media (max-width: 480px) {
  body { font-size: 14px; }
  .sidebar { padding: 0.75rem 0.85rem; }
  .sidebar-footer .user { display: none; }
  .nav a { padding-inline: 0.55rem; font-size: 0.76rem; }
  .main { padding: 1.1rem 0.85rem 2.5rem; }
  .page-title { font-size: 1.5rem; }
  .page-head { align-items: stretch; }
  .page-actions, .page-actions > *, .page-actions form { width: 100%; }
  .page-actions .btn { justify-content: center; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; }
  .stat { padding: 0.85rem; }
  .stat strong { font-size: 1.2rem; }
  input, select, textarea, .btn { min-height: 44px; }
  .inline-form, .inline-form input, .inline-form input[type='date'], .inline-form input[type='datetime-local'], .inline-form select, .inline-form .btn { width: 100%; flex-basis: auto; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .form-actions .btn { justify-content: center; }
  .card { padding: 1rem; border-radius: 12px; }
  .table-wrap.card { padding: 0; }
  .empty { padding: 1.1rem; }
  .lab-row { grid-template-columns: 64px minmax(0, 1fr); }
  .lab-status-button { grid-column: 1 / -1; width: 100%; }
  .lab-row .lab-arrived { grid-column: 1 / -1; }
}
