/* ============================================================================
 * chem_ptable.css
 * Periodic Table Grid, Radial Concentric Bohr, View Switcher & Curtain Motion
 * Part of [OAW-Chem] platform styles (<= 280 lines)
 * ============================================================================ */

:root, [data-theme="white"] {
  --chem-block-s: #f59e0b; --chem-block-p: #0284c7; --chem-block-d: #059669; --chem-block-f: #7c3aed; --chem-valence: #ea580c; --chem-ingredient: #10b981; --chem-tile-bg: var(--bg-elevated, #f8fafc); --chem-tile-border: var(--border-grid, #e2e8f0); --chem-radial-s: rgba(245, 158, 11, 0.22); --chem-radial-p: rgba(2, 132, 199, 0.22); --chem-radial-d: rgba(5, 150, 105, 0.22); --chem-radial-f: rgba(124, 58, 237, 0.22);
}
[data-theme="paper"] {
  --chem-block-s: #d97706; --chem-block-p: #0369a1; --chem-block-d: #047857; --chem-block-f: #6d28d9; --chem-valence: #c2410c; --chem-ingredient: #059669; --chem-tile-bg: var(--bg-elevated, #f3efe6); --chem-tile-border: var(--border-grid, #d6d0c4); --chem-radial-s: rgba(217, 119, 6, 0.24); --chem-radial-p: rgba(3, 105, 161, 0.24); --chem-radial-d: rgba(4, 120, 87, 0.24); --chem-radial-f: rgba(109, 40, 217, 0.24);
}
[data-theme="dark-paper"] {
  --chem-block-s: #fbbf24; --chem-block-p: #38bdf8; --chem-block-d: #34d399; --chem-block-f: #a78bfa; --chem-valence: #fb923c; --chem-ingredient: #34d399; --chem-tile-bg: var(--bg-elevated, #211e1b); --chem-tile-border: var(--border-grid, #332e29); --chem-radial-s: rgba(251, 191, 36, 0.28); --chem-radial-p: rgba(56, 189, 248, 0.28); --chem-radial-d: rgba(52, 211, 153, 0.28); --chem-radial-f: rgba(167, 139, 250, 0.28);
}
[data-theme="dark"] {
  --chem-block-s: #f59e0b; --chem-block-p: #0ea5e9; --chem-block-d: #10b981; --chem-block-f: #8b5cf6; --chem-valence: #f97316; --chem-ingredient: #10b981; --chem-tile-bg: var(--bg-elevated, #111827); --chem-tile-border: var(--border-grid, #1e293b); --chem-radial-s: rgba(245, 158, 11, 0.32); --chem-radial-p: rgba(14, 165, 233, 0.32); --chem-radial-d: rgba(16, 185, 129, 0.32); --chem-radial-f: rgba(139, 92, 246, 0.32);
}

.chem-btn-return-tabs {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  background: var(--bg-surface, #f1f5f9); border: 1px solid var(--border-grid, #cbd5e1);
  border-radius: var(--radius-ui, 6px); font-family: var(--font-sans);
  font-size: 0.82rem; font-weight: 600; color: var(--accent-link, #2563eb);
  cursor: pointer; transition: all 120ms ease;
}
.chem-btn-return-tabs:hover { background: var(--accent-link, #2563eb); color: #fff; border-color: var(--accent-link, #2563eb); }
.chem-btn-return-tabs.hidden { display: none !important; }

/* Chemistry Workbench Viewport & Stage Switching */
[data-view="chemistry"] #pubWorkspace {
  display: block !important; overflow: hidden !important; height: calc(100dvh - 46px) !important;
}
[data-view="chemistry"] #whitepaperMain,
[data-view="chemistry"] #tocSidebar,
[data-view="chemistry"] #codeDrawer,
[data-view="chemistry"] .portal-home-mount,
[data-view="chemistry"] #btnToggleTocSidebar,
[data-view="chemistry"] #btnToggleCodeDrawer,
[data-view="chemistry"] #btnToggleReviewMode,
[data-view="chemistry"] .pub-masthead .top-quick-search-wrap { display: none !important; }
html[data-view="chemistry"] #chemWorkspaceMount,
html[data-view="chemistry"] .chem-workspace-mount {
  display: flex !important; flex-direction: column; width: 100%; height: 100%; min-height: 0; overflow: hidden;
}
html:not([data-view="chemistry"]) #chemWorkspaceMount,
html:not([data-view="chemistry"]) .chem-workspace-mount {
  display: none !important;
}

/* Workbench Shell & Curtain Transition */
.chem-workbench-shell {
  display: flex; flex-direction: column; flex: 1;
  height: calc(100vh - var(--header-height, 56px));
  height: calc(100dvh - var(--header-height, 56px));
  min-height: 0; width: 100%; position: relative; overflow: hidden;
  background: var(--bg-canvas); color: var(--ink-primary);
}

.chem-stage-table {
  display: flex; flex-direction: column; width: 100%; flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: auto; padding: 4px 10px 8px;
  box-sizing: border-box;
}

.chem-curtain-pulled .chem-stage-table {
  display: none !important;
}

.chem-stage-workspace {
  display: flex; flex-direction: row; flex: 1; height: 100%; min-height: 0; overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .chem-stage-table, .chem-stage-workspace { transition: none !important; }
}

/* Toolbar & View Switcher */
.chem-stage-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 2px 4px 4px; border-bottom: 1px solid var(--border-grid);
  margin-bottom: 4px; flex-wrap: nowrap; gap: 8px; flex-shrink: 0; min-height: 36px;
}
.chem-toolbar-left { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chem-toolbar-center { flex: 1; min-width: 0; display: flex; justify-content: center; }
.chem-toolbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; flex-wrap: nowrap; }
.chem-stage-title { font-family: var(--font-serif); font-size: 1.05rem; font-weight: 600; margin: 0; color: var(--ink-primary); white-space: nowrap; }
.chem-stage-toolbar .chem-btn-principles { padding: 4px 10px; font-size: 0.78rem; height: 30px; box-sizing: border-box; white-space: nowrap; }
.chem-view-switcher { display: inline-flex; background: var(--bg-recessed); border-radius: var(--radius-ui, 6px); padding: 2px; gap: 2px; }
.chem-view-tab {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px;
  font-size: 0.78rem; font-weight: 500; border: none; background: transparent;
  color: var(--ink-secondary); border-radius: calc(var(--radius-ui, 6px) - 2px); cursor: pointer; transition: all 140ms ease; white-space: nowrap;
}
.chem-view-tab.active { background: var(--bg-canvas); color: var(--ink-primary); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }
@media (max-width: 1080px) { .chem-stage-title { display: none; } }
@media (max-width: 1040px) {
  .chem-stage-toolbar .chem-motd-pill { max-width: min(100%, 260px); overflow: hidden; white-space: nowrap; padding: 3px 10px; font-size: 0.74rem; }
  .chem-view-tab, .chem-stage-toolbar .chem-btn-principles { padding: 4px 8px; font-size: 0.74rem; }
}
@media (max-width: 820px) {
  .chem-stage-toolbar .chem-motd-pill { max-width: 210px; }
}
@media (max-width: 759px) {
  .chem-stage-toolbar { flex-wrap: wrap; gap: 6px; padding: 6px 4px; }
  .chem-toolbar-left { flex: 0 0 auto; }
  .chem-toolbar-right { flex: 1 1 auto; justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
  .chem-toolbar-center { order: 3; flex: 1 1 100%; justify-content: flex-start; }
  .chem-stage-toolbar .chem-motd-pill { max-width: 100%; }
}

/* MOTD Preview Card */
.chem-motd-card {
  display: flex; flex-direction: column; align-items: flex-start;
  background: var(--bg-elevated); border: 1px solid var(--border-grid);
  border-left: 4px solid var(--chem-ingredient); border-radius: var(--radius-card, 10px);
  padding: 8px 14px; margin: 0 auto 10px; max-width: 960px; width: 100%;
  box-sizing: border-box; gap: 8px; flex-shrink: 0;
}

.chem-motd-badge {
  font-size: 0.72rem; text-transform: uppercase; font-weight: 700;
  letter-spacing: 0.05em; padding: 2px 8px;
  background: var(--tint-emerald-bg, rgba(16, 185, 129, 0.12));
  color: var(--chem-ingredient); border-radius: var(--radius-pill);
  display: inline-flex; align-items: center; gap: 5px;
}

.chem-motd-main {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; width: 100%;
}

.chem-motd-preview {
  width: 120px; height: 78px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg-canvas); border: 1px solid var(--border-grid); border-radius: 8px;
  overflow: hidden; padding: 4px; box-sizing: border-box;
}
.chem-motd-preview svg { width: 100%; height: 100%; max-height: 70px; display: block; }

.chem-motd-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.chem-motd-title { margin: 0; font-family: var(--font-serif); font-size: 1.1rem; display: flex; align-items: baseline; gap: 8px; }
.chem-motd-name { color: var(--ink-primary); font-weight: 600; }
.chem-motd-formula { font-family: var(--font-mono); font-weight: 700; font-size: 0.95rem; color: var(--accent-link); }
.chem-motd-desc { margin: 0; font-size: 0.78rem; color: var(--ink-secondary); line-height: 1.35; }

.chem-motd-actions { flex-shrink: 0; }

/* 18-Column Periodic Table Grid */
.chem-ptable-grid-wrapper {
  position: relative; width: 100%; overflow-x: auto; padding-bottom: 16px; flex-shrink: 0;
}

.chem-ptable-grid {
  display: grid;
  grid-template-columns: 20px repeat(18, minmax(44px, 1fr));
  grid-template-rows: 18px repeat(7, minmax(38px, 1fr)) 8px repeat(2, minmax(36px, 1fr));
  gap: 2px; min-width: 860px;
}

@media (min-width: 1200px) {
  .chem-ptable-grid {
    grid-template-columns: 24px repeat(18, minmax(52px, 1fr));
    grid-template-rows: 22px repeat(7, minmax(48px, 1fr)) 10px repeat(2, minmax(44px, 1fr));
    gap: 3px; min-width: 980px;
  }
}

.chem-grid-header {
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 600; color: var(--ink-muted);
}

.chem-grid-tile {
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 4px; background: var(--chem-tile-bg); border: 1px solid var(--chem-tile-border);
  border-radius: var(--radius-ui, 6px); cursor: pointer; position: relative;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
  user-select: none;
}

.chem-grid-tile:hover {
  transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
  border-color: var(--accent-link); z-index: 5;
}

.chem-grid-tile.active {
  outline: 2px solid var(--accent-link); box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2);
  z-index: 6;
}

.chem-tile-top {
  display: flex; justify-content: space-between; font-size: 0.65rem; color: var(--ink-muted);
}

.chem-tile-sym {
  font-size: 1.15rem; font-weight: 700; text-align: center; line-height: 1.1;
  color: var(--ink-primary);
}

.chem-tile-name {
  font-size: 0.62rem; text-align: center; color: var(--ink-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Block Accents */
.chem-grid-tile.block-s, .chem-rail-badge.block-s { border-top: 3px solid var(--chem-block-s); }
.chem-grid-tile.block-p, .chem-rail-badge.block-p { border-top: 3px solid var(--chem-block-p); }
.chem-grid-tile.block-d, .chem-rail-badge.block-d { border-top: 3px solid var(--chem-block-d); }
.chem-grid-tile.block-f, .chem-rail-badge.block-f { border-top: 3px solid var(--chem-block-f); }

/* Lanthanide / Actinide Indicator Tiles */
.chem-placeholder-tile {
  align-items: center; justify-content: center; border-style: dashed;
  padding: 2px 1px; text-align: center; overflow: hidden;
}
.chem-placeholder-tile .chem-tile-sub {
  font-size: 0.58rem; font-weight: 600; line-height: 1.1; opacity: 0.85;
}
.chem-placeholder-tile .chem-tile-sym {
  font-size: 0.82rem; font-weight: 700; line-height: 1.1;
}

/* Tooltip */
.chem-ptable-tooltip {
  position: absolute; background: var(--bg-elevated); border: 1px solid var(--border-grid);
  border-radius: var(--radius-ui, 6px); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  padding: 6px 10px; font-size: 0.78rem; pointer-events: none; z-index: 50; white-space: nowrap;
}

.chem-ptable-tooltip.hidden { display: none; }
