/* =============================================================================
 * history-modal.css
 * --------------------------------------------------------------------------
 * Visible-on-every-theme styling for the version history modal. Loaded
 * after polish-final.css so it overrides legacy styles. The modal must:
 *   - Sit on top of every glass layer (z-index above modals)
 *   - Be readable in dark and light
 *   - Render usable layout even with a single version
 *   - Have a visible close button + overlay click + Esc closes
 * ============================================================================= */

#history-modal,
.history-modal {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#history-modal.hidden,
.history-modal.hidden { display: none !important; }

#history-modal .modal-overlay,
.history-modal .modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 9, 12, 0.62);
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
}

.history-card {
  position: relative;
  z-index: 1;
  width: min(1080px, calc(100vw - 32px));
  height: min(720px, calc(100vh - 56px));
  max-width: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  background: var(--bg, #14161c);
  color: var(--text, #f5f5f7);
  border: 1px solid var(--border, rgba(255,255,255,.16));
  box-shadow: 0 24px 80px rgba(0,0,0,.55), 0 4px 14px rgba(0,0,0,.32);
}
[data-theme="light"] .history-card {
  background: #ffffff;
  color: #0a0a0a;
  border-color: rgba(15,18,28,.12);
  box-shadow: 0 18px 50px rgba(15,18,28,.18);
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border, rgba(255,255,255,.10));
  flex: 0 0 auto;
}
.history-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}
.history-head-acts {
  display: flex;
  gap: 8px;
  align-items: center;
}
.history-head-acts .icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-2, rgba(245,245,247,.78));
  font-size: 18px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.history-head-acts .icon-btn:hover {
  background: rgba(255,255,255,.08);
  color: var(--text, #fff);
}
[data-theme="light"] .history-head-acts .icon-btn:hover {
  background: rgba(15,18,28,.08);
  color: #0a0a0a;
}
.history-head-acts .btn {
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--border, rgba(255,255,255,.16));
  background: rgba(255,255,255,.06);
  color: var(--text, #f5f5f7);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.history-head-acts .btn:hover { background: rgba(255,255,255,.12); }
[data-theme="light"] .history-head-acts .btn {
  background: #f4f5f7;
  color: #0a0a0a;
  border-color: rgba(15,18,28,.12);
}

.history-empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-2, rgba(245,245,247,.66));
  font-size: 14px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-wrap {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 0;
  overflow: hidden;
}
.history-list {
  overflow-y: auto;
  border-right: 1px solid var(--border, rgba(255,255,255,.10));
  background: rgba(255,255,255,.02);
}
[data-theme="light"] .history-list { background: rgba(15,18,28,.03); }

.history-item {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  cursor: pointer;
  transition: background 120ms ease;
}
.history-item:hover { background: rgba(255,255,255,.06); }
.history-item.active { background: rgba(91, 141, 239, .18); }
[data-theme="light"] .history-item:hover { background: rgba(15,18,28,.05); }
[data-theme="light"] .history-item.active { background: rgba(91, 141, 239, .14); }
.history-item .hi-time { font-size: 13px; font-weight: 600; }
.history-item .hi-meta { font-size: 12px; color: var(--text-2, rgba(245,245,247,.6)); margin-top: 2px; }

.history-diff-wrap {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.history-diff-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border, rgba(255,255,255,.10));
}
.history-diff-head .hd-title { font-size: 14px; font-weight: 600; }
.history-diff-head .hd-time { font-size: 12px; color: var(--text-2, rgba(245,245,247,.6)); margin-top: 2px; }
.history-diff-head .btn-primary {
  background: #fff;
  color: #0a0a0a;
  border: 1px solid #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.history-diff-head .btn-primary:hover { background: rgba(255,255,255,.92); }

.history-diff {
  flex: 1;
  overflow: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  padding: 16px 18px;
}
.history-diff h4 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-2, rgba(245,245,247,.62));
}
.diff-line {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12.5px;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}
.diff-line.added { background: rgba(126, 231, 135, 0.18); }
.diff-line.removed { background: rgba(255, 139, 139, 0.18); }
.diff-line.modified { background: rgba(255, 184, 107, 0.18); }
[data-theme="light"] .diff-line.added { background: rgba(46, 160, 67, 0.18); }
[data-theme="light"] .diff-line.removed { background: rgba(207, 34, 46, 0.16); }
[data-theme="light"] .diff-line.modified { background: rgba(212, 137, 18, 0.16); }

@media (max-width: 720px) {
  .history-card { width: 100%; height: calc(100vh - 24px); border-radius: 12px; }
  .history-wrap { grid-template-columns: 1fr; }
  .history-list { max-height: 200px; border-right: none; border-bottom: 1px solid var(--border, rgba(255,255,255,.10)); }
  .history-diff { grid-template-columns: 1fr; }
}
