/* Session-history browser (/history). Ported from the standalone archive
   viewer; scoped under .history-root so nothing leaks into the dashboard.
   The transcript message bodies come entirely from the portal's own
   messages.css / tool styles. */

.history-root {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

.history-root .history-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
}

.history-root .history-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 1rem;
    color: var(--text-bright, #c0caf5);
}

.history-root .history-nav {
    margin-bottom: 1rem;
}

.history-root .history-nav a,
.history-root .history-empty a {
    color: var(--accent, #7aa2f7);
    text-decoration: none;
}

.history-root .history-nav a:hover,
.history-root .history-empty a:hover {
    text-decoration: underline;
}

/* --- Stats strip --- */
.history-root .history-rollup {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.history-root .rollup-tile {
    display: flex;
    flex-direction: column;
    background: var(--bg-darker, #16161e);
    border: 1px solid var(--border, #292e42);
    border-radius: 8px;
    padding: 0.6rem 0.9rem;
    min-width: 6rem;
}

.history-root .rollup-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-bright, #c0caf5);
}

.history-root .rollup-label {
    font-size: 0.75rem;
    color: var(--text-dim, #7f849c);
}

.history-root .rollup-user .rollup-value {
    color: var(--accent, #7aa2f7);
}

/* --- Filters --- */
.history-root .history-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: flex-end;
}

.history-root .history-filters label {
    display: flex;
    flex-direction: column;
    font-size: 0.75rem;
    color: var(--text-dim, #7f849c);
    gap: 0.25rem;
}

.history-root .history-filters select,
.history-root .history-filters input {
    background: var(--bg-darker, #16161e);
    color: var(--text, #c0caf5);
    border: 1px solid var(--border, #292e42);
    border-radius: 6px;
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
}

.history-root .history-filter-search input {
    min-width: 12rem;
}

/* --- Session table --- */
.history-root .history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.history-root .history-table th,
.history-root .history-table td {
    text-align: left;
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid var(--border, #292e42);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 22ch;
}

.history-root .history-table th {
    color: var(--text-dim, #7f849c);
    font-weight: 600;
    position: sticky;
    top: 0;
    background: var(--bg-dark, #1a1b26);
}

.history-root .history-table th.num,
.history-root .history-table td.num {
    text-align: right;
}

.history-root .history-sort-button {
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.history-root .history-sort-button:hover,
.history-root th[aria-sort] .history-sort-button {
    color: var(--accent, #7aa2f7);
}

.history-root .history-row {
    cursor: pointer;
}

.history-root .history-row:hover {
    background: var(--bg-highlight, #1f2335);
}

.history-root .cell-name a {
    color: var(--accent, #7aa2f7);
    text-decoration: none;
    font-weight: 600;
}

.history-root .cell-date {
    color: var(--text-dim, #7f849c);
}

.history-root .cell-models {
    color: var(--text-dim, #7f849c);
    font-size: 0.78rem;
}

/* --- Manifest header card --- */
.history-root .history-manifest-card {
    background: var(--bg-darker, #16161e);
    border: 1px solid var(--border, #292e42);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

.history-root .history-manifest-card h2 {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
    color: var(--text-bright, #c0caf5);
}

.history-root .manifest-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.4rem 1.5rem;
}

.history-root .manifest-field {
    display: flex;
    gap: 0.5rem;
    font-size: 0.82rem;
}

.history-root .manifest-key {
    color: var(--text-dim, #7f849c);
    min-width: 6rem;
}

.history-root .manifest-val {
    color: var(--text, #c0caf5);
    word-break: break-word;
}

.history-root .manifest-provenance {
    margin-top: 0.75rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.history-root .provenance-chip {
    font-size: 0.72rem;
    color: var(--text-dim, #7f849c);
    background: var(--bg-dark, #1a1b26);
    border: 1px solid var(--border, #292e42);
    border-radius: 999px;
    padding: 0.15rem 0.6rem;
}

/* --- Loading / error / empty states --- */
.history-root .history-loading,
.history-root .history-empty {
    color: var(--text-dim, #7f849c);
    padding: 1.5rem 0;
    text-align: center;
}

.history-root .history-error {
    color: var(--error, #f7768e);
    background: rgba(247, 118, 142, 0.08);
    border: 1px solid var(--error, #f7768e);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin: 0.5rem 0;
}

/* --- Pagination --- */

/* Bounds the rendered table only; the endpoint still returns every visible
   session so the stats strip can total the whole filter. Hidden by the
   component when there is a single page. */
.history-root .history-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1rem;
}

.history-root .history-page-button {
    background: var(--bg-darker, #16161e);
    color: var(--text, #c0caf5);
    border: 1px solid var(--border, #292e42);
    border-radius: 6px;
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    cursor: pointer;
}

.history-root .history-page-button:hover:not(:disabled) {
    border-color: var(--accent, #7aa2f7);
    color: var(--accent, #7aa2f7);
}

.history-root .history-page-button:disabled {
    opacity: 0.4;
    cursor: default;
}

.history-root .history-page-status {
    font-size: 0.8rem;
    color: var(--text-dim, #7f849c);
    font-variant-numeric: tabular-nums;
}

/* Owner cell as a click-to-filter control: reads as a link inside the row,
   without disturbing table typography. */
.history-owner-filter {
    padding: 0;
    border: none;
    background: none;
    font: inherit;
    color: var(--accent);
    cursor: pointer;
}

.history-owner-filter:hover {
    text-decoration: underline;
}

.history-root .history-restore {
    margin: 1rem 0;
    padding: 1rem;
    border: 1px solid var(--border, #292e42);
    border-radius: 8px;
    background: var(--bg-darker, #16161e);
}

.history-root .history-restore p {
    margin: 0.65rem 0;
    line-height: 1.45;
}

.history-root .history-restore-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
    gap: 1rem;
}

.history-root .history-restore-fields label {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 0;
}

.history-root .history-restore-fields input,
.history-root .history-restore-fields select {
    padding: 0.5rem;
    color: var(--text, #c0caf5);
    background: var(--bg-dark, #1a1b26);
    border: 1px solid var(--border, #292e42);
    border-radius: 4px;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.history-root .history-restore-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

/* Archived transcripts can run to thousands of messages. Skip layout and
   paint for the ones off screen; `auto` remembers each card's real height
   once it has rendered, so scrolling back up is stable.
   Deliberately not applied to the live session view: that view starts at
   the bottom and is read by scrolling up, so a card would swap its
   placeholder height for its real one at the top edge of the viewport,
   moving the text being read wherever the browser has no scroll anchoring
   (mobile Safari). Here reading runs top to bottom, so the swap happens
   below the viewport. */
.history-root .messages-container > .claude-message {
    content-visibility: auto;
    contain-intrinsic-size: auto 240px;
}
