/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    background: #f5f5f5;
}

/* Header - Relative positioning to scroll naturally */
.main-header {
    background: #fff;
    padding: 1.25rem 2rem;
    border-bottom: 1px solid #e0e0e0;
    position: relative;
    z-index: 100;
}

/* Sidebar wrapper - contains the app container */
.sidebar-wrapper {
    display: flex;
    flex-direction: row;
    width: 100%;
}

/* App Container - contains sidebar and main content */
.app-container {
    display: flex;
    width: 100%;
    max-width: 100%;
    flex: 1;
    flex-direction: row;
}

/* Use a container to preserve layout when sidebar becomes fixed */
.content-wrapper {
    display: flex;
    flex: 1;
    width: 100%;
}

/* Main Content area - preserves horizontal layout */
.main-content-area {
    flex: 1;
    display: flex;
    flex-direction: row;
    width: 100%;
    min-width: 0;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.site-title {
    font-size: 1.5rem;
    color: #2c3e50;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s;
}

.site-title:hover {
    color: #3498db;
}

.back-link {
    color: #3498db;
    text-decoration: none;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    transition: color 0.2s;
}

.back-link:hover {
    color: #2980b9;
    text-decoration: underline;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.search-form {
    display: flex;
    align-items: center;
}

.search-input {
    padding: 0.6rem 1.2rem;
    background: #f8f9fa;
    color: #2c3e50;
    font-size: 0.9rem;
    border: 1px solid #e9ecef;
    border-radius: 24px;
    width: 300px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.search-input:focus {
    outline: none;
    background: #fff;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15), 0 2px 8px rgba(52, 152, 219, 0.2);
    width: 340px;
}

.search-input::placeholder {
    color: #9ca3af;
}


/* Sidebar */
.sidebar {
    width: 160px;
    min-width: 160px;
    background: #fff;
    border-right: 1px solid #e0e0e0;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 90;
    display: flex;
    flex-direction: column;
}

.sidebar-pre-collapsed .sidebar {
    width: 60px;
    min-width: 60px;
}

.sidebar-pre-collapsed .sidebar .sidebar-text {
    display: none;
}

.sidebar-pre-collapsed .sidebar .sidebar-icon {
    width: 24px;
    height: 24px;
}

.sidebar-pre-collapsed .sidebar .sidebar-item {
    padding: 0.5rem;
    margin: 0.25rem 0.5rem;
    border-radius: 8px;
    justify-content: center;
}

.sidebar-pre-collapsed .sidebar .sidebar-nav,
.sidebar-pre-collapsed .sidebar .sidebar-function-area {
    padding: 0.5rem 0;
    align-items: center;
}

.sidebar-pre-collapsed .sidebar .sidebar-separator {
    margin: 0.5rem 0.75rem;
}

.sidebar-pre-collapsed .sidebar .toggle-icon {
    transform: scaleX(-1);
}

.sidebar-pre-collapsed .sidebar .sidebar-submenu {
    display: none;
}

.sidebar-pre-collapsed .sidebar .sidebar-expand-btn {
    display: none;
}

.sidebar-pre-collapsed .sidebar .sidebar-item-wrapper {
    display: flex;
}

.sidebar-pre-collapsed .sidebar .sidebar-item-wrapper > .sidebar-item {
    padding: 0.5rem;
    margin: 0.25rem 0.5rem;
    border-radius: 8px;
    justify-content: center;
    padding-right: 0.5rem;
}

.sidebar.has-transition {
    transition: width 0.3s ease, min-width 0.3s ease;
}

/* Sidebar Collapsed State */
.sidebar.collapsed {
    width: 60px;
    min-width: 60px;
}

.sidebar.collapsed .sidebar-nav,
.sidebar.collapsed .sidebar-function-area {
    padding: 0.5rem 0;
    align-items: center;
}

.sidebar.collapsed .sidebar-item {
    padding: 0.5rem;
    margin: 0.25rem 0.5rem;
    border-radius: 8px;
    justify-content: center;
}

.sidebar.collapsed .sidebar-text {
    display: none;
}

.sidebar.collapsed .sidebar-icon {
    width: 24px;
    height: 24px;
}

.sidebar.collapsed .sidebar-separator {
    margin: 0.5rem 0.75rem;
}

.sidebar.collapsed .toggle-icon {
    transform: scaleX(-1);
}


/* Custom scrollbar for sidebar */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 2px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: #b0b0b0;
}

/* Sidebar Navigation */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 0.75rem 0;
    gap: 0.25rem;
    flex: 1;
}

/* Sidebar Separator */
.sidebar-separator {
    height: 1px;
    background: #e5e7eb;
    margin: 0.5rem 0.75rem;
    flex-shrink: 0;
}

/* Sidebar Function Area */
.sidebar-function-area {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0;
    gap: 0.25rem;
    flex-shrink: 0;
}

/* Function Button */
.sidebar-function-btn {
    background: none;
    border: none;
    cursor: pointer;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.sidebar-function-btn:hover {
    background: #f8f9fa;
}

.sidebar-function-btn:focus {
    outline: none;
    background: #eef2f5;
}

.sidebar-function-btn .toggle-icon {
    transition: transform 0.3s ease;
}

.sidebar-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 0.65rem 1rem;
    color: #666;
    text-decoration: none;
    transition: all 0.2s ease;
    border-radius: 8px;
    margin: 0.1rem 0.75rem;
    gap: 0.75rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.sidebar-item:hover {
    color: #2c3e50;
    background: #f8f9fa;
}

.sidebar-item.active {
    color: #2c3e50;
    background: #eef2f5;
}

.sidebar-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: currentColor;
}

.sidebar-text {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    flex: 1;
}

/* Sidebar item with submenu */
.sidebar-item-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
}

.sidebar-item-wrapper > .sidebar-item {
    padding-right: 2.5rem;
}

.sidebar-expand-btn {
    position: absolute;
    right: 0.75rem;
    top: 0.75rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #999;
    transition: color 0.2s ease;
    background: none;
    border: none;
    padding: 0;
    z-index: 1;
}

.sidebar-expand-btn:hover {
    color: #666;
}

.sidebar-expand-btn svg {
    width: 14px;
    height: 14px;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.sidebar-item-wrapper.expanded > .sidebar-expand-btn svg {
    transform: rotate(180deg);
}

/* Submenu */
.sidebar-submenu {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.25s ease-out;
}

.sidebar-item-wrapper.expanded > .sidebar-submenu {
    max-height: 200px;
}

.sidebar-submenu .sidebar-item {
    padding-left: 2.5rem;
    font-size: 0.85rem;
}

.sidebar-submenu .sidebar-item .sidebar-icon {
    width: 14px;
    height: 14px;
}

/* Collapsed state - hide submenu and expand button */
.sidebar.collapsed .sidebar-expand-btn {
    display: none;
}

.sidebar.collapsed .sidebar-submenu {
    display: none;
}

.sidebar.collapsed .sidebar-item-wrapper {
    display: flex;
}

/* Ensure collapsed state has same styling for all items */
.sidebar.collapsed .sidebar-item-wrapper > .sidebar-item {
    padding: 0.5rem;
    margin: 0.25rem 0.5rem;
    border-radius: 8px;
    justify-content: center;
    padding-right: 0.5rem;
}

/* Main Content - inside a wrapper to preserve layout */
.main-content {
    flex: 1;
    min-width: 0;
    padding: 1rem 2rem 2rem 2rem;
    max-width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* Custom scrollbar for main content */
.main-content::-webkit-scrollbar {
    width: 8px;
}

.main-content::-webkit-scrollbar-track {
    background: #f5f5f5;
}

.main-content::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 4px;
}

.main-content::-webkit-scrollbar-thumb:hover {
    background: #b0b0b0;
}

/* Category Filter */
.field-filter-bar {
    margin-bottom: 1rem;
    padding-bottom: 0.25rem;
}

.field-filter-container {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding: 0.1rem 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #d0d0d0 transparent;
}

.field-filter-container::-webkit-scrollbar {
    height: 4px;
}

.field-filter-container::-webkit-scrollbar-track {
    background: transparent;
}

.field-filter-container::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 2px;
}

.field-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    background: #f8f8f8;
    color: #666;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 20px;
    white-space: nowrap;
    transition: all 0.2s ease;
    border: 1px solid #e0e0e0;
    cursor: pointer;
}

.field-chip:hover {
    background: #e8e8e8;
    color: #2c3e50;
    border-color: #d0d0d0;
}

.field-chip.active {
    background: #2c3e50;
    color: #fff;
    border-color: #2c3e50;
}

/* Card Grid */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: linear-gradient(180deg, #ffffff 0%, #fcfcfc 100%);
    border-radius: 12px;
    border: 1px solid #ececec;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.card:hover {
    transform: translateY(-6px);
    border-color: #d6e0ea;
    box-shadow: 0 12px 24px rgba(44, 62, 80, 0.12);
}

.card-content {
    padding: 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1.15rem;
    color: #1f2d3d;
    font-weight: 700;
    line-height: 1.3;
    flex: 1;
}

.card-field {
    display: inline-flex;
    color: #3e5566;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    background: #eef2f5;
    border: 1px solid #e1e6eb;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
}

/* Chart Preview in Card */
.chart-preview {
    background: #f8f9fa;
    border-radius: 8px;
    height: 200px;
    margin-bottom: 1rem;
    overflow: hidden;
    position: relative;
}

.chart-preview canvas {
    width: 100%;
    height: 100%;
}

.card-description {
    color: #4a5a6a;
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 1rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-meta {
    display: flex;
    gap: 1rem;
    color: #7a8a99;
    font-size: 0.85rem;
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid #edf1f4;
    align-items: center;
}

/* Detail Page Styles */
.detail-header {
    background: #fff;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    margin-bottom: 1.5rem;
}

.detail-title {
    font-size: 2rem;
    color: #2c3e50;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.description-text {
    color: #666;
    line-height: 1.8;
    margin: 1rem 0;
}

/* Statistics Grid */
.statistics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.stat-item {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
}

.stat-label {
    color: #6c757d;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

.stat-value {
    color: #2c3e50;
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-date {
    color: #999;
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

/* Time Range Selector */
.time-range-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    justify-content: center;
}

.time-range-btn {
    padding: 0.5rem 1.5rem;
    background: #f8f9fa;
    color: #666;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.time-range-btn:hover {
    background: #e8e8e8;
    color: #2c3e50;
}

.time-range-btn.active {
    background: #2c3e50;
    color: #fff;
    border-color: #2c3e50;
}

/* Chart Container */
.chart-container {
    background: #fff;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    margin-bottom: 1.5rem;
}

.chart-header {
    margin-bottom: 1rem;
}

.chart-title {
    font-size: 1.2rem;
    color: #2c3e50;
    font-weight: 600;
}

.chart-wrapper {
    position: relative;
}

#chart {
    width: 100%;
    height: 500px;
}

/* Data Info */
.data-info {
    display: flex;
    gap: 2rem;
    background: #f8f9fa;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    flex-wrap: wrap;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.info-label {
    color: #6c757d;
    font-size: 0.9rem;
}

.info-value {
    color: #2c3e50;
    font-weight: 600;
    font-size: 0.9rem;
}

/* Loading States */
.card-loader {
    display: none;
    text-align: center;
    padding: 3rem 1rem;
    color: #666;
}

.card-loader.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: #999;
}

.empty-state p {
    font-size: 1.1rem;
}

/* Macro Dashboard */
.macro-main-content {
    max-width: 1400px;
    margin: 0 auto;
}

.macro-inline-note {
    font-size: 0.9rem;
    color: #5a6b7b;
}

.macro-section {
    margin-bottom: 1.5rem;
    background: #fff;
    border-radius: 12px;
    padding: 1.25rem 1.25rem 1rem 1.25rem;
    border: 1px solid #eceff3;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
}

.macro-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 0.75rem;
}

.macro-kpi-card {
    background: #f8fafc;
    border: 1px solid #e8eef4;
    border-radius: 10px;
    padding: 0.75rem 0.9rem;
}

.macro-kpi-label {
    font-size: 0.8rem;
    color: #6d7f8f;
    margin-bottom: 0.2rem;
}

.macro-kpi-value {
    font-size: 1.3rem;
    color: #213547;
    font-weight: 700;
}

.macro-kpi-date {
    font-size: 1rem;
    font-weight: 600;
}

.macro-source-list {
    margin-top: 0.9rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.macro-source-badge {
    display: inline-flex;
    align-items: center;
    background: #edf3f9;
    border: 1px solid #d8e4f0;
    color: #35516a;
    font-size: 0.8rem;
    border-radius: 16px;
    padding: 0.3rem 0.6rem;
}

.macro-control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.macro-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.macro-controls label {
    font-size: 0.85rem;
    color: #5a6b7b;
}

.macro-select,
.macro-input {
    background: #fff;
    border: 1px solid #d7e1ea;
    border-radius: 8px;
    padding: 0.46rem 0.6rem;
    font-size: 0.88rem;
    color: #22384a;
}

.macro-input {
    min-width: 240px;
}

#macroFactorChart,
#regimeChart {
    width: 100%;
    height: 420px;
}

#regimeChart {
    height: 300px;
}

#structuralChart {
    width: 100%;
    height: 320px;
}

.macro-factor-latest {
    margin-top: 0.7rem;
    color: #52677b;
    font-size: 0.9rem;
}

.macro-compare-list {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.macro-compare-item {
    display: grid;
    grid-template-columns: minmax(180px, 1.6fr) minmax(200px, 4fr) minmax(130px, 1.4fr);
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.7rem;
    background: #f9fbfd;
    border: 1px solid #e8edf2;
    border-radius: 8px;
}

.macro-compare-label {
    color: #2d4154;
    font-size: 0.88rem;
    font-weight: 600;
}

.macro-compare-bar-wrap {
    height: 10px;
    background: #e9eef4;
    border-radius: 999px;
    overflow: hidden;
}

.macro-compare-bar {
    height: 100%;
    border-radius: 999px;
}

.macro-compare-bar.positive {
    background: linear-gradient(90deg, #2d6fa2, #4ca5df);
}

.macro-compare-bar.negative {
    background: linear-gradient(90deg, #d66a3f, #f09c63);
}

.macro-compare-value {
    text-align: right;
    color: #34495e;
    font-size: 0.85rem;
    font-weight: 600;
}

.macro-table-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 0.85rem;
}

.macro-table-card {
    background: #f9fbfd;
    border: 1px solid #e7edf3;
    border-radius: 10px;
    padding: 0.85rem;
    margin-top: 0.8rem;
}

.macro-table-card h4 {
    color: #2f4358;
    font-size: 0.94rem;
    margin-bottom: 0.5rem;
}

.macro-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.83rem;
}

.macro-table th,
.macro-table td {
    text-align: left;
    padding: 0.42rem 0.35rem;
    border-bottom: 1px solid #e8edf3;
}

.macro-table th {
    color: #5c6f82;
    font-weight: 600;
}

.macro-table td {
    color: #30455a;
}

.macro-empty {
    padding: 0.8rem;
    font-size: 0.9rem;
    color: #6a7f95;
}

.macro-distribution {
    margin-top: 0.75rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        min-width: 100%;
        display: flex;
        min-height: auto;
        position: relative;
        top: auto;
        height: auto;
        overflow: visible;
    }
    
    .sidebar-nav {
        flex-direction: row;
        padding: 0.5rem 1rem;
        gap: 0.5rem;
        height: auto;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .sidebar-item {
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
        white-space: nowrap;
        margin: 0;
        border-radius: 20px;
    }
    
    .sidebar-icon {
        width: 16px;
        height: 16px;
    }
    
    .sidebar-text {
        font-size: 0.8rem;
    }
    
    .main-header {
        padding: 1rem;
    }
    
    .header-content {
        flex-direction: column;
        gap: 1rem;
    }
    
    .search-input {
        width: 100%;
    }
    
    .search-input:focus {
        width: 100%;
    }
    
    .main-content {
        padding: 1rem 1rem 2rem 1rem !important;
    }
    
    .card-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .statistics-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    .time-range-selector {
        flex-wrap: wrap;
    }
    
    #chart {
        height: 350px;
    }
    
    .detail-header {
        padding: 1.5rem;
    }
    
    .chart-container {
        padding: 1rem;
    }
    
    .data-info {
        flex-direction: column;
        gap: 0.75rem;
    }

    .macro-input {
        min-width: 180px;
        width: 100%;
    }

    .macro-compare-item {
        grid-template-columns: 1fr;
        gap: 0.4rem;
    }
}

@media (max-width: 480px) {
    .site-title {
        font-size: 1.2rem;
    }
    
    .card-title {
        font-size: 1rem;
    }
    
    .statistics-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-value {
        font-size: 1.3rem;
    }
    
    #chart {
        height: 300px;
    }
}
