/* Reset e base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    background: var(--surface);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow);
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 28px;
    color: var(--primary-color);
    font-weight: 700;
}

.header-actions {
    display: flex;
    gap: 10px;
}

/* Statistiche */
.statistics-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--surface);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow);
    text-align: center;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-5px);
}

.stat-card h3 {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 10px;
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--primary-color);
}

/* Container per affiancare working record e ricerca */
.search-container {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
}

/* Working Record Card */
.working-record-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    animation: slideInFromLeft 0.3s ease-out;
    flex: 0 0 20%;
    min-width: 200px;
}

.working-record-card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    opacity: 0.9;
}

.working-record-info {
    background: rgba(255, 255, 255, 0.15);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 12px;
    backdrop-filter: blur(10px);
}

.working-record-info p {
    margin: 6px 0;
    font-size: 12px;
    word-break: break-word;
}

.working-record-info strong {
    display: block;
    margin-bottom: 2px;
    opacity: 0.9;
    font-size: 11px;
}

.working-record-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.working-record-actions .btn {
    width: 100%;
    justify-content: center;
    padding: 8px 12px;
    font-size: 12px;
}

@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Search Panel */
.search-panel {
    background: var(--surface);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow);
    flex: 1;
}

.search-panel h2 {
    font-size: 20px;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.search-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 10px 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
    resize: vertical;
    font-family: inherit;
}

.form-actions {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-small {
    padding: 8px 16px;
    font-size: 13px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.icon {
    font-size: 16px;
}

/* Results Panel */
.results-panel {
    background: var(--surface);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow);
}

.results-panel h2 {
    font-size: 20px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.badge {
    background: var(--primary-color);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
}

.table-container {
    overflow-x: auto;
    margin-bottom: 20px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table thead {
    background: var(--background);
}

.data-table th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
}

.data-table td {
    padding: 15px;
    border-bottom: 1px solid var(--border);
}

.data-table tbody tr {
    transition: background 0.2s;
}

.data-table tbody tr:hover {
    background: var(--background);
}

.no-data {
    text-align: center;
    padding: 40px !important;
    color: var(--text-secondary);
    font-style: italic;
}

.action-buttons {
    display: flex;
    gap: 5px;
}

.btn-icon {
    padding: 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 16px;
}

.btn-icon:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 20px;
}

#pageInfo {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    overflow-y: auto;
}

.modal.active {
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 0;
}

.modal-content {
    background: var(--surface);
    border-radius: 0;
    width: 100%;
    height: 100vh;
    max-width: none;
    max-height: none;
    overflow-y: auto;
    box-shadow: none;
    display: flex;
    flex-direction: column;
}

.modal-content.modal-large {
    max-width: none;
}

.modal-header {
    padding: 25px 30px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 22px;
    color: var(--text-primary);
}

.btn-close {
    background: transparent;
    border: none;
    font-size: 32px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.btn-close:hover {
    background: var(--background);
    color: var(--danger-color);
}

.modal-body {
    padding: 30px;
    flex: 1;
    overflow-y: auto;
}

fieldset {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

legend {
    font-weight: 600;
    color: var(--primary-color);
    padding: 0 10px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 30px;
    padding: 30px;
    border-top: 1px solid var(--border);
    background: var(--background);
    flex-shrink: 0;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 25px;
    border-bottom: 2px solid var(--border);
    overflow-x: auto;
    flex-wrap: wrap;
}

.tab-button {
    padding: 12px 20px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s;
    white-space: nowrap;
}

.tab-button:hover {
    color: var(--primary-color);
    background: var(--background);
}

.tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.info-text {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
    margin: 0;
}

/* Loader */
.loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader p {
    margin-top: 20px;
    color: var(--text-secondary);
    font-weight: 600;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    padding: 15px 25px;
    background: var(--text-primary);
    color: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px var(--shadow);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 3000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--danger-color);
}

.toast.warning {
    background: var(--warning-color);
}

/* Responsive */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 20px;
        text-align: center;
    }

    .header-actions {
        width: 100%;
        justify-content: center;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column;
    }

    .statistics-panel {
        grid-template-columns: 1fr;
    }

    .modal-content {
        max-height: 95vh;
    }

    .data-table {
        font-size: 12px;
    }

    .data-table th,
    .data-table td {
        padding: 10px;
    }
}

@media print {
    .header-actions,
    .search-panel,
    .pagination,
    .action-buttons {
        display: none;
    }

    .container {
        max-width: 100%;
    }
}

/* Stili per i campi con select filtrabile */
.filter-input {
    width: 100%;
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s;
    background: white;
    margin-bottom: 5px;
}

.filter-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select[size] {
    border: 2px solid var(--border);
    border-radius: 6px;
    padding: 8px;
    font-size: 14px;
    cursor: pointer;
}

select[size]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select[size] option {
    padding: 8px;
    cursor: pointer;
}

select[size] option:hover {
    background: var(--primary-color);
    color: white;
}

small {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Stili per il configuratore AFIS */
.afis-reato-item {
    transition: all 0.3s ease;
}

.afis-reato-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.btn-remove:hover {
    background: #dc2626 !important;
    transform: scale(1.05);
}

#afis-preview {
    line-height: 1.6;
    word-wrap: break-word;
}

#afis-code-preview {
    word-break: break-all;
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #475569;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-secondary:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    transform: none;
}

/* Stili per lista contrassegni */
#contA-lista > div,
#contB-lista > div,
#contC-lista > div {
    transition: all 0.2s ease;
}

#contA-lista > div:hover,
#contB-lista > div:hover,
#contC-lista > div:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Scrollbar personalizzata per liste contrassegni */
#contA-lista::-webkit-scrollbar,
#contB-lista::-webkit-scrollbar,
#contC-lista::-webkit-scrollbar {
    width: 8px;
}

#contA-lista::-webkit-scrollbar-track,
#contB-lista::-webkit-scrollbar-track,
#contC-lista::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}

#contA-lista::-webkit-scrollbar-thumb,
#contB-lista::-webkit-scrollbar-thumb,
#contC-lista::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

#contA-lista::-webkit-scrollbar-thumb:hover,
#contB-lista::-webkit-scrollbar-thumb:hover,
#contC-lista::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}
