/* ============================================
   RIPARTITORI - Sostituzione Ripartitori
   Prefix: .rip-
   ============================================ */

/* --- KPI Dashboard --- */
.rip-kpi-strip {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 12px;
    background: hsl(var(--card));
    border-radius: 8px;
    border: 1px solid hsl(var(--border));
}
.rip-kpi-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 14px;
    border-radius: 6px;
    min-width: 80px;
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid transparent;
}
.rip-kpi-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.rip-kpi-card.active {
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 2px hsl(var(--primary) / 0.2);
}
.rip-kpi-value {
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
}
.rip-kpi-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-top: 4px;
    text-align: center;
    white-space: nowrap;
}

/* KPI color variants */
.rip-kpi-card[data-filter="all"] { background: hsl(var(--muted)); }
.rip-kpi-card[data-filter="IN ATTESA"] { background: #fef3c7; }
.rip-kpi-card[data-filter="PROGRAMMATO"] { background: #dbeafe; }
.rip-kpi-card[data-filter="IN LAVORAZIONE"] { background: #fed7aa; }
.rip-kpi-card[data-filter="TERMINATO NON COMPLETO"] { background: #e9d5ff; }
.rip-kpi-card[data-filter="TERMINATO COMPLETO"] { background: #bbf7d0; }
.rip-kpi-card[data-filter="SOSTITUZIONE GUAZZOTTI"] { background: #fce7f3; }
.rip-kpi-card[data-filter="CHIUSI"] { background: #d1d5db; }

/* --- Badge colori fasi --- */
.rip-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.rip-badge-attesa { background: #fef3c7; color: #92400e; }
.rip-badge-programmato { background: #dbeafe; color: #1e40af; }
.rip-badge-lavorazione { background: #fed7aa; color: #9a3412; }
.rip-badge-terminato-nc { background: #e9d5ff; color: #6b21a8; }
.rip-badge-terminato-c { background: #bbf7d0; color: #166534; }
.rip-badge-guazzotti { background: #fce7f3; color: #9d174d; }
.rip-badge-chiuso { background: #d1d5db; color: #374151; }

/* Badge stati commerciali */
.rip-badge-prev { background: #fef3c7; color: #92400e; }
.rip-badge-rdo-inv { background: #dbeafe; color: #1e40af; }
.rip-badge-rdo-acc { background: #bae6fd; color: #0369a1; }
.rip-badge-fatturaz { background: #d9f99d; color: #3f6212; }
.rip-badge-fatt-parz { background: #fed7aa; color: #9a3412; }
.rip-badge-fatt-tot { background: #bbf7d0; color: #166534; }
.rip-badge-pag-nc { background: #e9d5ff; color: #6b21a8; }
.rip-badge-pag-c { background: #d1d5db; color: #374151; }

/* Badge fornitori */
.rip-badge-ista { background: #fee2e2; color: #991b1b; }
.rip-badge-energreen { background: #d9f99d; color: #3f6212; }
.rip-badge-acg { background: #bae6fd; color: #0369a1; }

/* --- Toolbar --- */
.rip-toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.rip-search {
    flex: 1;
    min-width: 200px;
    padding: 8px 12px;
    border: 1px solid hsl(var(--border));
    border-radius: 6px;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    font-size: 13px;
}
.rip-select {
    padding: 8px 12px;
    border: 1px solid hsl(var(--border));
    border-radius: 6px;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    font-size: 13px;
    cursor: pointer;
}
.rip-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid hsl(var(--border));
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.rip-btn:hover { background: hsl(var(--muted)); }
.rip-btn-primary {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border-color: hsl(var(--primary));
}
.rip-btn-primary:hover { opacity: 0.9; }
.rip-btn-danger {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
}
.rip-btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

/* --- Tabella principale --- */
.rip-table-container {
    overflow-x: auto;
    border: 1px solid hsl(var(--border));
    border-radius: 8px;
}
.rip-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.rip-table th {
    background: hsl(var(--muted));
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: hsl(var(--muted-foreground));
    border-bottom: 1px solid hsl(var(--border));
    white-space: nowrap;
}
.rip-table td {
    padding: 8px 12px;
    border-bottom: 1px solid hsl(var(--border));
    vertical-align: middle;
}
.rip-table tr:hover { background: hsl(var(--muted) / 0.5); }
.rip-table tr { cursor: pointer; }
.rip-table-name {
    font-weight: 500;
    color: hsl(var(--foreground));
}

/* --- Modal dettaglio --- */
.rip-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
    overflow-y: auto;
}
.rip-modal-overlay.active { display: flex; }
.rip-modal {
    background: hsl(var(--card));
    border-radius: 12px;
    width: 100%;
    max-width: 1000px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    margin-top: 20px;
}
.rip-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px 24px 12px;
    border-bottom: 1px solid hsl(var(--border));
}
.rip-modal-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
}
.rip-modal-subtitle {
    font-size: 12px;
    color: hsl(var(--muted-foreground));
    margin-top: 2px;
}
.rip-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: hsl(var(--muted-foreground));
    padding: 0 4px;
    line-height: 1;
}
.rip-modal-close:hover { color: hsl(var(--foreground)); }

/* Tabs */
.rip-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid hsl(var(--border));
    padding: 0 24px;
    overflow-x: auto;
    flex-shrink: 0;
}
.rip-tab {
    padding: 10px 16px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: none;
    color: hsl(var(--muted-foreground));
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: all 0.15s;
}
.rip-tab:hover { color: hsl(var(--foreground)); }
.rip-tab.active {
    color: hsl(var(--primary));
    border-bottom-color: hsl(var(--primary));
    font-weight: 600;
}
.rip-tab-content {
    display: none;
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}
.rip-tab-content.active { display: block; }

/* --- Economico --- */
.rip-eco-section {
    margin-bottom: 20px;
}
.rip-eco-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.rip-eco-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-bottom: 8px;
}
.rip-eco-table th {
    background: hsl(var(--muted));
    padding: 6px 8px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    border-bottom: 1px solid hsl(var(--border));
}
.rip-eco-table td {
    padding: 6px 8px;
    border-bottom: 1px solid hsl(var(--border));
}
.rip-eco-table input {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid hsl(var(--border));
    border-radius: 4px;
    font-size: 12px;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
}
.rip-eco-total {
    text-align: right;
    font-weight: 600;
    font-size: 13px;
    padding: 6px 0;
}

/* --- Metriche finanziarie --- */
.rip-metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.rip-metric-card {
    padding: 14px;
    border-radius: 8px;
    border: 1px solid hsl(var(--border));
    background: hsl(var(--card));
}
.rip-metric-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: hsl(var(--muted-foreground));
    margin-bottom: 4px;
}
.rip-metric-value {
    font-size: 24px;
    font-weight: 700;
}
.rip-metric-unit {
    font-size: 12px;
    color: hsl(var(--muted-foreground));
}

/* --- Avanzamento --- */
.rip-progress-box {
    padding: 14px;
    border-radius: 8px;
    border: 1px solid hsl(var(--border));
    margin-bottom: 12px;
}
.rip-progress-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}
.rip-progress-item label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: hsl(var(--muted-foreground));
    margin-bottom: 2px;
}
.rip-progress-item input,
.rip-progress-item select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid hsl(var(--border));
    border-radius: 4px;
    font-size: 13px;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
}

/* --- Tabella appartamenti (passaggi) --- */
.rip-apt-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.rip-apt-table th {
    background: hsl(var(--muted));
    padding: 6px 6px;
    text-align: left;
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    border-bottom: 1px solid hsl(var(--border));
    white-space: nowrap;
}
.rip-apt-table td {
    padding: 4px 6px;
    border-bottom: 1px solid hsl(var(--border));
}
.rip-apt-table td input[type="text"],
.rip-apt-table td input[type="number"] {
    width: 100%;
    padding: 3px 5px;
    border: 1px solid transparent;
    border-radius: 3px;
    font-size: 12px;
    background: transparent;
    color: hsl(var(--foreground));
}
.rip-apt-table td input:focus {
    border-color: hsl(var(--primary));
    background: hsl(var(--background));
    outline: none;
}
.rip-apt-table tr.rip-apt-completed { opacity: 0.6; }
.rip-apt-table tr.rip-apt-skip { opacity: 0.4; text-decoration: line-through; }

/* --- Allegati --- */
.rip-allegati-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 10px;
    margin-top: 10px;
}
.rip-allegato-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid hsl(var(--border));
    border-radius: 6px;
    background: hsl(var(--background));
    font-size: 12px;
}
.rip-allegato-item a {
    flex: 1;
    color: hsl(var(--primary));
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rip-allegato-item a:hover { text-decoration: underline; }
.rip-allegato-delete {
    cursor: pointer;
    color: hsl(var(--muted-foreground));
    font-size: 16px;
    padding: 2px;
}
.rip-allegato-delete:hover { color: #ef4444; }
.rip-drop-zone {
    border: 2px dashed hsl(var(--border));
    border-radius: 8px;
    padding: 24px;
    text-align: center;
    color: hsl(var(--muted-foreground));
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}
.rip-drop-zone:hover,
.rip-drop-zone.dragover {
    border-color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.05);
    color: hsl(var(--primary));
}

/* --- Import modal --- */
.rip-import-area {
    width: 100%;
    min-height: 150px;
    padding: 12px;
    border: 1px solid hsl(var(--border));
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    resize: vertical;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
}
.rip-import-preview {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid hsl(var(--border));
    border-radius: 6px;
    margin-top: 10px;
}

/* --- Note textarea --- */
.rip-notes-area {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    border: 1px solid hsl(var(--border));
    border-radius: 6px;
    font-size: 13px;
    resize: vertical;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    line-height: 1.5;
}

/* --- Dati condominio --- */
.rip-cond-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}
.rip-cond-field label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: hsl(var(--muted-foreground));
    margin-bottom: 2px;
}
.rip-cond-field input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid hsl(var(--border));
    border-radius: 4px;
    font-size: 13px;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
}

/* --- Phase Group Headers in Table --- */
.rip-fase-group-header td {
    background: hsl(var(--muted) / 0.6);
    font-weight: 700;
    font-size: 12px;
    padding: 8px 12px;
    border-bottom: 2px solid hsl(var(--border));
    cursor: default;
    color: hsl(var(--foreground));
    letter-spacing: 0.3px;
}
.rip-fase-group-header:hover { background: hsl(var(--muted) / 0.6) !important; }

/* Inline dropdowns in table rows */
.rip-table td select.rip-inline-select {
    padding: 3px 6px;
    border: 1px solid transparent;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    background: transparent;
    color: inherit;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    max-width: 140px;
}
.rip-table td select.rip-inline-select:hover {
    border-color: hsl(var(--border));
    background: hsl(var(--background));
}
.rip-table td select.rip-inline-select:focus {
    border-color: hsl(var(--primary));
    background: hsl(var(--background));
    outline: none;
    appearance: auto;
    -webkit-appearance: auto;
}

/* --- Progress badges inline --- */
.rip-progress-badges {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
}
.rip-mini-badge {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.2px;
    white-space: nowrap;
}
.rip-mini-badge-def { background: #bbf7d0; color: #166534; }
.rip-mini-badge-pres { background: #fef3c7; color: #92400e; }
.rip-mini-badge-compl { background: #dbeafe; color: #1e40af; }

/* --- Discrepancy modal --- */
.rip-discrepancy-item {
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 8px;
    border-left: 3px solid;
    font-size: 13px;
}
.rip-discrepancy-warning {
    background: #fffbeb;
    border-color: #f59e0b;
}
.rip-discrepancy-error {
    background: #fef2f2;
    border-color: #ef4444;
}
.rip-discrepancy-item b { font-weight: 600; }
.rip-discrepancy-category {
    font-size: 13px;
    font-weight: 700;
    margin: 16px 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid hsl(var(--border));
}

/* --- Import wizard 2-step --- */
.rip-import-step { display: block; }
.rip-import-step.hidden { display: none; }
.rip-mapping-select {
    padding: 3px 6px;
    border: 1px solid hsl(var(--border));
    border-radius: 4px;
    font-size: 11px;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    min-width: 80px;
}

/* --- SVG Chart container --- */
.rip-chart-container {
    width: 100%;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid hsl(var(--border));
    border-radius: 8px;
    padding: 12px;
    background: hsl(var(--card));
}
.rip-chart-container svg {
    display: block;
    margin: 0 auto;
}

/* --- datiPresunti highlight --- */
.rip-apt-table tr.rip-apt-presunti {
    background: #fff8e1;
}
.rip-apt-table tr.rip-apt-presunti td {
    background: transparent;
}
.rip-presunti-indicator {
    display: inline-block;
    font-size: 10px;
    color: #f59e0b;
    margin-left: 2px;
}

/* --- RDO color-coded box --- */
.rip-rdo-definitivo {
    background: #e8f5e9 !important;
    border-color: #4caf50 !important;
}
.rip-rdo-definitivo select {
    color: #2e7d32;
    font-weight: 700;
}
.rip-rdo-presunto {
    background: #fffde7 !important;
    border-color: #fbc02d !important;
}
.rip-rdo-presunto select {
    color: #f57f17;
    font-weight: 700;
}

/* --- Allegati categorizzati --- */
.rip-allegati-category {
    margin-bottom: 16px;
}
.rip-allegati-category-title {
    font-size: 12px;
    font-weight: 700;
    color: hsl(var(--muted-foreground));
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid hsl(var(--border));
}
.rip-section-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    border: 1px solid hsl(var(--border));
    border-radius: 4px;
    background: hsl(var(--background));
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    margin-left: 8px;
}
.rip-section-upload-btn:hover {
    border-color: hsl(var(--primary));
    color: hsl(var(--primary));
}

/* --- Passaggi riepilogo table --- */
.rip-passaggi-summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 8px;
}
.rip-passaggi-summary-table th {
    background: hsl(var(--muted) / 0.5);
    padding: 6px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    border-bottom: 1px solid hsl(var(--border));
}
.rip-passaggi-summary-table td {
    padding: 6px 10px;
    border-bottom: 1px solid hsl(var(--border));
}
.rip-passaggi-esito-completato { color: #16a34a; font-weight: 600; }
.rip-passaggi-esito-parziale { color: #f59e0b; font-weight: 600; }
.rip-passaggi-esito-fallito { color: #ef4444; font-weight: 600; }
.rip-passaggi-esito-ricevuto { color: #3b82f6; font-weight: 600; }
.rip-passaggi-esito-nonricevuto { color: #6b7280; font-weight: 600; }
.rip-passaggi-esito-inattesa { color: #8b5cf6; font-weight: 600; }

/* --- ASSENTE indicator --- */
.rip-apt-assente {
    background: #fef2f2 !important;
}
.rip-apt-assente td { background: transparent; }

/* --- Split payment fields --- */
.rip-eco-table td.rip-split-cell {
    background: hsl(var(--muted) / 0.2);
}

/* --- Semaforo "Pronto per Lavori" --- */
.rip-semaforo-box {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid hsl(var(--border));
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.rip-semaforo-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}
.rip-semaforo-label {
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    color: hsl(var(--muted-foreground));
}
.rip-semaforo-light {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}
.rip-semaforo-green {
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
}
.rip-semaforo-red {
    background: #ef4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}
.rip-semaforo-text {
    font-weight: 600;
    font-size: 13px;
    margin-left: auto;
}
.rip-semaforo-text.ready { color: #16a34a; }
.rip-semaforo-text.waiting { color: #dc2626; }

/* Semaforo stato badges */
.rip-stato-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.rip-stato-badge-da-preparare { background: #f3f4f6; color: #6b7280; }
.rip-stato-badge-inviato { background: #dbeafe; color: #1e40af; }
.rip-stato-badge-accettato { background: #bbf7d0; color: #166534; }
.rip-stato-badge-rifiutato { background: #fee2e2; color: #991b1b; }
.rip-stato-badge-da-richiedere { background: #f3f4f6; color: #6b7280; }
.rip-stato-badge-richiesta { background: #fef3c7; color: #92400e; }
.rip-stato-badge-arrivata { background: #dbeafe; color: #1e40af; }
.rip-stato-badge-accettata { background: #bbf7d0; color: #166534; }

/* --- Warning banner --- */
.rip-warning-banner {
    background: #fffbeb;
    border: 1px solid #f59e0b;
    border-left: 4px solid #f59e0b;
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 13px;
    color: #92400e;
}
.rip-warning-banner strong { color: #78350f; }
.rip-warning-banner ul { margin: 4px 0 0; padding-left: 20px; }
.rip-warning-banner li { margin-bottom: 2px; }

/* --- Eco section subtitle note --- */
.rip-eco-note {
    font-size: 11px;
    color: hsl(var(--muted-foreground));
    font-weight: 400;
    margin-left: 8px;
    font-style: italic;
}

/* --- Report stampa --- */
@media print {
    .rip-no-print { display: none !important; }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .rip-kpi-strip { gap: 4px; }
    .rip-kpi-card { min-width: 60px; padding: 6px 8px; }
    .rip-kpi-value { font-size: 18px; }
    .rip-modal { max-width: 100%; margin-top: 10px; }
    .rip-tabs { gap: 0; }
    .rip-tab { padding: 8px 10px; font-size: 11px; }
    .rip-cond-grid { grid-template-columns: 1fr; }
    .rip-metric-grid { grid-template-columns: 1fr 1fr; }
    .rip-fase-group-header td { font-size: 11px; padding: 6px 8px; }
    .rip-inline-select { font-size: 10px; }
}
