/* History: one row per task. Uses the site's theme tokens; media plays in a dialog. */
.hist-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
body.in-app #page-hist .hist-head { row-gap: 8px; padding: 22px 26px 16px; }
body.in-app #page-hist .hist-head > h1 { font-size: 22px; }
body.in-app #page-hist .hist-head > .hist-retention { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 12.5px; color: var(--muted); }
#page-hist .hist-retention svg { flex: none; color: var(--gold); }
body.in-app #page-hist .hist-head > .hist-tools { grid-column: 2; grid-row: 1 / span 2; align-self: end; }
#page-hist .hist-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; min-width: 0; }
#page-hist .hist-tools .field { height: 38px; min-height: 38px; margin: 0; font-size: 13px; }
#page-hist #histSearch { width: 280px; max-width: 100%; padding: 0 12px; }
#page-hist .hist-tools select.field, #page-hist .hist-tools .glide-trigger { width: 124px; }
body.in-app #page-hist .hist-body { padding: 0 18px 18px; }
#page-hist .hist-summary { margin: 0; padding: 12px 8px 6px; color: var(--faint); font-size: 12px; }

.hist-table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: 13px; }
.hist-table th { position: sticky; top: 0; z-index: 1; padding: 10px 8px; text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); background: var(--panel); border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.hist-table td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; min-width: 0; }
.hist-table tbody tr:hover td { background: var(--field-bg); }
.hist-table th:nth-child(1) { width: 16%; }
.hist-table th:nth-child(2) { width: auto; }
.hist-table th:nth-child(3) { width: 10%; }
.hist-table th:nth-child(4) { width: 92px; }
.hist-table th:nth-child(5), .hist-table th:nth-child(6) { width: 120px; }
.hist-table th:nth-child(7) { width: 78px; }
.hist-table th:nth-child(8) { width: 186px; }
.hist-c-id { white-space: nowrap; }
.hist-c-id code { display: inline-block; max-width: calc(100% - 30px); margin: 0; padding: 0; border: 0; background: none; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; font-size: 12px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.hist-c-prompt { overflow: hidden; }
.hist-kind { display: inline-block; margin-right: 6px; padding: 1px 6px; border-radius: 6px; font-size: 11px; color: var(--gold); background: var(--accent-soft); vertical-align: 1px; }
.hist-text { color: var(--text); }
.hist-c-prompt .hist-text, .hist-note, .hist-c-model span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-c-prompt .hist-text { display: inline; }
.hist-c-prompt { white-space: nowrap; text-overflow: ellipsis; }
.hist-note { margin-top: 3px; font-size: 12px; color: var(--muted); }
.hist-row.is-bad .hist-note { color: var(--bad); }
.hist-c-model { color: var(--muted); }
.hist-state { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; white-space: nowrap; color: var(--muted); }
.hist-state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.hist-state.is-ok { color: var(--ok); }
.hist-state.is-bad { color: var(--bad); }
.hist-state.is-busy { color: var(--gold); }
.hist-state.is-busy::before { animation: hist-pulse 1.4s ease-in-out infinite; }
@keyframes hist-pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .hist-state.is-busy::before { animation: none; } }
.hist-c-time, .hist-c-elapsed { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12.5px; }
.hist-c-elapsed { color: var(--text); }
.hist-c-actions { white-space: nowrap; text-align: right; }
.hist-c-actions > * { vertical-align: middle; }
.hist-play { display: inline-flex; align-items: center; gap: 6px; height: 32px; margin: 0 4px 0 0; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 9px; background: transparent; color: var(--text); font-size: 13px; cursor: pointer; }
.hist-play:not(:disabled):hover { border-color: var(--accent-ring); background: var(--accent-soft); color: var(--gold); }
.hist-icon { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; margin: 0; padding: 0; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; }
.hist-icon:not(:disabled):hover { background: var(--field-hover); color: var(--text); }
.hist-icon.is-danger:not(:disabled):hover { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.hist-icon.is-done { color: var(--ok); }
.hist-c-id .hist-icon { width: 26px; height: 26px; margin-left: 2px; }
.hist-play:disabled, .hist-icon:disabled { opacity: .38; cursor: not-allowed; }
#page-hist .hist-more { display: block; margin: 16px auto 4px; min-height: 40px; padding: 0 18px; }
#page-hist .hist-more[hidden] { display: none; }
.hist-empty { padding: clamp(40px, 9vh, 96px) 16px; text-align: center; color: var(--muted); }
.hist-empty h2 { margin: 0 0 8px; font-size: 18px; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.hist-empty p { margin: 0 0 18px; font-size: 13.5px; }
.hist-empty button { min-height: 40px; padding: 0 18px; }
#page-hist :is(button, a, input, select):focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Playback dialog */
.hist-player { width: min(980px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--line-strong); border-radius: 18px; background: var(--panel-2); color: var(--text); box-shadow: 0 40px 90px -36px rgba(0, 0, 0, .8); overflow: hidden; }
.hist-player::backdrop { background: var(--veil); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.hist-player-card { display: flex; flex-direction: column; max-height: calc(100dvh - 34px); }
.hist-player-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 16px 18px 12px; }
.hist-player-head h2 { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.hist-player-meta { margin: 0; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hist-player .hist-player-x { position: static; flex: none; width: 34px; height: 34px; font-size: 20px; line-height: 1; }
.hist-player-stage { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; background: #000; }
.hist-player-stage video, .hist-player-stage img { display: block; width: 100%; max-height: min(68dvh, 640px); object-fit: contain; background: #000; }
.hist-player-stage figure { margin: 0; width: 100%; }
.hist-player-stage.is-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; overflow: auto; }
.hist-player-stage.is-grid img { max-height: 40dvh; }
.hist-player-stage figure a { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; margin: 0; border-radius: 0; font-size: 12.5px; color: #f2f0eb; border-color: transparent; }
.hist-player-status { margin: 0; padding: 0 18px; font-size: 13px; color: var(--muted); }
.hist-player-status:not(:empty) { padding-top: 10px; }
.hist-player-status button { min-height: 32px; margin-left: 6px; padding: 0 12px; }
.hist-player-foot { display: flex; align-items: center; gap: 16px; padding: 12px 18px 16px; }
.hist-player-prompt { flex: 1; min-width: 0; margin: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-player-dl { display: inline-flex; align-items: center; gap: 6px; flex: none; min-height: 38px; padding: 0 16px; text-decoration: none; font-size: 13.5px; }

/* Delete confirmation */
#histDelete .modal-card { max-height: calc(100dvh - 32px); overflow: auto; }
#histDelete h2 { font-size: 20px; margin: 0 0 12px; }
#histDelete .hist-delete-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
#histDelete button { min-height: 44px; margin: 0; padding: 0 18px; border-radius: 12px; }
#histDelete .hist-danger { border: 0; background: var(--bad); color: var(--bg); font-weight: 600; cursor: pointer; }
#histDelete .hist-danger:disabled { opacity: .6; cursor: wait; }
#histDeleteError { color: var(--bad); margin-top: 12px; font-size: 13px; }

@media (max-width: 1439px) {
  .hist-table th:nth-child(3), .hist-table td:nth-child(3) { display: none; }
}
@media (max-width: 1180px) {
  body.in-app #page-hist .hist-head > .hist-tools { grid-column: 1 / -1; grid-row: auto; justify-content: flex-start; }
}

/* Narrower screens: each task stays one compact entry. */
@media (max-width: 1100px) {
  body.in-app #page-hist .hist-head { padding: 16px 14px 12px; }
  #page-hist .hist-tools { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
  #page-hist #histSearch { grid-column: 1 / -1; width: 100%; }
  #page-hist .hist-tools select.field, #page-hist .hist-tools .glide-trigger { width: 100%; }
  #page-hist .hist-tools .field { height: 42px; min-height: 42px; }
  body.in-app #page-hist .hist-body { padding: 0 12px 18px; }
  .hist-table, .hist-table tbody { display: block; }
  .hist-table thead { display: none; }
  .hist-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "state elapsed" "prompt prompt" "start end" "id actions"; gap: 6px 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
  .hist-table tbody tr:hover td { background: none; }
  .hist-table td { display: block; padding: 0; border: 0; }
  .hist-table td:nth-child(3) { display: none; }
  .hist-c-id { grid-area: id; align-self: center; }
  .hist-c-prompt { grid-area: prompt; }
  .hist-c-state { grid-area: state; }
  .hist-c-time:nth-child(5) { grid-area: start; }
  .hist-c-time:nth-child(6) { grid-area: end; text-align: right; }
  .hist-c-elapsed { grid-area: elapsed; text-align: right; }
  .hist-c-actions { grid-area: actions; }
  .hist-c-time::before, .hist-c-elapsed::before { content: attr(data-label) " "; color: var(--faint); }
  .hist-play { height: 40px; padding: 0 14px; }
  .hist-icon { width: 40px; height: 40px; }
  .hist-c-id .hist-icon { width: 36px; height: 36px; }
  #histDelete .hist-delete-actions button { flex: 1; }
}
@media (max-width: 720px) {
  .hist-player { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); border-radius: 14px; }
  .hist-player-card { max-height: calc(100dvh - 18px); }
  .hist-player-head { padding: 14px 14px 10px; }
  .hist-player-foot { padding: 10px 14px 14px; }
  .hist-player-stage video, .hist-player-stage img { max-height: 58dvh; }
  .hist-player-stage.is-grid { grid-template-columns: minmax(0, 1fr); }
}
