/* Pali Periodic Table Styles - Based on periodic-example.html */
:root {
    --bg: #f8fafc;
    --panel: #fff;
    --text: #0f172a;
    --muted: #64748b;
    --b: #e2e8f0;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    /* font: 16px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Inter, Arial; */
}

h1 {
    margin: 16px 0 4px;
    font-size: 22px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px 16px 32px;
}

.page-title {
    text-align: center;
    margin-bottom: 2rem;
}

.page-title h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.page-title p {
    font-size: 1.1rem;
    color: var(--muted);
    margin: 0;
}

.stats-bar {
    background: var(--panel);
    border: 1px solid var(--b);
    border-radius: 14px;
    padding: 1rem 2rem;
    margin-bottom: 2rem;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.stats-item {
    display: inline-block;
    margin: 0 2rem;
    font-weight: 600;
    color: var(--text);
}

.stats-number {
    font-size: 1.5rem;
    color: #3b82f6;
    display: block;
}

.search-section .input-group {
    flex-wrap: nowrap !important;
    align-items: stretch;
}

.search-section .input-group .form-control {
    flex: 1;
    min-width: 200px;
    border-radius: 10px 0 0 10px;
}

.search-section .input-group .btn {
    width: 55px;
    padding: 6px;
}

@media (max-width: 576px) {
    .search-section .input-group .form-control {
        min-width: 60%;
        /* font-size: 16px; */
    }
    
    .search-section .input-group .btn {
        width: 55px;
        /* padding: 4px; */
        height: 50px;
        margin-bottom: 0;
    }
    

}

.btn-category-filter {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
    min-width: 42px;
}

.btn-category-filter::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.btn-category-filter:hover::before,
.btn-category-filter.active::before {
    opacity: 1;
}

.btn-category-filter > * {
    position: relative;
    z-index: 1;
}

.btn-category-filter .badge {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
}

.btn-category-filter:hover {
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-category-filter.active {
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.category-filter-panel {
    max-width: 800px;
    margin: 0 auto;
}

.category-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0 14px;
    justify-content: flex-start;
}

.legend-item {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    border: 1px solid var(--b);
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 14px;
    background: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
}

.legend-item:hover {
    background: #f1f5f9;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,.1);
}

.legend-item.active {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 999px;
}

/* Loading state */
.text-center {
    text-align: center;
}

.py-5 {
    padding: 2rem 0;
}

.spinner-border {
    display: inline-block;
    width: 2rem;
    height: 2rem;
    border: 3px solid var(--b);
    border-radius: 50%;
    border-top-color: #3b82f6;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.text-light {
    color: var(--muted);
}

.mt-3 {
    margin-top: 1rem;
}

.fs-5 {
    font-size: 1.25rem;
}

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Panel and Grid */
.panel {
    background: var(--panel);
    border: 1px solid var(--b);
    border-radius: 14px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.group-labels {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(4rem, 4rem));
    gap: 8px;
    margin-bottom: 1rem;
    justify-content: center;
}

.group-label {
    text-align: center;
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
    padding: 4px;
}

.periodic-table {
    display: grid;
    gap: 12px;
    min-height: 28rem;
    justify-content: center;
}

/* Mobile: try to fit 4 columns */
@media (max-width: 576px) {
    .periodic-table {
        grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr)) !important;
        gap: 4px !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    .element-card {
        padding: 6px !important;
        width: 100% !important;
        min-width: 5.5rem !important;
        max-width: none !important;
        height: auto !important;
        box-sizing: border-box !important;
    }
    .element-symbol {
        font-size: 24px !important;
        margin: 0.25rem 0 !important;
        margin-top: 12px !important;
    }
    .element-meaning {
        font-size: 14px !important;
        line-height: 1.2 !important;
        margin-top: 2px !important;
    }
    .atomic-number {
        font-size: 10px !important;
        top: 1px !important;
        left: 2px !important;
    }
    .word-count {
        font-size: 10px !important;
        min-width: 14px !important;
        height: 14px !important;
        top: 1px !important;
        right: 2px !important;
        padding: 0 2px !important;
    }
}

/* Tablet: 4-5 columns */
@media (min-width: 577px) and (max-width: 991px) {
    .periodic-table {
        grid-template-columns: repeat(auto-fill, minmax(7rem, 7rem));
        gap: 10px;
    }
}

/* Desktop: 6-8 columns */
@media (min-width: 992px) and (max-width: 1399px) {
    .periodic-table {
        grid-template-columns: repeat(auto-fill, minmax(7rem, 7rem));
    }
}

/* Large Desktop: 8-10 columns */
@media (min-width: 1400px) {
    .periodic-table {
        grid-template-columns: repeat(auto-fill, minmax(7rem, 7rem));
    }
}

.element-card {
    position: relative;
    padding: 8px;
    border-radius: 12px;
    border: 1px solid transparent;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
    transition: all 0.2s ease;
    background: #fff;
    aspect-ratio: 1;  /* ทำให้เป็นสี่เหลี่ยมจตุรัส */
    display: flex;
    flex-direction: column;
    justify-content: start;
    align-items: start;
    min-height: 7rem;
    gap: 4px;  /* ระยะห่างระหว่าง elements */
}

/* Dynamic category-based background colors - using opacity overlay for better compatibility */
.element-card[style*="--category-color"] {
    position: relative;
}

.element-card[style*="--category-color"]::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--category-color);
    opacity: 0.15;
    border-radius: 10px;
    pointer-events: none;
    z-index: 0;
}

.element-card[style*="--category-color"] > *:not(.atomic-number):not(.word-count) {
    position: relative;
    z-index: 1;
}

.element-card:hover {
    box-shadow: 0 6px 18px rgba(0,0,0,.08);
    transform: translateY(-2px);
}

.element-card[style*="--category-color"]:hover::before {
    opacity: 0.25;
}

.atomic-number {
    position: absolute;
    top: 3px;
    left: 4px;
    font-size: 10px;
    opacity: .7;
    font-weight: 600;
    z-index: 2;
    line-height: 16px;
}

.word-count {
    position: absolute;
    top: 4px;
    right: 4px;
    /* background: #3b82f6; */
    color: rgb(0, 0, 0);
    padding: 1px 5px;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    z-index: 2;
    min-width: 16px;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 16px;
    box-sizing: border-box;
}

.element-symbol {
    font-weight: 700;
    font-size: 32px !important;
    line-height: 1;
    text-align: left;
    margin: 0;
    margin-top: 15px;
}

.element-meaning {
    font-size: 15px !important;
    line-height: 1.3;
    text-align: left;
    opacity: 0.8;
    font-weight: 500;
    display: -webkit-box;
    /* -webkit-line-clamp: 3; */
    -webkit-box-orient: vertical;
    margin-top: 8px;
    /* overflow: hidden; */
    max-width: 100%;
    height: auto;
}

.element-spacer {
    background: none;
    border: none;
    pointer-events: none;
}

.period-separator {
    display: none;
}

.period-label {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-weight: bold;
    font-size: 0.9rem;
    background: rgba(100,116,139,0.1);
    border-radius: 4px;
    margin: 2px 0;
    padding: 0.5rem;
}

/* Lanthanides and Actinides section */
.lanthanides-actinides {
    margin-top: 18px;
}

.series-title {
    margin: 0 0 6px;
    color: var(--muted);
    text-transform: uppercase;
    font-size: 14px;
    letter-spacing: .08em;
    font-weight: 600;
}

.series-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(4rem, 4rem));
    gap: 8px;
    background: var(--panel);
    border: 1px solid var(--b);
    border-radius: 14px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
    margin-bottom: 1rem;
    justify-content: center;
}

/* Root Mini Card */
.root-mini-card {
    width: 80px;
    height: 80px;
    border-radius: 10px;
    padding: 8px;
    background: #fff;
    border: 1px solid var(--b);
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
    transition: all 0.2s ease;
    position: relative;
    flex-shrink: 0;
}

.root-mini-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--category-color);
    opacity: 0.15;
    border-radius: 10px;
    pointer-events: none;
}

.root-mini-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,.1);
}

.root-mini-card:hover::before {
    opacity: 0.25;
}

.root-mini-card .root-symbol {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
}

.root-mini-card .root-meaning {
    font-size: 0.75rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.8;
}

/* Search highlight */
mark {
    background-color: #fef08a;
    color: #854d0e;
    padding: 0.1em 0.2em;
    border-radius: 0.2em;
}

/* Category colors are now dynamically generated from database colors */

/* Modal styles */
.modal.fade .modal-dialog {
    transform: translate(0, -50px);
    transition: transform .3s ease-out;
}

.modal.show .modal-dialog {
    transform: none;
}

.element-modal .modal-dialog {
    max-width: 90%;
}

@media (min-width: 768px) {
    .element-modal .modal-dialog {
        max-width: 1000px;
    }
    
    .element-symbol {
        font-size: 24px;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .periodic-table {
        grid-template-columns: repeat(auto-fill, minmax(7rem, 7rem));
        gap: 10px;
    }
    
    .group-labels {
        grid-template-columns: repeat(auto-fill, minmax(7rem, 7rem));
        gap: 10px;
    }
    
    .series-grid {
        grid-template-columns: repeat(auto-fill, minmax(7rem, 7rem));
        gap: 10px;
    }
    
    .element-card {
        min-height: 7rem;
        padding: 4px 4px !important;
    }
    
    .element-symbol {
        font-size: 30px !important;
    }

    .element-meaning {
        font-size: 14px !important;
    }    
    
    .atomic-number, .word-count {
        font-size: 9px;
    }
    
    .page-title h1 {
        font-size: 2rem;
    }
    
    .stats-item {
        margin: 0 1rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .periodic-table {
        grid-template-columns: repeat(auto-fill, minmax(6rem, 6rem));
        gap: 8px;
    }
    
    .group-labels {
        grid-template-columns: repeat(auto-fill, minmax(6rem, 6rem));
        gap: 8px;
    }
    
    .series-grid {
        grid-template-columns: repeat(auto-fill, minmax(6rem, 6rem));
        gap: 8px;
    }
    
    .element-card {
        min-height: 6rem;
        padding: 4px 2px;
    }
    
    .element-symbol {
        font-size: 16px;
        margin: 0.5rem 0 0.25rem 0;
        margin-top: 15px;
    }    

    .element-meaning {
        font-size: 12px;
        /* -webkit-line-clamp: 2; */
    }


}