/* セグメント×カテゴリダッシュボードのスタイル */

.dashboard-container {
    padding: 20px;
    background-color: #f5f5f5;
    min-height: 100vh;
}

.dashboard-title {
    font-size: 24px;
    font-weight: bold;
    color: #333;
    margin-bottom: 20px;
}

.control-panel {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.control-label {
    font-size: 14px;
    font-weight: 600;
    color: #555;
    margin-bottom: 5px;
    display: block;
}

.control-dropdown {
    width: 100%;
}

.radio-items {
    margin-top: 5px;
}

.radio-items label {
    margin-right: 15px;
    cursor: pointer;
}

.update-button {
    width: 100%;
    margin-top: 20px;
}

/* 比較テーブルコンテナ */
.comparison-tables-container {
    width: 100%;
    padding: 20px;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.section-title {
    font-size: 22px;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 3px solid #3498db;
}

.table-title {
    font-size: 20px;
    font-weight: bold;
    color: #333;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e9ecef;
}

.table-subtitle {
    font-size: 18px;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 15px;
    padding: 10px;
    background-color: #f8f9fa;
    border-left: 4px solid #3498db;
}

.no-data-message {
    text-align: center;
    font-size: 16px;
    color: #666;
    padding: 40px;
}

.error-message {
    text-align: center;
    font-size: 16px;
    color: #dc3545;
    padding: 40px;
}

/* HTMLテーブルのカスタマイズ */
.table-container {
    width: 100%;
    overflow-x: auto;
    margin-bottom: 30px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.segment-table {
    width: 100%;
    border-collapse: collapse;
    background-color: white;
    font-size: 14px;
    table-layout: fixed; /* 固定レイアウトで列幅を統一 */
}

.segment-table th,
.segment-table td {
    border: 1px solid #e9ecef;
    padding: 10px;
}

.segment-table th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #34495e;
    color: white;
    font-weight: bold;
    text-align: center;
}

.segment-table th:first-child {
    text-align: left;
    width: 120px; /* 固定幅でセグメント列 */
    min-width: 120px;
}

.segment-table th:not(:first-child) {
    width: auto; /* カテゴリ列は残りスペースを均等分割 */
    min-width: 100px;
    text-align: center;
}

.segment-table td {
    text-align: right;
}

.segment-table td:first-child {
    text-align: left;
    font-weight: bold;
    background-color: #f8f9fa;
    position: sticky;
    left: 0;
    z-index: 5;
    width: 120px; /* セグメント列の固定幅 */
}

.segment-table td:not(:first-child) {
    text-align: right;
    min-width: 100px;
    word-break: keep-all; /* 数値の改行を防ぐ */
}

/* 行のホバー効果 */
.segment-table tbody tr:hover {
    background-color: #e3f2fd !important;
    transition: background-color 0.2s;
}

/* 偶数行の背景色 */
.segment-table tbody tr:nth-child(even) {
    background-color: #fafafa;
}

/* 第二階層用の横スクロール対応 */
.table-container.second-level {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
    margin-bottom: 30px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
}

.table-container.second-level .segment-table {
    min-width: max-content; /* コンテンツに応じて幅を決定 */
    width: max-content;
    table-layout: fixed; /* 固定レイアウトで列幅制御 */
    margin: 0;
}

.table-container.second-level .segment-table th:not(:first-child):not(:last-child),
.table-container.second-level .segment-table td:not(:first-child):not(:last-child) {
    min-width: 100px; /* 最低100pxを確保 */
    width: 100px;
    max-width: 140px;
    white-space: nowrap;
    padding: 8px 6px;
    font-size: 12px;
    text-overflow: ellipsis;
    overflow: hidden;
}

.table-container.second-level .segment-table th:first-child,
.table-container.second-level .segment-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 10;
    background-color: #f8f9fa !important;
    box-shadow: 2px 0 4px rgba(0,0,0,0.1);
    min-width: 100px;
    width: 100px;
    max-width: 100px;
    font-weight: bold;
}

/* 第二階層の合計列も固定 */
.table-container.second-level .segment-table th:last-child,
.table-container.second-level .segment-table td:last-child {
    position: sticky;
    right: 0;
    z-index: 9;
    background-color: #f0f0f0 !important;
    box-shadow: -2px 0 4px rgba(0,0,0,0.1);
    min-width: 80px;
    width: 80px;
    max-width: 80px;
    border-left: 2px solid #495057 !important;
}

/* テーブルのレスポンシブ対応 */
@media (max-width: 1200px) {
    .table-container:not(.second-level) {
        overflow-x: scroll;
        -webkit-overflow-scrolling: touch;
    }
    
    .segment-table:not(.second-level) {
        min-width: 1000px; /* 第一階層の最小幅 */
    }
}

/* 全てのテーブルコンテナの幅を統一 */
.comparison-tables-container .table-container {
    width: 100%;
    max-width: 100%;
}

.comparison-tables-container .segment-table {
    width: 100%;
    min-width: 100%;
}

/* 統一幅クラス */
.unified-width {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
}

.unified-width .segment-table {
    width: 100% !important;
    table-layout: fixed !important;
}

/* セクション内のテーブル幅統一 */
.comparison-tables-container > div {
    width: 100%;
}

.comparison-tables-container .table-container {
    width: 100% !important;
    margin-bottom: 30px;
}

/* 数値の右寄せを維持 */
.segment-table td[style*="textAlign: right"] {
    white-space: nowrap;
    font-family: 'Courier New', monospace;
}

/* カテゴリ数に関係なく列幅を統一 */
.segment-table th:not(:first-child),
.segment-table td:not(:first-child) {
    width: calc((100% - 120px) / var(--category-count, 5)); /* 最大5カテゴリ想定 */
    min-width: 80px;
    max-width: 150px;
}

/* テーブル全体の最小幅を確保 */
.segment-table {
    min-width: 600px; /* セグメント列120px + カテゴリ列80px×5 = 最小520px + マージン */
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .dashboard-container {
        padding: 10px;
    }
    
    .dashboard-title {
        font-size: 20px;
    }
    
    .section-title {
        font-size: 18px;
    }
    
    .table-subtitle {
        font-size: 16px;
    }
    
    .comparison-tables-container {
        padding: 10px;
    }
}