/* ==========================================================================
   My Chemical Inventory - Main Stylesheet
   Periwinkle/Navy palette — dark (Deno-inspired) + light (Scribd-inspired)
   ========================================================================== */

/* --- CSS Custom Properties --- */
:root {
  /* ── Periwinkle Dark (default) ────────────────────────────────────────── */
  --accent: #9fa1ff;
  --accent-hover: #7b7eff;
  --accent-subtle: #c5c6ff;
  --accent-glow: rgba(159, 161, 255, 0.15);
  --accent-glow-strong: rgba(159, 161, 255, 0.3);

  --bg-primary: #0d0d16;
  --bg-secondary: #12121e;
  --bg-tertiary: #1a1a2e;
  --bg-card: #161624;
  --bg-input: #12121e;

  --text-primary: #eeeef8;
  --text-secondary: #b5baff;
  --text-muted: #565870;
  --text-inverse: #0d0d16;

  --border: #1e1e32;
  --border-subtle: #28284a;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.55);
  --shadow-glow: 0 0 24px rgba(159, 161, 255, 0.12);

  --font-body: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Fira Code', monospace;

  --nav-height: 3.5rem;
  --container-width: 1080px;
  --container-narrow: 720px;

  --grid-line: rgba(159, 161, 255, 0.04);

  /* Difficulty colors */
  --diff-easy: #86efac;
  --diff-moderate: #fcd34d;
  --diff-advanced: #f87171;

  /* Semantic status colors — consistent across all themes */
  --color-good: #4ade80;
  --color-good-text: #86efac;
  --color-good-bg: rgba(74, 222, 128, 0.1);
  --color-good-border: rgba(74, 222, 128, 0.35);
  --color-warn: #fbbf24;
  --color-warn-text: #fcd34d;
  --color-warn-bg: rgba(251, 191, 36, 0.1);
  --color-warn-border: rgba(251, 191, 36, 0.35);
  --color-poor: #fb923c;
  --color-bad: #f87171;
  --color-bad-text: #fca5a5;
  --color-bad-bg: rgba(248, 113, 113, 0.1);
  --color-bad-border: rgba(248, 113, 113, 0.35);

  /* Legacy surface aliases — used by older templates */
  --surface: var(--bg-secondary);
  --surface-2: var(--bg-tertiary);
  --surface-alt: var(--bg-tertiary);

  /* Reaction type colors */
  --rxn-oxidation: #f87171;
  --rxn-reduction: #60a5fa;
  --rxn-substitution: #a78bfa;
  --rxn-elimination: #fbbf24;
  --rxn-addition: #34d399;
  --rxn-condensation: #f472b6;
  --rxn-hydrolysis: #22d3ee;
  --rxn-rearrangement: #fb923c;
  --rxn-other: #6b7280;
}

/* ===== THEME: Periwinkle Light (Scribd-inspired clean white) ===== */
[data-theme="light"] {
  --accent: #5c5ff5;
  --accent-hover: #4a4de0;
  --accent-subtle: #9fa1ff;
  --accent-glow: rgba(92, 95, 245, 0.1);
  --accent-glow-strong: rgba(92, 95, 245, 0.2);

  --bg-primary: #ffffff;
  --bg-secondary: #f7f7fb;
  --bg-tertiary: #ededf8;
  --bg-card: #ffffff;
  --bg-input: #f7f7fb;

  --text-primary: #111120;
  --text-secondary: #3d3d6b;
  --text-muted: #8888aa;
  --text-inverse: #ffffff;

  --border: #e5e5f0;
  --border-subtle: #d8d8ee;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.1);
  --shadow-glow: none;
  --grid-line: rgba(92, 95, 245, 0.03);
}

/* ===== THEME: Navy Dark (palette 2 — #112E81 → #4382DF) ===== */
[data-theme="navy"] {
  --accent: #4382df;
  --accent-hover: #3570cc;
  --accent-subtle: #aaccd6;
  --accent-glow: rgba(67, 130, 223, 0.15);
  --accent-glow-strong: rgba(67, 130, 223, 0.3);

  --bg-primary: #0a0f1e;
  --bg-secondary: #0f1628;
  --bg-tertiary: #1a2440;
  --bg-card: #141c33;
  --bg-input: #0f1628;

  --text-primary: #dce8f5;
  --text-secondary: #aaccd6;
  --text-muted: #4a6070;
  --text-inverse: #0a0f1e;

  --border: #1a2440;
  --border-subtle: #243358;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 24px rgba(67, 130, 223, 0.12);
  --grid-line: rgba(67, 130, 223, 0.05);
}

/* ===== THEME: Navy Light ===== */
[data-theme="navy-light"] {
  --accent: #4647ae;
  --accent-hover: #3638a0;
  --accent-subtle: #7b7dcc;
  --accent-glow: rgba(70, 71, 174, 0.1);
  --accent-glow-strong: rgba(70, 71, 174, 0.2);

  --bg-primary: #f8faff;
  --bg-secondary: #ffffff;
  --bg-tertiary: #edf0ff;
  --bg-card: #ffffff;
  --bg-input: #f8faff;

  --text-primary: #0f1628;
  --text-secondary: #2d3a6a;
  --text-muted: #8090b0;
  --text-inverse: #ffffff;

  --border: #dde3f5;
  --border-subtle: #ccd3f0;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.07);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.1);
  --shadow-glow: none;
  --grid-line: rgba(70, 71, 174, 0.04);
}

/* ===== THEME: Carbon Dark (near-black minimal) ===== */
[data-theme="carbon"] {
  --accent: #b5baff;
  --accent-hover: #9fa1ff;
  --accent-subtle: #d0d2ff;
  --accent-glow: rgba(181, 186, 255, 0.12);
  --accent-glow-strong: rgba(181, 186, 255, 0.25);

  --bg-primary: #080808;
  --bg-secondary: #111111;
  --bg-tertiary: #1c1c1c;
  --bg-card: #141414;
  --bg-input: #111111;

  --text-primary: #eeeeee;
  --text-secondary: #aaaaaa;
  --text-muted: #555555;
  --text-inverse: #080808;

  --border: #222222;
  --border-subtle: #2e2e2e;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.6);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.8);
  --shadow-glow: 0 0 20px rgba(181, 186, 255, 0.08);
  --grid-line: rgba(255, 255, 255, 0.02);
}

/* ===== THEME: Mint Dark (chemistry green, kept for lab feel) ===== */
[data-theme="mint"] {
  --accent: #6ee7b7;
  --accent-hover: #34d399;
  --accent-subtle: #a7f3d0;
  --accent-glow: rgba(110, 231, 183, 0.15);
  --accent-glow-strong: rgba(110, 231, 183, 0.3);

  --bg-primary: #080f0c;
  --bg-secondary: #0f1a14;
  --bg-tertiary: #162510;
  --bg-card: #121e17;
  --bg-input: #0f1a14;

  --text-primary: #e0f5ec;
  --text-secondary: #6ee7b7;
  --text-muted: #3d5c4a;
  --text-inverse: #080f0c;

  --border: #162510;
  --border-subtle: #1e3520;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.55);
  --shadow-glow: 0 0 24px rgba(110, 231, 183, 0.1);
  --grid-line: rgba(110, 231, 183, 0.04);
}

/* ===== Nav search bar ===== */
.nav__search {
  position: relative;
  margin-left: 1rem;
}
.nav__search-input {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.85rem;
  padding: 0.35rem 0.8rem;
  width: 200px;
  transition: width 0.2s, border-color 0.2s;
}
.nav__search-input:focus {
  outline: none;
  border-color: var(--accent);
  width: 280px;
}
.nav__search-input::placeholder {
  color: var(--text-muted);
}
.nav__search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  margin-top: 4px;
  max-height: 400px;
  overflow-y: auto;
}
.nav__search-results.is-open {
  display: block;
}
.nav__search-result {
  display: block;
  padding: 0.5rem 0.8rem;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.nav__search-result:last-child {
  border-bottom: none;
}
.nav__search-result:hover {
  background: var(--bg-tertiary);
  color: var(--accent);
}
.nav__search-result__formula {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  margin-left: 0.5rem;
}
.nav__search-result--nav {
  color: var(--accent-subtle);
  font-size: 0.82rem;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
}
.nav__search-result--nav:hover {
  color: var(--accent);
  background: var(--bg-secondary);
}
.nav__search-result__nav-icon {
  margin-right: 0.4rem;
  opacity: 0.6;
  font-size: 0.78rem;
}

@media (max-width: 768px) {
  .nav__search { display: none; }
}

/* ===== Theme picker styles ===== */
.theme-picker {
  position: relative;
  display: inline-flex;
}
.theme-picker__btn {
  background: none; border: none; cursor: pointer; padding: 4px;
  display: flex; align-items: center; gap: 4px; color: var(--text-muted);
  font-size: 0.8rem; border-radius: var(--radius-sm);
}
.theme-picker__btn:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.theme-picker__dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--border);
}
.theme-picker__menu {
  display: none; position: absolute; top: 100%; right: 0; z-index: 200;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  padding: 0.5rem; min-width: 160px; margin-top: 4px;
}
.theme-picker__menu.is-open { display: block; animation: fade-in-up 0.15s ease-out; }
.theme-picker__option {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  cursor: pointer; border-radius: var(--radius-sm); border: none;
  background: none; width: 100%; color: var(--text-primary);
  font-size: 0.85rem; font-family: var(--font-body);
}
.theme-picker__option:hover { background: var(--bg-tertiary); }
.theme-picker__swatch {
  width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--border);
}
.theme-picker__divider {
  border: none; border-top: 1px solid var(--border); margin: 4px 0;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  padding-top: var(--nav-height);
  min-height: 100vh;
}

/* Subtle hexagonal background pattern */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='49' viewBox='0 0 28 49'%3E%3Cg fill-rule='evenodd'%3E%3Cg fill='%2310b981' fill-opacity='1'%3E%3Cpath d='M13.99 9.25l13 7.5v15l-13 7.5L1 31.75v-15l12.99-7.5zM3 17.9v12.7l10.99 6.34 11-6.35V17.9l-11-6.34L3 17.9zM0 15l12.98-7.5V0h-2v6.35L0 12.69v2.3zm0 18.5L12.98 41v8h-2v-6.85L0 35.81v-2.3zM15 0v7.5L27.99 15H28v-2.31h-.01L17 6.35V0h-2zm0 49v-8l12.99-7.5H28v2.31h-.01L17 42.15V49h-2z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-body);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 0.5em;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }

p {
  margin-bottom: 1em;
  color: var(--text-primary);
}

a {
  color: var(--accent-subtle);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--accent);
  text-decoration: underline;
}

code, .mono {
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--accent-subtle);
  background: rgba(16, 185, 129, 0.08);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

pre {
  font-family: var(--font-mono);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1em;
  overflow-x: auto;
  font-size: 0.85rem;
  color: var(--text-primary);
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

em {
  color: var(--text-muted);
  font-style: italic;
}

strong {
  font-weight: 600;
  color: var(--text-secondary);
}

ul, ol {
  padding-left: 1.5em;
  margin-bottom: 1em;
}

li {
  margin-bottom: 0.3em;
}

/* --- Layout --- */
.container {
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.container--narrow {
  max-width: var(--container-narrow);
}

.main-content {
  padding: 2rem 0 4rem;
}

/* --- Grid System --- */
.grid {
  display: grid;
  gap: 1.5rem;
}

.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }

.grid--auto-fill {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.grid--auto-fit {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

@media (max-width: 768px) {
  .grid--2,
  .grid--3,
  .grid--4 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1024px) and (min-width: 769px) {
  .grid--3,
  .grid--4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* --- Flexbox Utilities --- */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }
.gap-lg { gap: 1.5rem; }

/* --- Navigation --- */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: var(--nav-height);
  background: color-mix(in srgb, var(--bg-secondary) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}

.nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.nav__brand {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent) !important;
  text-decoration: none !important;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  flex-shrink: 0;
  margin-right: 1.5rem;
}

.nav__brand:hover {
  color: var(--accent-subtle) !important;
}

.nav__brand-icon {
  display: none;
  width: 1.4rem;
  height: 1.4rem;
  background: var(--accent);
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M9 3h6v11l4 4H5l4-4V3z'/%3E%3Cpath d='M12 3V1'/%3E%3Cpath d='M8 3h8'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M9 3h6v11l4 4H5l4-4V3z'/%3E%3Cpath d='M12 3V1'/%3E%3Cpath d='M8 3h8'/%3E%3C/svg%3E");
  mask-size: contain;
  -webkit-mask-size: contain;
  mask-repeat: no-repeat;
  -webkit-mask-repeat: no-repeat;
}

.nav__links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-icon {
  width: 18px;
  height: 18px;
  vertical-align: middle;
  margin-right: 4px;
  display: inline-block;
  flex-shrink: 0;
}

.nav__link {
  display: block;
  padding: 0.4rem 0.75rem;
  color: var(--text-primary) !important;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  text-decoration: none !important;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.nav__link:hover,
.nav__link--active {
  background: var(--bg-tertiary);
  color: var(--accent-subtle) !important;
}

/* Nav dropdown */
.nav__dropdown {
  position: relative;
}

.nav__dropdown-toggle {
  cursor: pointer;
  user-select: none;
}

.nav__dropdown-toggle::after {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 0.35em;
  vertical-align: 0.15em;
  border-top: 0.3em solid;
  border-right: 0.3em solid transparent;
  border-left: 0.3em solid transparent;
  opacity: 0.6;
}

.nav__dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  min-width: 200px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.5rem;
  z-index: 1001;
  list-style: none;
}

.nav__dropdown.is-open .nav__dropdown-menu {
  display: block;
}

.nav__dropdown-item {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--text-primary) !important;
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
  text-decoration: none !important;
  transition: background 0.15s;
}

.nav__dropdown-item:hover {
  background: var(--bg-tertiary);
  color: var(--accent-subtle) !important;
}

.nav__dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 0.3rem 0.5rem;
  list-style: none;
}

/* Wider More-dropdown to handle many items */
.nav__dropdown:last-child .nav__dropdown-menu {
  min-width: 220px;
  max-height: 80vh;
  overflow-y: auto;
}

.nav__user {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-left: 0.5rem;
}
.nav__user-menu {
  position: relative;
}
.nav__user-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  cursor: pointer;
}
.nav__user-btn:hover,
.nav__user-menu.open .nav__user-btn {
  border-color: var(--border);
  color: var(--text-primary);
}
.nav__user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-secondary, var(--bg-card));
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 210px;
  padding: 0.4rem 0;
  z-index: 1000;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.nav__user-menu.open .nav__user-dropdown {
  display: block;
}
.nav__user-dropdown a {
  display: block;
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
  color: var(--text-primary);
  text-decoration: none;
}
.nav__user-dropdown a:hover {
  background: rgba(255,255,255,0.05);
}

/* Mobile nav toggle */
.nav__toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  padding: 0.5rem;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
}

.nav__toggle-icon {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  position: relative;
}

.nav__toggle-icon::before,
.nav__toggle-icon::after {
  content: '';
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  position: absolute;
  left: 0;
}

.nav__toggle-icon::before { top: -6px; }
.nav__toggle-icon::after { top: 6px; }

.nav__right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Mobile nav toggle visibility is handled in the comprehensive mobile section below */

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.2s ease;
}

.card:hover {
  border-color: var(--border-subtle);
  box-shadow: var(--shadow-glow);
}

.card--clickable {
  cursor: pointer;
}

.card--clickable:hover {
  transform: translateY(-2px);
}

.card--highlight {
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--bg-card), rgba(16, 185, 129, 0.05));
}

.card--highlight::before {
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  right: -1px;
  bottom: -1px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent), transparent 60%);
  z-index: -1;
  opacity: 0.1;
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.card__title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}

.card__subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.card__body {
  margin-bottom: 0.5rem;
}

.card__footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* --- Hero Section --- */
.hero {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  margin-bottom: 2rem;
}

.hero__image {
  flex-shrink: 0;
  width: 220px;
  height: 220px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 1rem;
}

.hero__image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  /* Invert SVGs for dark theme */
  filter: invert(0.85) hue-rotate(90deg) brightness(1.2);
}

.hero__content {
  flex: 1;
  min-width: 0;
}

.hero__name {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  color: var(--text-primary);
  line-height: 1.2;
}

.hero__formula {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  color: var(--accent-subtle);
  margin-bottom: 1rem;
}

.hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.hero__meta-item {
  display: flex;
  flex-direction: column;
}

.hero__meta-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.hero__meta-value {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text-primary);
  font-weight: 500;
}

@media (max-width: 640px) {
  .hero {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .hero__image {
    width: 180px;
    height: 180px;
  }

  .hero__meta {
    justify-content: center;
  }
}

/* --- Property Grid --- */
.prop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}

.prop-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
}

.prop-item__label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.prop-item__value {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text-primary);
  word-break: break-all;
}

.prop-item__value a {
  color: var(--accent-subtle);
}

/* --- SMILES Display --- */
.smiles-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  max-width: 100%;
}

.smiles-display__text {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent-subtle);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.smiles-display__copy {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.smiles-display__copy:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.smiles-display__copy.copied {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

/* --- Tables --- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
}

table.chem-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.chem-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  white-space: nowrap;
}

.chem-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid rgba(6, 78, 59, 0.5);
  color: var(--text-primary);
  vertical-align: middle;
}

.chem-table tbody tr:last-child td {
  border-bottom: none;
}

.chem-table tbody tr:hover {
  background: rgba(16, 185, 129, 0.04);
}

.chem-table .mono {
  background: none;
  padding: 0;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none !important;
  transition: all 0.2s ease;
  white-space: nowrap;
  line-height: 1.4;
}

.btn--primary {
  background: var(--accent);
  color: var(--text-inverse) !important;
  border-color: var(--accent);
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.3);
}

.btn--secondary {
  background: transparent;
  color: var(--accent-subtle) !important;
  border-color: var(--border-subtle);
}

.btn--secondary:hover {
  border-color: var(--accent);
  color: var(--accent) !important;
  background: var(--accent-glow);
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary) !important;
  border-color: transparent;
}

.btn--ghost:hover {
  background: var(--bg-tertiary);
  color: var(--accent-subtle) !important;
}

.btn--sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.btn--lg {
  padding: 0.7rem 1.5rem;
  font-size: 1rem;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* --- Badges / Tags --- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 100px;
  white-space: nowrap;
  line-height: 1.4;
}

.badge--accent {
  background: var(--accent-glow);
  color: var(--accent-subtle);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge--muted {
  background: rgba(107, 114, 128, 0.15);
  color: var(--text-muted);
  border: 1px solid rgba(107, 114, 128, 0.2);
}

/* Difficulty badges */
.badge--easy {
  background: rgba(52, 211, 153, 0.12);
  color: var(--diff-easy);
  border: 1px solid rgba(52, 211, 153, 0.25);
}

.badge--moderate {
  background: rgba(251, 191, 36, 0.12);
  color: var(--diff-moderate);
  border: 1px solid rgba(251, 191, 36, 0.25);
}

.badge--advanced {
  background: rgba(248, 113, 113, 0.12);
  color: var(--diff-advanced);
  border: 1px solid rgba(248, 113, 113, 0.25);
}

/* Reaction type badges */
.badge--oxidation { background: rgba(239, 68, 68, 0.12); color: var(--rxn-oxidation); border: 1px solid rgba(239, 68, 68, 0.2); }
.badge--reduction { background: rgba(59, 130, 246, 0.12); color: var(--rxn-reduction); border: 1px solid rgba(59, 130, 246, 0.2); }
.badge--substitution { background: rgba(139, 92, 246, 0.12); color: var(--rxn-substitution); border: 1px solid rgba(139, 92, 246, 0.2); }
.badge--elimination { background: rgba(245, 158, 11, 0.12); color: var(--rxn-elimination); border: 1px solid rgba(245, 158, 11, 0.2); }
.badge--addition { background: rgba(16, 185, 129, 0.12); color: var(--rxn-addition); border: 1px solid rgba(16, 185, 129, 0.2); }
.badge--condensation { background: rgba(236, 72, 153, 0.12); color: var(--rxn-condensation); border: 1px solid rgba(236, 72, 153, 0.2); }
.badge--hydrolysis { background: rgba(6, 182, 212, 0.12); color: var(--rxn-hydrolysis); border: 1px solid rgba(6, 182, 212, 0.2); }
.badge--rearrangement { background: rgba(249, 115, 22, 0.12); color: var(--rxn-rearrangement); border: 1px solid rgba(249, 115, 22, 0.2); }
.badge--other { background: rgba(107, 114, 128, 0.12); color: var(--rxn-other); border: 1px solid rgba(107, 114, 128, 0.2); }

/* Functional group badges */
.badge--func-group {
  background: rgba(110, 231, 183, 0.08);
  color: var(--accent-subtle);
  border: 1px solid rgba(110, 231, 183, 0.2);
  font-family: var(--font-mono);
}

.badge__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.2em;
  height: 1.2em;
  margin-left: 0.35em;
  padding: 0 0.25em;
  font-size: 0.7rem;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 100px;
  font-weight: 600;
}

/* --- Forms --- */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.4rem;
}

.form-input,
.form-select {
  display: block;
  width: 100%;
  padding: 0.6rem 0.9rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-input--lg {
  padding: 0.8rem 1.1rem;
  font-size: 1.1rem;
}

/* Search form inline */
.search-form {
  display: flex;
  gap: 0.5rem;
  max-width: 600px;
}

.search-form .form-input {
  flex: 1;
}

/* --- Sections --- */
.section {
  margin-bottom: 2.5rem;
}

.section__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.section__title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.section__count {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.section__line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* --- AI Enrichment Card --- */
.ai-card {
  position: relative;
  background: linear-gradient(135deg, var(--bg-card), rgba(16, 185, 129, 0.06));
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  overflow: hidden;
}

.ai-card::before {
  content: 'AI';
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.ai-card__title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--accent-subtle);
}

.ai-card__section {
  margin-bottom: 0.75rem;
}

.ai-card__section:last-child {
  margin-bottom: 0;
}

.ai-card__label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

/* --- Reaction Cards --- */
.reaction-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  transition: border-color 0.25s, box-shadow 0.25s;
}

.reaction-card:hover {
  border-color: var(--border-subtle);
  box-shadow: var(--shadow-glow);
}

.reaction-card__header {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.reaction-card__name {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
}

.reaction-card__badges {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.reaction-card__equation {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 0.75rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.reaction-card__arrow {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.1rem;
}

.reaction-card__reactant {
  color: var(--text-secondary);
  word-break: break-all;
  overflow-wrap: anywhere;
}

.reaction-card__product {
  color: var(--accent-subtle);
  word-break: break-all;
  overflow-wrap: anywhere;
}

.reaction-card__plus {
  color: var(--text-muted);
}

.reaction-card__details {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* --- Route Steps --- */
.route-step {
  display: flex;
  align-items: stretch;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.route-step__indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: 2rem;
}

.route-step__number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  background: var(--accent);
  color: var(--text-inverse);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 50%;
  flex-shrink: 0;
}

.route-step__line {
  flex: 1;
  width: 2px;
  background: var(--border);
  min-height: 1rem;
}

.route-step__content {
  flex: 1;
  padding-bottom: 1rem;
}

/* --- Status indicators --- */
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.status--have {
  color: var(--diff-easy);
}

.status--need {
  color: var(--diff-advanced);
}

.status__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status--have .status__dot {
  background: var(--diff-easy);
}

.status--need .status__dot {
  background: var(--diff-advanced);
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty-state__icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  opacity: 0.4;
}

.empty-state__text {
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.empty-state__hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* --- Page Header --- */
.page-header {
  margin-bottom: 2rem;
}

.page-header__title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.page-header__subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.page-header__stats {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.75rem;
}

.page-header__stat {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.page-header__stat-value {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.page-header__stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* --- Footer --- */
.footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  margin-top: 3rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-family: var(--font-mono);
}

/* --- Animations --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-in {
  animation: fadeInUp 0.4s ease-out both;
}

.stagger > * {
  opacity: 0;
  animation: fadeInUp 0.4s ease-out both;
}

.stagger > *:nth-child(1) { animation-delay: 0.05s; }
.stagger > *:nth-child(2) { animation-delay: 0.1s; }
.stagger > *:nth-child(3) { animation-delay: 0.15s; }
.stagger > *:nth-child(4) { animation-delay: 0.2s; }
.stagger > *:nth-child(5) { animation-delay: 0.25s; }
.stagger > *:nth-child(6) { animation-delay: 0.3s; }
.stagger > *:nth-child(7) { animation-delay: 0.35s; }
.stagger > *:nth-child(8) { animation-delay: 0.4s; }
.stagger > *:nth-child(9) { animation-delay: 0.45s; }
.stagger > *:nth-child(10) { animation-delay: 0.5s; }

/* --- Spacing utilities --- */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
.pt-0 { padding-top: 0; }
.pb-0 { padding-bottom: 0; }

/* --- Text utilities --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-secondary { color: var(--text-secondary); }
.font-mono { font-family: var(--font-mono); }

/* --- Visibility --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Molecular decoration --- */
.mol-deco {
  position: relative;
}

.mol-deco::after {
  content: '';
  position: absolute;
  top: -30px;
  right: -30px;
  width: 120px;
  height: 120px;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cpolygon fill='none' stroke='%2310b981' stroke-width='1' points='60,10 100,35 100,85 60,110 20,85 20,35'/%3E%3Ccircle cx='60' cy='10' r='4' fill='%2310b981'/%3E%3Ccircle cx='100' cy='35' r='4' fill='%2310b981'/%3E%3Ccircle cx='100' cy='85' r='4' fill='%2310b981'/%3E%3Ccircle cx='60' cy='110' r='4' fill='%2310b981'/%3E%3Ccircle cx='20' cy='85' r='4' fill='%2310b981'/%3E%3Ccircle cx='20' cy='35' r='4' fill='%2310b981'/%3E%3Cline x1='60' y1='10' x2='60' y2='60' stroke='%2310b981' stroke-width='0.5'/%3E%3Ccircle cx='60' cy='60' r='3' fill='%2310b981'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  pointer-events: none;
}

/* --- Divider with label --- */
.divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 2rem 0;
}

.divider__line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.divider__label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

/* --- Theme toggle button --- */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: all 0.2s;
  flex-shrink: 0;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- Light theme overrides --- */
[data-theme="light"],
[data-theme="emerald-light"] {
  --bg-primary: #f0fdf4;
  --bg-secondary: #ecfdf5;
  --bg-tertiary: #d1fae5;
  --bg-card: #ffffff;
  --bg-input: #ffffff;

  --text-primary: #064e3b;
  --text-secondary: #059669;
  --text-muted: #6b7280;
  --text-inverse: #ffffff;

  --border: #d1fae5;
  --border-subtle: #a7f3d0;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
  --shadow-glow: 0 0 20px rgba(16, 185, 129, 0.08);
}

[data-theme="light"] body::before,
[data-theme$="-light"] body::before {
  opacity: 0.02;
}

[data-theme="light"] .hero__image img,
[data-theme$="-light"] .hero__image img {
  filter: none;
}

[data-theme="light"] .nav,
[data-theme$="-light"] .nav {
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
}

/* Regulation badges */
.badge--danger {
  background: rgba(244, 63, 94, 0.15);
  color: #f43f5e;
  border: 1px solid rgba(244, 63, 94, 0.3);
}
.badge--warning {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* ==========================================================================
   MOBILE & RESPONSIVE
   Comprehensive mobile-first responsive system for iOS Safari + Android Chrome
   ========================================================================== */

/* --- Safe area insets for iPhone notch / Dynamic Island --- */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* Apply safe-area padding to nav and body */
.nav {
  padding-top: var(--safe-top);
  height: calc(var(--nav-height) + var(--safe-top));
}

body {
  padding-top: calc(var(--nav-height) + var(--safe-top));
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  min-height: 100vh;
  min-height: 100dvh;
}

.footer {
  padding-bottom: calc(1.5rem + var(--safe-bottom));
}

/* --- Mobile breakpoint: 768px --- */
@media (max-width: 768px) {

  /* ---- Navigation ---- */
  .nav__brand {
    font-size: 0.9rem;
    flex-shrink: 0;
  }

  /* Abbreviate brand text on mobile */
  .nav__brand-icon + span,
  .nav__brand::after {
    content: none;
  }

  .nav__right {
    gap: 0.3rem;
  }

  .nav__user {
    display: none;
  }

  .theme-picker span:last-child {
    display: none;
  }

  /* Hamburger toggle - larger touch target */
  .nav__toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
  }

  .nav__toggle-icon {
    width: 22px;
    height: 2px;
  }

  .nav__toggle-icon::before,
  .nav__toggle-icon::after {
    width: 22px;
  }

  /* Mobile nav panel - full-width slide down */
  .nav__links {
    display: none;
    position: absolute;
    top: calc(var(--nav-height) + var(--safe-top));
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 0.5rem 0;
    gap: 0;
    max-height: calc(100vh - var(--nav-height) - var(--safe-top));
    max-height: calc(100dvh - var(--nav-height) - var(--safe-top));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    box-shadow: var(--shadow-lg);
    z-index: 1001;
  }

  .nav__links.is-open {
    display: flex;
  }

  /* Nav links - full-width touch-friendly rows */
  .nav__link {
    padding: 0.85rem 1.25rem;
    font-size: 1rem;
    border-radius: 0;
    border-bottom: 1px solid var(--border);
  }

  .nav__link:active {
    background: var(--bg-tertiary);
  }

  /* Dropdown menus - inline on mobile, no absolute positioning */
  .nav__dropdown-menu {
    position: static;
    box-shadow: none;
    border: none;
    background: var(--bg-tertiary);
    margin: 0;
    padding: 0;
    border-radius: 0;
  }

  .nav__dropdown-item {
    padding: 0.75rem 1.25rem 0.75rem 2rem;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border);
  }

  .nav__dropdown-item:last-child {
    border-bottom: none;
  }

  .nav__dropdown-item:active {
    background: var(--bg-secondary);
  }

  /* Dropdown toggle arrow */
  .nav__dropdown-toggle::after {
    margin-left: auto;
    transition: transform 0.2s ease;
  }

  .nav__dropdown.is-open .nav__dropdown-toggle::after {
    transform: rotate(180deg);
  }

  /* ---- Container & Layout ---- */
  .container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .main-content {
    padding: 1rem 0 3rem;
  }

  /* ---- Page Headers ---- */
  .page-header {
    padding: 0.75rem 0;
  }

  .page-header__title {
    font-size: 1.4rem;
  }

  .page-header__subtitle {
    font-size: 0.85rem;
  }

  .page-header__stats {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .page-header__stat-value {
    font-size: 1.1rem;
  }

  /* ---- Hero ---- */
  .hero {
    flex-direction: column;
    text-align: center;
  }

  .hero__image {
    margin-bottom: 1rem;
    width: 160px;
    height: 160px;
  }

  .hero__name {
    font-size: 1.5rem;
  }

  .hero__formula {
    font-size: 1rem;
  }

  .hero__meta {
    justify-content: center;
    gap: 1rem;
  }

  /* ---- Buttons ---- */
  .btn-group {
    flex-direction: column;
  }

  .btn-group .btn {
    width: 100%;
    text-align: center;
    justify-content: center;
  }

  .btn {
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
  }

  /* ---- Property Grid ---- */
  .prop-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .prop-item {
    padding: 0.5rem 0.65rem;
  }

  .prop-item__label {
    font-size: 0.65rem;
  }

  .prop-item__value {
    font-size: 0.85rem;
  }

  /* ---- Search ---- */
  .search-form {
    flex-direction: column;
  }

  .search-form .btn {
    width: 100%;
  }

  .search-form .form-input {
    width: 100%;
  }

  /* ---- Tables - horizontal scroll ---- */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-left: -0.75rem;
    margin-right: -0.75rem;
    padding: 0 0.75rem;
    /* Scroll indicator shadow */
    background:
      linear-gradient(to right, var(--bg-secondary) 30%, transparent),
      linear-gradient(to left, var(--bg-secondary) 30%, transparent),
      linear-gradient(to right, rgba(0,0,0,0.15), transparent 15px),
      linear-gradient(to left, rgba(0,0,0,0.15), transparent 15px);
    background-position: left center, right center, left center, right center;
    background-repeat: no-repeat;
    background-size: 20px 100%, 20px 100%, 15px 100%, 15px 100%;
    background-attachment: local, local, scroll, scroll;
  }

  .chem-table {
    min-width: 520px;
    font-size: 0.8rem;
  }

  .chem-table th,
  .chem-table td {
    padding: 0.45rem 0.5rem;
  }

  /* ---- SMILES ---- */
  .smiles-display {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
  }

  .smiles-display__text {
    font-size: 0.7rem;
    word-break: break-all;
    white-space: normal;
  }

  .smiles-display__copy {
    align-self: flex-end;
  }

  /* ---- Cards ---- */
  .card {
    padding: 0.85rem;
  }

  .card__header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .card--clickable:hover {
    transform: none; /* Disable hover lift on touch */
  }

  /* ---- Sections ---- */
  .section {
    margin-bottom: 1.5rem;
  }

  .section__title {
    font-size: 1.05rem;
  }

  /* ---- Forms - prevent iOS zoom ---- */
  .form-input,
  .form-select,
  select.form-input,
  select,
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="search"],
  input[type="url"],
  textarea {
    font-size: 16px !important; /* Prevents iOS Safari zoom on focus */
    padding: 0.65rem 0.75rem;
  }

  textarea.form-input {
    min-height: 100px;
  }

  /* ---- Journal entries on mobile ---- */
  .journal-entry {
    padding: 0.75rem;
  }

  /* Journal card header - stack actions below title on mobile */
  .card .card__header > div:last-child {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  /* ---- Flex layouts - allow wrapping ---- */
  [style*="display:flex"][style*="gap"] {
    flex-wrap: wrap;
  }

  /* ---- Molecule Designer ---- */
  #ketcher-container {
    height: 50vw;
    min-height: 280px;
    max-height: 400px;
  }

  /* Molecule designer action buttons - grid for equal sizing */
  #ketcher-container + div {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem !important;
  }

  #ketcher-container + div .btn {
    width: 100%;
    justify-content: center;
    text-align: center;
    font-size: 0.8rem;
    padding: 0.6rem 0.5rem;
  }

  /* SMILES display span below buttons - full width */
  #ketcher-container + div > span {
    grid-column: 1 / -1;
    text-align: center;
  }

  /* ---- Score rows (docking) ---- */
  .score-row {
    font-size: 0.85rem;
    padding: 0.5rem 0;
  }

  /* ---- SAR Explorer ---- */
  .sar-scroll {
    margin-left: -0.85rem;
    margin-right: -0.85rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sar-table {
    font-size: 0.7rem;
    min-width: 500px;
  }

  .sar-table th,
  .sar-table td {
    padding: 0.3rem 0.35rem;
  }

  .sar-chart-svg {
    height: 200px;
  }

  .sar-legend {
    justify-content: center;
  }

  /* ---- Dashboard ---- */
  .stat-card {
    padding: 0.75rem;
  }

  .stat-card__value {
    font-size: 1.5rem;
  }

  /* Dashboard grid - 2 columns minimum */
  .grid--auto-fill,
  .grid--auto-fit {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  /* ---- Capture page ---- */
  .capture-btn {
    padding: 1.25rem 1rem !important;
    font-size: 1.1rem !important;
    border-radius: var(--radius-md) !important;
    min-height: 60px;
  }

  .capture-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  /* ---- Checklist ---- */
  .checklist-item {
    flex-direction: column;
    align-items: flex-start;
  }

  /* ---- Modal/dialogs ---- */
  .modal__content {
    width: 95%;
    margin: 1rem auto;
    padding: 1rem;
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
  }

  /* ---- Reaction cards ---- */
  .reaction-card__header {
    flex-direction: column;
  }

  .reaction-card__badges {
    flex-wrap: wrap;
  }

  .reaction-card__equation {
    font-size: 0.75rem;
    padding: 0.5rem;
  }

  /* ---- Route steps ---- */
  .route-step {
    gap: 0.65rem;
  }

  .route-step__number {
    width: 1.75rem;
    height: 1.75rem;
    font-size: 0.7rem;
  }

  .route-step__indicator {
    width: 1.75rem;
  }

  /* ---- AI card ---- */
  .ai-card {
    padding: 1rem;
  }

  /* ---- Badges ---- */
  .badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
  }

  /* ---- Typography ---- */
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.1rem; }
}

/* --- Small phone fixes (iPhone SE, Galaxy S series compact) --- */
@media (max-width: 375px) {
  .nav__brand {
    font-size: 0.8rem;
  }

  .page-header__title {
    font-size: 1.2rem;
  }

  .container {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .btn {
    padding: 0.55rem 0.75rem;
    font-size: 0.8rem;
  }

  .card {
    padding: 0.6rem;
  }

  #ketcher-container {
    height: 250px;
    min-height: 220px;
  }

  /* Single column prop grid on very small screens */
  .prop-grid {
    grid-template-columns: 1fr;
  }

  /* Dashboard cards single column */
  .grid--auto-fill,
  .grid--auto-fit {
    grid-template-columns: 1fr;
  }

  /* Capture buttons even more prominent */
  .capture-btn {
    padding: 1rem !important;
    font-size: 1rem !important;
  }
}

/* --- Touch-friendly targets (touch screens) --- */
@media (pointer: coarse) {
  /* Minimum 44px touch targets per Apple/Google HIG */
  .btn {
    min-height: 44px;
  }

  .nav__link,
  .nav__dropdown-item {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* Larger touch area for dropdown items */
  .nav__dropdown-menu .nav__dropdown-item {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
  }

  .nav__dropdown-menu .nav__dropdown-item:last-child {
    border-bottom: none;
  }

  /* Table cells need more padding for touch */
  .chem-table td,
  .chem-table th {
    padding: 0.6rem 0.5rem;
  }

  /* Larger checkboxes and radios */
  input[type="checkbox"],
  input[type="radio"] {
    width: 22px;
    height: 22px;
    margin-right: 0.5rem;
  }

  /* Disable hover effects on touch - they cause sticky states */
  .card:hover {
    border-color: var(--border);
    box-shadow: none;
  }

  .card--clickable:active {
    border-color: var(--border-subtle);
    box-shadow: var(--shadow-glow);
    transform: scale(0.98);
  }

  /* Journal entry toggle area - larger touch target */
  .card .card__header[style*="cursor:pointer"] {
    min-height: 48px;
  }

  /* Remove tap highlight flash on iOS */
  a, button, input, select, textarea, .btn, .nav__link, .nav__dropdown-item, .card--clickable {
    -webkit-tap-highlight-color: transparent;
  }

  /* Capture buttons - extra large on touch */
  .capture-btn {
    min-height: 56px;
  }

  /* Theme picker needs larger touch targets */
  .theme-picker__option {
    padding: 10px 12px;
    min-height: 44px;
  }

  .theme-picker__btn {
    min-height: 36px;
    padding: 6px 8px;
  }
}

/* --- Landscape phone orientation --- */
@media (max-width: 768px) and (orientation: landscape) {
  /* Reduce nav height in landscape */
  .nav {
    height: calc(2.75rem + var(--safe-top));
  }

  body {
    padding-top: calc(2.75rem + var(--safe-top));
  }

  .nav__links {
    top: calc(2.75rem + var(--safe-top));
    max-height: calc(100vh - 2.75rem - var(--safe-top));
    max-height: calc(100dvh - 2.75rem - var(--safe-top));
  }

  /* Ketcher needs more height in landscape */
  #ketcher-container {
    height: 60vw;
    max-height: 350px;
  }

  /* Capture grid - more columns in landscape */
  .capture-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}

/* --- Prevent horizontal overflow globally --- */
html {
  overflow-x: hidden;
}

/* Ensure images and media never overflow */
img, video, iframe, svg, canvas {
  max-width: 100%;
  height: auto;
}

/* Exception for iframes that need fixed dimensions (like Ketcher) */
#ketcher-frame {
  max-width: none;
  height: 100%;
}

/* Prevent long SMILES/formulas from breaking layout */
.font-mono,
.mono,
code {
  overflow-wrap: break-word;
  word-break: break-all;
}

/* --- Print styles --- */
@media print {
  body {
    background: white;
    color: black;
    padding-top: 0;
  }

  body::before,
  .nav,
  .footer,
  .btn,
  .theme-toggle {
    display: none !important;
  }

  .card,
  .ai-card,
  .reaction-card {
    border: 1px solid #ccc;
    box-shadow: none;
    background: white;
    break-inside: avoid;
  }
}

/* Compound link with action dropdown */
.chem-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.chem-link__name {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.chem-link__name:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.chem-link__btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  line-height: 1;
  opacity: 0.5;
  transition: opacity 0.15s, background 0.15s;
}

.chem-link:hover .chem-link__btn,
.chem-link__btn:hover {
  opacity: 1;
  background: var(--bg-tertiary);
}

.chem-link__menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 100;
  min-width: 200px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.3rem 0;
  margin-top: 2px;
}

.chem-link__menu.is-open {
  display: block;
  animation: fade-in-up 0.15s ease-out;
}

.chem-link__action {
  display: block;
  width: 100%;
  padding: 0.5rem 0.8rem;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--font-body);
}

.chem-link__action:hover {
  background: var(--bg-tertiary);
  color: var(--accent);
}

.chem-link__menu hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.3rem 0;
}

.chem-link__action[data-action="acquire"] { color: var(--accent); }
.chem-link__action[data-action="need"] { color: #f59e0b; }
.chem-link__action[data-action="remove"] { color: #f43f5e; }

/* ── Mobile bottom navigation ─────────────────────────────────────────────── */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary, #12121a);
    border-top: 1px solid var(--border, #2d2d3d);
    z-index: 1100;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    text-decoration: none;
    color: var(--text-muted, #6b7280);
    font-size: 0.6rem;
    gap: 2px;
    min-height: 56px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: color 0.15s;
  }

  .mobile-nav-item.active,
  .mobile-nav-item:active {
    color: var(--accent, #818cf8);
  }

  .mobile-nav-icon {
    font-size: 1.4rem;
    line-height: 1;
  }

  .mobile-nav-label {
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.02em;
  }

  /* Push page content above the bottom nav */
  .main-content {
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
  }

  /* Hide desktop footer on mobile */
  .footer {
    display: none;
  }
}

/* ==========================================================================
   COMPOUND DETAIL — Tabbed Layout
   ========================================================================== */

/* ── Compound Hero (sticky) ── */
.compound-hero {
  position: sticky;
  top: var(--nav-height);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 0;
  background: color-mix(in srgb, var(--bg-primary) 94%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.compound-hero__image {
  flex-shrink: 0;
  width: 100px;
  height: 100px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0.5rem;
}

.compound-hero__image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: invert(0.85) hue-rotate(90deg) brightness(1.2);
  cursor: pointer;
}

[data-theme="light"] .compound-hero__image img,
[data-theme$="-light"] .compound-hero__image img {
  filter: none;
}

.compound-hero__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.compound-hero__title-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.compound-hero__name {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
  line-height: 1.2;
}

.compound-hero__formula {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--accent-subtle);
}

.compound-hero__mw {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.compound-hero__iupac {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.compound-hero__smiles {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 100%;
}

.compound-hero__smiles-text {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent-subtle);
  background: none;
  padding: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 300px;
}

/* ── Hero actions ── */
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.3rem;
  align-items: center;
}

/* ── Hero more dropdown ── */
.hero-actions-more {
  position: relative;
  display: inline-block;
}

.hero-actions-more > summary {
  list-style: none;
  cursor: pointer;
}

.hero-actions-more > summary::-webkit-details-marker {
  display: none;
}

.hero-actions-more__menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 200;
  min-width: 220px;
  max-width: calc(100vw - 2rem);
  max-height: 70vh;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.4rem 0;
  animation: fade-in-up 0.15s ease-out;
}

.hero-actions-more__item {
  display: block;
  width: 100%;
  padding: 0.45rem 0.8rem;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.82rem;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--font-body);
  transition: background 0.1s;
}

.hero-actions-more__item:hover {
  background: var(--bg-tertiary);
  color: var(--accent);
}

/* ── Tab bar ── */
.compound-tabs {
  position: sticky;
  top: calc(var(--nav-height) + 100px + 1.5rem);
  z-index: 49;
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  white-space: nowrap;
  margin-bottom: 1.5rem;
}

.compound-tabs::-webkit-scrollbar {
  display: none;
}

.compound-tabs__btn {
  flex-shrink: 0;
  padding: 0.6rem 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.compound-tabs__btn:hover {
  color: var(--text-primary);
}

.compound-tabs__btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Tab panels ── */
.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeInUp 0.25s ease-out;
}

/* ── Mobile responsive for compound hero ── */
@media (max-width: 768px) {
  .compound-hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem 0;
    position: relative;
    top: auto;
  }

  .compound-hero__image {
    width: 70px;
    height: 70px;
    position: absolute;
    top: 0.5rem;
    right: 0;
  }

  .compound-hero__title-row {
    padding-right: 80px;
  }

  .compound-hero__name {
    font-size: 1.1rem;
  }

  .compound-hero__smiles-text {
    max-width: 180px;
  }

  .hero-actions {
    gap: 0.25rem;
  }

  .hero-actions .btn--sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
  }

  .compound-tabs {
    position: relative;
    top: auto;
  }

  .compound-tabs__btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
  }

  .hero-actions-more__menu {
    right: 0;
    left: auto;
  }
}

/* ── Extra-small mobile tweaks (640px) ── */
@media (max-width: 640px) {
  .compound-hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .compound-hero__image {
    position: static;
    width: 80px;
    height: 80px;
  }

  .compound-hero__title-row {
    flex-direction: column;
    gap: 0.25rem;
    padding-right: 0;
  }

  .compound-hero__name {
    font-size: 1rem;
  }
}

/* ── Loading skeleton shimmer ── */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton-line {
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    var(--bg-secondary) 25%,
    var(--bg-tertiary, rgba(255, 255, 255, 0.06)) 50%,
    var(--bg-secondary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  margin-bottom: 8px;
}

.skeleton-line--short { width: 40%; }
.skeleton-line--medium { width: 65%; }
.skeleton-line--long { width: 90%; }

/* ==========================================================================
   Journal Timeline View
   ========================================================================== */

.journal-view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.journal-view-toggle__btn {
  padding: 4px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.journal-view-toggle__btn:hover {
  color: var(--text-primary);
}
.journal-view-toggle__btn.active {
  background: var(--accent);
  color: var(--text-inverse);
}

.journal-timeline {
  position: relative;
  padding-left: 2rem;
}
.journal-timeline::before {
  content: '';
  position: absolute;
  left: 0.75rem;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-entry {
  position: relative;
  margin-bottom: 1.5rem;
  padding-left: 1.5rem;
}
.timeline-entry::before {
  content: '';
  position: absolute;
  left: -1.35rem;
  top: 0.5rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--bg-primary);
}
.timeline-entry.success::before { border-color: var(--color-good); background: var(--color-good); }
.timeline-entry.failed::before { border-color: var(--color-bad); background: var(--color-bad); }
.timeline-entry.partial::before { border-color: var(--color-warn); background: var(--color-warn); }
.timeline-entry.learning::before { border-color: #a78bfa; background: #a78bfa; }

.timeline-date-marker {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 1.5rem 0 0.75rem 0;
  padding-left: 1.5rem;
  position: relative;
}
.timeline-date-marker:first-child {
  margin-top: 0;
}

.timeline-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.timeline-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}

.timeline-card__title {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0 0 0.25rem 0;
}
.timeline-card__title a {
  color: var(--text-primary);
  text-decoration: none;
}
.timeline-card__title a:hover {
  color: var(--accent);
}

.timeline-card__meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.timeline-card__preview {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
  line-height: 1.4;
  display: none;
}
.timeline-card:hover .timeline-card__preview {
  display: block;
}

.timeline-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.timeline-badge--success { background: var(--color-good-bg); color: var(--color-good-text); border: 1px solid var(--color-good-border); }
.timeline-badge--partial { background: var(--color-warn-bg); color: var(--color-warn-text); border: 1px solid var(--color-warn-border); }
.timeline-badge--failed { background: var(--color-bad-bg); color: var(--color-bad-text); border: 1px solid var(--color-bad-border); }
.timeline-badge--learning { background: rgba(167, 139, 250, 0.1); color: #c4b5fd; border: 1px solid rgba(167, 139, 250, 0.35); }

.timeline-compound-tag {
  display: inline-block;
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--accent-glow);
  color: var(--accent-subtle);
  text-decoration: none;
}
.timeline-compound-tag:hover {
  background: var(--accent-glow-strong);
}

.timeline-media-indicator {
  font-size: 0.65rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

/* ── Chat UI ──────────────────────────────────────────────────────────── */

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  font-family: var(--font-sans);
}

.chat-status {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  text-align: center;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-msg { max-width: 85%; line-height: 1.5; }
.chat-msg--user { align-self: flex-end; }
.chat-msg--assistant { align-self: flex-start; }

.chat-msg--user .chat-msg__content {
  background: var(--accent);
  color: var(--bg-primary);
  padding: 0.5rem 0.85rem;
  border-radius: 1rem 1rem 0.25rem 1rem;
  font-size: 0.875rem;
  white-space: pre-wrap;
}

.chat-msg--assistant .chat-msg__content {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 0.6rem 0.85rem;
  border-radius: 1rem 1rem 1rem 0.25rem;
  font-size: 0.875rem;
  border: 1px solid var(--border);
}

.chat-msg--assistant .chat-msg__content p { margin: 0 0 0.5rem; }
.chat-msg--assistant .chat-msg__content p:last-child { margin-bottom: 0; }
.chat-msg--assistant .chat-msg__content pre {
  background: var(--bg-tertiary);
  padding: 0.5rem;
  border-radius: 0.4rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}
.chat-msg--assistant .chat-msg__content code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-tertiary);
  padding: 0.1em 0.3em;
  border-radius: 0.2rem;
}
.chat-msg--assistant .chat-msg__content pre code { background: none; padding: 0; }

/* Queued/unsent message (outbox) — dimmed with a clock marker */
.chat-msg--pending { opacity: 0.55; }
.chat-msg--pending .chat-msg__content::after { content: ' ⏳'; font-size: 0.85em; }

/* Model caption under an assistant answer */
.chat-msg__meta {
  font-size: 0.62rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-family: var(--font-mono);
  opacity: 0.7;
}

.chat-msg__error {
  background: var(--color-bad-bg, rgba(239,68,68,0.15));
  color: var(--color-bad);
  padding: 0.5rem 0.85rem;
  border-radius: 0.5rem;
  font-size: 0.8rem;
}

/* Thinking accordion */
.chat-thinking { margin-bottom: 0.4rem; font-size: 0.8rem; }
.chat-thinking-summary {
  cursor: pointer;
  color: var(--text-muted);
  font-style: italic;
  padding: 0.25rem 0;
  user-select: none;
}
.chat-thinking-content {
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg-tertiary);
  border-radius: 0.3rem;
  margin-top: 0.25rem;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  max-height: 200px;
  overflow-y: auto;
}

/* Tool accordion */
.chat-tool {
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  overflow: hidden;
}
.chat-tool-summary {
  cursor: pointer;
  padding: 0.35rem 0.6rem;
  background: var(--bg-tertiary);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  user-select: none;
}
.chat-tool-spinner {
  display: inline-block;
  width: 0.7em; height: 0.7em;
  border: 2px solid var(--text-muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: chat-spin 0.6s linear infinite;
  vertical-align: middle;
}
@keyframes chat-spin { to { transform: rotate(360deg); } }

.chat-tool-result {
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.chat-tool-pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
}

/* Sub-agent (Task) accordion */
.chat-subagent {
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  overflow: hidden;
}
.chat-subagent-summary {
  cursor: pointer;
  padding: 0.35rem 0.6rem;
  background: var(--bg-tertiary);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  user-select: none;
}
.chat-subagent-spinner {
  display: inline-block;
  width: 0.7em; height: 0.7em;
  border: 2px solid var(--text-muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: chat-spin 0.6s linear infinite;
  vertical-align: middle;
}
.chat-subagent-body {
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.chat-subagent-line {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.1rem 0;
}
.chat-subagent-text {
  white-space: pre-wrap;
  font-size: 0.72rem;
  padding: 0.2rem 0;
}
.chat-subagent-result {
  margin-top: 0.3rem;
  padding-top: 0.3rem;
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Input bar */
.chat-input-bar {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}
.chat-input {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  resize: none;
  min-height: 2rem;
  max-height: 150px;
}
.chat-input:focus { outline: none; border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-muted); }

.chat-send-btn {
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.875rem;
  align-self: flex-end;
}
.chat-send-btn:hover { opacity: 0.9; }

/* Per-session controls row (thinking toggle + model picker) */
.chat-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 1rem 0;
  flex-wrap: wrap;
}
.chat-thinking-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 1rem;
  padding: 0.2rem 0.6rem;
  font-size: 0.72rem;
  cursor: pointer;
}
.chat-thinking-toggle--on {
  color: var(--accent);
  border-color: var(--accent);
}
.chat-model-select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 1rem;
  padding: 0.2rem 0.5rem;
  font-size: 0.72rem;
  cursor: pointer;
}

/* Attach button + image attachments */
.chat-input-area { display: flex; flex-direction: column; }
.chat-attach-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1;
  padding: 0 0.6rem;
  cursor: pointer;
  align-self: flex-end;
  height: 2.15rem;
  flex-shrink: 0;
}
.chat-attach-btn:hover { color: var(--accent); border-color: var(--accent); }

.chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 1rem 0;
  background: var(--bg-secondary);
}
.chat-attachment {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 0.4rem;
  overflow: hidden;
  border: 1px solid var(--border);
}
.chat-attachment img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-attachment-remove {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 1.1rem;
  height: 1.1rem;
  line-height: 1;
  border: none;
  border-radius: 0.25rem;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
}

/* Images inside a message bubble */
.chat-msg__images {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}
.chat-msg--user .chat-msg__images { justify-content: flex-end; }
.chat-msg__image {
  max-width: 220px;
  max-height: 260px;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

/* Drag & drop highlight */
.chat-dragover { outline: 2px dashed var(--accent); outline-offset: -6px; }

/* Mobile: fullscreen chat, keyboard-aware */
@media (max-width: 768px) {
  .chat-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 100vh;    /* fallback for browsers without dvh */
    height: 100dvh;   /* dynamic viewport — keeps input above browser chrome */
    z-index: 9998;
    background: var(--bg-primary);
  }
  .chat-messages {
    padding: 0.75rem;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .chat-input-bar {
    padding: 0.5rem 0.75rem;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0));
  }
  .chat-msg { max-width: 92%; }
}

/* Chat FAB */
.chat-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 999;
  transition: transform 0.15s;
}
.chat-fab:hover { transform: scale(1.1); }
@media (max-width: 768px) {
  .chat-fab { display: none; }  /* mobile uses bottom nav instead */
}

/* ── Chat sidebar / multi-session ─────────────────────────────────────── */

/* When a sidebar is present the container becomes a row: [sidebar][main] */
.chat-container.chat-has-sidebar {
  flex-direction: row;
  align-items: stretch;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;   /* let the flex child shrink instead of overflowing */
  height: 100%;
}

.chat-sidebar {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-secondary);
  overflow-y: auto;
}

.chat-sidebar-head {
  padding: 0.6rem;
  border-bottom: 1px solid var(--border);
}
.chat-new-btn {
  width: 100%;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  border-radius: 0.5rem;
  padding: 0.5rem;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.chat-new-btn:hover { opacity: 0.9; }

.chat-session-list,
.chat-archived-list { display: flex; flex-direction: column; }

.chat-session-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.5rem 0.6rem;
  border-left: 2px solid transparent;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.chat-session-item:hover { background: var(--bg-tertiary); }
.chat-session-item--active {
  border-left-color: var(--accent);
  background: var(--bg-tertiary);
}
.chat-session-title {
  font-size: 0.82rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 1.1rem;  /* leave room for the archive button */
}
.chat-session-title.editing {
  white-space: normal;
  overflow: visible;
  outline: 1px solid var(--accent);
  border-radius: 0.2rem;
  cursor: text;
}
.chat-session-meta { font-size: 0.68rem; color: var(--text-muted); }
.chat-session-archive {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 1.1rem;
  height: 1.1rem;
  line-height: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: 0.2rem;
  opacity: 0;
  transition: opacity 0.1s;
}
.chat-session-item:hover .chat-session-archive { opacity: 1; }
.chat-session-archive:hover { color: var(--color-bad); background: var(--bg-secondary); }

.chat-archived { border-top: 1px solid var(--border); }
.chat-archived-summary {
  padding: 0.4rem 0.6rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

/* Chat header — mobile-only (hamburger + active session title) */
.chat-header { display: none; }
.chat-hamburger {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
}
.chat-header-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* WinBox session dropdown (no sidebar there) */
.chat-winbox-select {
  margin: 0.3rem;
  padding: 0.25rem 0.4rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  font-size: 0.78rem;
  flex-shrink: 0;
}

/* Mobile drawer backdrop */
.chat-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9998;
}
.chat-sidebar-backdrop--show { display: block; }

/* Mobile: sidebar becomes a slide-over drawer toggled by the hamburger */
@media (max-width: 768px) {
  .chat-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
  }
  .chat-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 82vw;
    max-width: 300px;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 9999;
  }
  .chat-sidebar--open { transform: translateX(0); }
}
