/* chem_modal.css - Two-Half Modal, Catalog & Calculators (<= 275 lines) */
html:has(dialog[open]:modal) { overflow: hidden; scrollbar-gutter: stable; }
dialog.chem-modal-dialog {
  border: 1px solid var(--border-grid, #e2e8f0); border-radius: var(--radius-card, 12px);
  background: var(--bg-canvas, #ffffff); color: var(--ink-primary, #0f172a);
  padding: 0; max-width: 980px; width: 92vw; max-height: 88vh;
  box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.35); overflow: hidden;
}
dialog.chem-modal-dialog:modal { overscroll-behavior: contain; }
dialog.chem-modal-dialog::backdrop {
  background: rgba(11, 15, 23, 0.65); backdrop-filter: blur(4px); overscroll-behavior: contain;
}
.chem-modal-wrapper { display: flex; flex-direction: column; max-height: 88vh; overflow: hidden; }
.chem-modal-header {
  display: flex; flex-wrap: nowrap; align-items: flex-start; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--border-grid, #e2e8f0);
  background: var(--bg-elevated, #f8fafc); flex-shrink: 0; gap: 8px;
}
.chem-modal-title-group { display: flex; flex: 1; align-items: center; gap: 10px; min-width: 0; min-height: 36px; }
.chem-modal-kicker {
  font-family: var(--font-mono, monospace); font-size: 0.75rem; font-weight: 700; flex-shrink: 0;
  color: var(--accent-link, #0284c7); background: var(--sig-bg, rgba(2, 132, 199, 0.1));
  padding: 2px 8px; border-radius: var(--radius-pill, 999px); white-space: nowrap;
}
.chem-modal-title {
  margin: 0; font-family: var(--font-sans, sans-serif); font-size: 1rem; font-weight: 700;
  color: var(--ink-primary, #0f172a); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chem-modal-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chem-modal-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; min-height: 36px;
  font-family: var(--font-sans, sans-serif); font-size: 0.8rem; font-weight: 600;
  border: 1px solid var(--border-grid, #e2e8f0); border-radius: var(--radius-ui, 8px);
  background: var(--bg-canvas, #ffffff); color: var(--ink-secondary, #334155);
  cursor: pointer; transition: all 0.15s ease;
}
.chem-modal-btn:hover { background: var(--bg-recessed, #f1f5f9); color: var(--ink-primary, #0f172a); }
.chem-modal-close-btn {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  padding: 6px 10px; border: none; background: transparent; color: var(--ink-muted, #64748b);
  border-radius: var(--radius-ui, 8px); cursor: pointer; min-height: 36px; min-width: 36px;
}
.chem-modal-close-btn:hover { background: var(--bg-recessed, #f1f5f9); color: var(--ink-primary, #0f172a); }
.chem-modal-close-btn:focus:not(:focus-visible), .chem-modal-btn:focus:not(:focus-visible) { outline: none; }
.chem-modal-close-btn:focus-visible, .chem-modal-btn:focus-visible {
  outline: 2px solid var(--accent-link, #1d4ed8); outline-offset: 2px;
}

/* 2-Half Split Container */
.chem-modal-body-split {
  display: grid; grid-template-columns: 1fr 1fr; flex: 1; min-height: 0; overflow: hidden;
}
.chem-modal-half { padding: 16px 20px; overflow-y: auto; overscroll-behavior: contain; min-width: 0; }
.chem-modal-half-1 { border-right: 1px solid var(--border-grid, #e2e8f0); background: var(--bg-canvas, #ffffff); }
.chem-modal-half-2 { background: var(--bg-elevated, #f8fafc); }
.chem-half-badge {
  display: inline-block; font-family: var(--font-mono, monospace); font-size: 0.72rem;
  font-weight: 600; color: var(--ink-muted, #64748b); text-transform: uppercase; margin-bottom: 6px;
}
.chem-rule-plain {
  font-family: var(--font-serif, serif); font-size: 1.05rem; line-height: 1.6;
  color: var(--ink-primary, #0f172a); margin: 0 0 14px 0;
}
.chem-boundary-card {
  background: var(--bg-recessed, #f1f5f9); border-left: 3px solid var(--accent-link, #1d4ed8);
  padding: 10px 14px; border-radius: 0 var(--radius-ui, 6px) var(--radius-ui, 6px) 0; margin-bottom: 14px;
}
.chem-boundary-title {
  font-family: var(--font-sans, sans-serif); font-size: 0.76rem; font-weight: 700;
  color: var(--ink-secondary, #334155); margin-bottom: 4px;
}
.chem-boundary-text {
  font-family: var(--font-mono, monospace); font-size: 0.8rem; color: var(--ink-secondary, #334155);
  line-height: 1.45; margin: 0;
}
.chem-half-sources { margin-top: 14px; border-top: 1px solid var(--border-grid, #e2e8f0); padding-top: 10px; }
.chem-half-sources summary {
  list-style: none !important; display: flex; align-items: center; gap: 8px;
  font-size: 0.78rem; font-weight: 600; color: var(--ink-muted, #64748b); cursor: pointer;
}
.chem-half-sources summary::-webkit-details-marker,
.chem-half-sources summary::marker,
.chem-modal-dialog summary::-webkit-details-marker,
.chem-modal-dialog summary::marker { display: none !important; }
.chem-half-sources-list { margin: 8px 0 0 0; padding-left: 16px; font-size: 0.76rem; color: var(--ink-secondary, #334155); }

/* Calculators Form & Controls */
.chem-calc-title {
  font-family: var(--font-sans, sans-serif); font-size: 0.95rem; font-weight: 700;
  color: var(--ink-primary, #0f172a); margin: 0 0 12px 0; display: flex; align-items: center; gap: 8px;
}
.chem-calc-row {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 10px;
}
.chem-calc-lbl {
  font-family: var(--font-sans, sans-serif); font-size: 0.82rem; font-weight: 600; color: var(--ink-secondary, #334155);
}
.chem-calc-select, .chem-calc-slider {
  font-family: var(--font-sans, sans-serif); font-size: 0.84rem; padding: 5px 8px;
  border: 1px solid var(--border-subtle, var(--border-grid, #e2e8f0)); border-radius: var(--radius-ui, 6px);
  background: var(--bg-canvas, #ffffff); color: var(--ink-primary, #0f172a); min-height: 36px; min-width: 0; max-width: 100%;
}
.chem-calc-select { flex: 1 1 180px; }
.chem-calc-select:focus:not(:focus-visible) { outline: none; }
.chem-calc-select:focus-visible, .chem-step-btn:focus-visible { outline: 2px solid var(--accent-link, #1d4ed8); outline-offset: 2px; border-color: var(--accent-link, #1d4ed8); }
.chem-calc-stepper { display: flex; align-items: center; gap: 6px; }
.chem-step-btn {
  width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-grid, #e2e8f0); border-radius: var(--radius-ui, 6px);
  background: var(--bg-canvas, #ffffff); color: var(--ink-primary, #0f172a); cursor: pointer; font-weight: 700;
}
.chem-step-val { font-family: var(--font-mono, monospace); font-size: 0.95rem; font-weight: 700; min-width: 44px; text-align: center; }
.chem-calc-vis-wrap {
  background: var(--bg-canvas, #ffffff); border: 1px solid var(--border-grid, #e2e8f0);
  border-radius: var(--radius-ui, 8px); padding: 8px 10px; margin: 10px 0;
  display: flex; flex-direction: column; align-items: center; width: 100%; box-sizing: border-box;
}
.chem-calc-vis-wrap svg { max-width: 100%; height: auto; }
.chem-energy-svg { width: 100%; max-width: 280px; height: auto; aspect-ratio: 280 / 124; display: block; margin-top: 6px; }
.chem-calc-metric {
  display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; width: 100%;
  font-family: var(--font-mono, monospace); font-size: 0.8rem; padding: 4px 0;
  color: var(--ink-secondary, #334155); border-bottom: 1px dashed var(--border-grid, #e2e8f0);
}
.chem-calc-metric strong { color: var(--ink-primary, #0f172a); }
.chem-nuclide-notation sup { font-size: 0.72em; vertical-align: super; line-height: 0; }
.chem-nuclide-notation sub { font-size: 0.72em; vertical-align: sub; line-height: 0; margin-right: 1px; }
.chem-calc-presets { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.chem-preset-btn {
  font-size: 0.72rem; padding: 3px 8px; border: 1px solid var(--border-grid, #e2e8f0);
  border-radius: var(--radius-pill, 999px); background: var(--bg-canvas, #ffffff);
  color: var(--ink-secondary, #334155); cursor: pointer;
}
.chem-preset-btn:hover { background: var(--bg-recessed, #f1f5f9); border-color: var(--accent-link, #0284c7); }

/* Principles Catalog */
.chem-principles-catalog { display: flex; flex-direction: column; gap: 12px; }
.chem-catalog-search {
  display: flex; align-items: center; gap: 8px; background: var(--bg-elevated, #f8fafc);
  border: 1px solid var(--border-grid, #e2e8f0); border-radius: var(--radius-ui, 8px); padding: 6px 12px;
}
.chem-catalog-search:focus-within, .chem-search-head:focus-within {
  outline: 2px solid var(--accent-link, #1d4ed8); outline-offset: -2px;
}
.chem-catalog-input {
  border: none; background: transparent; width: 100%; min-width: 0; font-family: var(--font-sans, sans-serif);
  font-size: 0.86rem; color: var(--ink-primary, #0f172a); outline: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chem-cat-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chem-cat-chip {
  padding: 4px 10px; font-size: 0.72rem; font-weight: 600; border: 1px solid var(--border-grid, #e2e8f0);
  border-radius: var(--radius-pill, 999px); background: var(--bg-canvas, #ffffff);
  color: var(--ink-secondary, #334155); cursor: pointer;
}
.chem-cat-chip.active { background: var(--ink-primary, #0f172a); color: var(--bg-canvas, #ffffff); border-color: var(--ink-primary, #0f172a); }
.chem-principles-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px;
  max-height: 55vh; overflow-y: auto; padding: 3px 4px;
}
button.chem-principle-card {
  display: block; width: 100%; text-align: left; font-family: inherit;
  padding: 10px 12px; border: 1px solid var(--border-grid, #e2e8f0); border-radius: var(--radius-ui, 8px);
  background: var(--bg-canvas, #ffffff); color: var(--ink-primary, #0f172a); cursor: pointer; transition: all 0.15s ease;
}
button.chem-principle-card:hover { border-color: var(--accent-link, #0284c7); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); }
button.chem-principle-card:focus-visible, .chem-cat-chip:focus-visible { outline: 2px solid var(--accent-link, #1d4ed8); outline-offset: -2px; }
.chem-principle-id { display: block; font-family: var(--font-mono, monospace); font-size: 0.7rem; font-weight: 600; color: var(--accent-link, #0284c7); }
.chem-principle-title { display: block; font-family: var(--font-sans, sans-serif); font-size: 0.85rem; font-weight: 700; margin: 2px 0 4px 0; }
.chem-principle-snippet {
  display: block; font-family: var(--font-sans, sans-serif); font-size: 0.75rem; line-height: 1.4;
  color: var(--ink-muted, #64748b); margin: 0;
}
.chem-btn-principles {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  font-family: var(--font-sans, sans-serif); font-size: 0.8rem; font-weight: 600;
  border: 1px solid var(--border-grid, #e2e8f0); border-radius: var(--radius-ui, 8px);
  background: var(--bg-canvas, #ffffff); color: var(--ink-secondary, #334155); cursor: pointer;
}
.chem-btn-principles:hover { background: var(--bg-recessed, #f1f5f9); color: var(--accent-link, #0284c7); }

/* Catalyst Toggle Switch */
.chem-toggle-wrap { display: flex; align-items: center; gap: 8px; }
.chem-toggle-switch { position: relative; display: inline-block; flex-shrink: 0; width: 44px; height: 24px; cursor: pointer; }
.chem-toggle-switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 2; }
.chem-toggle-slider {
  position: absolute; inset: 0; background: var(--ink-muted, #64748b);
  border: 1px solid var(--ink-muted, #64748b); border-radius: 24px; transition: background-color 0.12s ease, border-color 0.12s ease;
}
.chem-toggle-slider::before {
  content: ''; position: absolute; height: 18px; width: 18px; left: 2px; top: 2px;
  background: #ffffff; border-radius: 50%; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.12s ease;
}
.chem-toggle-switch input:checked + .chem-toggle-slider { background: var(--ink-primary, #0f172a); border-color: var(--ink-primary, #0f172a); }
[data-theme="dark"] .chem-toggle-switch input:checked + .chem-toggle-slider,
[data-theme="dark-paper"] .chem-toggle-switch input:checked + .chem-toggle-slider {
  background: var(--accent-link, #60a5fa); border-color: var(--accent-link, #60a5fa);
}
[data-theme="dark"] .chem-toggle-switch input:checked + .chem-toggle-slider::before,
[data-theme="dark-paper"] .chem-toggle-switch input:checked + .chem-toggle-slider::before {
  background: var(--bg-canvas, #0b0f17);
}
.chem-toggle-switch input:checked + .chem-toggle-slider::before { transform: translateX(20px); }
.chem-toggle-switch input:focus-visible + .chem-toggle-slider { outline: 2px solid var(--accent-link, #1d4ed8); outline-offset: 2px; }

/* Responsive Split & 390px Dialog Containment */
@media (max-width: 839px) {
  dialog.chem-modal-dialog { width: calc(100vw - 16px); max-width: calc(100vw - 16px); max-height: 92vh; }
  .chem-modal-wrapper { max-height: 92vh; }
  .chem-modal-body-split { display: flex; flex-direction: column; overflow-y: auto; }
  .chem-modal-half-1 { border-right: none; border-bottom: 1px solid var(--border-grid, #e2e8f0); }
  .chem-modal-half { overflow-y: visible; padding: 14px; }
  .chem-step-btn, .chem-calc-select, .chem-modal-btn { min-height: 44px; min-width: 44px; }
}
@media (max-width: 640px) {
  .chem-modal-header { flex-wrap: nowrap; padding: 10px 12px; gap: 8px; }
  .chem-modal-title-group { flex: 1; min-width: 0; align-items: flex-start; min-height: 0; gap: 6px; }
  .chem-modal-kicker { margin-top: 2px; }
  .chem-modal-title { white-space: normal; font-size: 0.92rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .chem-modal-half { padding: 10px 12px; }
  .chem-modal-half-2 { padding-bottom: 12px; }
  .chem-rule-plain { font-size: 0.86rem; line-height: 1.4; margin: 4px 0 8px; }
  .chem-boundary-card { padding: 8px 10px; }
  .chem-half-sources { margin-top: 8px; padding-top: 8px; }
  .chem-calc-title { margin-bottom: 6px; font-size: 0.88rem; }
  .chem-calc-row { flex-direction: column; align-items: stretch; gap: 3px; margin-bottom: 5px; }
  .chem-calc-select { flex: 0 0 auto; width: 100%; }
  .chem-calc-vis-wrap { padding: 6px 8px; margin: 5px 0 0; }
  .chem-calc-metric { font-size: 0.69rem; padding: 2px 0; gap: 4px; }
  .chem-energy-svg { max-width: 244px; margin-top: 4px; }
  .chem-principles-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .chem-modal-header .chem-modal-btn span { display: none; }
  .chem-modal-header .chem-modal-btn, .chem-modal-close-btn {
    min-width: 34px; min-height: 34px; width: 34px; height: 34px; padding: 0; justify-content: center;
  }
}

/* Chem Command Search Palette (Cmd+K) */
dialog.chem-search-dialog {
  border: 1px solid var(--border-grid, #cbd5e1); border-radius: 12px; background: var(--bg-canvas, #ffffff);
  color: var(--ink-primary, #0f172a); padding: 0; width: 620px; max-width: 94vw; max-height: 82vh;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.3); overflow: hidden;
}
dialog.chem-search-dialog::backdrop { background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(4px); }
.chem-search-palette { display: flex; flex-direction: column; max-height: 82vh; }
.chem-search-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border-grid);
  background: var(--bg-elevated, #f8fafc);
}
.chem-search-icon { color: var(--ink-muted); font-size: 0.9rem; }
.chem-search-input {
  flex: 1; min-width: 0; border: none; outline: none; background: transparent; font-size: 0.95rem;
  font-family: var(--font-sans); color: var(--ink-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chem-search-input::-webkit-search-cancel-button,
.chem-search-input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.chem-search-close-btn {
  background: transparent; border: none; font-size: 1.1rem; color: var(--ink-muted); cursor: pointer; padding: 4px;
}
.chem-search-results { overflow-y: auto; padding: 8px; max-height: 60vh; }
.chem-search-group { margin-bottom: 8px; }
.chem-search-group-title {
  font-size: 0.65rem; font-weight: 700; text-transform: uppercase; color: var(--ink-muted);
  padding: 4px 8px; letter-spacing: 0.05em;
}
.chem-search-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px;
  border-radius: 8px; cursor: pointer; transition: background 120ms ease;
}
.chem-search-row:hover, .chem-search-row.is-highlighted { background: var(--bg-recessed, #f1f5f9); }
.chem-search-row-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chem-search-badge {
  font-size: 0.65rem; font-weight: 600; padding: 1px 6px; border-radius: 4px;
  background: var(--bg-recessed); color: var(--ink-muted); font-family: var(--font-mono);
}
.chem-search-sym { font-weight: 700; font-family: var(--font-mono); font-size: 0.88rem; color: var(--ink-primary); }
.chem-search-name { font-size: 0.82rem; color: var(--ink-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chem-search-path { font-size: 0.72rem; color: var(--ink-muted); font-family: var(--font-mono); margin-left: 6px; }
.chem-search-chips { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.chem-search-chip {
  font-size: 0.65rem; font-weight: 600; padding: 2px 6px; border-radius: 4px; border: 1px solid var(--border-grid);
  background: var(--bg-canvas); color: var(--accent-link); cursor: pointer;
}
.chem-search-chip:hover { background: rgba(37, 99, 235, 0.1); }
.chem-search-footer {
  display: flex; align-items: center; justify-content: space-between; padding: 6px 12px;
  font-size: 0.7rem; color: var(--ink-muted); border-top: 1px solid var(--border-grid); background: var(--bg-elevated);
}

