/* CSS Variables per Temi */
:root {
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-yellow: #f59e0b;
    --bg-header: #ffffff;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --radius: 8px;
}

[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --bg-header: #1e293b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

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

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    transition: background-color 0.3s, color 0.3s;
    line-height: 1.5;
}

/* Header */
header {
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.theme-toggle {
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.avatar {
    width: 32px;
    height: 32px;
    background-color: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Views */
.view {
    display: none;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.view.active {
    display: block;
}

/* Auth Box */
.auth-box {
    background-color: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    max-width: 450px;
    margin: 2rem auto;
    text-align: center;
}

.auth-box h2 {
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.auth-box p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
}

.gdpr-notice {
    font-size: 0.85rem;
    color: var(--text-muted);
    max-width: 600px;
    margin: 2rem auto;
    text-align: center;
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.input-group {
    margin-bottom: 1rem;
}

input[type="text"], input[type="email"] {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background-color: var(--bg-body);
    color: var(--text-main);
    outline: none;
    transition: border-color 0.2s;
}

input[type="text"]:focus, input[type="email"]:focus {
    border-color: var(--primary);
}

/* Buttons */
.btn {
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    width: 100%;
}

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

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: var(--bg-body);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.error-text {
    color: var(--accent-red);
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* Search Bar Section */
.search-section {
    background-color: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
    border: 1px solid var(--border-color);
}

.search-input-wrapper {
    display: flex;
    gap: 1rem;
}

.search-input-wrapper .btn-primary {
    width: auto;
}

/* Code Header */
.code-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.code-badge {
    background-color: var(--primary);
    color: white;
    font-size: 1.25rem; /* Rimpicciolito in base al feedback */
    font-weight: 600;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius);
    letter-spacing: 0.5px;
}

.code-desc {
    font-size: 1.1rem;
    color: var(--text-muted);
}

/* Tabs */
.tabs-header {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
}

.tab-btn {
    background: none;
    border: none;
    padding: 0.75rem 1.25rem;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn:hover:not(.active) {
    color: var(--text-main);
}

.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
}

/* Data Rows (Key-Value) */
.data-row {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px dashed var(--border-color);
}
.data-row:last-child {
    border-bottom: none;
}
.data-label {
    color: var(--text-muted);
    font-size: 0.95rem;
}
.data-value {
    font-weight: 600;
    font-size: 0.95rem;
}

/* Testi Regolamenti e Note */
.text-block {
    margin-bottom: 1rem;
    padding: 1rem;
    background-color: var(--bg-body);
    border-radius: var(--radius);
    border-left: 4px solid var(--primary);
}

.text-block h4 {
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.text-block p {
    font-size: 0.95rem;
    color: var(--text-muted);
}

/* Badges */
.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    display: inline-block;
}
.badge-green { background-color: rgba(16, 185, 129, 0.1); color: var(--accent-green); }
.badge-red { background-color: rgba(239, 68, 68, 0.1); color: var(--accent-red); }
.badge-yellow { background-color: rgba(245, 158, 11, 0.1); color: var(--accent-yellow); }
.badge-blue { background-color: rgba(59, 130, 246, 0.1); color: var(--primary); }

/* Accordion for Long Text */
.accordion {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-top: 1rem;
    overflow: hidden;
}
.accordion-header {
    background-color: var(--bg-body);
    padding: 0.75rem 1rem;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.accordion-content {
    padding: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    display: none;
}

/* Risultati di Ricerca (Autocompletamento/Ricerca Testuale) */
#search-results {
    margin-top: 1rem;
}
.search-item {
    background-color: var(--bg-card);
    padding: 1rem;
    margin-bottom: 0.5rem;
    border-radius: var(--radius);
    border-left: 4px solid var(--primary);
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    border-top: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}
.search-item:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow);
}
.search-item strong {
    color: var(--primary);
    font-size: 1.1rem;
}
.search-item p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

/* CADD Codes - Chip interattivi (altamente visibili e invitanti al click) */
.cadd-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 700;
    font-size: 0.82rem;
    color: #ffffff;
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    padding: 4px 10px;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    box-shadow: 0 1px 3px rgba(124, 58, 237, 0.3);
    animation: cadd-pulse 2s ease-in-out 0.5s 2;
    vertical-align: middle;
    margin: 2px 2px;
}

.cadd-link::after {
    content: ' ▸';
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.cadd-link.expanded::after {
    content: ' ▾';
}

.cadd-link:hover {
    background: linear-gradient(135deg, #6d28d9, #5b21b6);
    transform: scale(1.05);
    box-shadow: 0 3px 8px rgba(124, 58, 237, 0.4);
}

.cadd-link:active {
    transform: scale(0.97);
}

@keyframes cadd-pulse {
    0%, 100% { box-shadow: 0 1px 3px rgba(124, 58, 237, 0.3); }
    50% { box-shadow: 0 2px 12px rgba(124, 58, 237, 0.6); }
}

.cadd-hint {
    font-size: 0.7rem;
    color: #9ca3af;
    font-style: italic;
    margin-left: 4px;
    vertical-align: middle;
}

.cadd-expanded {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    padding: 0.7rem 0.9rem;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #ddd6fe;
    border-left: 3px solid #7c3aed;
    border-radius: 8px;
    font-size: 0.8rem;
    line-height: 1.6;
    color: #374151;
    animation: cadd-slide-in 0.25s ease-out;
}

@keyframes cadd-slide-in {
    from { opacity: 0; max-height: 0; transform: translateY(-6px); }
    to { opacity: 1; max-height: 500px; transform: translateY(0); }
}

@media (max-width: 768px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .search-input-wrapper { flex-direction: column; }
    .search-input-wrapper .btn-primary { width: 100%; }
}

/* AI Analysis Tab Styles */
.main-tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--border-color);
}
.main-tab-btn {
    background: none;
    border: none;
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
}
.main-tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.main-tab-content {
    display: none;
}
.main-tab-content.active {
    display: block;
}

.credit-widget {
    background-color: var(--primary);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.upload-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
}
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}
.cost-estimator {
    padding: 1rem;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius);
    color: var(--accent-yellow);
    font-weight: 600;
    margin: 1rem 0;
}

.jobs-table {
    width: 100%;
    border-collapse: collapse;
}
.jobs-table th, .jobs-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
.jobs-table th {
    background: var(--bg-body);
    font-weight: 600;
}

/* Side by Side Review */
.review-container {
    display: flex;
    gap: 2rem;
    margin-top: 2rem;
}
.review-image-pane {
    flex: 1.6;
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}
.review-image-pane img {
    width: 100%;
    height: auto;
    display: block;
}
.review-form-pane {
    flex: 1;
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}
.bounding-box {
    border: 2px solid #e74c3c;
    background-color: rgba(231, 76, 60, 0.15);
    position: absolute;
    pointer-events: none;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.5);
}
.uncertain-field-group {
    margin-bottom: 1rem;
    padding: 1rem;
    background: rgba(239, 68, 68, 0.05);
    border-left: 4px solid var(--accent-red);
    border-radius: 4px;
}
.status-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: bold;
}
.status-pending { background: #f3f4f6; color: #4b5563; }
.status-review { background: #fef3c7; color: #b45309; }
.status-completed { background: #d1fae5; color: #065f46; }

/* Slot Flow Styles */
.slots-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}
.slot-item {
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: var(--radius);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-body);
    transition: box-shadow 0.2s;
}
.slot-item:hover {
    box-shadow: var(--shadow);
}
.slot-item strong {
    color: var(--primary);
}
