/* Shared ticket preview/detail styles (migrated from `Preview.razor` and `Details.razor`) */

.preview-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

.modern-preview-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
    width: 100%;
    box-sizing: border-box;
}

/* Allow more columns / width on large displays */
@media (min-width: 1400px) {
    .modern-preview-container {
        max-width: 1600px;
    }

    .info-grid {
        grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    }
}

/* Header Card - Simplified */
.preview-header-card {
    background: var(--crm-surface-muted);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    box-sizing: border-box;
}

.header-content {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.ticket-number {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--crm-text-secondary);
}

.ticket-number .material-icons {
    font-size: 1.5rem;
    color: var(--crm-text-muted);
}

.ticket-number h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    word-break: break-word;
    color: var(--crm-text);
}

.ticket-status {
    padding: 0.5rem 1.25rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
}

.status-text {
    font-weight: 600;
    font-size: 0.95rem;
    word-break: break-word;
}

/* Description Card - Simplified */
.description-card {
    background: var(--crm-surface);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    margin-bottom: 1.5rem;
    overflow: hidden;
    box-sizing: border-box;
}

.card-header-modern {
    background: var(--crm-surface-muted);
    border-bottom: 1px solid var(--crm-border);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.card-header-modern .material-icons {
    color: var(--crm-text-muted);
    font-size: 1.5rem;
}

.card-header-modern h5 {
    margin: 0;
    color: var(--crm-text-secondary);
    font-weight: 600;
}

.card-body-modern {
    padding: 1.5rem;
    box-sizing: border-box;
}

.description-text {
    margin: 0;
    color: var(--crm-text-secondary);
    font-size: 1rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Info Grid - Simplified */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    width: 100%;
    box-sizing: border-box;
}

.info-card {
    background: var(--crm-surface);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    overflow: hidden;
    box-sizing: border-box;
    min-width: 0;
}

.info-card-header {
    background: var(--crm-surface-muted);
    border-bottom: 1px solid var(--crm-border);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.info-card-header .material-icons {
    color: var(--crm-text-muted);
    font-size: 1.25rem;
}

.info-label {
    font-weight: 600;
    color: var(--crm-text-secondary);
    font-size: 0.95rem;
}

.info-card-body {
    padding: 1.25rem;
    box-sizing: border-box;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--crm-border);
    gap: 1rem;
    min-width: 0;
}

.info-row:last-child {
    border-bottom: none;
}

.info-key {
    color: var(--crm-text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    word-break: break-word;
    min-width: 0;
}

/* Alcune etichette arrivano come .label-floating (16px): qui devono avere la
   stessa misura delle altre chiavi della scheda. */
.info-key .label-floating,
.assigned-label .label-floating {
    color: inherit;
    font-size: inherit;
    font-weight: inherit;
}

.info-value {
    color: var(--crm-text);
    font-weight: 500;
    text-align: right;
    word-break: break-word;
    min-width: 0;
}

.company-name {
    color: var(--crm-primary);
}

.time-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--crm-primary-soft);
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    color: var(--crm-primary) !important;
}

.time-badge .material-icons {
    font-size: 1rem;
}

/* Users Card */
.users-card {
    grid-column: 1 / -1;
}

.user-badge-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.user-avatar-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--crm-text-muted);
    color: #fff;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 600;
    flex-shrink: 0;
}

.assigned-users-section {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--crm-border);
}

.assigned-header {
    margin-bottom: 1rem;
}

.assigned-label {
    font-weight: 600;
    color: var(--crm-text-secondary);
    font-size: 0.95rem;
}

.assigned-users-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.assigned-user-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--crm-surface-muted);
    border-radius: 6px;
}

.assigned-user-item.main-user {
    background: var(--crm-primary-soft);
    border-left: 3px solid var(--crm-primary);
}

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--crm-text-muted);
    color: #fff;
    border-radius: 50%;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

.assigned-user-item.main-user .user-avatar {
    background: var(--crm-primary);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
}

.user-name {
    color: var(--crm-text-secondary);
    font-weight: 500;
    word-break: break-word;
    min-width: 0;
}

.main-badge {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--crm-primary);
    background: var(--crm-primary-soft);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    flex-shrink: 0;
}

.no-users {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2rem;
    color: var(--crm-text-muted);
}

.no-users .material-icons {
    font-size: 2rem;
}

/* Legacy badges (kept for compatibility) */
.assigned-users-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.user-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--crm-text-muted);
    border-radius: 6px;
    color: white;
    font-size: 0.9rem;
}

.user-badge .user-avatar {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.badge-primary-indicator {
    color: var(--crm-warning);
    font-size: 1rem;
    margin-left: 0.25rem;
}

/* Details-only overrides */
.ticket-details-page .modern-preview-container {
    max-width: 100%;
    margin: 0;
    margin-left: 0;
    padding-left: 0;
}

.ticket-details-page .info-grid {
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
}

.ticket-details-page .info-row {
    justify-content: flex-start;
    align-items: flex-start;
}

/* L'etichetta prende lo spazio che le serve, non 220px fissi.
   Con 220px fissi, in una scheda da 480px al valore ne restavano altrettanti: nomi come
   "DIGITECH SOLUZIONI di ZAVOLI DENNIS" si spezzavano su tre righe e la scheda diventava
   altissima. Il minimo tiene le etichette incolonnate fra loro; niente tetto in percentuale,
   perche' con quello un'etichetta lunga come "Ore fatturabili (hh:mm)" andava a capo dentro una
   scheda quasi vuota. */
.ticket-details-page .info-key {
    flex: 0 0 auto;
    min-width: 8rem;
    padding-right: 1rem;
    white-space: nowrap;
}

.ticket-details-page .info-value {
    flex: 1 1 auto;
    text-align: left;
}

/* L'anteprima segue la scheda completa: stessa etichetta, stesso allineamento.
   Senza queste, nel dialogo l'etichetta non aveva una larghezza minima e parole come "Prodotto"
   si spezzavano a meta' ("Prodott / o"), e i valori restavano incolonnati a destra mentre nella
   scheda stanno a sinistra. */
.ticket-preview-dialog .info-key {
    flex: 0 0 auto;
    min-width: 8rem;
    padding-right: 1rem;
    white-space: nowrap;
}

.ticket-preview-dialog .info-value {
    flex: 1 1 auto;
    text-align: left;
}

/* Anche la scheda della commessa usa lo stesso modello: prima erano riquadri Bootstrap generici,
   diversi da tutto il resto dell'applicazione. */
.commessa-details-page .info-key {
    flex: 0 0 auto;
    min-width: 9rem;
    padding-right: 1rem;
    white-space: nowrap;
}

.commessa-details-page .info-value {
    flex: 1 1 auto;
    text-align: left;
}

/* Una data o un numero fuori tempo. */
.commessa-details-page .value-late {
    color: var(--crm-danger);
    font-weight: 700;
}

/* Avanzamento, stato e comandi in colonna, a destra del titolo. */
.commessa-azioni {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 260px;
}

.ticket-details-page .assigned-user-item .user-avatar {
    background: var(--crm-text-muted);
    color: #fff;
}

.ticket-details-page .assigned-user-item.main-user .user-avatar {
    background: var(--crm-primary);
}

/* Responsive */
@media (max-width: 768px) {
    .modern-preview-container {
        padding: 1rem;
    }

    .preview-header-card {
        padding: 1rem 1.25rem;
    }

    .ticket-number h3 {
        font-size: 1.5rem;
    }

    .info-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .ticket-details-page .info-grid {
        grid-template-columns: 1fr;
    }

    .info-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .info-value {
        text-align: left;
        width: 100%;
    }

    .ticket-details-page .info-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .ticket-details-page .info-key {
        flex: 0 0 auto;
        width: 100%;
    }

    .ticket-details-page .info-value {
        width: 100%;
    }
}

@media (max-width: 576px) {
    .user-badge {
        flex: 1 1 100%;
        justify-content: space-between;
    }

    .modern-preview-container {
        padding: 0.75rem;
    }

    .preview-header-card {
        padding: 0.75rem 1rem;
    }

    .ticket-number h3 {
        font-size: 1.25rem;
    }

    .ticket-number .material-icons {
        font-size: 1.5rem;
    }

    .status-text {
        font-size: 1rem;
    }

    .info-card-body {
        padding: 1rem;
    }

    .card-body-modern {
        padding: 1rem;
    }

    .info-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .ticket-details-page .info-grid {
        grid-template-columns: 1fr;
    }

    .info-card {
        min-width: 0;
        width: 100%;
    }
}
