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

:root {
    --bg: #0d0d0d;
    --bg-card: #1a1a1a;
    --bg-sidebar: #111111;
    --border: #2a2a2a;
    --accent: #8b5cf6;
    --accent-hover: #7c3aed;
    --text: #e4e4e7;
    --text-dim: #71717a;
    --success: #22c55e;
    --error: #ef4444;
    --radius: 12px;
    --sidebar-w: 240px;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ═══════════ SIDEBAR ═══════════ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-brand {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    font-size: 1.2rem;
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 8px;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}

.nav-item.active {
    background: rgba(139, 92, 246, 0.1);
    color: var(--accent);
}

.nav-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

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

.nav-logout:hover {
    color: var(--error);
}

.sidebar-overlay {
    display: none;
}

/* ═══════════ MAIN CONTENT ═══════════ */
.main-content {
    margin-left: var(--sidebar-w);
    max-width: 760px;
    padding: 40px 32px 60px;
    margin-right: auto;
    margin-left: calc(var(--sidebar-w) + (100vw - var(--sidebar-w) - 760px) / 2);
}

.mobile-header {
    display: none;
}

.page-title {
    margin-bottom: 24px;
}

.page-title h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
}

.page-title .subtitle {
    font-size: 0.82rem;
    color: var(--text-dim);
    margin-top: 4px;
}

/* ═══════════ LOGIN (no sidebar) ═══════════ */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 48px 20px;
}

.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 85vh;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px 32px;
    max-width: 380px;
    width: 100%;
    text-align: center;
}

.login-card h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--accent);
}

.login-card p {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-bottom: 24px;
}

.login-card input[type="password"] {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    margin-bottom: 16px;
    transition: border-color 0.2s;
}

.login-card input[type="password"]:focus {
    border-color: var(--accent);
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.error-msg {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: var(--error);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.82rem;
    margin-bottom: 16px;
}

/* ═══════════ CARD ═══════════ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 16px;
}

.card h2 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text);
}

/* ═══════════ FORM ═══════════ */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    padding: 11px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    appearance: none;
    -webkit-appearance: none;
}

.form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2371717a' d='M6 8.825a.5.5 0 0 1-.354-.146l-4-4a.5.5 0 0 1 .708-.708L6 7.617l3.646-3.646a.5.5 0 0 1 .708.708l-4 4A.5.5 0 0 1 6 8.825z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    cursor: pointer;
}

.form-group select option {
    background: var(--bg-card);
    color: var(--text);
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent);
}

.form-group input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.6);
    cursor: pointer;
}

.form-group textarea {
    padding: 11px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    resize: vertical;
    min-height: 80px;
}

.form-group textarea:focus {
    border-color: var(--accent);
}

/* Radio */
.radio-group {
    display: flex;
    gap: 10px;
}

.radio-option {
    flex: 1;
    position: relative;
}

.radio-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.radio-option label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 11px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    font-size: 0.88rem;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-dim);
}

.radio-option input:checked+label {
    border-color: var(--accent);
    background: rgba(139, 92, 246, 0.1);
    color: var(--text);
}

.radio-option label:hover {
    border-color: #3a3a3a;
}

/* Submit */
.form-actions {
    margin-top: 24px;
    display: flex;
    justify-content: flex-end;
}

.btn-submit {
    padding: 12px 28px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.btn-submit:hover {
    background: var(--accent-hover);
}

/* ═══════════ TOAST ═══════════ */
.toast {
    position: fixed;
    top: 24px;
    right: 24px;
    padding: 14px 20px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 1000;
    transition: opacity 0.4s, transform 0.4s;
    max-width: 360px;
}

.toast-success {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: var(--success);
}

.toast-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--error);
}

/* ═══════════ LOADING ═══════════ */
.loading-card {
    padding: 48px 28px;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.loading-content p {
    color: var(--text-dim);
    font-size: 0.88rem;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ═══════════ PREVIEW ═══════════ */
.preview-text {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    font-size: 0.88rem;
    line-height: 1.7;
    color: var(--text);
    margin-bottom: 20px;
    max-height: 400px;
    overflow-y: auto;
}

.preview-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.btn-export {
    padding: 10px 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s;
}

.btn-export:hover {
    background: var(--accent-hover);
}

.btn-discard {
    padding: 10px 24px;
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.btn-discard:hover {
    border-color: var(--error);
    color: var(--error);
}

/* Download card */
.download-card {
    text-align: center;
}

.download-text {
    color: var(--text-dim);
    font-size: 0.88rem;
    margin-bottom: 16px;
}

.btn-download {
    padding: 10px 24px;
    background: var(--success);
    color: #fff;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: opacity 0.2s;
    display: inline-block;
}

.btn-download:hover {
    opacity: 0.85;
}

/* ═══════════ STORICO (Filters) ═══════════ */
.filters-card {
    padding: 16px 20px;
}

.filters-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.filter-group {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.filter-group label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 5px;
}

.filter-group select {
    padding: 9px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.82rem;
    font-family: inherit;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%2371717a' d='M6 8.825a.5.5 0 0 1-.354-.146l-4-4a.5.5 0 0 1 .708-.708L6 7.617l3.646-3.646a.5.5 0 0 1 .708.708l-4 4A.5.5 0 0 1 6 8.825z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
    cursor: pointer;
}

.filter-group select option {
    background: var(--bg-card);
    color: var(--text);
}

.filter-reset {
    flex: 0;
}

.btn-reset {
    padding: 9px 16px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-dim);
    font-size: 0.82rem;
    font-weight: 500;
    text-decoration: none;
    transition: border-color 0.2s, color 0.2s;
    white-space: nowrap;
    display: inline-block;
}

.btn-reset:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ═══════════ STORICO (History Items) ═══════════ */
.history-item {
    padding: 20px 24px;
}

.history-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.history-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.history-genre {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text);
}

.history-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-success {
    background: rgba(34, 197, 94, 0.12);
    color: var(--success);
}

.badge-error {
    background: rgba(239, 68, 68, 0.12);
    color: var(--error);
}

.history-date {
    font-size: 0.75rem;
    color: var(--text-dim);
}

.history-details {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 0.82rem;
    color: var(--text-dim);
    margin-bottom: 14px;
}

.history-details strong {
    color: var(--text);
    font-weight: 500;
}

.history-actions {
    display: flex;
    justify-content: flex-end;
}

.btn-download-sm {
    padding: 7px 16px;
    background: rgba(139, 92, 246, 0.1);
    color: var(--accent);
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
    transition: background 0.15s;
}

.btn-download-sm:hover {
    background: rgba(139, 92, 246, 0.2);
}

.empty-card {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.88rem;
    padding: 40px;
}

/* ═══════════ MODAL ═══════════ */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    justify-content: center;
    align-items: center;
    padding: 24px;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 640px;
    width: 100%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
}

.modal-close:hover {
    color: var(--text);
}

.modal-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-dim);
}

.modal-body {
    padding: 20px 24px;
    font-size: 0.88rem;
    line-height: 1.7;
    color: var(--text);
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

.modal-footer:empty {
    display: none;
}

/* Filter date input */
.filter-group input[type="date"] {
    padding: 9px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.82rem;
    font-family: inherit;
    outline: none;
    cursor: pointer;
}

.filter-group input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.6);
    cursor: pointer;
}

/* ═══════════ RESPONSIVE ═══════════ */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
    }

    .sidebar-overlay.open {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 0 16px 40px;
    }

    .mobile-header {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 20px 0;
    }

    .mobile-header h1 {
        font-size: 1.15rem;
        font-weight: 700;
        color: var(--accent);
    }

    .hamburger {
        display: flex;
        align-items: center;
        justify-content: center;
        background: none;
        border: 1px solid var(--border);
        color: var(--text);
        font-size: 1.2rem;
        width: 38px;
        height: 38px;
        border-radius: 8px;
        cursor: pointer;
    }

    .hamburger:hover {
        border-color: var(--accent);
    }

    .page-title h1 {
        font-size: 1.2rem;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .filters-row {
        flex-direction: column;
    }

    .toast {
        right: 12px;
        left: 12px;
        max-width: none;
    }

    .preview-actions {
        flex-direction: column;
    }

    .history-top {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .modal-overlay {
        padding: 12px;
    }

    .modal {
        max-height: 90vh;
    }

    .modal-header,
    .modal-meta,
    .modal-body,
    .modal-footer {
        padding-left: 16px;
        padding-right: 16px;
    }
}

@media (min-width: 901px) {
    .hamburger {
        display: none;
    }

    .mobile-header {
        display: none;
    }
}