.history-dialog {
  width: min(1420px, calc(100% - 2rem));
  max-height: 92vh;
  padding: 0;
  border: 0;
  border-radius: 20px;
  color: var(--ink);
  box-shadow: 0 30px 90px rgba(0,0,0,.28);
}

.history-dialog::backdrop {
  background: rgba(5,22,17,.68);
  backdrop-filter: blur(3px);
}

.history-dialog > section {
  display: flex;
  flex-direction: column;
  max-height: 92vh;
}

.history-dialog .dialog-header h2 { margin: 0; font-size: 1.6rem; }
.history-dialog .dialog-header p:last-child { margin: .35rem 0 0; color: var(--muted); }
.history-body { min-height: 0; overflow: hidden; padding: 1rem 1.25rem 0; }

.history-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1.4fr) repeat(2, minmax(140px, .7fr)) repeat(2, minmax(145px, .65fr)) auto;
  gap: .7rem;
  align-items: end;
}

.history-toolbar label {
  display: grid;
  gap: .35rem;
  color: #53645e;
  font-size: .75rem;
  font-weight: 750;
}

.history-toolbar input,
.history-toolbar select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cbd8d3;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  padding: .62rem .72rem;
}

.history-toolbar-actions { display: flex; gap: .45rem; }
.history-meta { display: flex; justify-content: space-between; gap: 1rem; margin-top: 1rem; padding: .7rem .15rem; color: var(--muted); font-size: .78rem; border-bottom: 1px solid var(--line); }
.history-table-wrap { overflow: auto; max-height: 55vh; }
.history-table-wrap table { width: 100%; min-width: 1080px; border-collapse: separate; border-spacing: 0; font-size: .8rem; }
.history-table-wrap th { position: sticky; top: 0; z-index: 2; background: #eef4f1; color: #53645e; text-align: left; padding: .72rem; border-bottom: 1px solid #cfdcd7; text-transform: uppercase; letter-spacing: .055em; font-size: .68rem; }
.history-table-wrap td { padding: .72rem; border-bottom: 1px solid #e8eeeb; vertical-align: top; }
.history-table-wrap td:nth-child(1) { white-space: nowrap; }
.history-table-wrap td:nth-child(2) { min-width: 170px; }
.history-table-wrap td:nth-child(3) { min-width: 160px; }
.history-table-wrap td:last-child { min-width: 300px; max-width: 520px; }
.history-worker strong, .history-worker span { display: block; }
.history-worker span { margin-top: .2rem; color: var(--muted); font-size: .72rem; }
.history-change-list { display: grid; gap: .3rem; }
.history-more summary { cursor: pointer; color: var(--green); text-decoration: underline; text-underline-offset: .15em; }
.history-more summary:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
.history-more[open] .history-change { display: block; margin-top: .3rem; }
.history-change { line-height: 1.35; }
.history-change strong { color: #31554a; }
.history-change del { color: #9f1d1d; text-decoration: none; }
.history-change ins { color: #176e50; text-decoration: none; }
.history-pill { display: inline-flex; padding: .3rem .52rem; border-radius: 999px; background: #eef4f1; color: #31554a; font-size: .7rem; font-weight: 800; }
.history-pill.insert { background: #dff4eb; color: #176e50; }
.history-pill.update { background: #fff2cc; color: #725600; }
.history-pill.delete { background: #ffeded; color: #9f1d1d; }
.history-footer { display: flex; align-items: center; gap: .7rem; padding: 1rem 1.25rem; border-top: 1px solid var(--line); background: #f8faf9; }
.history-pagination { display: flex; align-items: center; justify-content: center; gap: .65rem; margin-left: auto; }
.history-pagination span { min-width: 70px; text-align: center; color: var(--muted); font-size: .82rem; }

.recent-history-panel {
  margin-top: 1rem;
}

.recent-history-panel .history-table-wrap td:nth-child(3) { min-width: 105px; white-space: nowrap; }
.recent-history-panel .history-table-wrap td:nth-child(4) { min-width: 75px; white-space: nowrap; }
.recent-history-panel .history-table-wrap td:nth-child(5) { min-width: 160px; }

.sim-renew-panel {
  margin-top: 1rem;
  border-top: 3px solid #ed7d31;
}

.sim-renew-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 1.15rem 1.25rem .9rem;
}

.sim-renew-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.sim-renew-header p:last-child {
  margin: .35rem 0 0;
  color: var(--muted);
  font-size: .86rem;
}

.sim-renew-size {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
  white-space: nowrap;
}

.sim-renew-size select {
  border: 1px solid #cbd8d3;
  border-radius: 8px;
  padding: .58rem .7rem;
  background: #fff;
  color: var(--ink);
}

.sim-renew-panel .table-wrap {
  max-height: 420px;
}

.sim-renew-resize-controls { display: flex; align-items: center; gap: .7rem; padding: .2rem 1rem; border-top: 1px solid var(--line); }
#sim-renew-table-wrap[hidden] + .sim-renew-resize-controls { display: none; }
#sim-renew-resizer { flex: 1; display: flex; justify-content: center; align-items: center; gap: .5rem; min-height: 28px; cursor: ns-resize; touch-action: none; user-select: none; color: var(--muted); font-size: .75rem; border-radius: 4px; }
#sim-renew-resizer:hover, #sim-renew-resizer:focus-visible { background: #edf5f1; color: #116b50; outline: 2px solid #128263; outline-offset: -2px; }
#sim-renew-resizer > span:first-child { font-size: 1rem; letter-spacing: 2px; transform: rotate(90deg); }
#sim-renew-reset-height { border: 1px solid #cbd8d3; border-radius: 5px; background: #fff; color: #31554a; font: inherit; font-size: .75rem; padding: .25rem .5rem; cursor: pointer; }

.sim-renew-panel .loading-state,
.sim-renew-panel .empty-state {
  min-height: 170px;
}

.sim-renew-panel .pagination {
  justify-content: space-between;
}

.sim-renew-hint {
  color: var(--muted);
  font-size: .78rem;
  text-align: left !important;
}

.sim-renew-panel tr.pending-removal {
  background: #fff7e7;
  opacity: .62;
  transition: opacity .25s ease, background-color .25s ease;
}

.recent-history-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 1.15rem 1.25rem .2rem;
}

.recent-history-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.recent-history-header p:last-child {
  margin: .35rem 0 0;
  color: var(--muted);
  font-size: .86rem;
}

.recent-history-size {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
  white-space: nowrap;
}

.recent-history-search { margin: .9rem 1.25rem 0; max-width: 510px; }
.recent-history-search label { display: block; font-size: .82rem; font-weight: 700; margin-bottom: .4rem; }
.recent-history-search-controls { display: flex; align-items: center; gap: .5rem; }
.recent-history-search input { min-width: 0; flex: 1; width: 100%; border: 1px solid #cbd8d3; border-radius: 8px; padding: .65rem .75rem; color: var(--ink); background: #fff; font: inherit; }
.recent-history-search input:focus { outline: 2px solid var(--accent, #128263); outline-offset: 2px; }
.recent-history-search .button { flex-shrink: 0; }

.recent-history-size select {
  border: 1px solid #cbd8d3;
  border-radius: 8px;
  padding: .58rem .7rem;
  background: #fff;
  color: var(--ink);
}

.recent-history-panel .history-meta {
  margin: .7rem 1.25rem 0;
  padding-inline: 0;
}

.recent-history-panel .history-table-wrap {
  max-height: 390px;
}

.recent-history-panel .loading-state,
.recent-history-panel .empty-state {
  min-height: 170px;
}

@media (max-width: 1050px) {
  .history-toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-search { grid-column: 1 / -1; }
  .history-toolbar-actions { justify-content: flex-end; }
}

@media (max-width: 650px) {
  .history-dialog { width: calc(100% - 1rem); }
  .history-toolbar { grid-template-columns: 1fr; }
  .history-search { grid-column: auto; }
  .history-toolbar-actions { justify-content: stretch; }
  .history-toolbar-actions .button { flex: 1; }
  .history-meta span:last-child { display: none; }
  .history-footer { flex-wrap: wrap; }
  .history-pagination { order: 3; width: 100%; margin-left: 0; }
  .recent-history-header { align-items: stretch; flex-direction: column; }
  .recent-history-size { justify-content: space-between; }
  .sim-renew-header { align-items: stretch; flex-direction: column; }
  .sim-renew-size { justify-content: space-between; }
  .sim-renew-panel .pagination { align-items: stretch; flex-direction: column; }
  .sim-renew-hint { text-align: center !important; }
}
