/* =========================================
   LAYOUT STYLES
   - Container & Grid Systems
   - Section Layouts
   - Responsive Structures
   ========================================= */

/* Main Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--bg-container);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px var(--shadow-strong);
    position: relative;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 30px;
    color: var(--text-secondary);
}

footer a {
    color: var(--text-link);
    text-decoration: underline;
}

/* Search Section */
.search-section {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-container);
    padding: 15px 0;
    margin: 0 0 20px 0;
    box-shadow: 0 2px 8px var(--shadow-default);
    transition: background 0.3s ease;
}

.search-filter-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.search-input-wrapper {
    grid-column: 1 / -1;
    position: relative;
}

/* Filter Groups */
.filter-group label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9rem;
}

/* Favorites Filter */
.favorites-filter {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    margin-top: 10px;
    position: relative;
    z-index: 20;
    padding: 10px 0;
}

/* Chosung Filter Section */
.chosung-filter-section {
    margin-bottom: 20px;
    padding: 20px;
    background: linear-gradient(135deg, var(--bg-body) 0%, var(--border-default) 100%);
    border-radius: 12px;
}

body.dark-mode .chosung-filter-section {
    background: linear-gradient(135deg, var(--bg-container) 0%, var(--bg-element) 100%);
}

.chosung-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
}

.syllable-buttons {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    padding: 15px;
    background: var(--bg-element);
    border-radius: 8px;
    max-height: 300px;
    overflow-y: auto;
}

.syllable-buttons.show {
    display: flex;
}

/* Result Info */
.result-info {
    margin-bottom: 20px;
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* Table Container */
.table-container {
    overflow-x: auto;
    border-radius: 10px;
    box-shadow: 0 2px 10px var(--shadow-default);
}

.table-container::-webkit-scrollbar {
    height: 8px;
}

.table-container::-webkit-scrollbar-track {
    background: var(--bg-hover-soft);
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb {
    background: var(--border-dark);
    border-radius: 4px;
}

/* Table Layout */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-container);
    table-layout: fixed;
    transition: background 0.3s ease;
}

thead {
    background: #4a5568;
    color: white;
}

body.dark-mode thead {
    background: #1a1a1a;
}

th {
    padding: 12px 8px;
    text-align: left;
    font-weight: 600;
    font-size: 0.9rem;
}

th:nth-child(1) { width: 6%; }
th:nth-child(2) { width: 30%; }
th:nth-child(3) { width: 13%; }
th:nth-child(4) { width: 13%; }
th:nth-child(5) { width: 18%; }
th:nth-child(6) { width: 12%; }
th:nth-child(7) { width: 8%; }

td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

body.dark-mode td {
    border-bottom-color: var(--border-default);
}

tbody tr:hover {
    background: var(--bg-hover-soft);
}

/* Pagination Layout */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 3px;
    padding: 30px 20px;
    margin-top: 20px;
}

.page-numbers {
    display: flex;
    gap: 3px;
    align-items: center;
}

/* Active Filters */
.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0 15px 0;
    padding: 12px;
    background: var(--bg-hover-soft);
    border-radius: 8px;
    border: 1px solid var(--border-light);
}

/* Custom Dropdown Layout */
.custom-dropdown {
    position: relative;
    width: 100%;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-container);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    max-height: 400px;
    display: none;
    flex-direction: column;
}

.custom-dropdown.open .dropdown-menu {
    display: flex;
}

.dropdown-search {
    padding: 10px;
    border-bottom: 1px solid var(--border-light);
}

.checkbox-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.dropdown-footer {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid var(--border-light);
}

/* Recent Modal Layout */
.recent-modal {
    position: fixed;
    bottom: 80px;
    right: 30px;
    width: 320px;
    max-height: 500px;
    background: var(--bg-container);
    border-radius: 15px;
    box-shadow: 0 10px 30px var(--shadow-strong);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-light);
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.recent-header {
    background: var(--accent-teal);
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

body.dark-mode .recent-header {
    background: var(--accent-teal-dark);
}

.recent-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    background: var(--bg-hover-soft);
}

.recent-item {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-container);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.recent-item:hover {
    background: var(--accent-teal-bg);
}

.recent-item-link {
    text-decoration: none;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    flex: 1;
    gap: 10px;
}

.recent-footer {
    padding: 10px;
    background: var(--bg-container);
    border-top: 1px solid var(--border-light);
    text-align: center;
}

/* Dark Mode Toggle Position */
.dark-mode-toggle {
    position: absolute;
    top: 30px;
    right: 30px;
    z-index: 100;
    margin: 0;
    padding: 0;
    display: block;
}

/* ==================== 
   Radicals Page Layout
   ==================== */

/* Stroke Filter Section */
.stroke-filter-section {
    margin-bottom: 25px;
}

.stroke-buttons {
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    gap: 10px;
    padding-bottom: 10px;
    scrollbar-width: thin;
    scrollbar-color: #ccc #f1f1f1;
}

.stroke-buttons::-webkit-scrollbar {
    height: 8px;
}

.stroke-buttons::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.stroke-buttons::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.stroke-buttons::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* Radicals Section */
.radicals-section {
    margin-bottom: 40px;
}

.radicals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    max-height: 200px;
    overflow-y: auto;
    padding: 5px;
}

.radicals-grid::-webkit-scrollbar {
    width: 8px;
}

.radicals-grid::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.radicals-grid::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.radicals-grid::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* Hanja Section */
.hanja-section {
    margin-top: 30px;
    padding-top: 30px;
    border-top: 3px solid var(--border-default);
}

.radical-info {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ==================== 
   Media Queries - Mobile Responsive
   ==================== */
@media (max-width: 768px) {
    .dark-mode-toggle {
        top: 20px;
        right: 15px;
    }

    header {
        padding-right: 50px;
    }

    .container {
        padding: 15px;
        border-radius: 15px;
    }

    .search-section {
        position: relative;
        top: auto;
    }

    .search-filter-grid {
        grid-template-columns: 1fr;
    }

    .chosung-filter-section {
        padding: 15px;
    }

    .syllable-buttons {
        max-height: 200px;
        padding: 10px;
    }

    .table-container {
        margin: 0 -15px;
        border-radius: 0;
        position: relative;
    }

    .table-container::after {
        content: '← 좌우로 스크롤 →';
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(102, 126, 234, 0.9);
        color: white;
        text-align: center;
        padding: 8px;
        font-size: 0.75rem;
        z-index: 5;
    }

    table {
        font-size: 0.75rem;
        min-width: 600px;
    }

    th, td {
        padding: 8px 6px;
        white-space: nowrap;
    }

    th:nth-child(1) { width: 40px; }
    th:nth-child(2) { width: auto; min-width: 120px; }
    th:nth-child(3) { width: 80px; }
    th:nth-child(4) { width: 70px; }
    th:nth-child(5) { width: 60px; }
    th:nth-child(6) { width: 60px; }
    th:nth-child(7) { width: 60px; text-align: center; }
    td:nth-child(7) { text-align: center; }

    .pagination {
        gap: 2px;
        padding: 20px 10px;
    }

    .page-numbers {
        gap: 2px;
    }

    .recent-modal {
        width: 90%;
        right: 5%;
        bottom: 20px;
    }

    .radicals-grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
        gap: 8px;
        padding: 15px;
        max-height: 400px;
    }
}
