/* ══════════════════════════════════════════════════════════════
   DELIVERY HUB — Premium Logistics Command Center
   Inspired by FedEx/DHL enterprise dashboards
   ══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;0,9..40,800;1,9..40,400&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    /* Core palette — midnight navy + electric teal */
    --bg: #080b12;
    --bg-elevated: #0d1117;
    --bg-card: #111620;
    --bg-card-hover: #161d2a;
    --bg-sidebar: #060910;
    --bg-sidebar-hover: rgba(56, 189, 248, 0.04);
    --bg-input: #0f1420;
    --bg-surface: #131925;

    /* Text hierarchy */
    --text: #e2e8f0;
    --text-muted: #7c8db5;
    --text-light: #4a5878;
    --text-sidebar: #5b6b8a;

    /* Accent — electric teal (logistics authority) */
    --accent: #38bdf8;
    --accent-glow: rgba(56, 189, 248, 0.12);
    --accent-2: #22d3ee;
    --accent-warm: #f59e0b;

    /* Borders */
    --border: rgba(148, 163, 184, 0.08);
    --border-hover: rgba(148, 163, 184, 0.15);
    --border-accent: rgba(56, 189, 248, 0.2);

    /* Status */
    --danger: #f43f5e;
    --danger-bg: rgba(244, 63, 94, 0.08);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.08);
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.08);
    --info: #38bdf8;
    --info-bg: rgba(56, 189, 248, 0.08);

    /* Radii */
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    /* Shadows */
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 24px rgba(0,0,0,0.5);
    --shadow-lg: 0 12px 48px rgba(0,0,0,0.6);
    --shadow-glow: 0 0 40px rgba(56, 189, 248, 0.06);

    /* Typography */
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Layout */
    --sidebar-w: 256px;
    --topbar-h: 56px;

    /* Gradients */
    --gradient-1: linear-gradient(135deg, #38bdf8 0%, #22d3ee 50%, #10b981 100%);
    --gradient-subtle: linear-gradient(180deg, rgba(56, 189, 248, 0.02) 0%, transparent 60%);
    --gradient-card: linear-gradient(160deg, rgba(56, 189, 248, 0.03) 0%, transparent 40%);
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::selection { background: rgba(56, 189, 248, 0.25); color: #fff; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.12); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.2); }

/* ══════════════════════════════════════════════════════════════
   SIDEBAR — Command Navigation
   ══════════════════════════════════════════════════════════════ */

.sidebar {
    position: fixed;
    left: 0; top: 0;
    width: var(--sidebar-w);
    height: 100vh; height: 100dvh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform .3s cubic-bezier(.4, 0, .2, 1);
}

.sidebar::after {
    content: '';
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 1px;
    background: linear-gradient(180deg, rgba(56,189,248,0.1) 0%, transparent 30%, transparent 70%, rgba(56,189,248,0.1) 100%);
}

.sidebar-header {
    padding: 20px 18px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 42px; height: 42px;
    background: var(--gradient-1);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 4px 15px rgba(56, 189, 248, 0.2);
}

.logo-title {
    font-size: 15px;
    font-weight: 800;
    color: #fff;
    letter-spacing: 2.5px;
    text-transform: uppercase;
}

.logo-subtitle {
    font-size: 10px;
    color: var(--text-light);
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-top: 1px;
    font-weight: 500;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-sidebar);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .2s;
    position: relative;
    border: 1px solid transparent;
}

.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text);
    border-color: rgba(148, 163, 184, 0.05);
}

.nav-item.active {
    background: var(--accent-glow);
    color: var(--accent);
    border-color: var(--border-accent);
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: -1px; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 18px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.4);
}

.nav-icon {
    font-size: 15px;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
    opacity: 0.85;
}

.nav-section-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-light);
    padding: 14px 14px 4px;
    margin-top: 4px;
}

.sidebar-footer {
    padding: 12px 10px;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    padding: 8px 10px;
    background: rgba(148, 163, 184, 0.03);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.user-avatar {
    width: 30px; height: 30px;
    background: var(--gradient-1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.user-email {
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.btn-logout {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-light);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all .2s;
    font-family: var(--font);
}

.btn-logout:hover {
    background: var(--danger-bg);
    border-color: rgba(244, 63, 94, 0.15);
    color: var(--danger);
}

.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 99;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.sidebar-overlay.visible { display: block; }

/* ══════════════════════════════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════════════════════════════ */

.main-content {
    margin-left: var(--sidebar-w);
    transition: margin-left .3s cubic-bezier(.4, 0, .2, 1);
    min-height: 100vh; min-height: 100dvh;
    background: var(--gradient-subtle);
    position: relative;
}

/* Subtle grid pattern overlay */
.main-content::before {
    content: '';
    position: fixed;
    inset: 0;
    left: var(--sidebar-w);
    background-image:
        linear-gradient(rgba(148, 163, 184, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, 0.02) 1px, transparent 1px);
    background-size: 60px 60px;
    pointer-events: none;
    z-index: 0;
}

.topbar {
    position: sticky; top: 0;
    height: var(--topbar-h);
    background: var(--topbar-bg, rgba(8, 11, 18, 0.88));
    backdrop-filter: blur(24px) saturate(120%);
    -webkit-backdrop-filter: blur(24px) saturate(120%);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 14px;
    z-index: 50;
}

.hamburger {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    cursor: pointer;
    padding: 5px 9px;
    color: var(--text);
    transition: all .2s;
}
.hamburger:hover { background: rgba(148, 163, 184, 0.05); }

.page-title {
    font-size: 17px;
    font-weight: 700;
    flex: 1;
    letter-spacing: -.2px;
    color: var(--text);
}

.topbar-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.mese-select {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    background: var(--bg-input);
    cursor: pointer;
    color: var(--text);
    outline: none;
    transition: all .2s;
}
.mese-select:focus { border-color: var(--accent); }
.mese-select option { background: var(--bg-card); }

.screen {
    padding: 24px;
    max-width: 1320px;
    position: relative;
    z-index: 1;
}

/* ══════════════════════════════════════════════════════════════
   LOGIN
   ══════════════════════════════════════════════════════════════ */

.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 24px;
    background:
        radial-gradient(ellipse at 25% 20%, rgba(56, 189, 248, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse at 75% 80%, rgba(16, 185, 129, 0.03) 0%, transparent 50%);
}

/* Nasconde sidebar/topbar quando l'utente non è loggato */
body.is-login .main-content { margin-left: 0; }
body.is-login .main-content::before { display: none; }
body.is-login .topbar { display: none; }

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 44px 36px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.login-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--gradient-1);
}

.login-logo {
    width: 72px; height: 72px;
    background: var(--bg-sidebar);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 18px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    border: 1px solid var(--border);
}

.login-card h2 {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 2.5px;
    margin-bottom: 4px;
    text-transform: uppercase;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 28px;
}

.login-card .input {
    width: 100%;
    margin-bottom: 12px;
    background: var(--bg-input);
    border-color: var(--border);
    color: var(--text);
}
.login-card .input::placeholder { color: var(--text-light); }

.error-msg {
    color: var(--danger);
    font-size: 12px;
    margin-top: 8px;
    min-height: 18px;
    font-weight: 500;
}

/* ══════════════════════════════════════════════════════════════
   INPUTS & BUTTONS
   ══════════════════════════════════════════════════════════════ */

.input {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13px;
    background: var(--bg-input);
    color: var(--text);
    transition: all .2s;
    outline: none;
}
.input::placeholder { color: var(--text-light); }
.input:hover { border-color: var(--border-hover); }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.search-input { width: 260px; }
.filter-select { min-width: 150px; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}
.btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--accent);
    color: #0c1524;
    border-color: var(--accent);
    font-weight: 700;
}
.btn-primary:hover {
    background: #0ea5e9;
    border-color: #0ea5e9;
    box-shadow: 0 4px 16px rgba(56, 189, 248, 0.25);
}

.btn-sm { padding: 5px 10px; font-size: 11px; }

.btn-danger { color: var(--danger); border-color: rgba(244, 63, 94, 0.15); }
.btn-danger:hover { background: var(--danger-bg); border-color: rgba(244, 63, 94, 0.25); }

/* ══════════════════════════════════════════════════════════════
   KPI CARDS
   ══════════════════════════════════════════════════════════════ */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px 22px;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    transition: all .25s;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 0;
    background: var(--gradient-1);
    transition: height .25s;
}

.kpi-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-card:hover::before { height: 2px; }

.kpi-card.accent {
    border-color: var(--border-accent);
    background: var(--gradient-card);
}
.kpi-card.accent::before { height: 2px; }

.kpi-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.8px;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: -.5px;
    line-height: 1.1;
}

.kpi-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
    font-weight: 500;
}

/* ══════════════════════════════════════════════════════════════
   CARDS
   ══════════════════════════════════════════════════════════════ */

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 22px;
    border: 1px solid var(--border);
    margin-bottom: 16px;
    transition: border-color .2s;
}
.card:hover { border-color: var(--border-hover); }

.card-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 16px;
    letter-spacing: -.1px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

.card-title::before {
    content: '';
    width: 3px; height: 16px;
    background: var(--gradient-1);
    border-radius: 2px;
    flex-shrink: 0;
}

.card-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 14px;
    line-height: 1.6;
}

/* ══════════════════════════════════════════════════════════════
   DATA TABLES
   ══════════════════════════════════════════════════════════════ */

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

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}

.data-table th {
    text-align: left;
    padding: 10px 14px;
    font-weight: 700;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-light);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: var(--bg-card);
}

.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.04);
    vertical-align: middle;
    color: var(--text-muted);
}

.data-table td strong { color: var(--text); }

.data-table tbody tr {
    transition: background .12s;
}

.data-table tbody tr:hover {
    background: rgba(56, 189, 248, 0.02);
}

.totals-row td {
    font-weight: 700;
    border-top: 2px solid var(--border-hover);
    background: rgba(56, 189, 248, 0.02);
    color: var(--text);
}

/* ══════════════════════════════════════════════════════════════
   BADGES
   ══════════════════════════════════════════════════════════════ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .5px;
    border: 1px solid transparent;
    text-transform: uppercase;
}

.badge-ok { background: var(--success-bg); color: var(--success); border-color: rgba(16, 185, 129, 0.12); }
.badge-warn { background: var(--warning-bg); color: var(--warning); border-color: rgba(245, 158, 11, 0.12); }
.badge-err { background: var(--danger-bg); color: var(--danger); border-color: rgba(244, 63, 94, 0.12); }
.badge-info { background: var(--info-bg); color: var(--info); border-color: rgba(56, 189, 248, 0.12); }

/* ══════════════════════════════════════════════════════════════
   TOOLBAR & PAGINATION
   ══════════════════════════════════════════════════════════════ */

.toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    margin-top: 16px;
}

.pagination button {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    font-family: var(--font);
    color: var(--text-muted);
    transition: all .12s;
}
.pagination button:hover { background: var(--bg-card-hover); border-color: var(--border-hover); color: var(--text); }
.pagination button.active { background: var(--accent); color: #0c1524; border-color: var(--accent); font-weight: 700; }
.pagination button:disabled { opacity: .25; cursor: not-allowed; }

/* ══════════════════════════════════════════════════════════════
   IMPORT ZONE
   ══════════════════════════════════════════════════════════════ */

.import-zone {
    border: 2px dashed var(--border-hover);
    border-radius: var(--radius-lg);
    padding: 40px 24px;
    text-align: center;
    color: var(--text-muted);
    transition: all .3s;
    cursor: pointer;
    background: rgba(56, 189, 248, 0.01);
}
.import-zone:hover, .import-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-glow);
}
.import-icon { font-size: 36px; margin-bottom: 10px; }
.import-link {
    color: var(--accent);
    cursor: pointer;
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px solid rgba(56, 189, 248, 0.25);
}
.import-link:hover { border-bottom-color: var(--accent); }

.progress-bar {
    height: 3px;
    background: rgba(148, 163, 184, 0.06);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 18px;
}
.progress-fill {
    height: 100%;
    background: var(--gradient-1);
    border-radius: 2px;
    transition: width .4s ease;
    width: 0%;
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.3);
}

.import-status {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
    text-align: center;
    font-weight: 500;
}

.import-log {
    margin-top: 16px;
    padding: 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 11px;
    max-height: 260px;
    overflow-y: auto;
    white-space: pre-wrap;
    color: var(--text-muted);
    line-height: 1.8;
}

/* ══════════════════════════════════════════════════════════════
   MODAL
   ══════════════════════════════════════════════════════════════ */

.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; color: var(--text); }

.modal-close {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 3px 9px;
    transition: all .2s;
}
.modal-close:hover {
    background: var(--danger-bg);
    border-color: rgba(244, 63, 94, 0.15);
    color: var(--danger);
}

.modal-body { padding: 22px; }
.modal-body .form-group { margin-bottom: 14px; }
.modal-body label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    margin-bottom: 5px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.modal-body .input { width: 100%; background: var(--bg-input); }

/* ══════════════════════════════════════════════════════════════
   RICONCILIAZIONE
   ══════════════════════════════════════════════════════════════ */

.ricon-area {
    margin-bottom: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.ricon-area-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(148, 163, 184, 0.02);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background .2s;
}
.ricon-area-header:hover { background: rgba(148, 163, 184, 0.04); }
.ricon-area-body { padding: 14px 16px; }
.ricon-match { color: var(--success); }
.ricon-mismatch { color: var(--danger); font-weight: 700; }

/* ══════════════════════════════════════════════════════════════
   GRID LAYOUT
   ══════════════════════════════════════════════════════════════ */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

textarea.input { resize: vertical; min-height: 56px; line-height: 1.5; }

/* ══════════════════════════════════════════════════════════════
   TOAST
   ══════════════════════════════════════════════════════════════ */

.toast {
    position: fixed;
    bottom: 24px; right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    z-index: 9999;
    animation: toastIn .3s cubic-bezier(.4, 0, .2, 1);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    box-shadow: var(--shadow-lg);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px) scale(.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ══════════════════════════════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════════════════════════════ */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.screen:not([style*="display: none"]):not([style*="display:none"]) {
    animation: fadeIn .3s cubic-bezier(.4, 0, .2, 1);
}

.kpi-card {
    animation: slideUp .35s cubic-bezier(.4, 0, .2, 1) backwards;
}
.kpi-card:nth-child(1) { animation-delay: .03s; }
.kpi-card:nth-child(2) { animation-delay: .06s; }
.kpi-card:nth-child(3) { animation-delay: .09s; }
.kpi-card:nth-child(4) { animation-delay: .12s; }

.login-card { animation: slideUp .45s cubic-bezier(.4, 0, .2, 1); }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .main-content::before { left: 0; }
    .hamburger { display: flex; align-items: center; }
    .screen { padding: 14px; }
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .kpi-card { padding: 14px 16px; }
    .kpi-value { font-size: 22px; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .search-input { width: 100%; }
    .topbar { padding: 0 12px; }
    .page-title { font-size: 15px; }
    .login-card { padding: 32px 22px; }
    .grid-2 { grid-template-columns: 1fr; }
    .card { padding: 16px; }
}

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


/* ══════════════════════════════════════════════════════════════
   TEMA CHIARO (default) — riposante per lavoro prolungato.
   La sidebar resta scura per contrasto. Toggle ☀️/🌙 in topbar,
   preferenza salvata in localStorage (lm_theme).
   ══════════════════════════════════════════════════════════════ */
html.theme-light body {
    --bg: #eef1f6;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f5f9;
    --bg-input: #f8fafc;
    --bg-surface: #ffffff;

    --text: #1e293b;
    --text-muted: #5b6b84;
    --text-light: #94a3b8;

    --accent: #0284c7;
    --accent-glow: rgba(2, 132, 199, 0.10);
    --accent-2: #0891b2;

    --border: rgba(15, 23, 42, 0.10);
    --border-hover: rgba(15, 23, 42, 0.20);
    --border-accent: rgba(2, 132, 199, 0.30);

    --danger: #e11d48;
    --danger-bg: rgba(225, 29, 72, 0.08);
    --warning: #d97706;
    --warning-bg: rgba(217, 119, 6, 0.08);
    --success: #059669;
    --success-bg: rgba(5, 150, 105, 0.08);
    --info: #0284c7;
    --info-bg: rgba(2, 132, 199, 0.08);

    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 20px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.14);
    --shadow-glow: none;

    --gradient-subtle: linear-gradient(180deg, rgba(2, 132, 199, 0.03) 0%, transparent 60%);
    --gradient-card: linear-gradient(160deg, rgba(2, 132, 199, 0.02) 0%, transparent 40%);

    --topbar-bg: rgba(255, 255, 255, 0.88);
}

/* La sidebar mantiene la palette scura anche in tema chiaro */
html.theme-light .sidebar {
    --text: #e2e8f0;
    --text-muted: #7c8db5;
    --text-light: #4a5878;
    --bg-card: #111620;
    --bg-card-hover: #161d2a;
    --border: rgba(148, 163, 184, 0.08);
    --border-hover: rgba(148, 163, 184, 0.15);
    --accent: #38bdf8;
    --accent-glow: rgba(56, 189, 248, 0.12);
    --info-bg: rgba(56, 189, 248, 0.08);
}

html.theme-light ::selection { background: rgba(2, 132, 199, 0.18); color: inherit; }
html.theme-light ::-webkit-scrollbar-thumb { background: rgba(15, 23, 42, 0.15); }
html.theme-light ::-webkit-scrollbar-thumb:hover { background: rgba(15, 23, 42, 0.28); }
html.theme-light .btn-primary { color: #ffffff; }
html.theme-light .btn-primary:hover { background: #0369a1; border-color: #0369a1; box-shadow: 0 4px 16px rgba(2, 132, 199, 0.25); }
html.theme-light .main-content::before {
    background-image:
        linear-gradient(rgba(15, 23, 42, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(15, 23, 42, 0.025) 1px, transparent 1px);
}

/* Bottone toggle tema */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 15px;
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: all .15s;
}
.theme-toggle:hover { border-color: var(--border-hover); color: var(--text); }


/* ══════════════════════════════════════════════════════════════
   SIDEBAR A SCOMPARSA (desktop) — hamburger sempre visibile
   ══════════════════════════════════════════════════════════════ */
@media (min-width: 769px) {
    .hamburger { display: flex; align-items: center; }
    html.sidebar-collapsed .sidebar { transform: translateX(-100%); }
    html.sidebar-collapsed .main-content { margin-left: 0; }
    html.sidebar-collapsed .main-content::before { left: 0; }
}

/* ══════════════════════════════════════════════════════════════
   MOBILE / TABLET UX
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) and (min-width: 769px) {
    /* Tablet: sidebar più stretta */
    :root { --sidebar-w: 200px; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    /* Touch target più generosi */
    .btn, .nav-item, .theme-toggle { min-height: 42px; }
    .btn-sm { min-height: 36px; }
    .data-table th, .data-table td { padding: 10px 8px; font-size: 12px; white-space: nowrap; }
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .mese-select { min-height: 40px; }
    .modal { max-width: calc(100vw - 24px); max-height: 88dvh; overflow-y: auto; }
    .input, select.input { min-height: 42px; font-size: 16px; } /* 16px evita lo zoom iOS */
    .topbar-actions { gap: 6px; }
    .kpi-label { font-size: 10px; }
    .toast-wrap, #toastContainer { left: 12px; right: 12px; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .kpi-value { font-size: 19px; }
    .screen { padding: 10px; }
    .card { padding: 12px; }
    .page-title { font-size: 14px; }
}


/* ══════════════════════════════════════════════════════════════
   DESIGN PASS v2 — smartphone & tablet
   ══════════════════════════════════════════════════════════════ */

/* ── Affordance scroll orizzontale tabelle: sfumatura sul bordo ── */
.table-wrap { position: relative; -webkit-overflow-scrolling: touch; }
@media (max-width: 768px) {
    .table-wrap::after {
        content: '';
        position: sticky;
        left: 100%;
        top: 0;
        display: block;
        width: 0;
    }
    .card .table-wrap {
        margin-left: -12px;
        margin-right: -12px;
        padding-left: 12px;
        padding-right: 12px;
        mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 22px), transparent 100%);
        -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 22px), transparent 100%);
    }
}

/* ── Modali come bottom-sheet su telefono ── */
@media (max-width: 640px) {
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal-card {
        max-width: 100%;
        max-height: 92dvh;
        border-radius: 20px 20px 0 0;
        border-bottom: none;
        animation: sheetUp .22s cubic-bezier(.3, .9, .4, 1);
        padding-bottom: env(safe-area-inset-bottom);
    }
    @keyframes sheetUp { from { transform: translateY(40%); opacity: .4; } to { transform: none; opacity: 1; } }
    .modal-header { position: sticky; top: 0; background: var(--bg-card); z-index: 2; }
    .modal-close { width: 40px; height: 40px; }
}

/* ── KPI a scorrimento orizzontale con snap su telefono ── */
@media (max-width: 640px) {
    .kpi-grid {
        display: flex;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        gap: 10px;
        padding-bottom: 6px;
        margin-left: -14px;
        margin-right: -14px;
        padding-left: 14px;
        padding-right: 14px;
        scrollbar-width: none;
    }
    .kpi-grid::-webkit-scrollbar { display: none; }
    .kpi-grid .kpi-card {
        min-width: 46%;
        flex: 0 0 auto;
        scroll-snap-align: start;
        padding: 14px 16px;
    }
    .kpi-value { font-size: 24px; }
}

/* ── Topbar compatta su telefono: titolo con ellipsis, niente wrap ── */
@media (max-width: 640px) {
    .topbar { gap: 8px; }
    .page-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
    .mese-select { max-width: 128px; font-size: 13px; }
    .theme-toggle { width: 38px; height: 38px; flex-shrink: 0; }
    .hamburger { flex-shrink: 0; min-width: 42px; justify-content: center; }
}

/* ── Toolbar: filtri e bottoni a tutta larghezza su telefono ── */
@media (max-width: 640px) {
    .toolbar .btn, .toolbar .input, .toolbar select.input,
    .toolbar .search-input, .toolbar .filter-select { width: 100%; }
    .toolbar input[type="date"], .toolbar input[type="month"] { width: 100% !important; }
}

/* ── Card e sezioni: respiro coerente su telefono ── */
@media (max-width: 640px) {
    .card { border-radius: 12px; margin-bottom: 12px; }
    .card-title { font-size: 15px; }
    .card-desc { font-size: 12px; line-height: 1.55; }
    .screen { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}

/* ── Tablet (769–1024): densità intermedia ── */
@media (max-width: 1024px) and (min-width: 769px) {
    .screen { padding: 18px; }
    .card { padding: 18px; }
    .kpi-card { padding: 16px 18px; }
    .kpi-value { font-size: 24px; }
    .data-table th, .data-table td { padding: 10px 10px; font-size: 12.5px; }
    .page-title { font-size: 16px; }
}

/* ── Tap feedback su touch (niente hover sui touch device) ── */
@media (hover: none) {
    .btn:active, .nav-item:active { transform: scale(.985); }
    .data-table tr:active td { background: var(--bg-card-hover); }
}

/* ── Riduzione animazioni se richiesto dal sistema ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
