/* Variables: No Red, Modern, Simple, Smart */
:root {
    --color-primary: #1e3a8a; /* Deep Navy (Trust, History) */
    --color-secondary: #0ea5e9; /* Sky Blue accent */
    --color-text-main: #334155; /* Slate dark */
    --color-text-muted: #64748b; /* Slate gray */
    --color-border: #cbd5e1;
    --color-bg-light: #f8fafc;
    --color-white: #ffffff;
    --color-hover: #f1f5f9;
}

/* Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    overflow-x: hidden;
}

body {
    font-family: 'Malgun Gothic', 'Noto Sans KR', sans-serif;
    color: var(--color-text-main);
    background-color: var(--color-bg-light);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px 20px 60px;
    background-color: var(--color-white);
    min-height: 100vh;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

/* Header */
.header {
    margin-bottom: 40px;
}
.logo {
    max-height: 60px;
    object-fit: contain;
}
#btnGenealogy {
    bottom: -32px;
}

/* Search Filters Section */
.search-section {
    border-top: 2px solid var(--color-primary);
    border-bottom: 1px solid var(--color-border);
    padding: 20px 0;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.search-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.form-select, .form-input {
    height: 44px;
    padding: 0 14px;
    line-height: 42px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--color-text-main);
    outline: none;
    transition: all 0.2s ease;
    background-color: var(--color-white);
    font-family: inherit;
    vertical-align: middle;
}

.form-select:focus, .form-input:focus {
    border-color: var(--color-secondary);
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.1);
}

/* 1st Row Adjustments */
#docType { min-width: 120px; }
#kingSelect { min-width: 140px; }
.search-keyword { min-width: 200px; }

.and-search-wrapper {
    position: relative;
    flex-grow: 1;
    min-width: 280px;
}
.and-search-wrapper .search-icon {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-muted);
}
.and-search-wrapper .and-input {
    width: 100%;
    height: 44px;
    padding-left: 36px;
}
.and-search-wrapper .and-input:focus {
    border-bottom-color: var(--color-primary);
    box-shadow: none;
}

/* 2nd Row Adjustments */
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.filter-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
}
.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--color-border);
    color: var(--color-white);
    font-size: 11px;
    cursor: help;
}

.action-buttons {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    margin-left: auto;
    flex-grow: 1;
    justify-content: flex-end;
}

.btn {
    height: 44px;
    min-width: 44px;
    padding: 0 20px;
    background-color: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--color-text-main);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn:hover {
    background-color: var(--color-hover);
    border-color: var(--color-text-muted);
}
.btn-search {
    background-color: #cbd5e1;
    color: #334155;
    gap: 8px;
    font-weight: 600;
    padding: 0 24px;
}
.btn-search:hover {
    background-color: #94a3b8;
    box-shadow: 0 4px 12px rgba(148, 163, 184, 0.25);
}
.btn-search:hover {
    background-color: #94a3b8;
    box-shadow: 0 4px 6px rgba(148, 163, 184, 0.2);
}
.btn-download {
    margin-left: auto;
    color: var(--color-text-main);
}
.btn-download:hover, .btn-refresh:hover {
    background-color: #f1f5f9;
}
.btn-refresh {
    background-color: transparent;
    color: var(--color-text-main);
}
.btn-download:hover, .btn-refresh:hover {
    background-color: var(--color-hover);
    border-color: #94a3b8;
}
.btn-download:hover {
    background-color: rgba(14, 165, 233, 0.05);
}

/* Search Results Section */
.results-section {
    padding-top: 10px;
}

.result-item {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 24px 0;
    border-bottom: 1px solid var(--color-border);
}

.result-content {
    flex: 1;
    min-width: 0; /* Ensures truncation works in flex container */
}

/* Title: 1 line ellipsis */
.result-title {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--color-text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Desc: 5 lines ellipsis */
.result-desc {
    font-size: 14px;
    color: var(--color-text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 5px;
}

.result-desc.expanded {
    display: block;
    -webkit-line-clamp: unset;
}

/* 원문 모달 뒷배경 투명 & 클릭 통과 처리 */
#contentModal {
    background-color: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    pointer-events: none;
}
#contentModal .modal-content {
    pointer-events: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    border: 1px solid rgba(0,0,0,0.1);
}

.expand-btn {
    background: none;
    border: none;
    color: #3b82f6;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    padding: 0;
    margin-bottom: 10px;
    outline: none;
}

.expand-btn:hover {
    text-decoration: underline;
}

.result-meta {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-end;
    min-width: 320px;
}

.meta-tags {
    display: flex;
    gap: 8px;
    font-size: 13px;
    flex-wrap: wrap;
}

.meta-tags span {
    background-color: #f1f5f9;
    color: #475569;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid #e2e8f0;
}

.meta-links {
    display: flex;
    gap: 8px;
    margin-top: 15px;
}

.link-item {
    text-decoration: none;
    color: #64748b;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid transparent;
    background-color: #f8fafc;
    transition: all 0.2s ease;
}

.link-item:hover { 
    color: var(--color-primary); 
    background-color: #e0f2fe;
}




/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 50px;
    padding-bottom: 30px;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    text-decoration: none;
    color: var(--color-text-main);
    border: 1px solid transparent;
    border-radius: 4px;
    font-size: 14px;
    transition: background-color 0.2s;
}

.page-link:hover {
    background-color: var(--color-hover);
}

.page-link.active {
    color: var(--color-primary);
    font-weight: bold;
    border-bottom: 2px solid var(--color-primary);
    border-radius: 0;
}

/* Mobile Responsive (360px ~ 768px) */
@media (max-width: 768px) {
    .container {
        padding: 15px 12px;
    }
    
    .header {
        margin-bottom: 20px;
    }
    .logo {
        max-height: 45px;
    }
    #btnGenealogy {
        bottom: -12px;
    }

    /* Primary Search Grid */
    .primary-search {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .primary-search #docType, .primary-search #kingSelect {
        width: 100%;
        min-width: 0;
    }
    .primary-search .search-keyword {
        grid-column: 1 / -1;
        width: 100%;
        min-width: 0;
    }
    .primary-search .date-range-group {
        grid-column: 1 / -1;
        width: 100%;
        justify-content: space-between;
        flex-direction: row !important;
        align-items: center;
    }
    .primary-search .date-input-wrapper {
        flex: 1;
        min-width: 0;
    }
    .primary-search .date-input {
        width: 100% !important;
    }
    .primary-search .range-separator {
        text-align: center;
    }
    .primary-search .and-search-wrapper {
        grid-column: 1 / -1;
        width: 100%;
        min-width: 0;
    }

    /* Secondary Search Grid */
    .secondary-search {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .secondary-search .filter-group {
        width: 100%;
        min-width: 0;
    }
    .secondary-search .form-select {
        min-width: 0 !important;
        width: 100%;
    }

    /* Action Buttons */
    .action-buttons {
        order: 10;
        grid-column: 1 / -1;
        display: flex;
        width: 100%;
        gap: 8px;
        margin-top: 8px;
    }
    .trans-mode-group {
        order: 11;
        width: 100%;
        display: flex;
        gap: 6px;
        margin-top: 4px;
        justify-content: flex-start;
    }
    .btn-search {
        flex: 1; 
        justify-content: center;
    }
    .btn-download {
        margin-left: 0;
    }
    .btn-refresh {
        flex-shrink: 0;
    }

    /* Result List */
    .result-item {
        flex-direction: column;
        gap: 12px;
        padding: 20px 0;
    }
    .result-title {
        font-size: 18px;
        white-space: normal;
        line-height: 1.4;
    }
    .result-desc {
        font-size: 16px;
        line-height: 1.6;
    }
    .result-meta {
        align-items: flex-start;
        width: 100%;
        min-width: auto;
    }
    .meta-tags {
        flex-wrap: wrap;
        gap: 6px;
    }
    .meta-links {
        width: 100%;
        flex-wrap: wrap;
        gap: 6px;
        margin-top: 12px;
    }
    .link-item {
        flex: 1;
        text-align: center;
        padding: 8px 4px;
        min-width: calc(25% - 6px);
    }

    /* Pagination */
    .pagination {
        margin-top: 30px;
        padding-bottom: 20px;
    }
    .page-link {
        min-width: 30px;
        height: 30px;
        font-size: 13px;
    }

    /* Prevent overflow */
    .searchable-select-wrapper {
        min-width: 0;
        max-width: 100%;
    }
    .searchable-select-dropdown {
        width: 100%;
        max-width: 100%;
    }
    .date-input {
        width: auto !important;
        min-width: 0 !important;
        padding: 0 10px !important;
        font-size: 14px !important;
        height: 44px !important;
        min-height: 44px;
    }
    .and-search-wrapper {
        min-width: 0;
    }
}

/* 초소형 모바일 (가로 480px 이하 좁은 폰) */
@media (max-width: 480px) {
    .primary-search .date-range-group {
        flex-direction: row !important;
        align-items: center;
        gap: 6px;
    }
    .primary-search .date-input-wrapper {
        flex: 1;
        min-width: 0;
    }
    .primary-search .date-input {
        width: 100% !important;
        padding: 0 10px !important;
        font-size: 14px !important;
    }
    .date-placeholder {
        font-size: 14px;
    }
}

.link-item.active-link {
    color: var(--color-white);
    background-color: var(--color-primary);
    border-color: var(--color-primary);
    font-weight: 600;
}
.form-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
    padding-right: 36px;
    cursor: pointer;
}
.form-select::-ms-expand {
    display: none;
}

/* Modal Styles */
.modal {
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    background-color: rgba(0,0,0,0.4); 
    align-items: center;
    justify-content: center;
}
.modal.show {
    display: flex;
}
.modal-content {
    background-color: var(--color-white);
    padding: 24px;
    border-radius: 8px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    animation: fadeIn 0.2s ease;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 12px;
}
.modal-header h4 {
    margin: 0;
    color: var(--color-primary);
    font-size: 16px;
}
.close-btn {
    color: var(--color-text-muted);
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}
.close-btn:hover {
    color: var(--color-text-main);
}
.modal-body p {
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--color-text-main);
}
.modal-body ul {
    font-size: 14px;
    padding-left: 20px;
    color: var(--color-text-muted);
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Ensure help icon looks clickable */
.help-icon {
    cursor: pointer;
}
.help-icon:hover {
    background-color: var(--color-primary);
    color: var(--color-white);
}

/* =========================================
   Custom Searchable Select UI
   ========================================= */
.searchable-select-wrapper {
    position: relative;
    width: 100%;
    min-width: 180px;
}

/* Trigger inherits .form-select but we ensure it displays correctly as a div */
div.searchable-select-trigger {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    user-select: none;
    line-height: 42px; /* Vertically center text in div */
}

.searchable-select-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: max-content;
    min-width: 100%;
    background: var(--color-white);
    border: 1px solid var(--color-primary);
    border-radius: 6px;
    box-shadow: 0 8px 16px rgba(30, 58, 138, 0.15);
    z-index: 1050;
    margin-top: 4px;
    flex-direction: column;
}

.searchable-select-dropdown.open {
    display: flex;
}

.searchable-select-search {
    width: calc(100% - 16px);
    box-sizing: border-box;
    margin: 8px;
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    outline: none;
    font-size: 14px;
    color: var(--color-text-main);
    transition: border-color 0.2s ease;
}

.searchable-select-search:focus {
    border-color: var(--color-primary);
}

.searchable-select-options {
    max-height: 250px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding-bottom: 8px;
}

.searchable-select-option {
    flex-shrink: 0;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    cursor: pointer;
    color: var(--color-text-main);
    transition: background-color 0.1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.searchable-select-option:hover {
    background-color: var(--color-hover);
}

.searchable-select-option.selected {
    background-color: #e2e8f0;
    font-weight: 600;
    color: var(--color-primary);
}

/* Custom scrollbar for options */
.searchable-select-options::-webkit-scrollbar {
    width: 6px;
}
.searchable-select-options::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 3px;
}

/* =========================================
   Date Range (FROM ~ TO) UI
   ========================================= */
.date-range-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
@media (min-width: 769px) {
    .date-range-group {
        flex-direction: row !important;
    }
}
.date-input {
    text-align: left;
    padding: 0 12px !important;
    position: relative;
}
@media (min-width: 769px) {
    .date-input {
        width: 135px !important;
    }
}
/* 날짜 입력 wrapper (placeholder span 방식 - 모든 모바일 브라우저 호환) */
.date-input-wrapper {
    position: relative;
    flex: 1;
    min-width: 0;
}
.date-input-wrapper .date-input {
    width: 100%;
}
.date-placeholder {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    padding-left: 10px;
    color: var(--color-text-muted);
    font-size: 14px;
    pointer-events: none;
}
.date-placeholder.hidden {
    display: none;
}
/* 브라우저 기본 날짜 플레이스홀더 숨김 (커스텀 placeholder와 겹침 방지) */
.date-input::-webkit-datetime-edit {
    color: transparent;
}
.date-input::-webkit-datetime-edit-text,
.date-input::-webkit-datetime-edit-month-field,
.date-input::-webkit-datetime-edit-day-field,
.date-input::-webkit-datetime-edit-year-field {
    color: transparent;
}
/* 값이 입력되면 날짜 텍스트를 다시 표시 */
.date-input.has-value::-webkit-datetime-edit,
.date-input.has-value::-webkit-datetime-edit-text,
.date-input.has-value::-webkit-datetime-edit-month-field,
.date-input.has-value::-webkit-datetime-edit-day-field,
.date-input.has-value::-webkit-datetime-edit-year-field {
    color: inherit;
}
.range-separator {
    color: var(--color-text-main);
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
    padding: 0 2px;
}

/* Secondary Search Select Box Widths */
#yearSelect, #articleSelect, #categorySelect {
    min-width: 110px;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0 12px;
    border-bottom: 2px solid var(--color-text-main);
    margin-top: 10px;
}
.results-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-text-main);
}
#totalCountBadge {
    font-weight: 400;
    color: var(--color-text-muted);
    font-size: 15px;
    margin-left: 6px;
}
.no-results {
    text-align: center;
    padding: 80px 20px;
    color: var(--color-text-muted);
    font-size: 16px;
}
.content-modal .modal-content {
    max-width: 700px;
    width: 95%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}
.content-modal .modal-body {
    overflow-y: auto;
    flex: 1;
    padding: 20px 24px;
    line-height: 1.9;
    font-size: 15px;
    white-space: pre-line;
    color: var(--color-text-main);
    word-break: break-all;
    overflow-wrap: break-word;
}
.modal-subtitle {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-top: 4px;
    font-weight: 400;
}
.tag-modal .modal-content {
    max-width: 600px;
    width: 95%;
}
.tag-section {
    margin-bottom: 20px;
}
.tag-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--color-border);
}
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.tag-badge {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
}
.tag-badge.place {
    background-color: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
}
span.tag-badge.place:hover {
    background-color: #bae6fd;
    text-decoration: underline;
}
.tag-badge.people {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}
.detail-modal .modal-content {
    max-width: 900px;
    width: 95%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
.detail-modal .modal-body {
    overflow-y: auto;
    flex: 1;
}
.detail-section {
    margin-bottom: 24px;
}
.detail-section-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.detail-info-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid var(--color-border);
}
.detail-info-table th {
    text-align: left;
    padding: 10px 16px;
    background-color: #f8fafc;
    color: var(--color-text-muted);
    font-size: 13px;
    font-weight: 600;
    width: 100px;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}
.detail-info-table td {
    padding: 10px 16px;
    font-size: 14px;
    color: var(--color-text-main);
    border-bottom: 1px solid var(--color-border);
}
.detail-text-box {
    background-color: #f8fafc;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 20px;
    line-height: 1.9;
    font-size: 15px;
    white-space: pre-line;
    max-height: 300px;
    overflow-y: auto;
    word-break: break-all;
    overflow-wrap: break-word;
}
.detail-text-box.original {
    background-color: #fffbeb;
    border-color: #fde68a;
    font-family: 'Batang', 'SimSun', serif;
    font-size: 16px;
}
.detail-tags {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.detail-tags-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-right: 4px;
}
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}
.modal.show {
    display: flex;
}
.modal-content {
    background-color: var(--color-white);
    padding: 0;
    border-radius: 12px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: modalFadeIn 0.25s ease;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0;
}
.modal-header h4 {
    margin: 0;
    color: var(--color-primary);
    font-size: 17px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.modal-body {
    padding: 20px 24px 24px;
    word-break: break-all;
    overflow-wrap: break-word;
}
.close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--color-text-muted);
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: all 0.15s ease;
    background: transparent;
    border: none;
}
.close-btn:hover {
    background-color: #fee2e2;
    color: #dc2626;
}
@keyframes modalFadeIn {
    from { opacity: 0; transform: translateY(-20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.result-title {
    cursor: pointer;
    transition: color 0.2s;
}
.result-title:hover {
    color: var(--color-secondary);
}
.loading-spinner {
    text-align: center;
    padding: 60px 20px;
    color: var(--color-text-muted);
}
@media (max-width: 768px) {
    .content-modal .modal-content,
    .tag-modal .modal-content,
    .detail-modal .modal-content {
        width: 94%;
        max-width: 94%;
        max-height: 90vh;
        border-radius: 8px;
        margin: 0 auto;
    }
    .modal-content {
        width: 94%;
        max-width: 94%;
    }
    .detail-info-table th { width: 80px; font-size: 12px; }
    .detail-info-table td { font-size: 13px; }
    .detail-text-box { padding: 14px; font-size: 14px; }
    .results-header { padding: 12px 0 10px; }
    .modal-header { padding: 16px 20px; }
    .modal-body { padding: 16px 20px 20px; word-break: break-all; overflow-wrap: break-word; }
    .content-modal .modal-body { padding: 16px 20px; word-break: break-all; overflow-wrap: break-word; }
}

/* Genealogy Table */
.genealogy-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.genealogy-table th {
    background-color: #f1f5f9;
    color: var(--color-primary);
    font-weight: 700;
    text-align: center;
    padding: 12px 10px;
    border-bottom: 2px solid var(--color-border);
}
.genealogy-table td {
    padding: 10px;
    border-bottom: 1px solid var(--color-border);
    text-align: center;
    color: var(--color-text-main);
    vertical-align: middle;
    white-space: nowrap; /* 줄바꿈 방지 */
}
.genealogy-table td:last-child {
    text-align: left; /* 주요역사는 좌측 정렬 */
    white-space: normal; /* 마지막 열(주요역사)은 줄바꿈 허용 */
    min-width: 250px;
}
.genealogy-table tbody tr:hover {
    background-color: var(--color-hover);
}

/* Footer */
.site-footer {
    width: 100%;
    border-top: 1px solid var(--color-border);
    padding: 15px 20px 15px; /* Tighter padding */
    text-align: center;
    background-color: #f8fafc; /* Subtle light background */
    margin-top: 40px;
}
.footer-links {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 8px; /* Tighter margin */
    font-size: 14px;
    font-weight: 500;
}
.footer-links a {
    text-decoration: none;
    color: var(--color-text-main);
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    white-space: nowrap; /* Prevent individual links from wrapping */
}
.footer-links a:hover {
    color: var(--color-primary);
    background-color: #e2e8f0;
}
.footer-links .divider {
    color: #cbd5e1;
    font-size: 12px;
}
.biz-info-box {
    display: flex;
    justify-content: center;
    margin-bottom: 12px; /* Tighter margin */
}
.biz-info-content {
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 15px 25px;
    font-size: 13px;
    color: var(--color-text-muted);
    line-height: 1.8;
    max-width: 700px;
    width: 100%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.biz-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-text-main);
    margin-bottom: 8px;
}
.biz-details {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.biz-details .divider {
    color: #cbd5e1;
}
.copyright {
    font-size: 12px; /* Slightly smaller for compactness */
    color: #94a3b8;
    margin-top: 0; /* Removed top margin */
}
@media (max-width: 768px) {
    .site-footer {
        padding: 20px 10px; /* Reduced for mobile */
        margin-top: 30px;
    }
    .footer-links {
        flex-wrap: nowrap; /* Prevent wrapping entirely */
        gap: 4px; /* Tighter gap */
        font-size: 12px; /* Smaller font to fit 360px */
    }
    .footer-links a {
        padding: 4px 6px;
    }
    .biz-info-content {
        padding: 15px;
        text-align: left;
    }
    .biz-details {
        justify-content: flex-start;
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
        margin-bottom: 6px;
    }
    .biz-details .divider {
        display: none;
    }
    .biz-details span, .biz-details a {
        display: block;
        margin-left: 0 !important;
        margin-bottom: 4px;
    }
}

/* Go to Top Button (Modern Floating UI) */
.btn-go-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: var(--color-primary);
    color: var(--color-white);
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(30, 58, 138, 0.3);
}
.btn-go-top:hover {
    background-color: #152c6b;
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(30, 58, 138, 0.4);
}
.btn-go-top svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
}
@media (max-width: 768px) {
    .btn-go-top {
        bottom: 20px;
        right: 20px;
        width: 44px;
        height: 44px;
    }
    .btn-go-top svg {
        width: 20px;
        height: 20px;
    }
}

/* Document Type Tabs (Pill Style) */
.doc-type-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: auto;
}
.doc-type-tabs .doc-tab {
    cursor: pointer;
    user-select: none;
}
.doc-type-tabs .doc-tab input[type="radio"] {
    display: none;
}
.doc-type-tabs .doc-tab span {
    display: inline-block;
    padding: 8px 16px;
    border: 1px solid var(--color-border);
    border-radius: 20px;
    font-size: 14px;
    color: var(--color-text-main);
    background-color: var(--color-white);
    transition: all 0.2s ease;
}
.doc-type-tabs .doc-tab input[type="radio"]:checked + span {
    background-color: var(--color-primary);
    color: var(--color-white);
    border-color: var(--color-primary);
    font-weight: 600;
}
.doc-type-tabs .doc-tab:hover span {
    background-color: var(--color-hover);
}
.doc-type-tabs .doc-tab input[type="radio"]:checked:hover + span {
    background-color: var(--color-primary);
}


/* Mobile UX Refinements (Order & Tab Scroll) */
@media (max-width: 768px) {
    /* 1. Make tabs scrollable horizontally instead of stacking 6 lines */
    .doc-type-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 5px;
        width: 100%;
    }
    .doc-type-tabs::-webkit-scrollbar {
        display: none; /* Hide scrollbar for cleaner look */
    }
    .doc-tab {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* 2. Reorder elements: Keyword Search above Search Button */
    .search-row {
        display: contents !important; /* Strip row wrapper to allow global flex ordering */
    }
    .search-section {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px;
    }

    /* Assign explicit order for mobile */
    .doc-type-tabs { order: 1; }
    #kingSelect { order: 2; }
    .date-range-group { order: 3; }
    
    /* Make all filter groups (volume, year) follow */
    .filter-group { order: 4; width: 100%; } 
    
    /* The keyword search goes AFTER the dropdowns (Swapped: Now above action-buttons) */
    .and-search-wrapper { order: 5; width: 100%; }
    
    /* The action buttons (Search) */
    .action-buttons { order: 6; width: 100%; display: flex; gap: 8px; }
    .action-buttons .btn-search { flex: 1; }
    
    /* Translation mode toggles (Swapped: Now below action-buttons) */
    .trans-mode-group { order: 7; width: 100%; display: flex; gap: 6px; margin-top: 4px; justify-content: flex-start; margin-left: 0 !important; }
}

/* Trans Mode Buttons Global Styles */
.trans-mode-group { display: flex; gap: 8px; align-items: center; margin-left: 8px; }
.btn-trans-mode { padding: 6px 12px; font-size: 13px; font-weight: 600; border: 1px solid #bde0fe; background-color: #f8fafc; color: #475569; border-radius: 20px; cursor: pointer; transition: all 0.2s ease; display: inline-flex; align-items: center; line-height: 1.2; }
.btn-trans-mode:hover { background-color: #f1f5f9; }
.btn-trans-mode.active { background-color: #0ea5e9; border-color: #0284c7; color: white; }
.btn-trans-mode.active .help-icon { background-color: white !important; color: #0ea5e9 !important; border: none !important; }

/* Desktop explicit ordering */
@media (min-width: 769px) {
    .secondary-search .filter-group { order: 1; }
    .secondary-search .trans-mode-group { order: 2; }
    .secondary-search .action-buttons { order: 3; }
}


/* Z-index override to ensure detail modal shows above term search modal */
.detail-modal {
    z-index: 10010 !important;
}
