.history-page {
  --history-columns: minmax(150px, .82fr) minmax(268px, 1.9fr) minmax(92px, .66fr) minmax(170px, 1.06fr) minmax(145px, .9fr) minmax(72px, .5fr) 78px;
  gap: 14px;
}

.history-page .page-context-head { margin-bottom: 14px; }
.history-workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; min-width: 0; }

.history-search {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 46px;
  border: 1px solid rgba(139, 92, 246, .18);
  border-radius: 8px;
  background: rgba(10, 14, 28, .72);
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}
.history-search:focus-within { border-color: rgba(168, 85, 247, .42); background: rgba(12, 16, 32, .88); box-shadow: 0 0 16px rgba(139, 92, 246, .1); }
.history-search .review-icon { width: 18px; height: 18px; margin-left: 15px; color: #94a3b8; }
.history-search input { width: 100%; min-height: 44px; padding: 9px 14px 9px 11px; border: 0; outline: 0; background: transparent; color: #f8fafc; font-size: 14px; font-weight: 420; }
.history-search input::placeholder { color: #718096; }

.history-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.history-filter-group { display: flex; align-items: center; gap: 7px; min-width: 0; }
.history-filter-group--right { justify-content: flex-end; }
.history-filter-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 36px; padding: 7px 12px; border: 1px solid rgba(139, 92, 246, .16); border-radius: 7px; background: rgba(7, 10, 19, .36); color: #a8b2c2; font-size: 13px; font-weight: 450; cursor: pointer; transition: 160ms ease; white-space: nowrap; }
.history-filter-button .review-icon { width: 15px; height: 15px; color: currentColor; transform: translateY(-2px); }
.history-filter-button:hover, .history-filter-button:focus-visible { border-color: rgba(168, 85, 247, .36); background: rgba(139, 92, 246, .07); color: #e9d5ff; outline: 0; }
.history-filter-button.active { border-color: rgba(217, 70, 239, .52); background: rgba(139, 92, 246, .12); color: #f5d0fe; box-shadow: 0 0 13px rgba(139, 92, 246, .1); }
.history-toolbar-action { min-height: 36px !important; height: 36px; padding: 7px 12px !important; border-radius: 7px !important; font-size: 13px !important; font-weight: 450 !important; }
.history-toolbar-action svg { width: 16px; height: 16px; flex: 0 0 auto; vertical-align: middle; transform: translateY(-.5px); }
.history-clear-button { color: #c4b5fd !important; }

.history-summary-strip { display: grid; grid-template-columns: repeat(4, 1fr); min-height: 50px; border: 1px solid rgba(139, 92, 246, .16); border-radius: 8px; background: rgba(13, 16, 32, .58); }
.history-summary-item { display: flex; align-items: center; justify-content: center; gap: 9px; min-width: 0; padding: 9px 14px; color: #b8c2d2; }
.history-summary-item + .history-summary-item { border-left: 1px solid rgba(139, 92, 246, .14); }
.history-summary-item .review-icon { width: 17px; height: 17px; color: #d946ef; transform: translateY(-2px);}
.history-summary-item strong { color: #f8fafc; font-size: 17px; font-weight: 520; }
.history-summary-item span { font-size: 12.5px; font-weight: 420; white-space: nowrap; }

.history-results { min-width: 0; }
.history-table-shell { min-width: 0; border: 1px solid rgba(139, 92, 246, .16); border-radius: 8px; background: rgba(8, 11, 23, .34); overflow: hidden; }
.history-table-head, .history-record-row { display: grid; grid-template-columns: var(--history-columns); align-items: center; column-gap: 12px; }
.history-table-head { min-height: 38px; padding: 0 12px; background: rgba(16, 21, 42, .72); color: #8793a7; font-size: 12px; font-weight: 560; text-transform: uppercase; }
.history-table-head span:first-child { padding-left: 8px; }
.history-table-head span:nth-child(n+3) { text-align: center; }
.history-date-group + .history-date-group { margin-top: 2px; }
.history-date-heading { display: grid; gap: 6px; padding: 11px 12px 0; }
.history-date-heading strong { color: #edf2f8; font-size: 13.5px; font-weight: 560; text-transform: uppercase; }
.history-date-heading::after { content: ""; height: 1px; background: linear-gradient(90deg, rgba(217, 70, 239, .34), rgba(139, 92, 246, .12) 72%, transparent); }
.history-record-row { min-height: 51px; padding: 5px 12px; border-bottom: 1px solid rgba(139, 92, 246, .1); color: #d7dfeb; }
.history-record-row:last-child { border-bottom: 0; }
.history-record-row:hover { background: rgba(139, 92, 246, .035); }
.history-record-row > div:nth-child(n+3) { text-align: center; }
.history-content-cell { min-width: 0; text-align: left !important; }
.history-content-cell strong, .history-content-cell span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-content-cell strong { color: #f8fafc; font-size: 14px; font-weight: 500; }
.history-content-cell span { margin-top: 2px; color: #98a5b8; font-size: 13px; font-weight: 400; }
.history-data-cell { color: #d6deea; font-size: 14px; font-weight: 420; white-space: nowrap; }
.history-duration-cell { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.history-duration-cell i { color: #566278; font-style: normal; }
.history-type-badge { display: inline-flex; align-items: center; gap: 6px; width: fit-content; min-width: 104px; min-height: 29px; padding: 5px 8px; border: 1px solid currentColor; border-radius: 6px; background: rgba(7, 10, 19, .34); font-size: 12px; font-weight: 560; text-transform: uppercase; white-space: nowrap; }
.history-type-badge .review-icon { width: 16px; height: 16px; }
.history-type-badge.theory { color: #22c55e; background: rgba(34, 197, 94, .055); }
.history-type-badge.review { color: #38bdf8; background: rgba(14, 165, 233, .055); }
.history-type-badge.questions { color: #e247c8; background: rgba(226, 71, 200, .055); }
.history-type-badge.mock { color: #facc15; background: rgba(250, 204, 21, .05); }
.history-actions { display: flex; justify-content: center; gap: 4px; }
.history-actions .ds-icon-button { width: 32px; height: 32px; min-height: 32px; border-radius: 6px; }
.history-actions .ds-icon-button svg { width: 18px; height: 18px; }
.history-actions .danger-soft { color: #fb7185; }
.history-actions .danger-soft:hover, .history-actions .danger-soft:focus-visible { border-color: rgba(244, 63, 94, .44); background: rgba(244, 63, 94, .08); color: #fb7185; }
.history-empty { margin: 12px; min-height: 220px; }
.history-empty .ds-action-button { margin-top: 10px; }

.history-filter-drawer .form-grid { grid-template-columns: 1fr; gap: 14px; }
.history-filter-drawer label { color: #cbd5e1; font-size: 12px; font-weight: 450; }
.history-filter-drawer input, .history-filter-drawer select { margin-top: 6px; }
.history-delete-confirm { width: min(430px, calc(100vw - 32px)); padding: 24px; }
.history-delete-confirm .history-confirm-icon { display: grid; width: 42px; height: 42px; margin: 0 auto 12px; place-items: center; border: 1px solid rgba(244, 63, 94, .34); border-radius: 50%; background: rgba(244, 63, 94, .08); color: #fb7185; font-size: 21px; }
.history-delete-confirm h2, .history-delete-confirm p { text-align: center; }
.history-delete-confirm h2 { margin: 0; font-size: 21px; font-weight: 540; }
.history-delete-confirm p { margin: 10px 0 0; color: #94a3b8; font-size: 13px; line-height: 1.5; }
.history-delete-confirm .history-confirm-record { color: #d8b4fe; font-weight: 500; }
.history-delete-confirm .dialog-actions { margin-top: 20px; justify-content: center; }

@media (max-width: 1380px) {
  .history-page { --history-columns: minmax(148px, .8fr) minmax(207px, 1.55fr) minmax(82px, .62fr) minmax(150px, 1fr) minmax(130px, .85fr) 64px 72px; }
  .history-record-row, .history-table-head { column-gap: 8px; }
  .history-toolbar { align-items: flex-start; }
  .history-filter-group { flex-wrap: wrap; }
}

@media (max-width: 1100px) {
  .history-toolbar { flex-direction: column; align-items: stretch; }
  .history-filter-group--right { justify-content: flex-start; }
  .history-summary-strip { grid-template-columns: repeat(2, 1fr); }
  .history-summary-item:nth-child(3) { border-left: 0; border-top: 1px solid rgba(139, 92, 246, .14); }
  .history-summary-item:nth-child(4) { border-top: 1px solid rgba(139, 92, 246, .14); }
  .history-table-shell { overflow-x: auto; }
  .history-table-head, .history-date-group { min-width: 980px; }
}

/* ==========================================================================
   Histórico mobile (<= 900px). A tabela de 7 colunas (980px de largura mínima, 107 células cortadas) vira uma lista de
   cartões por data: 1ª linha tipo + horário + ações, 2ª o conteúdo (disciplina e tópico), 3ª origem / tempo / resultado
   com rótulos. Filtros: tipos numa faixa que rola na horizontal; períodos, Filtros e Exportar em grade de 6 colunas.
   Resumo em 2x2. Acima de 900px nada muda.
   ========================================================================== */
@media (max-width: 900px) {
  .history-page { gap: 12px; }
  .history-toolbar { gap: 8px; }

  /* Os cinco tipos cabem numa linha só: fonte e espaçamento menores, ícone escondido e largura dividida por igual. */
  .history-toolbar > .history-filter-group:first-child { display: flex; flex-wrap: nowrap; gap: 5px; }
  .history-toolbar > .history-filter-group:first-child .history-filter-button { flex: 1 1 0; width: auto; min-width: 0; min-height: 36px; padding: 6px 4px; gap: 0; font-size: 12px; letter-spacing: 0; }
  .history-toolbar > .history-filter-group:first-child .history-filter-button .review-icon { display: none; }

  .history-filter-group--right { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
  .history-filter-group--right > * { grid-column: span 2; width: 100%; min-width: 0; min-height: 40px; }
  .history-filter-group--right > [data-action="open-history-filters"],
  .history-filter-group--right > [data-action="export-history"] { grid-column: span 3; height: 40px; }
  .history-filter-group--right > .history-clear-button { grid-column: 1 / -1; }

  .history-summary-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-summary-item { justify-content: flex-start; gap: 7px; padding: 9px 12px; }
  .history-summary-item strong { font-size: 16px; }
  .history-summary-item span { font-size: 12px; line-height: 1.2; white-space: normal; }
  .history-summary-item + .history-summary-item { border-left: 1px solid rgba(139, 92, 246, .14); border-top: 0; }
  .history-summary-item:nth-child(odd) { border-left: 0; }
  .history-summary-item:nth-child(n+3) { border-top: 1px solid rgba(139, 92, 246, .14); }

  .history-table-shell { overflow: visible; border: 0; background: transparent; }
  .history-table-head { display: none; }
  .history-table-head, .history-date-group { min-width: 0; }
  .history-date-heading { padding: 12px 2px 8px; }

  .history-page .history-record-row {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    align-items: center;
    gap: 6px 8px;
    min-height: 0;
    margin-bottom: 8px;
    padding: 10px 12px;
    border: 1px solid rgba(139, 92, 246, .16);
    border-radius: 10px;
    background: rgba(13, 16, 32, .58);
  }
  .history-page .history-record-row:last-child { border-bottom: 1px solid rgba(139, 92, 246, .16); }
  .history-page .history-record-row > div { min-width: 0; text-align: left; }
  .history-record-row > :nth-child(1) { grid-column: 1 / 7; grid-row: 1; }
  .history-record-row > :nth-child(6) { grid-column: 7 / 10; grid-row: 1; color: #98a5b8; text-align: right !important; }
  .history-record-row > :nth-child(7) { grid-column: 10 / 13; grid-row: 1; justify-content: flex-end; }
  .history-record-row > :nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  .history-record-row > :nth-child(3) { grid-column: 1 / 5; grid-row: 3; }
  .history-record-row > :nth-child(4) { grid-column: 5 / 9; grid-row: 3; }
  .history-record-row > :nth-child(5) { grid-column: 9 / 13; grid-row: 3; }

  .history-content-cell strong { overflow: visible; font-size: 15px; line-height: 1.3; text-overflow: clip; white-space: normal; }
  .history-content-cell span { display: -webkit-box; overflow: hidden; font-size: 13px; line-height: 1.35; white-space: normal; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }

  .history-record-row > :nth-child(3),
  .history-record-row > :nth-child(4),
  .history-record-row > :nth-child(5) { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 6px; padding-top: 7px; border-top: 1px solid rgba(139, 92, 246, .12); font-size: 13.5px; white-space: normal; }
  .history-record-row > :nth-child(3)::before,
  .history-record-row > :nth-child(4)::before,
  .history-record-row > :nth-child(5)::before { flex: 0 0 100%; margin-bottom: 1px; color: #8793a7; font-size: 10px; font-weight: 560; letter-spacing: .05em; text-transform: uppercase; }
  .history-record-row > :nth-child(3)::before { content: "Origem"; }
  .history-record-row > :nth-child(4)::before { content: "Plan. / real."; }
  .history-record-row > :nth-child(5)::before { content: "Resultado"; }

  .history-record-row > .history-duration-cell { justify-content: flex-start; row-gap: 0; }
  .history-actions .ds-icon-button { width: 36px; height: 36px; min-height: 36px; }
  .history-empty { margin: 0; }
}

/* ==========================================================================
   Tema claro — Histórico
   Escopado em html[data-theme="light"]; o tema escuro não é afetado. Só cor, via tokens de design-system.css.
   ========================================================================== */
html[data-theme="light"] .history-page { color: var(--ink); }
html[data-theme="light"] .history-search { border-color: var(--input-border); background: var(--input-bg); }
html[data-theme="light"] .history-search:focus-within { border-color: rgba(124, 58, 237, 0.5); background: var(--input-bg); box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12); }
html[data-theme="light"] .history-search .review-icon { color: var(--muted); }
html[data-theme="light"] .history-search input { color: var(--ink); }
html[data-theme="light"] .history-search input::placeholder { color: var(--text-muted); }
html[data-theme="light"] .history-filter-button { border-color: var(--card-border); background: var(--surface-soft); color: var(--muted); }
html[data-theme="light"] .history-filter-button:hover,
html[data-theme="light"] .history-filter-button:focus-visible { border-color: rgba(124, 58, 237, 0.4); background: var(--primary-2); color: var(--primary); }
html[data-theme="light"] .history-filter-button.active { border-color: rgba(124, 58, 237, 0.55); background: rgba(124, 58, 237, 0.14); color: var(--primary); box-shadow: none; }
html[data-theme="light"] .history-clear-button { color: var(--primary) !important; }
html[data-theme="light"] .history-summary-strip { border-color: var(--card-border); background: linear-gradient(145deg, var(--card-1), var(--card-2)); }
html[data-theme="light"] .history-summary-item { color: var(--muted); }
html[data-theme="light"] .history-summary-item + .history-summary-item,
html[data-theme="light"] .history-summary-item:nth-child(3),
html[data-theme="light"] .history-summary-item:nth-child(4) { border-color: var(--card-border); }
html[data-theme="light"] .history-summary-item .review-icon { color: var(--magenta); }
html[data-theme="light"] .history-summary-item strong,
html[data-theme="light"] .history-content-cell strong,
html[data-theme="light"] .history-date-heading strong { color: var(--ink); }
html[data-theme="light"] .history-table-shell { border-color: var(--card-border); background: var(--card-1); box-shadow: 0 10px 28px rgba(57, 44, 89, 0.06); }
html[data-theme="light"] .history-table-head { background: rgba(83, 62, 116, 0.035); color: var(--text-muted); }
html[data-theme="light"] .history-date-heading::after { background: linear-gradient(90deg, rgba(192, 38, 211, 0.3), rgba(124, 58, 237, 0.1) 72%, transparent); }
html[data-theme="light"] .history-record-row { border-bottom-color: var(--card-border); color: var(--text-secondary); }
html[data-theme="light"] .history-record-row:hover { background: rgba(124, 58, 237, 0.05); }
html[data-theme="light"] .history-content-cell span { color: var(--muted); }
html[data-theme="light"] .history-data-cell { color: var(--text-secondary); }
html[data-theme="light"] .history-duration-cell i { color: var(--text-muted); }
html[data-theme="light"] .history-type-badge { background: var(--surface-soft); }
html[data-theme="light"] .history-type-badge.theory { color: var(--success); background: rgba(22, 138, 80, 0.08); }
html[data-theme="light"] .history-type-badge.review { color: var(--blue); background: rgba(37, 99, 235, 0.08); }
html[data-theme="light"] .history-type-badge.questions { color: var(--magenta); background: rgba(192, 38, 211, 0.08); }
html[data-theme="light"] .history-type-badge.mock { color: var(--warning); background: rgba(161, 98, 7, 0.08); }
html[data-theme="light"] .history-actions .danger-soft { color: var(--danger); }
html[data-theme="light"] .history-actions .danger-soft:hover,
html[data-theme="light"] .history-actions .danger-soft:focus-visible { border-color: rgba(217, 45, 78, 0.44); background: rgba(217, 45, 78, 0.08); color: var(--danger); }
html[data-theme="light"] .history-filter-drawer label { color: var(--text-secondary); }
html[data-theme="light"] .history-delete-confirm .history-confirm-icon { border-color: rgba(217, 45, 78, 0.34); background: rgba(217, 45, 78, 0.08); color: var(--danger); }
html[data-theme="light"] .history-delete-confirm p { color: var(--muted); }
html[data-theme="light"] .history-delete-confirm .history-confirm-record { color: var(--primary); }
@media (max-width: 900px) {
  html[data-theme="light"] .history-page .history-record-row,
  html[data-theme="light"] .history-page .history-record-row:last-child { border-color: var(--card-border); background: var(--card-1); }
  html[data-theme="light"] .history-record-row > :nth-child(3),
  html[data-theme="light"] .history-record-row > :nth-child(4),
  html[data-theme="light"] .history-record-row > :nth-child(5) { border-top-color: var(--card-border); }
  html[data-theme="light"] .history-record-row > :nth-child(3)::before,
  html[data-theme="light"] .history-record-row > :nth-child(4)::before,
  html[data-theme="light"] .history-record-row > :nth-child(5)::before,
  html[data-theme="light"] .history-record-row > :nth-child(6) { color: var(--text-muted); }
  html[data-theme="light"] .history-summary-item + .history-summary-item,
  html[data-theme="light"] .history-summary-item:nth-child(n+3) { border-color: var(--card-border); }
}
