/* Large formula input */
.formula-input-wrap {
    position: relative;
    margin-bottom: 1rem;
}

.formula-input-wrap input {
    width: 100%;
    padding: 0.9rem 3rem 0.9rem 1.1rem;
    font-size: 1.25rem;
    font-family: 'Ubuntu', monospace, sans-serif;
    font-weight: 700;
    letter-spacing: 0.04em;
    border: 2px solid var(--border, #e2e8f0);
    border-radius: 10px;
    background: var(--bg-input, #f8fafc);
    color: var(--text, #1e293b);
    transition: border-color 0.18s, box-shadow 0.18s;
    box-sizing: border-box;
}

.formula-input-wrap input:focus {
    outline: none;
    border-color: var(--primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.formula-input-wrap input.input-error {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.formula-clear-btn {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
    transition: color 0.15s;
}

.formula-clear-btn:hover {
    color: #ef4444;
}

/* Quick Examples */
.formula-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1.5rem;
}

.formula-examples span {
    font-size: 0.75rem;
    color: var(--text-muted, #64748b);
    font-weight: 600;
    font-family: 'Montserrat', sans-serif;
    align-self: center;
    margin-right: 0.25rem;
}

.example-chip {
    padding: 0.3rem 0.75rem;
    border: 1.5px solid var(--border, #e2e8f0);
    border-radius: 20px;
    background: transparent;
    color: var(--text, #1e293b);
    font-family: 'Ubuntu', monospace, sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.example-chip:hover {
    border-color: var(--primary, #2563eb);
    background: var(--primary, #2563eb);
    color: #fff;
}

/* Breakdown of elements */
.breakdown-section {
    margin-top: 1.5rem;
}

.breakdown-section h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text, #1e293b);
    font-family: 'Montserrat', sans-serif;
    margin-bottom: 0.75rem;
}

.breakdown-table-wrap {
    overflow-x: auto;
    border-radius: 10px;
    border: 1px solid var(--border, #e2e8f0);
}

.breakdown-table-wrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.breakdown-table-wrap thead {
    background: var(--primary, #2563eb);
    color: #fff;
}

.breakdown-table-wrap thead th {
    padding: 0.6rem 1rem;
    text-align: left;
    font-weight: 600;
    font-family: 'Montserrat', sans-serif;
    white-space: nowrap;
}

.breakdown-table-wrap thead th:not(:first-child) {
    text-align: right;
}

.breakdown-table-wrap tbody tr:nth-child(even) {
    background: var(--bg-alt, #f8fafc);
}

.breakdown-table-wrap tbody td {
    padding: 0.55rem 1rem;
    color: var(--text, #1e293b);
    border-bottom: 1px solid var(--border, #e2e8f0);
    vertical-align: middle;
}

.breakdown-table-wrap tbody td:not(:first-child) {
    text-align: right;
}

.breakdown-table-wrap tbody tr:last-child td {
    border-bottom: none;
}

.breakdown-table-wrap tfoot td {
    padding: 0.6rem 1rem;
    font-weight: 700;
    font-family: 'Montserrat', sans-serif;
    border-top: 2px solid var(--border, #e2e8f0);
    color: var(--primary, #2563eb);
}

.breakdown-table-wrap tfoot td:not(:first-child) {
    text-align: right;
}

/* Percentage bar in table */
.pct-bar-cell {
    min-width: 120px;
}

.pct-bar-bg {
    height: 8px;
    background: var(--border, #e2e8f0);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 4px;
}

.pct-bar-fill {
    height: 100%;
    background: var(--primary, #2563eb);
    border-radius: 4px;
    transition: width 0.4s ease;
}

/* Element symbol with group color */
.elem-symbol {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 6px;
    font-family: 'Ubuntu', sans-serif;
    font-weight: 700;
    font-size: 0.95rem;
    color: #fff;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.elem-cell {
    display: flex;
    align-items: center;
}

.elem-name {
    font-size: 0.78rem;
    color: var(--text-muted, #64748b);
    display: block;
}

/* Moles to grams conversion */
.conversion-section {
    margin-top: 1.75rem;
    padding: 1.25rem 1.5rem;
    background: var(--bg-alt, #f8fafc);
    border-radius: 12px;
    border: 1px solid var(--border, #e2e8f0);
}

.conversion-section h3 {
    font-size: 0.95rem;
    font-weight: 700;
    font-family: 'Montserrat', sans-serif;
    color: var(--text, #1e293b);
    margin-bottom: 1rem;
}

.conv-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.conv-field label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted, #64748b);
    font-family: 'Montserrat', sans-serif;
    margin-bottom: 0.35rem;
}

.conv-input-wrap {
    display: flex;
    align-items: center;
    border: 2px solid var(--border, #e2e8f0);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    transition: border-color 0.18s;
}

.conv-input-wrap:focus-within {
    border-color: var(--primary, #2563eb);
}

.conv-input-wrap input {
    flex: 1;
    border: none;
    padding: 0.55rem 0.75rem;
    font-size: 0.95rem;
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    color: var(--text, #1e293b);
    background: transparent;
    min-width: 0;
}

.conv-input-wrap input:focus {
    outline: none;
}

.conv-input-wrap .conv-unit {
    padding: 0.55rem 0.75rem;
    background: var(--bg-alt, #f1f5f9);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted, #64748b);
    font-family: 'Montserrat', sans-serif;
    border-left: 1px solid var(--border, #e2e8f0);
    white-space: nowrap;
}

/* Reference Periodic Table */
.periodic-ref {
    margin-top: 1.75rem;
}

.periodic-ref h3 {
    font-size: 1rem;
    font-weight: 700;
    font-family: 'Montserrat', sans-serif;
    color: var(--text, #1e293b);
    margin-bottom: 0.75rem;
}

.periodic-filter {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.periodic-filter button {
    padding: 0.3rem 0.8rem;
    border: 1.5px solid var(--border, #e2e8f0);
    border-radius: 20px;
    background: transparent;
    color: var(--text-muted, #64748b);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.periodic-filter button.active,
.periodic-filter button:hover {
    border-color: var(--primary, #2563eb);
    background: var(--primary, #2563eb);
    color: #fff;
}

.periodic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 0.4rem;
    max-height: 340px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.elem-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 0.25rem 0.4rem;
    border-radius: 8px;
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
    text-align: center;
    user-select: none;
}

.elem-card:hover {
    border-color: var(--primary, #2563eb);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.elem-card .num {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted, #94a3b8);
    font-family: 'Montserrat', sans-serif;
    align-self: flex-end;
    line-height: 1;
}

.elem-card .sym {
    font-size: 1.2rem;
    font-weight: 700;
    font-family: 'Ubuntu', sans-serif;
    color: var(--text, #1e293b);
    line-height: 1.2;
}

.elem-card .mass {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted, #64748b);
    font-family: 'Montserrat', sans-serif;
    line-height: 1;
    margin-top: 2px;
}

/* Error message */
.parse-error {
    display: none;
    background: #fee2e2;
    border: 1px solid #fca5a5;
    border-radius: 8px;
    padding: 0.6rem 1rem;
    color: #991b1b;
    font-size: 0.875rem;
    font-family: 'Montserrat', sans-serif;
    font-weight: 500;
    margin-bottom: 1rem;
}

/* SEO formulas */
.seo-block .formula-box {
    background: var(--bg-formula, #f1f5f9);
    border-left: 4px solid var(--primary, #2563eb);
    border-radius: 0 8px 8px 0;
    padding: 0.75rem 1.1rem;
    margin: 0.75rem 0 1rem;
    overflow-x: auto;
}

.seo-block .formula-box code {
    font-size: 0.95rem;
    color: var(--primary, #2563eb);
    font-weight: 600;
    white-space: nowrap;
}

.formula-legend {
    list-style: none;
    padding: 0;
    margin: 0 0 1.25rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.4rem 1rem;
}

.formula-legend li {
    font-size: 0.875rem;
    color: var(--text-muted, #64748b);
}

.formula-legend strong {
    color: var(--text, #1e293b);
}

/* Responsive */
@media (max-width: 600px) {
    .conv-grid {
        grid-template-columns: 1fr;
    }

    .periodic-grid {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    }

    .formula-input-wrap input {
        font-size: 1rem;
    }
}