/* ============================================
   OCC Bot — chat.html left history rail (#history-rail)
   ============================================
   Permanent left column on the full-page Chat tab (frontend/chat.html)
   listing the last 7 days of conversations, plus the class-based list styles
   reused by the chat drawer's "Conversas" panel (shell.js / shell.css).
   js/history-rail.js populates .history-rail-list and toggles
   .history-rail-empty.

   Reuses the color/spacing/border/radius tokens already defined on :root in
   /static/widget/css/widget.css (loaded before this file) instead of
   introducing new ad-hoc values, so the rail visually matches the rest of
   the app.
   ============================================ */

#history-rail {
    flex: 0 0 280px;
    width: 280px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-white);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
}

.history-rail-header {
    flex-shrink: 0;
    padding: var(--spacing-md);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.history-rail-empty {
    margin: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-gray-50);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
    text-align: center;
}

/* Session list — populated by js/history-rail.js. Class-based so the chat
   drawer's "Conversas" panel (shell.js) can host the same list. Per-item
   structure:
     <li class="history-rail-item" data-session-id="...">
       <span class="history-rail-item-title">...</span>
       <span class="history-rail-item-preview">...</span>
       <span class="history-rail-item-time">...</span>
     </li>
*/
.history-rail-list {
    list-style: none;
    margin: 0;
    padding: 0 var(--spacing-sm) var(--spacing-md);
    flex: 1 1 auto;
}

/* Keep the reserved space collapsed while the list has no items. */
.history-rail-list:empty {
    display: none;
}

/* Day-bucket group header ("Hoje" / "Ontem" / weekday name), rendered as a
   plain <li> ahead of that day's session rows. */
.history-rail-day-header {
    padding: var(--spacing-sm) var(--spacing-sm) var(--spacing-xs);
    margin-top: var(--spacing-xs);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
}

.history-rail-day-header:first-child {
    margin-top: 0;
}

/* Session row. */
.history-rail-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--spacing-sm);
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.history-rail-item:hover {
    background: var(--bg-gray-50);
}

.history-rail-item:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

.history-rail-item.active {
    background: var(--primary-light);
}

.history-rail-item-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-rail-item.active .history-rail-item-title {
    color: var(--primary-dark);
}

.history-rail-item-preview {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-rail-item-time {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* Scrollbar treatment, mirroring .chat-messages in widget.css. */
#history-rail::-webkit-scrollbar,
.history-rail-scroll::-webkit-scrollbar {
    width: 6px;
}

#history-rail::-webkit-scrollbar-track,
.history-rail-scroll::-webkit-scrollbar-track {
    background: transparent;
}

#history-rail::-webkit-scrollbar-thumb,
.history-rail-scroll::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

#history-rail::-webkit-scrollbar-thumb:hover,
.history-rail-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--border-color-dark);
}

/* ============================================
   Mobile: off-canvas drawer (<=1023px)
   Copies document_detail.html's inspector drawer/scrim pattern.
   Open state = body.history-rail-open, toggled by js/history-rail.js
   via the #history-rail-toggle toolbar button (chat.html).
   ============================================ */
@media (max-width: 1023px) {
    #history-rail {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(320px, 85vw);
        z-index: 70;
        transform: translateX(-100%);
        transition: transform 200ms ease;
    }
    body.history-rail-open #history-rail {
        transform: translateX(0);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    }
    body.history-rail-open .chat-page-body::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.25);
        z-index: 65;
    }
}

@media (prefers-reduced-motion: reduce) {
    #history-rail { transition: none; }
}
