/* ============================================================================
   CHAT HISTORY MODAL  (#chatHistoryModal)
   ----------------------------------------------------------------------------
   The sheet that lists a character's past conversations, opened from the chat
   actions menu ("Chat history"). Markup: views/partials/dashboard-modals.hbs.
   Rows: `displayUserChatHistoryInModal` in public/js/chat-list.js.

   WHY THIS FILE EXISTS. The modal used to lean on the platform's generic modal
   chrome (`.modal-header` in overwrite-bootstrap.css) over a hardcoded
   `linear-gradient(#dbdbdb, #d5d5d5)` sheet: a pale grey bar, a gradient-clipped
   title that vanished into it, and 20px of padding everywhere. Here the sheet
   draws its OWN header, so nothing upstream can repaint it, and every colour is
   a theme token — it follows whichever skin theme.css has lit (docs/DESIGN_SYSTEM.md).
   ========================================================================== */

.chm-dialog {
    max-width: 440px;
}

.chm-sheet {
    background: var(--surface-overlay) !important;
    border: 1px solid var(--line) !important;
    border-radius: 18px !important;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    color: var(--ink);
}

/* ── Header ──────────────────────────────────────────────────────────────
   Deliberately NOT `.modal-header`: that class carries the platform's glass
   strip and a right-aligned, gradient-clipped title. */
.chm-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--surface-raised);
    border-bottom: 1px solid var(--line);
}

.chm-header-icon {
    width: 36px;
    height: 36px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 11px;
    background: var(--brand-fill-soft);
    color: var(--brand-fill);
    font-size: 1rem;
}

.chm-header-text {
    flex: 1;
    min-width: 0;
}

.chm-title {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: 0.01em;
    color: var(--ink);
    /* The global `.modal-title` clips a gradient through the text; this one is
       plain ink, and says so loudly enough to survive that rule. */
    background: none;
    -webkit-text-fill-color: var(--ink);
}

.chm-sub {
    margin: 2px 0 0;
    font-size: 0.72rem;
    line-height: 1.3;
    color: var(--ink-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.chm-close {
    width: 32px;
    height: 32px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--glass);
    color: var(--ink-soft);
    font-size: 0.8rem;
    transition: background 0.15s ease, color 0.15s ease;
}

.chm-close:hover {
    background: var(--glass-strong);
    color: var(--ink);
}

/* ── Body ─────────────────────────────────────────────────────────────── */
.chm-body {
    padding: 10px;
    max-height: min(62vh, 520px);
    background: var(--surface-overlay);
}

.chm-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* ── One conversation ─────────────────────────────────────────────────── */
.chm-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 12px;
    background: var(--glass);
    border: 1px solid var(--line-soft);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.chm-item:hover,
.chm-item:focus-visible {
    background: var(--glass-strong);
    border-color: var(--line);
}

.chm-item.is-current {
    border-color: var(--brand-fill);
    background: var(--brand-fill-soft);
}

.chm-item-icon {
    width: 32px;
    height: 32px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: var(--glass-strong);
    color: var(--ink-soft);
    font-size: 0.85rem;
}

.chm-item-main {
    flex: 1;
    min-width: 0;
}

.chm-item-date {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chm-item-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 1px;
    font-size: 0.7rem;
    color: var(--ink-muted);
}

.chm-item-badge {
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--brand-fill-soft);
    color: var(--brand-fill);
    font-weight: 700;
    font-size: 0.62rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.chm-item-delete {
    width: 28px;
    height: 28px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--ink-muted);
    font-size: 0.75rem;
    transition: background 0.15s ease, color 0.15s ease;
}

.chm-item-delete:hover {
    background: rgba(213, 11, 11, 0.12);
    color: var(--status-danger);
}

/* ── States ───────────────────────────────────────────────────────────── */
.chm-empty,
.chm-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 34px 16px;
    text-align: center;
    color: var(--ink-muted);
    font-size: 0.82rem;
}

.chm-empty i,
.chm-state i {
    font-size: 1.6rem;
    opacity: 0.6;
}

.chm-state .spinner-border {
    width: 1.5rem;
    height: 1.5rem;
    color: var(--brand-fill);
}

@media (max-width: 480px) {
    .chm-dialog {
        max-width: none;
        margin: 0.75rem;
    }
    .chm-body {
        max-height: 68vh;
    }
}
