/* =====================================================================
   Gestionale Giorgio Fortis - stile gestionale minimalista
   ===================================================================== */

:root {
    --bg:        #eaeef4;
    --surface:   #ffffff;
    --border:    #d3dbe5;
    --border-2:  #e4e9f0;
    --text:      #1f2733;
    --text-soft: #5b6573;
    --text-mute: #98a1ad;

    --primary:   #2563eb;
    --primary-d: #1d4ed8;
    --primary-l: #eff4ff;

    --green:     #16a34a;
    --green-l:   #e9f7ee;
    --amber:     #d97706;
    --amber-l:   #fdf3e3;
    --red:       #dc2626;
    --red-l:     #fdecec;
    --slate-l:   #eef1f5;

    --radius:    12px;
    --radius-sm: 8px;
    --shadow:    0 1px 2px rgba(16,24,40,.05), 0 1px 1px rgba(16,24,40,.04);
    --shadow-md: 0 4px 14px rgba(16,24,40,.09);
    --sidebar-w: 248px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: #0f172a;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 18px 20px;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand .logo-mark { display: block; flex-shrink: 0; }
.brand-text { font-size: 17px; font-weight: 800; letter-spacing: 3px; }

.nav { padding: 12px 12px; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: #cbd5e1;
    font-weight: 500;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link svg { width: 19px; height: 19px; fill: currentColor; flex-shrink: 0; }

.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,.07); }
.user-box { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: grid; place-items: center; font-weight: 600;
}
.user-meta { display: flex; flex-direction: column; overflow: hidden; }
.user-name { color: #fff; font-weight: 600; font-size: 13.5px; }
.user-email { color: #94a3b8; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-logout {
    width: 100%;
    background: rgba(255,255,255,.06);
    color: #e2e8f0;
    border: 1px solid rgba(255,255,255,.1);
    padding: 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font: inherit;
    font-size: 13px;
}
.btn-logout:hover { background: rgba(255,255,255,.12); }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 14px;
    padding: 14px 26px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.page-title { font-size: 18px; font-weight: 800; letter-spacing: -.02em; margin: 0; flex: 1; }
.topbar-right { display: flex; gap: 8px; }
.hamburger { display: none; background: none; border: none; cursor: pointer; padding: 4px; }
.hamburger svg { width: 24px; height: 24px; fill: var(--text); }

.content { padding: 26px; max-width: 1280px; width: 100%; }

/* ---------- Alert ---------- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 18px; font-weight: 500; }
.alert-success { background: var(--green-l); color: #146c43; border: 1px solid #bfe6cd; }
.alert-error   { background: var(--red-l);   color: #b42318; border: 1px solid #f6c7c4; }

/* ---------- KPI / stat cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 26px; }
.stat {
    display: flex; align-items: center; gap: 15px;
    background: linear-gradient(180deg, #ffffff 0%, #eef2f8 100%);
    border: 1px solid #d6dde8;
    border-radius: 14px;
    padding: 18px;
    color: var(--text);
    text-decoration: none;
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,.9),
        0 1px 2px rgba(16,24,40,.06),
        0 6px 16px rgba(16,24,40,.09);
    transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
a.stat:hover {
    transform: translateY(-3px);
    border-color: var(--primary);
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,.9),
        0 2px 4px rgba(16,24,40,.08),
        0 14px 26px rgba(16,24,40,.16);
    text-decoration: none;
}
a.stat:active { transform: translateY(-1px); }
.stat-icon {
    width: 50px; height: 50px; border-radius: 13px;
    display: grid; place-items: center; flex-shrink: 0;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.7), 0 3px 6px rgba(16,24,40,.14);
}
.stat-icon svg { width: 25px; height: 25px; fill: currentColor; }
.stat-meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.stat-label { color: var(--text-soft); font-size: 13px; font-weight: 600; }
.stat-value { color: var(--text); font-size: 30px; font-weight: 800; line-height: 1.05; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-blue  .stat-icon { background: var(--primary-l); color: var(--primary-d); }
.stat-slate .stat-icon { background: var(--slate-l);   color: var(--text-soft); }
.stat-amber .stat-icon { background: var(--amber-l);   color: var(--amber); }
.stat-amber .stat-value { color: var(--amber); }
.stat-red   .stat-icon { background: var(--red-l);     color: var(--red); }
.stat-red   .stat-value { color: var(--red); }
.stat-green .stat-icon { background: var(--green-l);   color: var(--green); }

/* ---------- Cards / pannelli ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgba(16,24,40,.05), 0 5px 14px rgba(16,24,40,.07);
    margin-bottom: 22px;
    overflow: hidden;
}
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 14px 20px;
    background: #f3f5f9;
    border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 15px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.card-body { padding: 20px; }
.card-body.flush { padding: 0; }

/* ---------- Tabelle ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 13px 16px; text-align: left; vertical-align: middle; }
table.data thead th {
    font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-soft); font-weight: 700;
    border-bottom: 2px solid var(--border);
    background: #eef2f7;
    white-space: nowrap;
}
table.data tbody td { border-bottom: 1px solid var(--border-2); }
table.data tbody tr:nth-child(even) td { background: #f9fafc; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover td { background: var(--primary-l); }
table.data th.num, table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-strong { font-weight: 600; color: var(--text); }
.cell-sub { color: var(--text-mute); font-size: 12.5px; }

/* ---------- Badge ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: 999px;
    font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-blue  { background: var(--primary-l); color: var(--primary-d); border: 1px solid #c5d9fb; }
.badge-green { background: var(--green-l); color: #146c43; border: 1px solid #bfe6cd; }
.badge-amber { background: var(--amber-l); color: #92400e; border: 1px solid #f3ddb3; }
.badge-red   { background: var(--red-l); color: #b42318; border: 1px solid #f4c7c4; }
.badge-gray  { background: var(--slate-l); color: var(--text-soft); border: 1px solid #dde3ea; }
.badge-type  { background: var(--slate-l); color: var(--text-soft); border: 1px solid #dde3ea; }

.chips { display: inline-flex; gap: 5px; flex-wrap: wrap; }
.chip-ch { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: #f1f4f8; color: var(--text-mute); font-weight: 600; border: 1px solid var(--border-2); }
.chip-ch.on { background: var(--primary-l); color: var(--primary-d); border-color: #c5d9fb; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 16px; border-radius: var(--radius-sm);
    font: inherit; font-weight: 600; font-size: 14px;
    cursor: pointer; border: 1px solid transparent; transition: .12s;
    text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: #fafbfc; }
.btn-danger { background: var(--surface); color: var(--red); border-color: #f1c9c6; }
.btn-danger:hover { background: var(--red-l); }
.btn-link { background: none; color: var(--primary); padding: 6px 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Form ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 20px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.field .hint { font-size: 12px; color: var(--text-mute); }
.field input[type=text], .field input[type=email], .field input[type=tel],
.field input[type=date], .field input[type=number], .field input[type=password],
.field select, .field textarea {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font: inherit; color: var(--text); background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-l);
}
.field textarea { resize: vertical; min-height: 90px; }
.check { display: flex; align-items: center; gap: 9px; font-weight: 500; color: var(--text); cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--primary); }
.form-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border-2); }
.field-error { color: var(--red); font-size: 12.5px; }
.input-invalid { border-color: var(--red) !important; }

fieldset.group { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin: 0; }
fieldset.group legend { padding: 0 8px; font-weight: 600; font-size: 13px; color: var(--text-soft); }

/* ---------- Toolbar / filtri ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .search { flex: 1; min-width: 200px; }
.toolbar input, .toolbar select {
    padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit; background: #fff;
}
.toolbar input[type=search] { width: 100%; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--text-mute); }
.empty svg { width: 46px; height: 46px; fill: #cbd5e1; margin-bottom: 12px; }
.empty p { margin: 0 0 14px; }

/* ---------- Misc ---------- */
.muted { color: var(--text-mute); }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.text-green { color: var(--green); }
.flex { display: flex; gap: 10px; align-items: center; }
.between { justify-content: space-between; }
.mt0 { margin-top: 0; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-mute); font-weight: 700; margin: 0 0 12px; }
.detail-grid { display: grid; grid-template-columns: 160px 1fr; gap: 10px 16px; }
.detail-grid dt { color: var(--text-soft); font-weight: 500; }
.detail-grid dd { margin: 0; font-weight: 500; }

/* ---------- Calendario ---------- */
#calendar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.cal-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.cal-legend span { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-soft); }
.cal-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ---------- Overlay (mobile) ---------- */
.overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 35; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
    .layout.nav-open .sidebar { transform: translateX(0); }
    .layout.nav-open .overlay { display: block; }
    .main { margin-left: 0; }
    .hamburger { display: inline-flex; }
    .form-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; gap: 4px 0; }
    .detail-grid dt { margin-top: 8px; }
    .topbar-right .btn span, .topbar-right { font-size: 13px; }
}
