/* ==========================================
   CALCULATOR WIDGET STYLES
   ========================================== */
.gm-calc-wrapper * { box-sizing: border-box; margin: 0; padding: 0; }
.gm-calc-wrapper { font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 720px; width: 100%; margin: 24px auto; color: #1e293b; padding: 0 16px; }

/* Calculator Hero */
.calculator-hero { text-align: center; padding: 16px 0 8px; margin-bottom: 0; }
.calculator-hero h1 { font-size: 1.75rem; font-weight: 800; margin-bottom: 12px; background: linear-gradient(135deg, #5b21b6, #8b5cf6); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; line-height: 1.2; letter-spacing: -0.02em; }
.calculator-hero p { font-size: 1rem; color: #64748b; max-width: 600px; margin: 0 auto; line-height: 1.6; padding: 0 10px; }

/* Main Grid */
.calc-main-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin: 24px 0; }
.left-panel, .right-panel { background: #ffffff; border: 1px solid #f1f5f9; border-radius: 16px; padding: 24px; min-height: 400px; width: 100%; min-width: 0; }
.left-panel h2, .right-panel h2 { font-size: 0.875rem; font-weight: 700; color: #0f172a; margin-bottom: 20px; text-transform: uppercase; letter-spacing: 0.05em; }

/* Substance Row */
.substance-row { display: flex; gap: 8px; margin-bottom: 20px; width: 100%; position: relative; }
.substance-dropdown-wrapper { position: static; flex: 1; min-width: 0; }
.substance-trigger { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border: 1px solid #e2e8f0; border-radius: 10px; background: white; cursor: pointer; transition: all 0.2s; min-height: 48px; width: 100%; }
.substance-trigger:hover { border-color: #8b5cf6; }
.substance-trigger::after { content: '▼'; font-size: 0.6rem; color: #94a3b8; margin-left: 8px; }
.substance-selected-name { font-weight: 600; color: #0f172a; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.substance-selected-formula { font-size: 0.875rem; color: #64748b; margin-left: 8px; flex-shrink: 0; }
.elements-btn { padding: 12px 16px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px; color: #475569; font-size: 0.875rem; font-weight: 600; cursor: pointer; transition: all 0.2s; font-family: inherit; white-space: nowrap; }
.elements-btn:hover { background: #f5f3ff; border-color: #8b5cf6; color: #5b21b6; }

/* Substance Options Dropdown */
.substance-options { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: white; border: 1px solid #e2e8f0; border-radius: 10px; box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1); z-index: 100; display: none; max-height: 400px; overflow-y: auto; }
.substance-options.open { display: block; }
.substance-search { width: 100%; padding: 12px 14px; border: none; border-bottom: 1px solid #e2e8f0; font-size: 0.875rem; outline: none; font-family: inherit; }
.substance-search:focus { background: #faf5ff; }
.substance-category { padding: 10px 14px; font-size: 0.75rem; font-weight: 700; color: #5b21b6; text-transform: uppercase; letter-spacing: 0.05em; background: #faf5ff; border-bottom: 1px solid #f1f5f9; position: sticky; top: 0; }
.substance-option { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; cursor: pointer; transition: background 0.15s; border-bottom: 1px solid #f8fafc; gap: 12px; }
.substance-option:hover { background: #f5f3ff; }
.substance-name { font-size: 0.875rem; color: #0f172a; font-weight: 500; flex: 1; min-width: 0; }
.substance-formula { font-size: 0.8125rem; color: #64748b; flex-shrink: 0; white-space: nowrap; }

/* Formula Input */
.formula-input-section { margin-bottom: 20px; width: 100%; }
.formula-input-label { font-size: 0.75rem; font-weight: 600; color: #475569; margin-bottom: 8px; display: block; }
.formula-input-row { display: flex; gap: 8px; width: 100%; }
.formula-input { flex: 1; min-width: 0; padding: 12px 14px; border: 1px solid #e2e8f0; border-radius: 10px; font-family: 'Courier New', monospace; font-size: 0.9375rem; outline: none; transition: border-color 0.2s; }
.formula-input:focus { border-color: #8b5cf6; box-shadow: 0 0 0 3px rgba(139,92,246,0.1); }
.formula-parse-btn { padding: 12px 18px; background: #5b21b6; color: white; border: none; border-radius: 10px; font-weight: 600; font-size: 0.875rem; cursor: pointer; transition: background 0.2s; flex-shrink: 0; }
.formula-parse-btn:hover { background: #7c3aed; }

/* Ephemeral feedback */
.formula-help { margin-top: 10px; padding: 12px 14px; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px; font-size: 0.75rem; color: #1e40af; line-height: 1.5; display: none; }
.formula-help.visible { display: block; }
.formula-feedback { margin-top: 10px; padding: 10px 14px; border-radius: 8px; font-size: 0.8125rem; min-height: 0; display: none; }
.formula-feedback.visible { display: block; }
.formula-feedback.success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.formula-feedback.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.composition-display { margin-top: 8px; font-size: 0.8125rem; color: #64748b; display: none; padding: 8px 12px; background: #f8fafc; border-radius: 6px; }
.composition-display.visible { display: block; }

/* Formula Card */
.formula-wrapper { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 20px; text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; width: 100%; margin-top: 20px; }
.formula-heading { font-size: 0.75rem; font-weight: 700; color: #64748b; text-transform: uppercase; letter-spacing: 0.08em; }
.formula-wrapper .katex { font-size: 1.4rem; }
.param-desc { font-size: 0.75rem; color: #64748b; line-height: 1.5; max-width: 100%; word-wrap: break-word; }

/* Right Panel Inputs */
.input-section { display: flex; flex-direction: column; gap: 28px; width: 100%; }
.input-group { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.input-label { font-weight: 600; font-size: 0.8125rem; color: #475569; }
.input-label.result-label { color: #5b21b6; }
.input-field { display: flex; border: 1px solid #e2e8f0; border-radius: 10px; background: white; transition: all 0.2s; width: 100%; }
.input-field:focus-within { border-color: #8b5cf6; box-shadow: 0 0 0 4px rgba(139,92,246,0.15); }
.input-field input { flex: 1; min-width: 0; border: none; border-radius: 10px 0 0 10px; padding: 14px 16px; font-size: 1rem; font-family: inherit; color: #0f172a; outline: none; background: transparent; }
.input-field input.result-input { background: #f5f3ff; font-weight: 600; color: #5b21b6; }
.input-field input.auto-filled { background: #faf5ff; }
.unit-select { min-width: 62px; max-width: 62px; padding: 14px 6px; border: none; border-left: 1px solid #e2e8f0; background: #f8fafc; border-radius: 0 10px 10px 0; font-size: 0.8125rem; font-weight: 600; color: #475569; cursor: pointer; outline: none; font-family: inherit; text-align: center; appearance: auto; }
.unit-select:hover { background: #f1f5f9; }
.unit-select:focus { background: #f5f3ff; color: #5b21b6; }
.molar-mass-wrapper { position: relative; }

/* Periodic Table Modal */
.periodic-table-modal { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; padding: 20px; }
.periodic-table-modal.open { display: flex; }
.periodic-table-content { background: white; border-radius: 16px; max-width: 1100px; width: 100%; max-height: 90vh; overflow-y: auto; padding: 24px; position: relative; }
.periodic-table-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.periodic-table-header h3 { font-size: 1.25rem; font-weight: 700; color: #0f172a; }
.periodic-table-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #64748b; padding: 4px 8px; border-radius: 6px; font-family: inherit; }
.periodic-table-close:hover { background: #f1f5f9; color: #0f172a; }
.periodic-table-grid-wrapper { overflow-x: auto; margin-bottom: 16px; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
.periodic-table-grid { display: grid; grid-template-columns: repeat(18, minmax(40px, 1fr)); gap: 3px; min-width: 720px; }
.pt-element { aspect-ratio: 1; border: 2px solid; border-radius: 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; padding: 2px; min-width: 0; overflow: hidden; }
.pt-element:hover { transform: scale(1.2); box-shadow: 0 4px 12px rgba(0,0,0,0.2); z-index: 2; }
.pt-symbol { font-size: 0.75rem; font-weight: 700; line-height: 1; }
.pt-mass { font-size: 0.5rem; opacity: 0.8; line-height: 1; }
.pt-placeholder { background: #f1f5f9; border: 1px dashed #cbd5e1; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 0.625rem; color: #64748b; aspect-ratio: 1; }
.periodic-table-info { padding: 12px 16px; background: #f8fafc; border-radius: 10px; font-size: 0.875rem; color: #334155; min-height: 60px; }

/* Element Popup */
.element-popup { position: absolute; width: 240px; background: white; border: 2px solid #8b5cf6; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); padding: 14px; z-index: 1001; animation: popupFadeIn 0.15s ease-out; }
@keyframes popupFadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.element-popup-header { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid #f1f5f9; }
.element-popup-symbol { font-size: 2rem; font-weight: 800; color: #5b21b6; line-height: 1; min-width: 50px; text-align: center; }
.element-popup-details { flex: 1; min-width: 0; }
.element-popup-name { font-size: 1rem; font-weight: 700; color: #0f172a; line-height: 1.2; }
.element-popup-cat { font-size: 0.75rem; color: #64748b; margin-top: 2px; text-transform: capitalize; }
.element-popup-mass { font-size: 0.875rem; color: #334155; margin-bottom: 12px; }
.element-popup-mass strong { color: #0f172a; }
.element-popup-select-btn { width: 100%; padding: 10px; background: #5b21b6; color: white; border: none; border-radius: 8px; font-weight: 600; font-size: 0.875rem; cursor: pointer; transition: background 0.2s; font-family: inherit; }
.element-popup-select-btn:hover { background: #7c3aed; }
.element-popup-select-btn:active { background: #4c1d95; }

/* ==========================================
   ARTICLE CONTENT STYLES (Purple Theme)
   ========================================== */
.article-content { line-height: 1.7; color: #334155; }
.article-content h2 { font-size: 1.5rem; font-weight: 700; margin-top: 48px; margin-bottom: 16px; color: #0f172a; letter-spacing: -0.01em; }
.article-content h3 { font-size: 1.25rem; font-weight: 700; margin-top: 32px; margin-bottom: 12px; color: #1e293b; }
.article-content p { margin-bottom: 16px; font-size: 1rem; }
.article-content ul, .article-content ol { margin-bottom: 16px; padding-left: 24px; }
.article-content li { margin-bottom: 8px; }
.article-content strong { color: #0f172a; font-weight: 600; }
.article-content a { color: #5b21b6; text-decoration: underline; text-underline-offset: 2px; }
.article-content a:hover { color: #8b5cf6; }

/* Tables */
.article-content table { width: 100%; border-collapse: collapse; margin: 20px 0 28px; font-size: 0.9rem; background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; overflow: hidden; }
.article-content th, .article-content td { padding: 12px 16px; text-align: left; border-bottom: 1px solid #f1f5f9; }
.article-content th { background: #f8fafc; font-weight: 700; color: #0f172a; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.article-content tr:last-child td { border-bottom: none; }
.article-content tr:hover td { background: #fafafa; }

/* Formula Block (Purple Accent) */
.article-content .formula-block { background: #faf5ff; border: 1px solid #e9d5ff; border-left: 4px solid #8b5cf6; border-radius: 0 10px 10px 0; padding: 24px; margin: 24px 0; text-align: center; overflow-x: auto; }

/* Example Block (Purple Accent) */
.article-content .example-block { background: #faf5ff; border-left: 4px solid #8b5cf6; border-radius: 0 10px 10px 0; padding: 16px 20px; margin: 20px 0; }
.article-content .example-block h4 { font-size: 0.9375rem; font-weight: 700; color: #5b21b6; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.article-content .example-block ol { padding-left: 20px; margin-bottom: 0; }
.article-content .example-block li { margin-bottom: 10px; }
.article-content .example-block p { margin-bottom: 8px; }

/* FAQ Items */
.article-content .faq-item { border-bottom: 1px solid #e2e8f0; padding: 20px 0; }
.article-content .faq-item:last-child { border-bottom: none; }
.article-content .faq-item h3 { margin-top: 0; color: #5b21b6; font-size: 1.125rem; }
.article-content .faq-item p:last-child { margin-bottom: 0; }

/* Sources List */
.article-content .sources-list { list-style: none; padding: 0; counter-reset: source-counter; }
.article-content .sources-list li { margin-bottom: 12px; padding-left: 30px; position: relative; counter-increment: source-counter; }
.article-content .sources-list li::before { content: '[' counter(source-counter) ']'; position: absolute; left: 0; color: #8b5cf6; font-weight: 700; }
.article-content .sources-list a { color: #5b21b6; text-decoration: none; font-weight: 600; border-bottom: 1px dashed #8b5cf6; }
.article-content .sources-list a:hover { color: #4c1d95; border-bottom-style: solid; }

/* Superscript Citations */
.article-content sup { font-size: 0.75em; color: #8b5cf6; font-weight: 700; }
.article-content sup a { color: #8b5cf6; text-decoration: none; border-bottom: none; }

/* KaTeX */
.article-content .katex { font-size: 1.1em; }
.article-content .katex-display { margin: 20px 0; overflow-x: auto; overflow-y: hidden; }

/* Article Content Responsive */
@media (max-width: 768px) {
.article-content { padding: 24px 8px 48px; }
.article-content h2 { font-size: 1.375rem; margin-top: 32px; }
.article-content h3 { font-size: 1.125rem; }
.article-content p, .article-content li { font-size: 0.95rem; }
.article-content table { font-size: 0.8rem; }
.article-content th, .article-content td { padding: 10px 12px; }
}

/* Widget Responsive */
@media (max-width: 768px) {
.calc-main-grid { grid-template-columns: 1fr; gap: 20px; }
.left-panel, .right-panel { padding: 20px; min-height: auto; }
.gm-calc-wrapper { padding: 0 12px; }
.periodic-table-grid { min-width: 720px; }
.pt-symbol { font-size: 0.625rem; }
.pt-mass { font-size: 0.4rem; }
.periodic-table-content { padding: 16px; }
.input-section { gap: 24px; }
.calculator-hero h1 { font-size: 1.75rem; }
}
@media (min-width: 769px) {
.left-panel, .right-panel { box-shadow: 0 10px 40px -10px rgba(0,0,0,0.08); }
.calculator-hero h1 { font-size: 2.25rem; }
.calculator-hero p { padding: 0; }
}