:root {
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --primary: #f97316;
    --primary-hover: #ea580c;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --blue: #3b82f6;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', sans-serif; }

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
}

/* === SIDEBAR === */
.sidebar {
    width: 240px;
    min-width: 240px;
    background-color: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}

.logo { padding: 24px; border-bottom: 1px solid var(--border); }
.logo h2 { font-size: 22px; font-weight: 700; }
.accent { color: var(--primary); }
.logo p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

.nav { list-style: none; padding: 16px 0; flex-grow: 1; }
.nav li a {
    display: block; padding: 12px 24px;
    color: var(--text-muted); text-decoration: none;
    font-weight: 600; font-size: 14px; transition: all 0.2s;
}
.nav li.active a, .nav li a:hover {
    background-color: rgba(249,115,22,0.1);
    color: var(--primary);
    border-right: 3px solid var(--primary);
}

.sidebar-footer {
    padding: 16px 24px; border-top: 1px solid var(--border);
    color: var(--text-muted); font-size: 11px; text-align: center;
}

/* === MAIN === */
.content { flex-grow: 1; margin-left: 240px; padding: 32px 40px; overflow-y: auto; }

.page { display: none; }
.page.active { display: block; }

header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 32px; flex-wrap: wrap; gap: 16px;
}
header h1 { font-size: 24px; font-weight: 700; }

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

.user-profile { display: flex; align-items: center; gap: 12px; }
.user-profile span { color: var(--text-muted); font-weight: 600; font-size: 13px; }
.avatar {
    width: 36px; height: 36px; background-color: var(--primary);
    color: white; border-radius: 50%; display: flex;
    align-items: center; justify-content: center; font-weight: bold; font-size: 13px;
}

/* === STATS === */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 32px; }

.stat-card {
    background-color: var(--bg-card); padding: 20px; border-radius: 12px;
    border: 1px solid var(--border); position: relative; overflow: hidden;
}
.stat-card::before {
    content: ''; position: absolute; top: 0; left: 0;
    width: 4px; height: 100%; border-radius: 12px 0 0 12px;
}
.card-green::before { background: var(--success); }
.card-orange::before { background: var(--primary); }
.card-red::before { background: var(--danger); }
.card-blue::before { background: var(--blue); }

.stat-card h3 {
    color: var(--text-muted); font-size: 12px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.stat-card h2 { font-size: 28px; margin: 10px 0 4px; }
.stat-card p { color: var(--text-muted); font-size: 12px; }

/* === TABLES === */
.transactions-section, .full-table {
    background-color: var(--bg-card); border-radius: 12px;
    border: 1px solid var(--border); overflow: hidden;
}
.section-header {
    padding: 20px 24px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 12px;
}
.section-header h2 { font-size: 18px; }

.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 20px; text-align: left; border-bottom: 1px solid var(--border); }
th {
    color: var(--text-muted); font-size: 11px; text-transform: uppercase;
    font-weight: 600; background-color: rgba(0,0,0,0.2);
}
td { font-size: 13px; }

.badge {
    padding: 5px 10px; border-radius: 6px; font-size: 11px; font-weight: 700;
    display: inline-block; letter-spacing: 0.2px; text-transform: uppercase;
}
.badge-source { background: rgba(255,255,255,0.08); color: var(--text-muted); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); border: 1px solid rgba(245,158,11,0.3); }
.badge-success { background: rgba(16,185,129,0.15); color: var(--success); border: 1px solid rgba(16,185,129,0.3); }
.badge-method { background: rgba(59,130,246,0.15); color: var(--blue); }

.empty-state { padding: 40px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* === BUTTONS === */
.btn-refresh {
    background: transparent; color: var(--text-muted);
    border: 1px solid var(--border); padding: 8px 14px;
    border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 12px;
    transition: all 0.2s;
}
.btn-refresh:hover { color: var(--text-main); border-color: var(--text-muted); }

.btn-secondary {
    background: rgba(249,115,22,0.1); color: var(--primary);
    border: 1px solid var(--primary); padding: 8px 16px;
    border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 12px;
    transition: all 0.2s;
}
.btn-secondary:hover { background: rgba(249,115,22,0.2); }

.btn-action {
    background: var(--primary); color: white; border: none;
    padding: 6px 14px; border-radius: 6px; cursor: pointer;
    font-weight: 600; font-size: 11px; transition: background 0.2s;
}
.btn-action:hover { background: var(--primary-hover); }

.btn-download {
    background: transparent; color: var(--success);
    border: 1px solid var(--success); padding: 6px 14px;
    border-radius: 6px; cursor: pointer; font-weight: 600;
    font-size: 11px; text-decoration: none; display: inline-block;
}
.btn-download:hover { background: rgba(16,185,129,0.1); }

.btn-danger-sm {
    background: transparent; color: var(--danger);
    border: 1px solid var(--danger); padding: 6px 12px;
    border-radius: 6px; cursor: pointer; font-weight: 600;
    font-size: 11px; transition: all 0.2s;
}
.btn-danger-sm:hover { background: rgba(239,68,68,0.1); }

/* === MODALS === */
.modal {
    display: none; position: fixed; z-index: 1000;
    left: 0; top: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
}
.modal-content {
    background: var(--bg-card); margin: 3% auto;
    width: 640px; max-height: 90vh; overflow-y: auto;
    border-radius: 12px; border: 1px solid var(--border);
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.5);
    animation: slideIn 0.25s ease-out;
}
@keyframes slideIn { from { transform: translateY(-20px); opacity:0; } to { transform: translateY(0); opacity:1; } }

.modal-header {
    padding: 20px 24px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.modal-header h2 { font-size: 18px; }
.close { color: var(--text-muted); font-size: 24px; cursor: pointer; }
.close:hover { color: var(--text-main); }

.modal-body { padding: 24px; }

.form-group { margin-bottom: 14px; flex: 1; }
.form-row { display: flex; gap: 14px; }

label {
    display: block; margin-bottom: 6px;
    color: var(--text-muted); font-size: 12px; font-weight: 600;
}
input, select {
    width: 100%; padding: 9px 12px;
    background: rgba(0,0,0,0.25); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text-main); font-size: 13px;
}
input:focus, select:focus { outline: none; border-color: var(--primary); }

.file-input {
    padding: 10px; background: rgba(0,0,0,0.15);
    border: 1px dashed var(--border);
}

.form-summary {
    margin-top: 16px; padding: 14px;
    background: rgba(0,0,0,0.2); border-radius: 8px;
    border: 1px dashed var(--border);
}

.modal-footer {
    padding: 16px 24px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 12px;
}
.btn-cancel {
    background: transparent; color: var(--text-main);
    border: 1px solid var(--border); padding: 9px 18px;
    border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 13px;
}
.btn-primary {
    background: var(--primary); color: white; border: none;
    padding: 9px 18px; border-radius: 6px; cursor: pointer;
    font-weight: 600; font-size: 13px;
}
.btn-primary:hover { background: var(--primary-hover); }

@media (max-width: 768px) {
    .sidebar { width: 60px; min-width: 60px; }
    .logo { padding: 12px; text-align: center; }
    .desktop-only, .logo p, .nav li a span, .sidebar-footer { display: none !important; }
    .mobile-only { display: inline !important; font-size: 20px; }
    .nav li a { padding: 14px 0; text-align: center; font-size: 18px; display: flex; justify-content: center; }
    
    .content { margin-left: 60px; padding: 16px; max-width: calc(100vw - 60px); }
    .stats { grid-template-columns: 1fr; gap: 12px; margin-bottom: 24px; }
    .stat-card { padding: 16px; }
    .stat-card h2 { font-size: 22px; margin: 6px 0 2px; }
    
    header { margin-bottom: 20px; }
    header h1 { font-size: 18px; line-height: 1.3; }
    .user-profile span { display: none; } /* Nascondo la mail su mobile */
    
    .section-header { padding: 16px; flex-direction: column; align-items: flex-start; gap: 16px; }
    .header-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
    .header-actions button { width: 100%; padding: 10px 8px; font-size: 11px; }
    
    .table-container { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    th, td { padding: 10px 12px; font-size: 12px; white-space: nowrap; }
}

/* === UI/UX IMPROVEMENTS === */

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

td {
    white-space: nowrap;
}

/* === MOBILE TABLE RESPONSIVENESS (CARD LAYOUT) === */
@media (max-width: 768px) {
    /* Hide the table headers */
    .table-container thead {
        display: none;
    }

    /* Transform table into flex layout for cards */
    .table-container table, 
    .table-container tbody, 
    .table-container tr, 
    .table-container td {
        display: block;
        width: 100%;
    }

    /* Styling each row as a card */
    .table-container tr {
        background-color: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: 12px;
        margin-bottom: 16px;
        padding: 16px;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    }

    /* Remove borders from cells */
    .table-container td {
        border-bottom: none;
        padding: 8px 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
        font-size: 13px;
    }

    /* Add the label before the cell content */
    .table-container td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        text-transform: uppercase;
        font-size: 11px;
        margin-right: 16px;
        text-align: left;
    }

    /* For the actions, make them span full width and put them on a new line if needed */
    .table-container td[data-label="Azione"] {
        flex-direction: column;
        align-items: stretch;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid var(--border);
    }

    .table-container td[data-label="Azione"]::before {
        display: none; /* Hide 'Azione' label */
    }

    .actions-wrapper {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 8px;
        width: 100%;
    }

    .btn-action, .btn-download {
        text-align: center;
        padding: 10px;
        font-size: 13px;
    }
    
    .btn-danger-sm {
        padding: 10px 14px;
    }
}

/* LOGIN MODAL GLASSMORPHISM */
.login-modal {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card {
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    width: 350px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: slideUpFade 0.4s ease-out forwards;
}
@keyframes slideUpFade {
    0% { opacity: 0; transform: translateY(20px); }
    100% { opacity: 1; transform: translateY(0); }
}
.login-logo h2 {
    font-size: 2rem;
    color: white;
    margin-bottom: 20px;
}
.login-card h3 {
    color: white;
    margin-bottom: 10px;
    font-size: 1.3rem;
}
.login-card p {
    color: #94a3b8;
    font-size: 0.9rem;
    margin-bottom: 25px;
}
.login-card input {
    width: 100%;
    padding: 12px 15px;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    margin-bottom: 20px;
    outline: none;
    transition: all 0.3s ease;
}
.login-card input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}
.login-card button {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.login-card button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.4);
}
