:root {
    --bg-main: #f3f4f6;
    --sidebar-bg: #ffffff;
    --panel-bg: #ffffff;
    --border-color: #e5e7eb;
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --radius: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

button,
select,
input {
    font: inherit;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ===================== Sidebar ===================== */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.sidebar-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.sidebar-header p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li {
    padding: 10px 24px;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
}

.sidebar-nav li:hover {
    background: #f9fafb;
    color: var(--text-primary);
}

.sidebar-nav li.active {
    background: #eff6ff;
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 500;
}

.mobile-table-switcher {
    display: none;
}

/* ===================== Main Content ===================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-main);
    overflow: hidden;
    min-width: 0;
}

/* ===================== List View ===================== */
#list-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#detail-view {
    display: none;
    flex-direction: column;
    height: 100%;
}

.topbar {
    padding: 16px 28px;
    background: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.topbar h1 {
    font-size: 1.2rem;
    font-weight: 600;
}

.topbar-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.badge {
    background: #eff6ff;
    color: var(--primary-color);
    padding: 5px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid #bfdbfe;
}

.date-badge {
    background: #f0fdf4;
    color: #166534;
    border-color: #bbf7d0;
}

/* ===================== Search Panel ===================== */
.search-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
    padding: 14px 28px;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    position: relative;
    z-index: 20;
}

.search-conditions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
    min-width: 0;
}

.search-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.search-field label {
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
}

.search-field input,
.search-field select {
    width: 100%;
    min-height: 38px;
    padding: 0 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #ffffff;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-field select {
    cursor: pointer;
}

.search-field input:focus,
.search-field select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.suggestion-combobox {
    position: relative;
}

.suggestion-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    display: none;
    max-height: 240px;
    overflow-y: auto;
    padding: 6px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: var(--shadow-md);
    z-index: 60;
}

.search-condition-field.suggestions-open .suggestion-menu {
    display: block;
}

.suggestion-option {
    display: block;
    width: 100%;
    padding: 9px 10px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.8125rem;
    line-height: 1.35;
    text-align: left;
}

.suggestion-option:hover,
.suggestion-option:focus {
    background: #eff6ff;
    color: var(--primary-color);
    outline: none;
}

.suggestion-empty {
    padding: 12px 10px;
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.search-actions {
    display: flex;
    gap: 8px;
}

.search-actions .btn {
    min-height: 38px;
    min-width: 76px;
}

.search-condition-empty {
    min-height: 38px;
    display: flex;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.data-container {
    flex: 1;
    padding: 20px;
    overflow: hidden;
}

.table-wrapper {
    background: var(--panel-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    height: 100%;
    overflow: auto;
    box-shadow: var(--shadow-md);
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th, td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

th {
    position: sticky;
    top: 0;
    background: #f9fafb;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    z-index: 10;
    border-bottom: 1px solid var(--border-color);
}

td {
    font-size: 0.8125rem;
    color: var(--text-primary);
}

tbody tr:hover {
    background-color: #f9fafb;
}

/* Pagination */
.pagination-container {
    padding: 14px 28px;
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

/* ===================== Buttons ===================== */
.btn {
    background: #ffffff;
    border: 1px solid #d1d5db;
    color: var(--text-primary);
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all 0.15s ease;
}

.btn:hover:not(:disabled) {
    background: #f9fafb;
    border-color: #9ca3af;
}

.btn.primary {
    background: var(--primary-color);
    color: white;
    border: none;
}

.btn.primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-info {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.page-info span {
    color: var(--text-primary);
    font-weight: 600;
}

/* ===================== Detail View ===================== */

/* Breadcrumb */
.detail-breadcrumb {
    padding: 14px 28px;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.breadcrumb-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.breadcrumb-back:hover {
    background: #f9fafb;
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.breadcrumb-path {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.breadcrumb-path .separator {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.breadcrumb-path .current {
    color: var(--text-primary);
    font-weight: 600;
}

/* Info Card */
.detail-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 20px;
    gap: 16px;
}

.info-card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.info-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: #f9fafb;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
}

.info-card-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-card-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s;
    line-height: 1;
}

.info-card-toggle:hover {
    background: #e5e7eb;
    color: var(--text-primary);
}

.info-card-body {
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px 20px;
    max-height: 400px;
    overflow-y: auto;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.info-card.collapsed .info-card-body {
    max-height: 0;
    padding: 0 20px;
    overflow: hidden;
}

.info-card.collapsed .info-card-header {
    border-bottom-color: transparent;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.detail-label {
    font-size: 0.6875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.025em;
}

.detail-value {
    font-size: 0.8125rem;
    color: var(--text-primary);
    word-break: break-all;
    line-height: 1.4;
}

/* Related Data Tabs Area */
.related-data-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    min-height: 0;
}

.related-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: #fafbfc;
    padding: 0 12px;
    flex-shrink: 0;
    overflow-x: auto;
}

.related-tab {
    padding: 12px 18px;
    border: none;
    background: none;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.related-tab:hover {
    color: var(--primary-color);
}

.related-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: #ffffff;
}

.related-tab-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Sub-table inside related data panel */
.related-table-wrapper {
    flex: 1;
    overflow: auto;
}

.related-table {
    width: 100%;
    border-collapse: collapse;
    background: #ffffff;
}

.related-table th,
.related-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    font-size: 0.8125rem;
    white-space: nowrap;
}

.related-table th {
    background: #f3f4f6;
    position: sticky;
    top: 0;
    z-index: 2;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.related-table tbody tr:hover {
    background: #f9fafb;
}

/* Map container inside related panel */
#detail-map-container {
    flex: 1;
    min-height: 0;
    border-radius: 4px;
    overflow: hidden;
}

/* ===================== Scrollbar ===================== */
::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

::-webkit-scrollbar-track {
    background: #f3f4f6;
}

::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ===================== Animations ===================== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

#detail-view.active {
    animation: fadeIn 0.2s ease-out;
}

/* ===================== Responsive ===================== */
@media (max-width: 900px) {
    body {
        height: auto;
        min-height: 100dvh;
        overflow: auto;
    }

    .app-container {
        display: block;
        width: 100%;
        min-height: 100dvh;
        height: auto;
    }

    .sidebar {
        display: none;
    }

    .main-content {
        min-height: 100dvh;
        height: auto;
        overflow: visible;
    }

    #list-view,
    #detail-view {
        min-height: 100dvh;
        height: auto;
    }

    .mobile-table-switcher {
        position: sticky;
        top: 0;
        z-index: 30;
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        align-items: center;
        gap: 10px;
        padding: 12px 14px;
        background: #ffffff;
        border-bottom: 1px solid var(--border-color);
    }

    .mobile-table-switcher label {
        color: var(--text-secondary);
        font-size: 0.8125rem;
        font-weight: 600;
        white-space: nowrap;
    }

    .mobile-table-switcher select {
        width: 100%;
        min-width: 0;
        min-height: 40px;
        padding: 0 36px 0 12px;
        border: 1px solid #d1d5db;
        border-radius: 6px;
        background: #ffffff;
        color: var(--text-primary);
        font-size: 0.9375rem;
    }

    .topbar {
        align-items: flex-start;
        gap: 12px;
        padding: 14px;
        flex-direction: column;
    }

    .topbar h1 {
        width: 100%;
        font-size: 1.05rem;
        line-height: 1.3;
        word-break: break-word;
    }

    .topbar-actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .badge {
        justify-self: start;
        min-height: 32px;
        display: inline-flex;
        align-items: center;
    }

    .search-panel {
        grid-template-columns: 1fr;
        gap: 10px;
        padding: 12px 14px;
    }

    .search-conditions {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .search-field input,
    .search-field select {
        min-height: 40px;
    }

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

    .btn,
    .breadcrumb-back,
    .related-tab {
        min-height: 40px;
    }

    .data-container {
        flex: none;
        height: calc(100dvh - 336px);
        min-height: 360px;
        padding: 12px;
        overflow: hidden;
    }

    .table-wrapper {
        border-radius: 6px;
        box-shadow: var(--shadow-sm);
        -webkit-overflow-scrolling: touch;
    }

    th,
    td,
    .related-table th,
    .related-table td {
        padding: 9px 10px;
        font-size: 0.8125rem;
    }

    .pagination-container {
        position: sticky;
        bottom: 0;
        justify-content: space-between;
        gap: 8px;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    }

    .pagination-container .btn {
        flex: 1;
        padding-inline: 8px;
    }

    .page-info {
        flex: 1.2;
        text-align: center;
        line-height: 1.35;
    }

    .detail-breadcrumb {
        flex-wrap: wrap;
        align-items: flex-start;
        padding: 12px 14px;
        gap: 8px;
    }

    .breadcrumb-path {
        min-width: 0;
        flex: 1 1 220px;
        line-height: 1.4;
    }

    .breadcrumb-path .current {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .detail-body {
        flex: none;
        min-height: calc(100dvh - 65px);
        height: auto;
        overflow: visible;
        padding: 12px;
        gap: 12px;
    }

    .info-card-header {
        padding: 12px 14px;
    }

    .info-card-body {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-height: 42dvh;
        padding: 14px;
        gap: 12px;
    }

    .info-card.collapsed .info-card-body {
        padding: 0 14px;
    }

    .related-data-panel {
        min-height: 420px;
        height: 55dvh;
    }

    .related-tabs {
        padding: 0 8px;
        -webkit-overflow-scrolling: touch;
    }

    .related-tab {
        padding: 10px 14px;
    }

    #detail-map-container {
        min-height: 360px;
    }
}

@media (max-width: 520px) {
    .mobile-table-switcher {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .topbar-actions {
        display: flex;
    }

    .badge {
        width: 100%;
        justify-content: center;
    }

    .data-container {
        height: calc(100dvh - 374px);
        min-height: 320px;
        padding: 10px;
    }

    .pagination-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .page-info {
        grid-column: 1 / -1;
        grid-row: 1;
        padding-bottom: 2px;
    }

    .pagination-container #prev-page {
        grid-column: 1;
    }

    .pagination-container #next-page {
        grid-column: 2;
    }

    .info-card-body {
        grid-template-columns: 1fr;
        max-height: 36dvh;
    }

    .related-data-panel {
        height: 58dvh;
        min-height: 380px;
    }
}
