/* ==========================================================================
   TUTTO IL TUO CSS ORIGINALE (INTATTO)
   ========================================================================== */

/* 1. IMPORT FONT GOOGLE (PLUS JAKARTA SANS) */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

/* 2. CARICAMENTO FONT LOCALE (STARA) */
@font-face {
    font-family: 'Stara';
    src: url('../fonts/Stara-SemiBold.otf') format('opentype');
    font-weight: 600;
    font-style: normal;
    font-display: swap; 
}

:root {
    /* Palette Enterprise "Crisp" */
    --bg-body: #f3f4f6;       /* Grigio freddo */
    --surface: #ffffff;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    
    --text-primary: #111827;  /* Quasi nero */
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;

    --brand: #2563eb;         /* Blu elettrico serio */
    --brand-dark: #1e40af;
    --brand-light: #eff6ff;   /* Aggiunto per hover/active chiari */

    /* Font Families - UPDATE */
    --font-main: 'Plus Jakarta Sans', -apple-system, sans-serif;
    --font-display: 'Stara', 'Plus Jakarta Sans', sans-serif;

    /* Status Colors */
    --green-text: #059669; --green-bg: #ecfdf5; --green-border: #a7f3d0;
    --red-text: #dc2626;   --red-bg: #fef2f2;   --red-border: #fecaca;
    --amber-text: #d97706; --amber-bg: #fffbeb; --amber-border: #fde68a;
    --blue-text: #2563eb;  --blue-bg: #eff6ff;  --blue-border: #bfdbfe;

    --shadow-soft: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

/* --- DARK MODE (Si aggancia alle tue variabili) --- */
[data-theme="dark"] {
    --bg-body: #0f172a;       /* Slate 900 */
    --surface: #1e293b;       /* Slate 800 */
    --border: #334155;        /* Slate 700 */
    --border-strong: #475569; /* Slate 600 */
    
    --text-primary: #f8fafc;  /* Slate 50 */
    --text-secondary: #94a3b8; /* Slate 400 */
    --text-tertiary: #64748b;

    --brand: #60a5fa;         /* Blue 400 (più leggibile su scuro) */
    --brand-dark: #3b82f6;
    --brand-light: rgba(59, 130, 246, 0.15);

    --shadow-soft: 0 4px 6px -1px rgba(0, 0, 0, 0.5);

    /* Status Dark adjustments */
    --green-bg: rgba(6, 95, 70, 0.3); --green-text: #34d399; --green-border: rgba(52, 211, 153, 0.2);
    --red-bg: rgba(127, 29, 29, 0.3); --red-text: #f87171;   --red-border: rgba(248, 113, 113, 0.2);
    --amber-bg: rgba(120, 53, 15, 0.3); --amber-text: #fbbf24; --amber-border: rgba(251, 191, 36, 0.2);
    --blue-bg: rgba(30, 64, 175, 0.3); --blue-text: #60a5fa; --blue-border: rgba(59, 130, 246, 0.2);
}

* { box-sizing: border-box; margin: 0; padding: 0; outline: none; }

/* FIX CRITICO LOADER & FONT APPLICAZIONE */
body {
    font-family: var(--font-main); /* Usa Plus Jakarta Sans ovunque */
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh; /* Changed from height to min-height for mobile scrolling */
    opacity: 0; 
    transition: opacity 0.25s ease-in-out;
}

body.loaded { opacity: 1; }

/* Global Loader Spinner */
#page-loader {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg-body); 
    z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;
}
body.loaded #page-loader { opacity: 0; visibility: hidden; }

.loader-spinner {
    width: 32px; height: 32px; border: 3px solid var(--border-strong);
    border-top-color: var(--brand); border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Layout --- */
.main-content { max-width: 1400px; margin: 32px auto; padding: 0 40px; }

/* --- Navigation (DESKTOP DEFAULT) --- */
nav {
    position: sticky; top: 0; z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    height: 60px;
    transition: background-color 0.2s;
}
.nav-container {
    max-width: 1400px; margin: 0 auto; padding: 0 40px;
    height: 100%; display: flex; align-items: center; justify-content: space-between;
}

/* Brand */
.brand {
    display: flex; align-items: center; gap: 10px;
    font-family: var(--font-display); 
    font-weight: 600; 
    font-size: 20px; 
    color: var(--text-primary); 
    text-decoration: none;
    letter-spacing: -0.01em;
    flex-shrink: 0;
    position: relative; 
    z-index: 50; 
}

/* Default Links (Horizontal) */
.nav-links { display: flex; gap: 8px; height: 100%; align-items: center; }
.nav-link {
    text-decoration: none; color: var(--text-secondary); font-weight: 500; font-size: 13px;
    padding: 6px 12px; border-radius: 6px;
    transition: color 0.1s, background 0.1s;
    display: flex; align-items: center; gap: 6px;
    white-space: nowrap;
}
.nav-link:hover { color: var(--text-primary); background: var(--bg-body); }
.nav-link.active { color: var(--brand); background: var(--brand-light); font-weight: 600; }

/* Hamburger & Close - NASCOSTI SU DESKTOP */
.hamburger, .close-menu { display: none !important; }

/* --- Header Section --- */
.page-header {
    display: flex; justify-content: space-between; align-items: flex-end;
    margin-bottom: 24px; padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

h1 { 
    font-family: var(--font-display);
    font-size: 24px; 
    font-weight: 600; 
    color: var(--text-primary); 
    margin-bottom: 4px; 
    letter-spacing: -0.01em;
}

.subtitle { color: var(--text-secondary); font-size: 13px; }

/* --- Stats Grid --- */
.grid-3 {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 32px;
}
.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 20px;
    box-shadow: var(--shadow-soft);
}
.stat-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text-primary); margin: 8px 0; letter-spacing: -0.03em; }
.stat-trend { font-size: 12px; display: flex; align-items: center; gap: 4px; font-weight: 500; }

/* --- Control Bar --- */
.control-bar {
    background: var(--surface); border: 1px solid var(--border); border-bottom: none;
    border-top-left-radius: 8px; border-top-right-radius: 8px;
    padding: 12px 24px;
    display: flex; justify-content: space-between; align-items: center;
}
.bulk-wrapper { display: flex; align-items: center; gap: 10px; }
.bulk-select {
    padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: 6px;
    font-size: 13px; color: var(--text-primary); background: var(--surface); cursor: pointer;
    min-width: 200px;
    font-family: var(--font-main);
}
.bulk-select:disabled { background: var(--bg-body); color: var(--text-tertiary); cursor: not-allowed; border-color: var(--border); }

/* --- Panel & Table --- */
.panel {
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: var(--shadow-soft); overflow: hidden; margin-bottom: 24px;
}
.panel.has-controls { border-top-left-radius: 0; border-top-right-radius: 0; border-top: 1px solid var(--border); }

.panel-header {
    padding: 16px 24px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.panel-title { font-weight: 600; font-size: 14px; color: var(--text-primary); }
.panel-body { padding: 24px; }

/* Table Responsive Handling */
.table-wrapper { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 600px; /* Ensure table doesn't squish too much */ }

thead th {
    text-align: left; background: var(--bg-body);
    border-bottom: 1px solid var(--border); padding: 12px 24px;
    font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-secondary);
}
tbody td {
    padding: 14px 24px; border-bottom: 1px solid var(--border);
    vertical-align: middle; font-size: 13px; color: var(--text-primary);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: var(--bg-body); }

/* --- Components --- */
.pill {
    display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 4px;
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em;
    border: 1px solid transparent;
}
.pill.pay, .pill.success { background: var(--green-bg); color: var(--green-text); border-color: var(--green-border); }
.pill.reject, .pill.danger { background: var(--red-bg); color: var(--red-text); border-color: var(--red-border); }
.pill.pending, .pill.warn { background: var(--amber-bg); color: var(--amber-text); border-color: var(--amber-border); }
.pill.sent, .pill.info { background: var(--blue-bg); color: var(--blue-text); border-color: var(--blue-border); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer;
    border: 1px solid transparent; transition: all 0.1s;
    font-family: var(--font-main);
}
.btn-primary { background: var(--brand); color: white; border-color: var(--brand-dark); }
.btn-primary:hover { background: var(--brand-dark); } 
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-body); border-color: var(--text-secondary); }

.btn-danger { background: var(--red-bg); color: var(--red-text); border-color: var(--red-border); }
.btn-danger:hover { background: #fee2e2; border-color: #fca5a5; }

.btn-ghost {
    background: transparent; border: 1px solid var(--border); color: var(--text-secondary);
    padding: 4px 10px; border-radius: 4px; font-size: 12px; cursor: pointer;
}
.btn-ghost:hover { border-color: var(--text-secondary); color: var(--text-primary); background: var(--surface); }
.btn-ghost.active { background: var(--text-primary); color: var(--surface); border-color: var(--text-primary); }

/* --- Forms --- */
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary);
    margin-bottom: 6px;
}
.input-field {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--border-strong); border-radius: 6px;
    font-size: 14px; color: var(--text-primary); background: var(--surface);
    transition: border-color 0.15s;
    font-family: var(--font-main);
}
.input-field:focus { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-light); }
.input-help { font-size: 12px; color: var(--text-tertiary); margin-top: 6px; }

/* Switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--border-strong); transition: .2s; border-radius: 22px;
}
.slider:before {
    position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px;
    background-color: white; transition: .2s; border-radius: 50%;
}
input:checked + .slider { background-color: var(--brand); }
input:checked + .slider:before { transform: translateX(18px); }

/* Integration Card */
.integration-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg-body); 
}
.integration-info { display: flex; align-items: center; gap: 16px; }
.integration-icon { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; background: var(--surface); border-radius: 8px; border: 1px solid var(--border); }

/* Files */
.file-row { cursor: pointer; transition: background 0.1s; }
.file-icon { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 6px; background: var(--bg-body); color: var(--text-secondary); }
.file-name-group { display: flex; align-items: center; gap: 12px; font-weight: 500; }
.breadcrumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.crumb { cursor: pointer; transition: color 0.1s; }
.crumb:hover { color: var(--brand); }
.crumb.active { color: var(--text-primary); font-weight: 600; cursor: default; }
.separator { color: var(--text-tertiary); font-size: 10px; }

/* Modal */
.modal-backdrop {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(17, 24, 39, 0.4); backdrop-filter: blur(2px);
    z-index: 1000; display: none; align-items: center; justify-content: center;
}
.modal-backdrop.active { display: flex; }
.modal-content {
    background: var(--surface); border-radius: 12px; width: 480px; padding: 24px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1); border: 1px solid var(--border);
    max-width: 90%; 
}

/* Action Cards */
.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}
.action-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    transition: box-shadow 0.2s, border-color 0.2s; 
    position: relative;
    overflow: hidden;
}
.action-card:hover {
    border-color: var(--brand);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
}
.action-icon { 
    width: 56px; height: 56px;
    background: var(--bg-body);
    color: var(--text-secondary);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 20px;
    transition: background 0.2s, color 0.2s;
}
.action-card:hover .action-icon {
    background: var(--brand-light);
    color: var(--brand);
}
.action-title {
    font-family: var(--font-display); 
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.action-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

#upload-trigger { display: none; }

[data-theme="dark"] .brand img {
    filter: brightness(0) invert(1);
    opacity: 0.9; 
    transition: filter 0.2s ease;
}

/* ==========================================================================
   MOBILE ONLY (@media max-width: 768px)
   ========================================================================== */

@media (max-width: 768px) {
    /* 1. Layout PADDING */
    .main-content { padding: 0 16px; margin: 24px auto; }
    
    /* 2. NAVIGATION: DRAWER & HAMBURGER (Solo Mobile!) */
    nav { height: 60px; padding: 0; }
    .nav-container { padding: 0 20px; flex-direction: row; justify-content: space-between; width: 100%; }

    /* Show Hamburger */
    .hamburger { 
        display: flex !important; /* Forces visibility only on mobile */
        background: var(--bg-body); 
        border: 1px solid var(--border);
        border-radius: 8px;
        width: 40px; height: 40px;
        padding: 0;
        cursor: pointer;
        flex-direction: column; justify-content: center; align-items: center; gap: 5px;
    }
    .hamburger-line {
        display: block; width: 18px; height: 2px;
        background-color: var(--text-primary);
        border-radius: 2px;
    }

    /* The Drawer Menu (Z-INDEX 99999 PER COPRIRE IL LOGO) */
    .nav-links {
        position: fixed; top: 0; right: -100%;
        width: 280px; height: 100vh;
        background: var(--surface);
        flex-direction: column; align-items: flex-start; justify-content: flex-start;
        padding: 80px 24px 24px 24px;
        box-shadow: -4px 0 15px rgba(0,0,0,0.5);
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 99999; /* ALZATO PER COPRIRE TUTTO */
    }
    .nav-links.active { right: 0; }
    
    .nav-link { 
        width: 100%; padding: 12px 0; font-size: 16px; 
        border-bottom: 1px solid var(--border); background: transparent !important; 
    }
    .nav-link:last-child { border-bottom: none; }

    /* Close Button */
    .close-menu {
        display: flex !important; align-items: center; justify-content: center;
        position: absolute; top: 15px; right: 15px;
        background: var(--bg-body); border: 1px solid var(--border); border-radius: 8px;
        width: 40px; height: 40px;
        font-size: 24px; color: var(--text-secondary); cursor: pointer;
    }

    /* 3. GRID & HEADERS */
    .grid-3 { grid-template-columns: 1fr; gap: 16px; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }

    /* 4. FIX TABELLA SCROLL (Slide) */
    /* Abilitiamo lo scroll sul pannello se la tabella è troppo larga */
    .panel {
        overflow-x: auto; /* <--- QUESTA È LA SOLUZIONE PER LO SLIDE */
    }
    
    /* Assicuriamoci che la tabella abbia una larghezza minima per attivare lo scroll */
    table {
        min-width: 600px;
    }
}