/* --- VARIABLES --- */
:root {
    --bal-primary: #7C3AED; /* Tím đậm */
    --bal-accent: #8B5CF6;
    --bal-bg: #F5F3FF;
    --bal-card: #ffffff;
    --bal-text: #1F2937;
    --bal-border: #E5E7EB;
    --bal-radius: 12px;
}

#kth-balancer-app {
    font-family: 'Segoe UI', Roboto, sans-serif;
    max-width: 900px;
    margin: 40px auto;
}

[v-cloak] { display: none; }

/* --- MAIN CARD --- */
.bal-card {
    background: var(--bal-card);
    border-radius: 20px;
    box-shadow: 0 20px 40px -5px rgba(124, 58, 237, 0.15);
    padding: 40px;
    border: 1px solid rgba(0,0,0,0.05);
}

.bal-header { text-align: center; margin-bottom: 40px; }
.tool-tag { color: var(--bal-primary); font-weight: 800; font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; background: #EDE9FE; padding: 5px 12px; border-radius: 20px; }
.bal-header h2 { font-size: 36px; margin: 15px 0; color: var(--bal-text); font-weight: 800; }
.bal-header p { color: #6B7280; font-size: 16px; }

/* --- INPUT SECTION --- */
.input-wrapper {
    display: flex;
    gap: 10px;
    position: relative;
    margin-bottom: 15px;
}

.input-wrapper input {
    flex: 1;
    padding: 18px 25px;
    font-size: 18px;
    border: 2px solid var(--bal-border);
    border-radius: var(--bal-radius);
    font-family: monospace; /* Font code để nhập công thức dễ hơn */
    outline: none;
    transition: all 0.3s;
}

.input-wrapper input:focus { border-color: var(--bal-primary); box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.1); }
.input-wrapper input.error { border-color: #EF4444; background: #FEF2F2; }

/* Buttons */
.btn-balance {
    background: linear-gradient(135deg, var(--bal-primary), #D946EF);
    color: white;
    font-weight: 700;
    border: none;
    padding: 0 30px;
    border-radius: var(--bal-radius);
    cursor: pointer;
    font-size: 16px;
    transition: transform 0.2s;
    white-space: nowrap;
}
.btn-balance:hover { transform: translateY(-2px); box-shadow: 0 10px 20px -5px rgba(124, 58, 237, 0.4); }

.error-msg { color: #DC2626; margin-top: 10px; font-weight: 600; text-align: center; }

/* Quick Actions & Suggestions */
.quick-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn-random, .btn-library {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
    border: none;
    transition: all 0.2s;
}

.btn-random {
    background: #F3F4F6;
    color: #4B5563;
}
.btn-random:hover { background: #E5E7EB; }

.btn-library {
    background: #ECFDF5;
    color: #059669;
    border: 1px solid #A7F3D0;
    flex-grow: 1; /* Nút thư viện dài hơn */
    max-width: 300px;
}
.btn-library:hover { background: #D1FAE5; }

.suggestions { margin-top: 30px; }
.suggestions h3 {
    font-size: 14px;
    color: #6B7280;
    margin-bottom: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

.example-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.example-item {
    background: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    padding: 10px 15px;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    font-family: monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.example-item:hover {
    background: #EDE9FE;
    border-color: #8B5CF6;
    color: #7C3AED;
    transform: translateY(-2px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

/* --- RESULT SECTION --- */
.bal-result {
    margin-top: 40px;
    background: #F0FDFA; /* Xanh ngọc nhạt */
    border: 1px solid #CCFBF1;
    border-radius: 16px;
    padding: 30px;
    animation: slideUp 0.5s ease;
}

.result-header { color: #0D9488; font-weight: 700; text-transform: uppercase; font-size: 13px; margin-bottom: 15px; letter-spacing: 1px; }

.chemical-equation {
    font-size: 32px;
    font-weight: 700;
    text-align: center;
    color: #111827;
    margin-bottom: 30px;
    font-family: 'Georgia', serif;
    word-break: break-word; /* Tránh tràn dòng trên mobile */
}

.coef-big { color: #DC2626; font-size: 1.2em; margin-right: 2px; }
.chem-form sub { font-size: 0.6em; vertical-align: sub; }
.arrow { color: #9CA3AF; margin: 0 15px; }

/* Stoichiometry Box */
.stoichiometry-box {
    background: white;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid #E5E7EB;
}
.stoichiometry-box h4 { margin: 0 0 15px 0; font-size: 16px; color: #374151; }

.stoch-grid { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.stoch-col { flex: 1; }
.stoch-col h5 { font-size: 12px; text-transform: uppercase; color: #9CA3AF; border-bottom: 1px solid #E5E7EB; padding-bottom: 5px; margin-bottom: 10px; }

.chem-item { 
    display: flex; 
    flex-direction: column;
    margin-bottom: 10px;
    background: #F9FAFB;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #F3F4F6;
}
.chem-formula { font-weight: 600; font-size: 16px; color: #111827; margin-bottom: 5px; font-family: 'Georgia', serif; }
.chem-formula .coef { color: #DC2626; margin-right: 3px; font-weight: bold; }

.chem-mass { font-size: 13px; color: #4B5563; }

.stoch-arrow { align-self: center; font-size: 20px; color: #D1D5DB; }

.total-mass {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px dashed #E5E7EB;
    text-align: center;
    color: #059669;
    font-weight: 600;
}

/* --- MODAL LIBRARY STYLES --- */
.bal-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(3px);
}

.bal-modal {
    background: white;
    width: 90%;
    max-width: 700px;
    height: 80vh;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #E5E7EB;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { margin: 0; font-size: 20px; color: #111827; }
.close-btn { background: none; border: none; font-size: 24px; cursor: pointer; color: #9CA3AF; transition: 0.2s; }
.close-btn:hover { color: #EF4444; transform: rotate(90deg); }

.modal-search { padding: 15px 20px; background: #F9FAFB; border-bottom: 1px solid #E5E7EB; }
.modal-search input {
    width: 100%;
    padding: 12px;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    font-size: 16px;
    outline: none;
}
.modal-search input:focus { border-color: var(--bal-primary); }

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.eq-category { margin-bottom: 25px; }
.eq-category h4 { 
    margin: 0 0 10px 0; 
    color: #4B5563; 
    font-size: 14px; 
    text-transform: uppercase; 
    letter-spacing: 1px;
    border-left: 4px solid #3B82F6;
    padding-left: 10px;
}

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

.eq-list button {
    background: #fff;
    border: 1px solid #E5E7EB;
    padding: 12px;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    font-family: monospace;
    font-size: 13px;
    transition: all 0.2s;
    color: #374151;
    line-height: 1.4;
}
.eq-list button:hover {
    border-color: #3B82F6;
    background: #EFF6FF;
    color: #1D4ED8;
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

.no-result { text-align: center; color: #9CA3AF; padding: 40px; }

/* --- ANIMATIONS --- */
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes modalPop { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* --- MOBILE RESPONSIVE --- */
@media (max-width: 600px) {
    .bal-card { padding: 20px; }
    .input-wrapper { flex-direction: column; }
    .btn-balance { padding: 15px; width: 100%; }
    .chemical-equation { font-size: 24px; }
    .stoch-grid { flex-direction: column; }
    .stoch-arrow { transform: rotate(90deg); margin: 10px 0; }
    .eq-list { grid-template-columns: 1fr; } /* List thành 1 cột trên mobile */
    .btn-library { width: 100%; max-width: none; }
}