/* Reset & Core Design Tokens */
:root {
  --bg-dark: #0b0f19;
  --bg-card: rgba(18, 24, 38, 0.85);
  --bg-card-hover: rgba(26, 34, 52, 0.95);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(79, 172, 254, 0.5);
  
  --primary: #4facfe;
  --primary-glow: rgba(79, 172, 254, 0.35);
  --secondary: #00f2fe;
  --accent-purple: #9d4edd;
  --accent-pink: #f72585;
  --accent-amber: #ff9e00;
  --accent-green: #00f5d4;
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(79, 172, 254, 0.07) 0%, transparent 40%),
    radial-gradient(circle at 85% 75%, rgba(157, 78, 221, 0.07) 0%, transparent 40%);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header & Top Navigation */
.top-nav {
  position: relative;
  z-index: 2000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px 28px;
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  white-space: nowrap;
}

.logo-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #0b0f19;
  box-shadow: 0 0 20px var(--primary-glow);
}

.brand-text h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.badge-tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  background: rgba(79, 172, 254, 0.15);
  color: var(--primary);
  border: 1px solid rgba(79, 172, 254, 0.3);
  border-radius: 20px;
}

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

/* Search Bar */
.search-section {
  position: relative;
  z-index: 2001;
  flex: 1;
  max-width: 600px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: rgba(11, 15, 25, 0.85);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 4px 6px 4px 16px;
  transition: all 0.3s ease;
}

.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 16px var(--primary-glow);
}

.search-icon {
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-right: 12px;
}

.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.95rem;
}

.search-box input::placeholder {
  color: var(--text-dim);
}

.btn {
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #0b0f19;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--primary-glow);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.btn-outline.active, .btn-outline:hover {
  background: rgba(79, 172, 254, 0.15);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

/* Search Dropdown */
.suggestions-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: #121826;
  border: 1px solid var(--border-focus);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.85);
  max-height: 320px;
  overflow-y: auto;
  z-index: 99999;
}

.suggestion-item {
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.15s ease;
}

.suggestion-item:hover {
  background: rgba(79, 172, 254, 0.2);
}

.suggestion-name {
  font-weight: 500;
  color: var(--text-main);
  text-transform: capitalize;
}

/* Compound History Bar */
.history-bar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 20px;
}

.history-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.history-buttons {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  flex: 1;
}

.history-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.history-btn:hover {
  border-color: rgba(79, 172, 254, 0.4);
  color: var(--text-main);
  background: rgba(79, 172, 254, 0.08);
}

.history-btn.active {
  background: linear-gradient(135deg, rgba(79, 172, 254, 0.2), rgba(0, 242, 254, 0.2));
  border-color: var(--primary);
  color: var(--secondary);
  font-weight: 600;
  box-shadow: 0 0 10px rgba(79, 172, 254, 0.2);
}

.history-btn .hist-formula {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  opacity: 0.8;
}

/* Grid Layout */
.dashboard-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 20px;
}

@media (max-width: 1100px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

/* Card Styling & Header Fixes */
.grid-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  overflow: hidden;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: nowrap;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  overflow: hidden;
}

.card-title h2 {
  font-size: 1.2rem;
  font-weight: 600;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-accent {
  color: var(--primary);
  font-size: 1.2rem;
  flex-shrink: 0;
}

.sub-title {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 4px;
  white-space: nowrap;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

.unit-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.unit-toggle label {
  white-space: nowrap;
}

.unit-toggle select {
  background: rgba(11, 15, 25, 0.8);
  border: 1px solid var(--border-color);
  color: var(--primary);
  font-family: var(--font-mono);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  outline: none;
  font-size: 0.8rem;
}

.viewer-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Phase Diagram Container */
.chart-container {
  height: 450px;
  position: relative;
  width: 100%;
  border-radius: var(--radius-md);
  background: rgba(11, 15, 25, 0.5);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

#phaseDiagramPlot {
  width: 100%;
  height: 100%;
}

/* Loader Overlay */
.loader-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 10;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(79, 172, 254, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s infinite linear;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* State Inspector Panel */
.state-inspector-panel {
  background: rgba(11, 15, 25, 0.7);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.inspector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.inspector-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.phase-tag {
  font-size: 0.8rem;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 4px 12px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}

.phase-solid { background: rgba(0, 242, 254, 0.2); color: #00f2fe; border: 1px solid #00f2fe; }
.phase-liquid { background: rgba(79, 172, 254, 0.2); color: #4facfe; border: 1px solid #4facfe; }
.phase-gas { background: rgba(255, 158, 0, 0.2); color: #ff9e00; border: 1px solid #ff9e00; }
.phase-supercritical { background: rgba(247, 37, 133, 0.2); color: #f72585; border: 1px solid #f72585; }

.sliders-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.val-highlight {
  color: var(--primary);
  font-family: var(--font-mono);
  font-weight: 600;
}

input[type=range] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

.computed-state-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.state-metric {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.metric-val {
  font-size: 0.85rem;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-main);
  margin-top: 2px;
}

/* Right Column Stack */
.right-column-stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Molecule Card */
.formula-badge {
  font-family: var(--font-mono);
  background: rgba(157, 78, 221, 0.2);
  color: #c77dff;
  border: 1px solid rgba(157, 78, 221, 0.4);
  font-size: 0.85rem;
  padding: 2px 10px;
  border-radius: 12px;
}

.molecule-viewer-wrapper {
  height: 250px;
  position: relative;
  width: 100%;
  border-radius: var(--radius-md);
  background: radial-gradient(circle at center, rgba(30, 41, 59, 0.5) 0%, rgba(11, 15, 25, 0.8) 100%);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.mol-container {
  width: 100%;
  height: 100%;
  position: relative;
}

.mol-container-2d {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mol-container-2d img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
  filter: drop-shadow(0 0 10px rgba(79, 172, 254, 0.3));
}

.mol-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(11, 15, 25, 0.5);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.mol-meta-row strong {
  color: var(--text-main);
  font-family: var(--font-mono);
}

/* Data Points Card */
.data-points-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.point-box {
  background: rgba(11, 15, 25, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.point-box:hover {
  transform: translateY(-2px);
  border-color: rgba(79, 172, 254, 0.3);
}

.point-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.triple-point .point-icon { background: rgba(0, 242, 254, 0.15); color: #00f2fe; }
.critical-point .point-icon { background: rgba(247, 37, 133, 0.15); color: #f72585; }
.boiling-point .point-icon { background: rgba(255, 158, 0, 0.15); color: #ff9e00; }
.melting-point .point-icon { background: rgba(0, 245, 212, 0.15); color: #00f5d4; }

.point-info {
  display: flex;
  flex-direction: column;
}

.point-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.point-val {
  font-size: 0.9rem;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-main);
}

.point-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Full Span Cards & Tabs */
.full-span-card {
  grid-column: 1 / -1;
}

.tabs-header {
  display: flex;
  gap: 10px;
}

.tab-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  background: rgba(79, 172, 254, 0.15);
  color: var(--primary);
  border-color: var(--primary);
}

.tab-content {
  padding-top: 10px;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* Property Tables */
.properties-table-wrapper {
  overflow-x: auto;
}

.property-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.property-table th {
  padding: 12px 16px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  background: rgba(11, 15, 25, 0.4);
}

.property-table td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.property-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.prop-symbol {
  font-family: var(--font-mono);
  color: var(--secondary);
}

.prop-val {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-main);
}

/* Reference Section Styling */
.reference-content-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.equations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.eq-card {
  background: rgba(11, 15, 25, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.eq-card h3 {
  font-size: 0.95rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.math-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  font-size: 1rem;
}

.math-note {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 6px;
}

/* FAQ Styles */
.faq-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.faq-item {
  background: rgba(11, 15, 25, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.faq-item h4 {
  font-size: 1rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.faq-item p {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Footer */
.app-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 12px 0;
}

.hidden {
  display: none !important;
}
