/* ============================================================
   historypanel.css
   Widget "Storico" dello Smart Panel: unisce Storico portale (audit timeline)
   e Storico ERP (conversazione) con selettore. Stessa cornice grafica degli
   altri widget; larghezza unica --vp-smart-panel-width.
   Le regole trasversali (push/hidden/offset popup) sono in side-rail.css.
   Override scoped sotto .vp-historypanel riorganizzano timeline/chat per
   rientrare nella larghezza fissa (tabelle field-change -> blocco verticale).
   ============================================================ */

.vp-historypanel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 1080;
}

.vp-historypanel {
    position: fixed;
    top: 0;
    right: var(--vp-rail-width, 48px);
    bottom: 0;
    width: 100%;
    max-width: var(--vp-smart-panel-width, 420px);
    background: #ffffff;
    box-shadow: -2px 0 16px rgba(0, 0, 0, 0.18);
    z-index: 1081;
    display: flex;
    flex-direction: column;
}

.vp-historypanel-pinned {
    box-shadow: -2px 0 16px rgba(0, 0, 0, 0.12);
    border-left: 3px solid #0078d4;
}

@keyframes vp-historypanel-slide-in {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.vp-historypanel.vp-historypanel-animate {
    animation: vp-historypanel-slide-in 200ms ease-in-out;
}

.vp-historypanel-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e1e1e1;
}

.vp-historypanel-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.vp-historypanel-actions {
    display: flex;
    gap: 4px;
}

.vp-historypanel-iconbtn {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    background: transparent;
    border: 1px solid transparent;
    color: #555;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.vp-historypanel-iconbtn:hover {
    background: #f3f4f6;
    color: #111;
}

.vp-historypanel-iconbtn.is-active {
    background: #0078d4;
    color: #ffffff;
    border-color: #0078d4;
}

/* Selettore segmentato Portale | ERP */
.vp-historypanel-tabs {
    flex: 0 0 auto;
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    border-bottom: 1px solid #e1e1e1;
}

.vp-historypanel-tab {
    flex: 1 1 0;
    height: 32px;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #374151;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.vp-historypanel-tab:hover {
    background: #f3f4f6;
}

.vp-historypanel-tab.is-active {
    background: #0078d4;
    border-color: #0078d4;
    color: #ffffff;
}

.vp-historypanel-body {
    flex: 1 1 auto;
    overflow: auto;
    min-height: 0;
    padding: 12px;
}

.vp-historypanel-status {
    padding: 24px 16px;
    text-align: center;
    color: #6b7280;
    font-size: 14px;
}

.vp-historypanel-status-error {
    color: #b91c1c;
}

/* ============================================================
   Riorganizzazione per larghezza fissa (420px): override scoped delle
   tabelle field-change a 4 colonne in layout a blocco verticale.
   ============================================================ */

.vp-historypanel .audit-timeline-fields,
.vp-historypanel .erp-conversation-fields {
    display: block;
    width: 100%;
    border: none;
    margin-top: 6px;
}

.vp-historypanel .audit-timeline-fields thead,
.vp-historypanel .erp-conversation-fields thead {
    display: none;
}

.vp-historypanel .audit-timeline-fields tbody,
.vp-historypanel .erp-conversation-fields tbody {
    display: block;
}

.vp-historypanel .audit-timeline-fields tr,
.vp-historypanel .erp-conversation-fields tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
    border-bottom: 1px solid #eef0f2;
}

.vp-historypanel .audit-timeline-fields td,
.vp-historypanel .erp-conversation-fields td {
    display: inline;
    padding: 0;
    border: none;
    font-size: 12px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Nome campo: prima cella a tutta larghezza, in grassetto. */
.vp-historypanel .audit-timeline-fields td:first-child,
.vp-historypanel .erp-conversation-fields td:first-child {
    flex-basis: 100%;
    font-weight: 600;
    color: #374151;
}

/* Valori e freccia: compatti, vanno a capo se troppo lunghi. */
.vp-historypanel .audit-timeline-old-value,
.vp-historypanel .erp-conversation-old-value {
    color: #9ca3af;
}

.vp-historypanel .audit-timeline-new-value,
.vp-historypanel .erp-conversation-new-value {
    color: #111827;
}

/* Card audit e bolle chat: piu' compatte e con wrap nella larghezza fissa. */
.vp-historypanel .audit-timeline-card,
.vp-historypanel .erp-conversation-bubble {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.vp-historypanel .audit-timeline-head,
.vp-historypanel .erp-conversation-meta {
    flex-wrap: wrap;
}

/* ============================================================
   ERP conversation: nel widget (larghezza fissa) il layout originale ha
   min-width:1200px e bolle laterali con padding 50% (pensato per il popup
   largo) -> straborda. Lo ristrutturiamo come LISTA VERTICALE a tutta
   larghezza: niente linea centrale, niente offset laterali, bolle full-width
   colorate per direzione (grigio = ERP, azzurro = Portale). Il pallino sulla
   linea centrale non ha senso senza linea: nascosto (l'esito e' nel badge).
   ============================================================ */
.vp-historypanel .erp-conversation {
    min-width: 0 !important;
    width: 100% !important;
    padding: 0 !important;
    gap: 10px !important;
}

.vp-historypanel .erp-conversation-line {
    display: none !important;
}

.vp-historypanel .erp-conversation-msg {
    display: block !important;
}

.vp-historypanel .erp-conversation-msg-left,
.vp-historypanel .erp-conversation-msg-right {
    padding-left: 0 !important;
    padding-right: 0 !important;
    justify-content: flex-start !important;
}

.vp-historypanel .erp-conversation-bubble {
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box;
}

.vp-historypanel .erp-conversation-dot {
    display: none !important;
}

/* ============================================================
   Storico portale (audit timeline): uniformato allo Storico ERP.
   Eliminiamo la timeline verticale a sinistra (linea + pallini): diventa una
   semplice lista di card a tutta larghezza, come la conversazione ERP. Il tipo
   evento e' gia' indicato dal badge nell'header della card.
   ============================================================ */
.vp-historypanel .audit-timeline {
    padding: 0 !important;
}

.vp-historypanel .audit-timeline-line {
    display: none !important;
}

.vp-historypanel .audit-timeline-dot {
    display: none !important;
}

.vp-historypanel .audit-timeline-row {
    margin-bottom: 10px !important;
}

.vp-historypanel .audit-timeline-card {
    width: 100% !important;
    box-sizing: border-box;
}

/* ============================================================
   DARK MODE
   ============================================================ */

[data-vp-theme="dark"] .vp-historypanel,
[data-bs-theme="dark"] .vp-historypanel {
    background: #1e293b;
    box-shadow: -2px 0 16px rgba(0, 0, 0, 0.55);
}

[data-vp-theme="dark"] .vp-historypanel-overlay,
[data-bs-theme="dark"] .vp-historypanel-overlay {
    background: rgba(0, 0, 0, 0.55);
}

[data-vp-theme="dark"] .vp-historypanel-pinned,
[data-bs-theme="dark"] .vp-historypanel-pinned {
    border-left-color: #4dabf7;
}

[data-vp-theme="dark"] .vp-historypanel-header,
[data-bs-theme="dark"] .vp-historypanel-header,
[data-vp-theme="dark"] .vp-historypanel-tabs,
[data-bs-theme="dark"] .vp-historypanel-tabs {
    border-color: #334155;
}

[data-vp-theme="dark"] .vp-historypanel-title,
[data-bs-theme="dark"] .vp-historypanel-title {
    color: #e5e9f0;
}

[data-vp-theme="dark"] .vp-historypanel-iconbtn,
[data-bs-theme="dark"] .vp-historypanel-iconbtn,
[data-vp-theme="dark"] .vp-historypanel-tab,
[data-bs-theme="dark"] .vp-historypanel-tab {
    color: #b8c1cf;
}

[data-vp-theme="dark"] .vp-historypanel-tab,
[data-bs-theme="dark"] .vp-historypanel-tab {
    background: #15181e;
    border-color: #353a45;
}

[data-vp-theme="dark"] .vp-historypanel-iconbtn:hover,
[data-bs-theme="dark"] .vp-historypanel-iconbtn:hover,
[data-vp-theme="dark"] .vp-historypanel-tab:hover,
[data-bs-theme="dark"] .vp-historypanel-tab:hover {
    background: #334155;
    color: #ffffff;
}

[data-vp-theme="dark"] .vp-historypanel-iconbtn.is-active,
[data-bs-theme="dark"] .vp-historypanel-iconbtn.is-active,
[data-vp-theme="dark"] .vp-historypanel-tab.is-active,
[data-bs-theme="dark"] .vp-historypanel-tab.is-active {
    background: #1971c2;
    border-color: #1971c2;
    color: #ffffff;
}

[data-vp-theme="dark"] .vp-historypanel .audit-timeline-fields tr,
[data-bs-theme="dark"] .vp-historypanel .audit-timeline-fields tr,
[data-vp-theme="dark"] .vp-historypanel .erp-conversation-fields tr,
[data-bs-theme="dark"] .vp-historypanel .erp-conversation-fields tr {
    border-bottom-color: #334155;
}

[data-vp-theme="dark"] .vp-historypanel .audit-timeline-fields td:first-child,
[data-bs-theme="dark"] .vp-historypanel .audit-timeline-fields td:first-child,
[data-vp-theme="dark"] .vp-historypanel .erp-conversation-fields td:first-child,
[data-bs-theme="dark"] .vp-historypanel .erp-conversation-fields td:first-child {
    color: #e5e9f0;
}

[data-vp-theme="dark"] .vp-historypanel .audit-timeline-new-value,
[data-bs-theme="dark"] .vp-historypanel .audit-timeline-new-value,
[data-vp-theme="dark"] .vp-historypanel .erp-conversation-new-value,
[data-bs-theme="dark"] .vp-historypanel .erp-conversation-new-value {
    color: #e5e9f0;
}
