/* The history surface stays quiet until the operator asks for it. */
.history-dialog {
  width: min(720px, calc(100vw - 28px));
  max-height: min(780px, calc(100vh - 32px));
  padding: 0;
  border: 1px solid #cbd8c4;
  border-radius: 18px;
  color: var(--ink);
  background: #fbfcf8;
  box-shadow: 0 24px 80px rgba(16, 38, 29, .28);
}
.topbar-actions #history-button { display: inline-flex; }
.history-dialog::backdrop { background: rgba(15, 33, 25, .52); backdrop-filter: blur(2px); }
.history-dialog:not([open]) { display: none; }
.history-dialog.is-open { display: block; position: fixed; inset: 50% auto auto 50%; transform: translate(-50%, -50%); z-index: 30; }
.history-dialog-shell { display: flex; max-height: min(780px, calc(100vh - 32px)); flex-direction: column; overflow: hidden; }
.history-dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 22px 24px 15px; border-bottom: 1px solid #e2e9de; background: linear-gradient(140deg, #f7faf2, #fbfcf8); }
.history-dialog-header h2 { margin: 0; color: var(--ink); font-size: 22px; letter-spacing: -.03em; }
.history-dialog-subtitle { max-width: 510px; margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.history-close-button { flex: 0 0 auto; width: 36px; height: 36px; border-color: #cbd8c4; border-radius: 9px; font-size: 21px; }
.history-search-form { display: grid; grid-template-columns: minmax(0, 1fr) 175px auto; align-items: end; gap: 9px; padding: 14px 24px 10px; border-bottom: 1px solid #edf1e9; }
.history-search-field, .history-filter-field { display: grid; gap: 4px; color: var(--muted); font-size: 10px; font-weight: 800; }
.history-search-field input, .history-filter-field select, .history-edit-form input, .history-edit-form textarea { width: 100%; min-height: 38px; padding: 7px 10px; border: 1px solid #cbd8c4; border-radius: 8px; color: var(--ink); background: #fff; font-size: 13px; }
.history-search-field input:focus, .history-filter-field select:focus, .history-edit-form input:focus, .history-edit-form textarea:focus { border-color: #8ca96f; outline: 3px solid rgba(123, 159, 91, .18); }
.history-search-button { min-height: 38px; }
.history-error { margin: 8px 24px 0; padding: 8px 10px; border: 1px solid #edc8c8; border-radius: 8px; color: #9e3543; background: #fff0f1; font-size: 12px; }
.history-status { min-height: 31px; padding: 9px 24px 4px; color: var(--muted); font-size: 11px; }
.history-status.is-success { color: #287050; }
.history-status.is-loading { color: #6f7f6f; }
.history-list { display: grid; gap: 7px; max-height: min(465px, 54vh); padding: 2px 24px 10px; overflow: auto; overscroll-behavior: contain; }
.history-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px 14px; padding: 12px 13px; border: 1px solid #dbe5d5; border-radius: 11px; background: #fff; }
.history-row:hover { border-color: #b6c99f; box-shadow: 0 5px 15px rgba(43, 75, 42, .06); }
.history-row-main { min-width: 0; }
.history-row-title { display: flex; min-width: 0; align-items: center; gap: 7px; }
.history-row-title strong { overflow: hidden; color: var(--ink); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.history-row-meta { display: flex; flex-wrap: wrap; gap: 5px 12px; margin-top: 5px; color: var(--muted); font-size: 11px; }
.history-row-note { margin: 6px 0 0; overflow: hidden; color: var(--ink-soft); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.history-status-badge { display: inline-flex; min-height: 21px; align-items: center; flex: 0 0 auto; padding: 0 6px; border-radius: 5px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.history-status-badge.is-complete { color: #35603f; background: #e5f0df; }
.history-status-badge.is-active { color: #8b641c; background: #fff1c9; }
.history-status-badge.is-error { color: #9e3543; background: #fff0f1; }
.history-row-actions { display: flex; align-items: flex-start; justify-content: flex-end; gap: 5px; }
.history-row-actions .text-button { min-height: 31px; padding: 0 8px; border-color: #cad8c4; color: var(--blue-deep); background: #f7faf2; font-size: 11px; white-space: nowrap; }
.history-row-actions .text-button:hover { border-color: #8aa877; background: #edf3e5; }
.history-row-actions .history-archive-button { color: #7f6653; }
.history-edit-form { grid-column: 1 / -1; display: grid; gap: 7px; margin-top: 2px; padding-top: 10px; border-top: 1px solid #edf1e9; }
.history-edit-form label { display: grid; gap: 4px; color: var(--muted); font-size: 10px; font-weight: 800; }
.history-edit-form textarea { min-height: 58px; resize: vertical; }
.history-edit-actions { display: flex; justify-content: flex-end; gap: 6px; }
.history-edit-actions .button { min-height: 32px; padding: 0 10px; font-size: 11px; }
.history-empty { display: grid; justify-items: center; gap: 4px; padding: 34px 24px 38px; color: var(--muted); text-align: center; font-size: 12px; }
.history-empty strong { color: var(--ink-soft); font-size: 14px; }
.history-empty-icon { display: grid; width: 34px; height: 34px; place-items: center; margin-bottom: 3px; border-radius: 10px; color: var(--blue-deep); background: #edf3e5; font-size: 20px; }
.history-pagination { display: flex; min-height: 53px; align-items: center; justify-content: center; gap: 14px; padding: 9px 24px 14px; border-top: 1px solid #e2e9de; color: var(--muted); font-size: 11px; }
.history-pagination .text-button:disabled { color: #a7b1a3; border-color: #e0e7dc; background: #f4f6f1; }

@media (max-width: 720px) {
  .topbar-actions #history-button { display: inline-flex; }
  .topbar-actions #history-button .history-button-label { display: none; }
  .history-dialog { width: calc(100vw - 16px); max-height: calc(100vh - 16px); border-radius: 14px; }
  .history-dialog-shell { max-height: calc(100vh - 16px); }
  .history-dialog-header { padding: 17px 15px 12px; }
  .history-dialog-header h2 { font-size: 20px; }
  .history-dialog-subtitle { font-size: 11px; line-height: 1.5; }
  .history-search-form { grid-template-columns: minmax(0, 1fr) minmax(106px, .62fr); padding: 11px 15px 8px; }
  .history-search-button { grid-column: 1 / -1; width: 100%; }
  .history-error { margin-right: 15px; margin-left: 15px; }
  .history-status { padding-right: 15px; padding-left: 15px; }
  .history-list { max-height: calc(100vh - 300px); padding-right: 15px; padding-left: 15px; }
  .history-row { grid-template-columns: 1fr; gap: 8px; padding: 11px; }
  .history-row-actions { justify-content: stretch; }
  .history-row-actions .text-button { flex: 1; min-height: 38px; }
  .history-pagination { padding-right: 15px; padding-left: 15px; }
}

.history-row-actions .history-delete-button, .history-delete-confirm .history-delete-button { color: #ac3b32; border-color: #dfb5b0; }
.history-delete-button:disabled { opacity: .45; cursor: not-allowed; }
.history-delete-confirm { grid-column: 1 / -1; padding: 10px; border: 1px solid #dfb5b0; border-radius: 8px; background: #fff8f6; color: #953a32; }
.history-delete-confirm p { margin: 0 0 10px; font-size: 12px; }
.history-delete-confirm .button { margin-right: 8px; }

@media (prefers-reduced-motion: reduce) {
  .history-dialog::backdrop { backdrop-filter: none; }
}
