/* ============================================
   ANALYSIS SECTION - Button Grids & Collapsible
   ============================================ */

/* Collapsible Section Container */
.collapsible-section {
    margin-bottom: 24px;
    background: transparent;
    overflow: visible;
}

.collapsible-header {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--color-primary-lighter, #f0fdf4) 0%, #d1fae5 100%);
    border: 1px solid var(--color-primary, #1A8B58);
    border-radius: var(--radius-md, 8px);
    margin-bottom: 12px;
    cursor: default;
    user-select: none;
}

.collapsible-title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-primary, #1A8B58);
    letter-spacing: 0.15em;
}

.collapsible-actions {
    position: absolute;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-select-all {
    padding: 6px 14px;
    background: #fff;
    border: 1px solid var(--color-primary);
    border-radius: 4px;
    color: var(--color-primary);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-select-all:hover {
    background: var(--color-primary-lighter);
}

.btn-select-all.all-selected {
    background: var(--color-primary);
    color: #fff;
}

.btn-toggle-collapse {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    color: #fff;
}

.btn-toggle-collapse:hover {
    background: var(--color-primary-dark);
}

.btn-toggle-collapse svg {
    width: 18px;
    height: 18px;
    transition: transform 0.3s ease;
}

.collapsible-section.collapsed .btn-toggle-collapse svg {
    transform: rotate(180deg);
}

.collapsible-body {
    padding: 16px 20px;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
    overflow: hidden;
}

.collapsible-section.collapsed .collapsible-body {
    max-height: 0 !important;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
}

/* Button Grid */
.btn-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
}

.btn-grid-item {
    padding: 10px 24px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-md, 6px);
    color: var(--text-primary, #374151);
    font-size: 0.9rem;
    font-weight: normal;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    white-space: nowrap;
}

.btn-grid-item:hover {
    border-color: var(--color-primary, #1A8B58);
    background: var(--color-primary-lighter, #f0fdf4);
    color: var(--text-primary, #374151);
}

.btn-grid-item.selected {
    background: var(--color-primary, #1A8B58);
    border-color: var(--color-primary, #1A8B58);
    color: #fff;
    font-weight: normal;
    box-shadow: none;
}

.btn-grid-item.disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* AB Color Grid Items (Subject Combinations) */
.btn-grid-item.combo-ab-item {
    background: #e2e8f0;
    border-color: #cbd5e1;
    color: #475569;
}

.btn-grid-item.combo-ab-item:hover {
    background: #cbd5e1;
    border-color: #94a3b8;
}

.btn-grid-item.combo-ab-item.selected {
    background: #e56555;
    border-color: #e56555;
    color: #fff;
}

/* Warning Badge */
.analysis-warning {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 6px;
    color: #92400e;
    font-size: 0.85rem;
    font-weight: 600;
    margin-left: 12px;
    animation: fadeIn 0.3s ease;
}

.analysis-warning::before {
    content: '⚠';
    font-size: 1rem;
}

/* Fixed Class Label (Teacher View) */
.fixed-class-label {
    display: inline-block;
    padding: 10px 28px;
    background: #f0fdf4;
    border: 2px solid var(--color-primary);
    border-radius: 8px;
    color: var(--color-primary-dark);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
}

/* ============================================
   ANALYSIS - Student Table
   (Unified with .data-table from main.css)
   ============================================ */

.analysis-table-container {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    margin-top: 16px;
    margin-bottom: 16px;
}

.analysis-student-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.analysis-student-table th,
.analysis-student-table td {
    padding: 12px 10px;
    text-align: center;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
    position: relative;
}

/* Pseudo-element vertical separators */
.analysis-student-table th:not(:last-child)::after,
.analysis-student-table td:not(:last-child)::after {
    content: "";
    position: absolute;
    right: 0;
    top: 20%;
    height: 60%;
    width: 1px;
    background-color: rgba(0, 0, 0, 0.12);
}

.analysis-student-table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    font-weight: 700;
    font-size: 1rem;
    color: #1e293b;
    padding: 14px 12px;
    text-align: center;
    vertical-align: middle;
}

.analysis-student-table tbody td {
    font-size: 0.88rem;
    color: #374151;
}

/* Zebra Striping */
.analysis-student-table tbody tr:nth-child(even) {
    background-color: #f8fafc;
}

/* Hover - Light Yellow */
.analysis-student-table tbody tr:hover {
    background-color: #FFFDE7 !important;
}

.analysis-student-table tbody tr:hover td {
    background-color: #FFFDE7 !important;
}

/* Subject Count Buttons (AB Color) in Student Table */
.subject-count-btns {
    display: inline-flex;
    gap: 4px;
}

.subject-count-btn {
    padding: 4px 10px;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.15s ease;
}

.subject-count-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.subject-count-btn.selected {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
    font-weight: 600;
}

/* Select-all count buttons (全選二科/三科/四科/五科) */
.subject-count-select-all-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
    justify-content: center;
}

.btn-count-select-all {
    padding: 3px 10px;
    font-size: 0.78rem;
    font-weight: 500;
    border: 1px solid #94a3b8;
    border-radius: 4px;
    background: #f1f5f9;
    color: #475569;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-count-select-all:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: #fff;
}

.btn-count-select-all.selected {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
    font-weight: 600;
}

/* Select Button (for Placement Analysis) */
.btn-select-student {
    padding: 5px 14px;
    background: #fff;
    border: 1px solid var(--color-primary);
    border-radius: 4px;
    color: var(--color-primary);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-select-student:hover {
    background: var(--color-primary);
    color: #fff;
}

.btn-select-student.selected {
    background: var(--color-primary);
    color: #fff;
}

/* ============================================
   ANALYSIS - Score Panel (Student View)
   ============================================ */

.score-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.score-card {
    flex: 1;
    min-width: 100px;
    background: #f0fdf4;
    border: 1px solid #a7f3d0;
    border-radius: 8px;
    padding: 12px 16px;
    text-align: center;
}

.score-card-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-primary-dark);
    margin-bottom: 6px;
}

.score-card-value {
    font-size: 1.15rem;
    font-weight: 700;
    color: #1e293b;
    font-family: 'Courier New', monospace;
}

/* ============================================
   ANALYSIS - Star Rating
   ============================================ */

.star-rating {
    display: inline-flex;
    gap: 2px;
    font-size: 1.1rem;
}

.star-filled {
    color: #f59e0b;
    text-shadow: 0 1px 2px rgba(245, 158, 11, 0.3);
}

.star-empty {
    color: #d1d5db;
}

/* Star Legend (Student Result Page) */
.star-legend {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px 24px;
    margin-bottom: 24px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(3, auto);
    grid-auto-flow: column;
    column-gap: 32px;
    row-gap: 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.star-legend-item {
    display: grid;
    grid-template-columns: 110px 1fr;
    align-items: center;
    gap: 12px;
}

.legend-stars {
    text-align: right;
}

.legend-text {
    font-size: 0.95rem;
    font-weight: 600;
    color: #1e293b;
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.star-desc {
    font-weight: 400;
    font-size: 0.85rem;
    color: #64748b;
    margin-left: 8px;
    white-space: normal;
    /* Allow description to wrap if container is too small */
}

/* Star rating colors by level */
.star-level-1 .star-filled {
    color: #ef4444;
}

.star-level-2 .star-filled {
    color: #f97316;
}

.star-level-3 .star-filled {
    color: #eab308;
}

.star-level-4 .star-filled {
    color: #22c55e;
}

.star-level-5 .star-filled {
    color: #f59e0b;
    text-shadow: 0 0 4px rgba(245, 158, 11, 0.4);
}

/* ============================================
   ANALYSIS - Result Tables
   (Unified with .data-table from main.css)
   ============================================ */

.analysis-result-wrapper {
    animation: fadeIn 0.4s ease-out;
}

.analysis-result-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--color-primary-light);
}

.analysis-result-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.analysis-result-table th,
.analysis-result-table td {
    padding: 12px 10px;
    text-align: center;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
    position: relative;
}

/* Pseudo-element vertical separators */
.analysis-result-table th:not(:last-child)::after,
.analysis-result-table td:not(:last-child)::after {
    content: "";
    position: absolute;
    right: 0;
    top: 20%;
    height: 60%;
    width: 1px;
    background-color: rgba(0, 0, 0, 0.12);
}

.analysis-result-table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    font-weight: 700;
    font-size: 1rem;
    color: #1e293b;
    padding: 14px 12px;
}

.analysis-result-table tbody td {
    font-size: 0.88rem;
    color: #374151;
}

/* Zebra Striping */
.analysis-result-table tbody tr:nth-child(even) {
    background-color: #f8fafc;
}

/* Hover - Light Yellow */
.analysis-result-table tbody tr:hover {
    background-color: #FFFDE7 !important;
}

.analysis-result-table tbody tr:hover td {
    background-color: #FFFDE7 !important;
}

/* Combo text (left-aligned) */
.analysis-result-table td.col-combo {
    text-align: left;
    font-weight: 500;
}

/* ============================================
   ANALYSIS - Result Twin-Table Styling
   (Unified with .data-table from main.css)
   ============================================ */

/* Subject Colors: reuse the same .col-chi, .col-eng etc.
   classes from main.css for consistency.
   The old .col-chinese / .col-english classes are kept
   as aliases in case analysis.js still references them. */

/* 國文 (Blue) - alias */
.combo-detail-table th.col-chinese {
    background-color: #3b82f6 !important;
    color: white !important;
}

.combo-detail-table td.col-chinese {
    background-color: #eff6ff !important;
    color: #1e3a8a !important;
    font-weight: 500;
}

/* 英文 (Orange) - alias */
.combo-detail-table th.col-english {
    background-color: #f97316 !important;
    color: white !important;
}

.combo-detail-table td.col-english {
    background-color: #fff7ed !important;
    color: #7c2d12 !important;
    font-weight: 500;
}

/* 數學 (Red) - alias */
.combo-detail-table th.col-math {
    background-color: #ef4444 !important;
    color: white !important;
}

.combo-detail-table td.col-math {
    background-color: #fef2f2 !important;
    color: #7f1d1d !important;
    font-weight: 500;
}

/* 專一 (Green) - alias */
.combo-detail-table th.col-pro1 {
    background-color: #22c55e !important;
    color: white !important;
}

.combo-detail-table td.col-pro1 {
    background-color: #f0fdf4 !important;
    color: #14532d !important;
    font-weight: 500;
}

/* 專二 (Purple) - alias */
.combo-detail-table th.col-pro2 {
    background-color: #6366f1 !important;
    color: white !important;
}

.combo-detail-table td.col-pro2 {
    background-color: #eef2ff !important;
    color: #312e81 !important;
    font-weight: 500;
}

/* Summary Table (Top) — Unified */
.combo-summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.combo-summary-table th,
.combo-summary-table td {
    padding: 12px 10px;
    text-align: center;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
    position: relative;
}

/* Pseudo-element vertical separators */
.combo-summary-table th:not(:last-child)::after,
.combo-summary-table td:not(:last-child)::after {
    content: "";
    position: absolute;
    right: 0;
    top: 20%;
    height: 60%;
    width: 1px;
    background-color: rgba(0, 0, 0, 0.12);
}

.combo-summary-table th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    font-weight: 700;
    font-size: 1rem;
    color: #1e293b;
    padding: 14px 12px;
}

.combo-summary-table td {
    font-size: 0.88rem;
    color: #374151;
}

.combo-summary-table tbody tr:nth-child(even) {
    background-color: #f8fafc;
}

.combo-summary-table tbody tr:hover {
    background-color: #FFFDE7 !important;
}

.combo-summary-table tbody tr:hover td {
    background-color: #FFFDE7 !important;
}

/* Detailed Table Container (Horizontal Scroll) */
.table-scroll-container {
    width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 65vh;
    margin-bottom: 20px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* Detailed Table (Bottom) — Unified */
.combo-detail-table {
    width: 100%;
    min-width: 1400px;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.combo-detail-table th,
.combo-detail-table td {
    padding: 12px 10px;
    text-align: center;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
    position: relative;
}

/* Pseudo-element vertical separators */
.combo-detail-table th:not(:last-child)::after,
.combo-detail-table td:not(:last-child)::after {
    content: "";
    position: absolute;
    right: 0;
    top: 20%;
    height: 60%;
    width: 1px;
    background-color: rgba(0, 0, 0, 0.12);
}

.combo-detail-table th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    font-weight: 700;
    font-size: 1rem;
    color: #1e293b;
    line-height: 1.3;
    padding: 14px 12px;
}

.combo-detail-table td {
    font-size: 0.85rem;
    color: #374151;
}

/* Zebra Striping */
.combo-detail-table tbody tr:nth-child(even) {
    background-color: #f8fafc;
}

/* Hover - Light Yellow */
.combo-detail-table tbody tr:hover {
    background-color: #FFFDE7 !important;
}

.combo-detail-table tbody tr:hover td {
    background-color: #FFFDE7 !important;
}

/* Action buttons at bottom */
.analysis-result-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 24px;
}

.btn-refilter {
    padding: 10px 28px;
    background: #fff;
    border: 2px solid var(--color-primary);
    border-radius: 6px;
    color: var(--color-primary);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-refilter:hover {
    background: var(--color-primary);
    color: #fff;
}

.btn-next-step {
    padding: 10px 28px;
    background: var(--color-primary);
    border: 2px solid var(--color-primary);
    border-radius: 6px;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-next-step:hover {
    background: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
    box-shadow: 0 4px 12px rgba(26, 139, 88, 0.3);
}

/* Step Separator (blue dotted line) */
.step-separator {
    border: none;
    border-top: 2px dashed #93c5fd;
    margin: 24px 0;
}

/* Tab disabled state */
.score-action-btn.tab-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    position: relative;
}

.score-action-btn.tab-disabled:hover::after {
    content: '即將推出';
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    pointer-events: none;
}

/* Schools section sub-headers */
.school-subheader {
    display: flex;
    justify-content: center;
    margin: 12px 0 8px;
}

.btn-school-select-all {
    padding: 6px 20px;
    background: var(--color-primary-lighter);
    border: 1px solid var(--color-primary);
    border-radius: 4px;
    color: var(--color-primary-dark);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-school-select-all:hover {
    background: var(--color-primary);
    color: #fff;
}

.btn-school-select-all.all-selected {
    background: var(--color-primary);
    color: #fff;
}

/* Responsive */
@media (max-width: 768px) {
    .btn-grid {
        gap: 6px;
    }

    .btn-grid-item {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .score-panel {
        gap: 6px;
    }

    .score-card {
        min-width: 80px;
        padding: 8px 10px;
    }

    /* 星等圖例 - 手機端單欄 */
    .star-legend {
        grid-template-columns: 1fr;
        padding: 14px 16px;
    }

    .star-legend-item {
        grid-template-columns: 90px 1fr;
        gap: 8px;
    }

    .legend-text {
        font-size: 0.85rem;
    }

    .star-desc {
        font-size: 0.78rem;
    }

    /* 分析表格容器 - 橫向滾動 + 滑動提示 */
    .analysis-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        overflow-y: visible;
        position: relative;
    }

    .analysis-table-container::after {
        content: "← 左右滑動查看更多 →";
        display: block;
        text-align: center;
        color: #94a3b8;
        font-size: 0.72rem;
        padding: 6px;
        background: #f8fafc;
    }

    /* 分析結果表格 - 縮小 */
    .analysis-result-table {
        font-size: 0.78rem;
    }

    .analysis-result-table thead th,
    .analysis-result-table tbody td {
        padding: 6px 8px;
    }

    /* 分析學生表格 - 縮小 */
    .analysis-student-table th,
    .analysis-student-table td {
        padding: 8px 6px;
        font-size: 0.78rem;
    }

    /* 組合摘要表格 - 縮小 */
    .combo-summary-table th,
    .combo-summary-table td {
        padding: 8px 6px;
        font-size: 0.78rem;
    }

    /* 組合明細表格容器 */
    .table-scroll-container {
        max-height: none;
        -webkit-overflow-scrolling: touch;
    }

    .combo-detail-table th,
    .combo-detail-table td {
        padding: 8px 6px;
        font-size: 0.75rem;
    }

    /* 操作按鈕 - 全寬 */
    .analysis-result-actions {
        flex-direction: column;
        gap: 10px;
    }

    .btn-refilter,
    .btn-next-step {
        width: 100%;
        text-align: center;
        justify-content: center;
    }

    /* 可摺疊區塊 */
    .collapsible-header {
        padding: 10px 12px;
    }

    .collapsible-title {
        font-size: 0.88rem;
        letter-spacing: 0.1em;
    }

    .collapsible-body {
        padding: 12px;
    }
}