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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f7fa;
    color: #333;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container { max-width: 1400px; margin: 0 auto; padding: 0 20px; width: 100%; }

header {
    background: linear-gradient(135deg, #1a3a5c 0%, #2c5f8a 100%);
    color: white;
    padding: 24px 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
header h1 { font-size: 1.8rem; font-weight: 700; }
header .subtitle { font-size: 0.95rem; opacity: 0.85; margin-top: 4px; }

main { flex: 1; padding: 20px 0; }

/* Stats */
.stats-bar {
    display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.stat-item {
    background: white; border-radius: 8px; padding: 16px 24px;
    flex: 1; min-width: 160px; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    display: flex; flex-direction: column; align-items: center;
}
.stat-value { font-size: 1.8rem; font-weight: 700; color: #1a3a5c; }
.stat-label { font-size: 0.8rem; color: #666; margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }

/* Search */
.search-section {
    background: white; border-radius: 8px; padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08); margin-bottom: 20px;
}
.search-bar { display: flex; gap: 10px; margin-bottom: 12px; }
.search-bar input {
    flex: 1; padding: 12px 16px; border: 2px solid #e0e4e8; border-radius: 6px;
    font-size: 1rem; transition: border-color 0.2s;
}
.search-bar input:focus { outline: none; border-color: #2c5f8a; }
.search-bar button {
    padding: 12px 32px; background: #1a3a5c; color: white; border: none;
    border-radius: 6px; font-size: 1rem; cursor: pointer; font-weight: 600;
    transition: background 0.2s;
}
.search-bar button:hover { background: #2c5f8a; }

.filters {
    display: flex; gap: 10px; flex-wrap: wrap;
}
.filters select, .filters input {
    padding: 8px 12px; border: 1px solid #e0e4e8; border-radius: 4px;
    font-size: 0.85rem; background: white; min-width: 140px;
}
.filters select:focus, .filters input:focus { outline: none; border-color: #2c5f8a; }

/* Results */
.results-section {
    background: white; border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08); overflow: hidden;
}
.results-header {
    padding: 14px 20px; border-bottom: 1px solid #e0e4e8;
    font-size: 0.9rem; color: #666;
}
#results-table { width: 100%; border-collapse: collapse; }
#results-table thead { background: #f8f9fb; }
#results-table th {
    padding: 10px 14px; text-align: left; font-size: 0.8rem;
    text-transform: uppercase; letter-spacing: 0.5px; color: #666;
    border-bottom: 2px solid #e0e4e8; white-space: nowrap;
}
#results-table td {
    padding: 10px 14px; border-bottom: 1px solid #f0f2f5;
    font-size: 0.88rem; vertical-align: top;
}
#results-table tbody tr { cursor: pointer; transition: background 0.15s; }
#results-table tbody tr:hover { background: #f0f5ff; }

.td-oggetto { max-width: 400px; }
.td-struttura { max-width: 200px; font-size: 0.8rem; color: #666; }

.badge {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.badge-E { background: #e3f2fd; color: #1565c0; }
.badge-G { background: #fce4ec; color: #c62828; }
.badge-A { background: #fff3e0; color: #e65100; }
.badge-D { background: #e8f5e9; color: #2e7d32; }
.badge-S { background: #f3e5f5; color: #7b1fa2; }
.badge-P { background: #fff8e1; color: #f57f17; }

.badge-fonte { font-size: 0.7rem; padding: 2px 6px; }
.badge-nuovo { background: #e8f5e9; color: #2e7d32; }
.badge-vecchio { background: #fff3e0; color: #e65100; }

.pdf-link {
    color: #c62828; text-decoration: none; font-weight: 600; font-size: 0.85rem;
}
.pdf-link:hover { text-decoration: underline; }
.no-pdf { color: #ccc; font-size: 0.8rem; }

/* Pagination */
.pagination {
    display: flex; justify-content: center; gap: 4px; padding: 16px;
}
.pagination button {
    padding: 6px 12px; border: 1px solid #e0e4e8; background: white;
    border-radius: 4px; cursor: pointer; font-size: 0.85rem;
}
.pagination button:hover { background: #f0f5ff; }
.pagination button.active { background: #1a3a5c; color: white; border-color: #1a3a5c; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Tabs */
.tabs {
    display: flex; gap: 0; margin-bottom: 20px; background: white;
    border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.tab {
    flex: 1; padding: 14px 20px; border: none; background: white;
    font-size: 0.95rem; font-weight: 600; color: #666; cursor: pointer;
    transition: all 0.2s; border-bottom: 3px solid transparent;
}
.tab:hover { background: #f8f9fb; color: #1a3a5c; }
.tab.active { color: #1a3a5c; border-bottom-color: #1a3a5c; background: #f0f5ff; }

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

/* Cards */
.card {
    background: white; border-radius: 8px; padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08); margin-bottom: 20px;
}
.card-title {
    font-size: 1.1rem; font-weight: 700; color: #1a3a5c;
    margin-bottom: 16px; padding-bottom: 8px; border-bottom: 2px solid #e0e4e8;
}

/* Stats grid */
.stats-grid { display: flex; gap: 12px; flex-wrap: wrap; }
.stats-grid-item {
    background: #f8f9fb; border-radius: 6px; padding: 12px 16px;
    min-width: 140px; flex: 1; text-align: center;
}
.stats-grid-item .sg-value { font-size: 1.4rem; font-weight: 700; color: #1a3a5c; }
.stats-grid-item .sg-label { font-size: 0.8rem; color: #666; margin-top: 2px; }

/* Mini tables */
.mini-table { width: 100%; border-collapse: collapse; }
.mini-table thead { background: #f8f9fb; }
.mini-table th {
    padding: 8px 12px; text-align: left; font-size: 0.75rem;
    text-transform: uppercase; letter-spacing: 0.5px; color: #666;
    border-bottom: 2px solid #e0e4e8; white-space: nowrap;
}
.mini-table td {
    padding: 8px 12px; border-bottom: 1px solid #f0f2f5;
    font-size: 0.82rem; vertical-align: top;
}
.mini-table tbody tr:hover { background: #f8f9fb; }

.stato-running { color: #e65100; font-weight: 600; }
.stato-completed { color: #2e7d32; font-weight: 600; }

/* Modal */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
}
.modal-content {
    background: white; border-radius: 12px; padding: 32px;
    max-width: 800px; width: 90%; max-height: 85vh; overflow-y: auto;
    position: relative;
}
.modal-close {
    position: absolute; top: 12px; right: 16px; font-size: 1.5rem;
    background: none; border: none; cursor: pointer; color: #999;
}
.modal-close:hover { color: #333; }
.modal-field { margin-bottom: 12px; }
.modal-field-label { font-size: 0.8rem; color: #666; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 2px; }
.modal-field-value { font-size: 0.95rem; }
.modal-oggetto { font-size: 1.1rem; font-weight: 600; line-height: 1.4; margin-bottom: 16px; }
.modal-testo { background: #f8f9fb; padding: 16px; border-radius: 6px; font-size: 0.85rem; line-height: 1.5; max-height: 300px; overflow-y: auto; white-space: pre-wrap; }
.modal-allegati { margin-top: 16px; }
.modal-allegati h4 { font-size: 0.9rem; margin-bottom: 8px; }
.modal-allegati a { display: block; color: #1a3a5c; margin-bottom: 4px; font-size: 0.85rem; }

/* Auth area */
.header-flex { display: flex; justify-content: space-between; align-items: center; }
.auth-area { display: flex; align-items: center; gap: 10px; }
.auth-btn {
    padding: 6px 16px; border: 1px solid rgba(255,255,255,0.4); border-radius: 4px;
    color: white; text-decoration: none; font-size: 0.85rem; cursor: pointer;
    background: transparent; transition: background 0.2s;
}
.auth-btn:hover { background: rgba(255,255,255,0.15); }
.auth-btn-logout { border-color: rgba(255,100,100,0.5); }
.user-email { color: rgba(255,255,255,0.8); font-size: 0.85rem; }

/* Tags */
.tag {
    display: inline-block; padding: 2px 8px; border-radius: 3px;
    font-size: 0.7rem; font-weight: 600; margin: 1px 2px; cursor: pointer;
    transition: opacity 0.2s; text-transform: lowercase;
}
.tag:hover { opacity: 0.8; }
.tag-bando { background: #e3f2fd; color: #1565c0; }
.tag-avviso { background: #fff3e0; color: #e65100; }
.tag-manifestazione { background: #f3e5f5; color: #7b1fa2; }
.tag-concorso { background: #e8f5e9; color: #2e7d32; }
.tag-contributo { background: #fce4ec; color: #c62828; }
.tag-appalto { background: #e0f7fa; color: #00838f; }
.tag-delibera { background: #fce4ec; color: #c62828; }
.tag-decreto { background: #e3f2fd; color: #1565c0; }
.tag-determina { background: #e8f5e9; color: #2e7d32; }
.tag-pnrr { background: #fff8e1; color: #f57f17; }
.tag-default { background: #f0f2f5; color: #555; }

/* Navigation bar */
.nav-bar {
    display: flex; gap: 4px; padding: 8px 0; flex-wrap: wrap; margin-bottom: 16px;
    border-bottom: 2px solid #e0e4e8;
}
.nav-link {
    padding: 8px 16px; border-radius: 6px 6px 0 0; text-decoration: none;
    color: #1a3a5c; font-weight: 600; font-size: 0.85rem;
    transition: background 0.2s; border: 1px solid transparent; border-bottom: none;
}
.nav-link:hover { background: #f0f5ff; }
.nav-link.active { background: white; border-color: #e0e4e8; color: #2c5f8a; }

/* Home grid */
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-top: 16px; }
.home-card {
    background: #f8fafc; border: 1px solid #e0e4e8; border-radius: 8px;
    padding: 20px; text-decoration: none; color: inherit; transition: all 0.2s;
    border-left: 4px solid #1a3a5c;
}
.home-card:hover { box-shadow: 0 3px 12px rgba(0,0,0,0.1); transform: translateY(-2px); }
.home-card h3 { font-size: 1rem; color: #1a3a5c; margin-bottom: 6px; }
.home-card p { font-size: 0.85rem; color: #666; line-height: 1.4; }

/* Breadcrumb */
.breadcrumb { font-size: 0.85rem; color: #888; margin-bottom: 16px; }
.breadcrumb a { color: #2c5f8a; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* Sync buttons */
.sync-buttons { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.sync-btn {
    padding: 10px 18px; border: 1px solid #e0e4e8; background: white;
    border-radius: 6px; font-size: 0.85rem; cursor: pointer; font-weight: 600;
    color: #1a3a5c; transition: all 0.2s;
}
.sync-btn:hover { background: #f0f5ff; border-color: #2c5f8a; }
.sync-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.sync-btn-primary { background: #1a3a5c; color: white; border-color: #1a3a5c; }
.sync-btn-primary:hover { background: #2c5f8a; }
.sync-btn-accent { background: #2e7d32; color: white; border-color: #2e7d32; }
.sync-btn-accent:hover { background: #388e3c; }
.sync-status { font-size: 0.85rem; color: #666; min-height: 24px; }
.sync-status.success { color: #2e7d32; }
.sync-status.error { color: #c62828; }
.sync-status.loading { color: #e65100; }

/* Section titles */
.section-title { font-size: 1.3rem; font-weight: 700; color: #1a3a5c; margin-bottom: 8px; }
.section-desc { color: #666; font-size: 0.9rem; margin-bottom: 20px; }

/* News list */
.news-list { display: flex; flex-direction: column; gap: 12px; }
.news-item {
    background: white; border-radius: 8px; padding: 16px 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08); cursor: pointer;
    transition: box-shadow 0.2s; border-left: 4px solid #1a3a5c;
}
.news-item:hover { box-shadow: 0 3px 12px rgba(0,0,0,0.12); }
.news-item-header { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.news-item-title { font-size: 0.95rem; font-weight: 600; color: #333; line-height: 1.4; }
.news-item-meta { font-size: 0.8rem; color: #888; margin-top: 4px; }

/* Report list */
.report-list { display: flex; flex-direction: column; gap: 16px; }
.report-card {
    background: white; border-radius: 8px; padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08); cursor: pointer;
    transition: box-shadow 0.2s; border-left: 4px solid #2c5f8a;
}
.report-card:hover { box-shadow: 0 3px 12px rgba(0,0,0,0.12); }
.report-card h3 { font-size: 1.1rem; color: #1a3a5c; margin-bottom: 8px; }
.report-card p { font-size: 0.9rem; color: #555; line-height: 1.5; }
.report-card-meta { font-size: 0.8rem; color: #888; margin-top: 8px; }
.report-detail { background: white; border-radius: 8px; padding: 32px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.report-detail h2 { font-size: 1.4rem; color: #1a3a5c; margin-bottom: 12px; }
.report-detail-content { font-size: 0.95rem; line-height: 1.7; color: #333; }
.report-back { color: #2c5f8a; cursor: pointer; font-size: 0.9rem; margin-bottom: 16px; display: inline-block; }
.report-empty { color: #999; font-size: 0.95rem; padding: 40px 0; text-align: center; }

/* Ad banner */
.ad-banner { margin: 24px 0 8px; text-align: center; }
.ad-placeholder {
    background: #f0f2f5; border: 2px dashed #d0d4d8; border-radius: 8px;
    padding: 20px; color: #999; font-size: 0.85rem;
    min-height: 90px; display: flex; align-items: center; justify-content: center;
}

footer {
    background: #1a3a5c; color: rgba(255,255,255,0.7); padding: 16px 0;
    text-align: center; font-size: 0.85rem;
}
footer a { color: rgba(255,255,255,0.9); }

@media (max-width: 768px) {
    .stats-bar { flex-direction: column; }
    .filters { flex-direction: column; }
    .search-bar { flex-direction: column; }
    #results-table th:nth-child(5), #results-table td:nth-child(5) { display: none; }
}
