/* ============================================
   HOS TICKET STYLE — coerente con /cs/ esistente
   ============================================ */

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

:root {
    --bg: #0a0a0f;
    --card: #12121a;
    --border: #1e1e2e;
    --text: #e0e0e0;
    --text-muted: #888;
    --accent: #f0b429;
    --green: #22c55e;
    --orange: #f59e0b;
    --red: #ef4444;
    --blue: #3b82f6;
    --purple: #8b5cf6;
    /* HOS primary color: teal, distinguibile da CS (blue) */
    --hos: #14b8a6;
    --hos-dim: rgba(20, 184, 166, 0.12);
    --hos-border: rgba(20, 184, 166, 0.3);
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.hidden { display: none !important; }

/* ============================================
   HEADER
   ============================================ */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 28px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 16px;
}

.header-left h1 {
    font-size: 1.3rem;
    color: var(--hos);
    white-space: nowrap;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.stats-inline {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 18px;
}

.stat-inline { color: var(--text-muted); }
.stat-inline strong { color: var(--text); }
.stat-inline.stat-urgent strong { color: var(--red); }
.stat-sep { color: var(--border); }

.header-right { display: flex; gap: 8px; align-items: center; }

.btn-icon {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: border-color 0.2s;
}
.btn-icon:hover { border-color: var(--hos); }

.btn-logout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    white-space: nowrap;
}
.btn-logout:hover { color: var(--text); border-color: var(--text-muted); }

/* ============================================
   SPLIT LAYOUT
   ============================================ */
.split-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ============================================
   PANNELLO SINISTRA — lista ticket
   ============================================ */
.tickets-panel {
    width: 360px;
    min-width: 320px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.filters-bar {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.filters-bar select,
.filters-bar input {
    width: 100%;
    padding: 9px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
}

.filters-bar select:focus,
.filters-bar input:focus {
    outline: none;
    border-color: var(--hos);
}

.tickets-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.loading-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state p { margin-bottom: 12px; font-size: 0.9rem; }

.empty-state button {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
}
.empty-state button:hover { border-color: var(--hos); color: var(--text); }

/* Card ticket */
.ticket-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.ticket-card:hover { border-color: var(--hos); }
.ticket-card.active {
    border-color: var(--hos);
    background: var(--hos-dim);
}

.ticket-card-top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

/* Pill priorità */
.priority-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.priority-urgente { background: rgba(239,68,68,0.18); color: var(--red); }
.priority-alta { background: rgba(245,158,11,0.18); color: var(--orange); }
.priority-media { background: rgba(234,179,8,0.18); color: #eab308; }
.priority-bassa { background: rgba(100,116,139,0.18); color: #94a3b8; }

/* Badge categoria */
.categoria-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.72rem;
    background: rgba(139,92,246,0.15);
    color: var(--purple);
    font-weight: 500;
}

/* Badge stato */
.stato-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 600;
}
.stato-aperto { background: rgba(59,130,246,0.15); color: var(--blue); }
.stato-in_lavorazione_hos { background: rgba(20,184,166,0.15); color: var(--hos); }
.stato-risolto { background: rgba(34,197,94,0.15); color: var(--green); }
.stato-chiuso { background: rgba(100,116,139,0.15); color: #94a3b8; }
.stato-escalato { background: rgba(245,158,11,0.15); color: var(--orange); }

.ticket-card-contratto {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 3px;
}

.ticket-card-consulente {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.ticket-card-desc {
    font-size: 0.82rem;
    color: #aaa;
    line-height: 1.4;
    margin-bottom: 8px;
    word-break: break-word;
}

.ticket-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* ============================================
   PANNELLO DESTRA — dettaglio ticket
   ============================================ */
.detail-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.detail-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 12px;
}

.detail-empty-icon { font-size: 3rem; opacity: 0.3; }
.detail-empty p { font-size: 0.9rem; }

.detail-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header dettaglio */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px;
    flex-wrap: wrap;
}

.detail-meta {
    flex: 1;
    min-width: 0;
}

.detail-meta-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.detail-meta-sub {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.detail-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.btn-action {
    padding: 7px 14px;
    border-radius: 8px;
    border: 1px solid;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-resolve {
    background: rgba(34,197,94,0.1);
    border-color: rgba(34,197,94,0.4);
    color: var(--green);
}
.btn-resolve:hover { background: rgba(34,197,94,0.2); }

.btn-close-ticket {
    background: rgba(100,116,139,0.1);
    border-color: rgba(100,116,139,0.4);
    color: #94a3b8;
}
.btn-close-ticket:hover { background: rgba(100,116,139,0.2); }

.btn-escala {
    background: rgba(245,158,11,0.1);
    border-color: rgba(245,158,11,0.4);
    color: var(--orange);
}
.btn-escala:hover { background: rgba(245,158,11,0.2); }

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

/* Info attivazione */
.detail-info {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.info-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.info-value { font-size: 0.85rem; color: var(--text); font-weight: 500; }

/* Scrollable body del dettaglio */
.detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Sezioni nel body */
.detail-section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.detail-section-title {
    padding: 10px 14px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,0.02);
}

.detail-descrizione {
    padding: 14px;
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--text);
    word-break: break-word;
    white-space: pre-wrap;
}

.detail-allegati-originali {
    padding: 0 14px 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Thread messaggi */
.thread-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    min-height: 40px;
}

.thread-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Bubble messaggi */
.msg-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.5;
}

/* Consulente: sinistra, neutro */
.msg-consulente {
    align-self: flex-start;
    background: rgba(59,130,246,0.1);
    border: 1px solid rgba(59,130,246,0.2);
}

/* HOS: destra, colore primario HOS */
.msg-hos {
    align-self: flex-end;
    background: var(--hos-dim);
    border: 1px solid var(--hos-border);
}

/* CS: sinistra, badge arancio */
.msg-cs {
    align-self: flex-start;
    background: rgba(245,158,11,0.1);
    border: 1px solid rgba(245,158,11,0.2);
}

.msg-sender {
    font-size: 0.72rem;
    font-weight: 700;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.msg-consulente .msg-sender { color: var(--blue); }
.msg-hos .msg-sender { color: var(--hos); }
.msg-cs .msg-sender { color: var(--orange); }

.msg-cs-badge {
    background: rgba(245,158,11,0.2);
    color: var(--orange);
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 700;
}

.msg-text {
    color: var(--text);
    word-break: break-word;
    white-space: pre-wrap;
}

.msg-time {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 5px;
    text-align: right;
}

/* Allegati nel thread */
.msg-allegati {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.attach-img {
    max-width: 180px;
    max-height: 140px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.1);
    object-fit: cover;
}

.attach-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: rgba(59,130,246,0.15);
    border: 1px solid rgba(59,130,246,0.4);
    border-radius: 6px;
    color: #93c5fd;
    text-decoration: none;
    font-size: 0.78rem;
}
.attach-file:hover { background: rgba(59,130,246,0.25); }

/* ============================================
   COMPOSER
   ============================================ */
.composer {
    padding: 12px 20px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg);
}

.composer-attach-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px;
    background: rgba(20,184,166,0.04);
    border: 1px dashed var(--hos-border);
    border-radius: 8px;
    margin-bottom: 8px;
}

.composer-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.composer-row textarea {
    flex: 1;
    padding: 10px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.88rem;
    resize: none;
    line-height: 1.5;
}
.composer-row textarea:focus {
    outline: none;
    border-color: var(--hos);
}

.composer-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.btn-attach {
    background: rgba(255,255,255,0.06);
    color: var(--accent);
    border: 1px solid rgba(240,180,41,0.4);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-attach:hover { background: rgba(240,180,41,0.12); }

.btn-send {
    background: var(--hos);
    color: #000;
    border: none;
    border-radius: 8px;
    padding: 9px 18px;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
    transition: filter 0.15s;
}
.btn-send:hover { filter: brightness(1.15); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }

/* Chip allegati in preview */
.attach-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    font-size: 0.78rem;
    color: rgba(255,255,255,0.85);
    max-width: 220px;
}
.attach-chip .chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.attach-chip .chip-remove {
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 0.95rem;
    padding: 0 2px;
}

/* ============================================
   MODALE ESCALATION
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    width: 460px;
    max-width: calc(100vw - 32px);
}

.modal h2 {
    color: var(--orange);
    font-size: 1.1rem;
    margin-bottom: 10px;
}

.modal-desc {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-bottom: 20px;
    line-height: 1.5;
}

.modal-label {
    display: block;
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.modal-label textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    resize: vertical;
}
.modal-label textarea:focus { outline: none; border-color: var(--orange); }

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.btn-cancel {
    flex: 1;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}
.btn-cancel:hover { border-color: var(--text-muted); color: var(--text); }

.btn-confirm-escala {
    flex: 1;
    padding: 10px;
    background: rgba(245,158,11,0.15);
    border: 1px solid rgba(245,158,11,0.5);
    color: var(--orange);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9rem;
    transition: all 0.15s;
}
.btn-confirm-escala:hover { background: rgba(245,158,11,0.25); }

/* ============================================
   TOAST
   ============================================ */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 500;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    transition: opacity 0.3s;
}
.toast.toast-ok { border-color: var(--green); color: var(--green); }
.toast.toast-err { border-color: var(--red); color: var(--red); }
.toast.toast-warn { border-color: var(--orange); color: var(--orange); }

/* ============================================
   SCROLLBAR
   ============================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a2a3e; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a5e; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 900px) {
    .split-layout { flex-direction: column; overflow: auto; }
    .tickets-panel { width: 100%; min-width: 0; border-right: none; border-bottom: 1px solid var(--border); max-height: 50vh; }
    .detail-panel { max-height: 50vh; }
    .stats-inline { display: none; }
    body { overflow: auto; height: auto; }
}
