/* Chemical Equation Balancer - Component Styles */

:root {
    --cb-tool: #ec4899;
    --cb-tool-dark: #db2777;
    --cb-gradient: linear-gradient(135deg, #ec4899 0%, #f472b6 100%);
    --cb-light: rgba(236, 72, 153, 0.08);
}
[data-theme="dark"] {
    --cb-light: rgba(236, 72, 153, 0.15);
}

/* ===== Mode Toggle ===== */
.cb-mode-toggle {
    display: flex;
    border: 1.5px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
    margin-bottom: 1rem;
}
.cb-mode-btn {
    flex: 1;
    padding: 0.5rem 0.25rem;
    font-weight: 600;
    font-size: 0.75rem;
    border: none;
    cursor: pointer;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    transition: all 0.15s;
    font-family: var(--font-sans);
    text-align: center;
}
.cb-mode-btn.active {
    background: var(--cb-gradient);
    color: #fff;
}
.cb-mode-btn:hover:not(.active) {
    background: var(--bg-tertiary);
}
[data-theme="dark"] .cb-mode-btn { background: var(--bg-tertiary); }
[data-theme="dark"] .cb-mode-btn.active { background: var(--cb-gradient); color: #fff; }

/* ===== Output Tabs ===== */
.cb-output-tabs {
    display: flex;
    border-bottom: 1.5px solid var(--border);
    background: var(--bg-secondary);
    border-radius: 0.75rem 0.75rem 0 0;
    overflow: hidden;
}
.cb-output-tab {
    flex: 1;
    padding: 0.625rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    background: transparent;
    color: var(--text-secondary);
    transition: all 0.15s;
    font-family: var(--font-sans);
    text-align: center;
    position: relative;
}
.cb-output-tab.active {
    color: var(--cb-tool);
    background: var(--bg-primary);
}
.cb-output-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--cb-tool);
}
.cb-output-tab:hover:not(.active) {
    background: var(--bg-tertiary);
}

/* ===== Panels ===== */
.cb-panel { display: none; }
.cb-panel.active { display: block; }

/* ===== Input Groups ===== */
.cb-input-label {
    display: block;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}
.cb-input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-size: 1rem;
    font-family: var(--font-mono);
    border: 1.5px solid var(--border);
    border-radius: 0.375rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    text-align: left;
    transition: border-color 0.15s;
    box-sizing: border-box;
}
.cb-input:focus {
    outline: none;
    border-color: var(--cb-tool);
    box-shadow: 0 0 0 2px rgba(236, 72, 153, 0.1);
}
.cb-input-hint {
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ===== Equation Preview ===== */
.cb-eq-preview {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border-radius: 0.375rem;
    margin-top: 0.5rem;
    min-height: 1.5rem;
    font-family: var(--font-mono);
}
.cb-eq-preview:empty { display: none; }
.cb-eq-preview sub { font-size: 0.7em; }

/* ===== Options ===== */
.cb-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin: 0.75rem 0;
}
.cb-option {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
}
.cb-option input[type="checkbox"] {
    accent-color: var(--cb-tool);
    width: 14px;
    height: 14px;
}

/* ===== Chips Bar ===== */
.cb-chips-section {
    margin: 0.75rem 0;
}
.cb-chips-title {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.375rem;
}
.cb-chip-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-bottom: 0.375rem;
}
.cb-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 1rem;
    background: var(--bg-secondary);
    font-size: 0.8125rem;
    font-family: var(--font-mono);
    transition: all 0.15s;
}
.cb-chip:hover {
    border-color: var(--cb-tool);
}
.cb-chip sub { font-size: 0.7em; }
.cb-chip-coeff {
    font-weight: 600;
    color: var(--cb-tool);
    min-width: 0.75rem;
    text-align: center;
}
.cb-chip-formula {
    cursor: pointer;
}
.cb-chip-btn {
    border: none;
    background: none;
    cursor: pointer;
    padding: 0 0.15rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1;
    border-radius: 2px;
    transition: all 0.1s;
}
.cb-chip-btn:hover {
    color: var(--cb-tool);
    background: var(--cb-light);
}
.cb-chip-btn.cb-chip-del:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
}
.cb-add-row {
    display: flex;
    gap: 0.375rem;
    max-width: 320px;
}
.cb-add-input {
    flex: 1;
    padding: 0.35rem 0.5rem;
    font-size: 0.8125rem;
    font-family: var(--font-mono);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    box-sizing: border-box;
}
.cb-add-input:focus {
    outline: none;
    border-color: var(--cb-tool);
}
.cb-add-btn {
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}
.cb-add-btn:hover {
    border-color: var(--cb-tool);
    color: var(--cb-tool);
}

/* ===== Example Chips ===== */
.cb-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}
.cb-example-chip {
    padding: 0.3rem 0.625rem;
    font-size: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 1rem;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font-sans);
    white-space: nowrap;
}
.cb-example-chip:hover {
    border-color: var(--cb-tool);
    color: var(--cb-tool);
    background: var(--cb-light);
}

/* ===== Result Display ===== */
.cb-balanced-eq {
    font-size: 1.05rem;
    font-family: var(--font-mono);
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    line-height: 1.7;
    word-break: break-word;
}
.cb-balanced-eq sub { font-size: 0.75em; }
.cb-coeff {
    font-weight: 700;
    color: var(--cb-tool);
    margin-right: 0.15rem;
}
.cb-arrow {
    margin: 0 0.35rem;
    color: var(--text-muted);
}
.cb-nowrap { white-space: nowrap; }
.cb-fractions-view {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border-radius: 0.375rem;
}

/* ===== Atom Count Table ===== */
.cb-atom-table-wrap {
    overflow-x: auto;
    margin: 0.75rem 0;
}
.cb-atom-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}
.cb-atom-table th {
    padding: 0.375rem 0.5rem;
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1.5px solid var(--border);
}
.cb-atom-table td {
    padding: 0.375rem 0.5rem;
    border-bottom: 1px solid var(--border);
}
.cb-atom-equal { color: #059669; font-weight: 600; }
.cb-atom-mismatch { color: #ef4444; font-weight: 600; }

/* ===== Action Buttons Row ===== */
.cb-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: 0.75rem;
}
.cb-action-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.cb-action-btn:hover {
    border-color: var(--cb-tool);
    color: var(--cb-tool);
}
.cb-action-btn.cb-copied {
    border-color: #059669;
    color: #059669;
}

/* ===== Redox Panel ===== */
.cb-redox-group {
    margin-bottom: 0.75rem;
}
.cb-redox-label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}
.cb-redox-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-family: var(--font-mono);
    border: 1.5px solid var(--border);
    border-radius: 0.375rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    box-sizing: border-box;
}
.cb-redox-input:focus {
    outline: none;
    border-color: var(--cb-tool);
    box-shadow: 0 0 0 2px rgba(236, 72, 153, 0.1);
}
.cb-medium-select {
    padding: 0.375rem 0.5rem;
    font-size: 0.8125rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    margin-top: 0.375rem;
}

/* ===== Database Panel ===== */
.cb-search-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    border: 1.5px solid var(--border);
    border-radius: 0.375rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    box-sizing: border-box;
}
.cb-search-input:focus {
    outline: none;
    border-color: var(--cb-tool);
}
.cb-db-table-wrap {
    overflow-x: auto;
    max-height: 420px;
    overflow-y: auto;
}
.cb-db-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}
.cb-db-table th {
    padding: 0.375rem 0.5rem;
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1.5px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 1;
}
.cb-db-table td {
    padding: 0.375rem 0.5rem;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
}
.cb-db-table td:last-child {
    font-family: var(--font-sans);
}
.cb-db-table tr { cursor: pointer; transition: background 0.1s; }
.cb-db-table tbody tr:hover { background: var(--cb-light); }
.cb-db-table td sub { font-size: 0.7em; }

/* ===== Learn Panel ===== */
.cb-learn-section {
    padding: 0.75rem;
}
.cb-learn-section h4 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 1rem 0 0.5rem;
}
.cb-learn-section h4:first-child { margin-top: 0; }
.cb-learn-section p,
.cb-learn-section li {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.6;
}
.cb-learn-section ol, .cb-learn-section ul {
    padding-left: 1.25rem;
    margin: 0.5rem 0;
}

/* ===== History ===== */
.cb-history {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}
.cb-history-title {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.375rem;
}
.cb-history-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.cb-history-item {
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.2rem 0.375rem;
    border-radius: 0.25rem;
    transition: all 0.1s;
    text-decoration: none;
    display: block;
}
.cb-history-item:hover {
    background: var(--cb-light);
    color: var(--cb-tool);
}
.cb-history-clear {
    font-size: 0.6875rem;
    color: var(--text-muted);
    cursor: pointer;
    background: none;
    border: none;
    padding: 0.25rem 0;
    margin-top: 0.25rem;
}
.cb-history-clear:hover { color: var(--cb-tool); }

/* ===== Educational Section Numbers ===== */
.cb-section-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    background: var(--cb-gradient);
    color: #fff;
    font-size: 0.8125rem;
    font-weight: 700;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

/* ===== Educational Cards Grid ===== */
.cb-edu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.75rem;
}
.cb-edu-card {
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    border-left: 3px solid var(--cb-tool);
}
.cb-edu-card h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 0.375rem;
}
.cb-edu-card p {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
}

/* ===== Callout ===== */
.cb-callout {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-top: 1rem;
}
.cb-callout-insight {
    background: rgba(236, 72, 153, 0.06);
    border: 1px solid rgba(236, 72, 153, 0.15);
}
.cb-callout-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}
.cb-callout-text {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ===== FAQ ===== */
.cb-faq-item {
    border-bottom: 1px solid var(--border);
}
.cb-faq-item:last-child { border-bottom: none; }
.cb-faq-question {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    gap: 0.5rem;
    font-family: var(--font-sans);
}
.cb-faq-question:hover { color: var(--cb-tool); }
.cb-faq-chevron {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    transition: transform 0.2s;
}
.cb-faq-item.open .cb-faq-chevron { transform: rotate(180deg); }
.cb-faq-answer {
    display: none;
    padding: 0 0 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.7;
}
.cb-faq-item.open .cb-faq-answer { display: block; }

/* ===== Scroll Animations ===== */
.cb-anim {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}
.cb-anim.cb-visible {
    opacity: 1;
    transform: translateY(0);
}
.cb-anim-d1 { transition-delay: 0.05s; }
.cb-anim-d2 { transition-delay: 0.1s; }
.cb-anim-d3 { transition-delay: 0.15s; }
.cb-anim-d4 { transition-delay: 0.2s; }

/* ===== Alert ===== */
.cb-alert {
    padding: 0.625rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    line-height: 1.5;
}
.cb-alert-warning {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.2);
    color: #92400e;
}
.cb-alert-info {
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: #1e40af;
}
[data-theme="dark"] .cb-alert-warning { color: #fbbf24; }
[data-theme="dark"] .cb-alert-info { color: #60a5fa; }

/* ===== Step Visual ===== */
.cb-steps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}
.cb-step-card {
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 0.75rem;
    text-align: center;
}
.cb-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--cb-gradient);
    color: #fff;
    font-weight: 700;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}
.cb-step-card h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin: 0 0 0.375rem;
    color: var(--text-primary);
}
.cb-step-card p {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
}

/* ===== Reaction Type Cards ===== */
.cb-reaction-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
}
.cb-reaction-card {
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
}
.cb-reaction-card h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 0.375rem;
}
.cb-reaction-card p {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
    font-family: var(--font-mono);
}

/* ===== Random Button ===== */
.cb-random-btn {
    padding: 0.3rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid var(--border);
    border-radius: 1rem;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font-sans);
    white-space: nowrap;
}
.cb-random-btn:hover {
    border-color: var(--cb-tool);
    color: var(--cb-tool);
    background: var(--cb-light);
}

/* ===== Worksheet Button ===== */
.cb-worksheet-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1.5px solid var(--cb-tool);
    border-radius: 0.375rem;
    background: var(--cb-light);
    color: var(--cb-tool);
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font-sans);
    white-space: nowrap;
}
.cb-worksheet-btn:hover {
    background: var(--cb-gradient);
    color: #fff;
    border-color: transparent;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .cb-steps-grid { grid-template-columns: 1fr 1fr; }
    .cb-edu-grid { grid-template-columns: 1fr; }
    .cb-reaction-grid { grid-template-columns: 1fr; }
}
