/* ═══════════════════════════════════════════
   app.css — index.html 專用樣式
   ═══════════════════════════════════════════ */

/* ── Score input grid ── */
.score-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

@media(max-width:600px) {
    .score-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.score-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.score-label {
    font-size: 14px;
    font-weight: 500;
    min-width: 50px;
}

@media(min-width:768px) {
    .score-label {
        font-size: 16px;
        min-width: 60px;
    }
}

.score-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
    color: var(--primary-dark);
}

.score-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.score-btn:hover svg {
    stroke: #fff;
}

.score-btn:active {
    transform: scale(0.9);
}

.score-btn svg {
    width: 16px;
    height: 16px;
    stroke: var(--primary-dark);
    stroke-width: 2.5;
    stroke-linecap: round;
    fill: none;
}

.score-val {
    width: 40px;
    text-align: center;
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    border: none;
    background: none;
    font-family: inherit;
    cursor: pointer;
    position: relative;
    user-select: none;
    border-radius: 6px;
    transition: background .15s;
}

.score-val:hover {
    background: var(--surface2);
}

.score-val.zero {
    color: #ccc;
}

@media(min-width:768px) {
    .score-val {
        font-size: 24px;
        width: 48px;
    }
}

/* Score slider popup */
.score-slider-wrap {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px 6px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .12);
    width: 180px;
    text-align: center;
}

.score-slider-wrap.show {
    display: block;
    animation: fadeSlideIn .15s ease;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.score-slider-wrap input[type=range] {
    width: 100%;
    accent-color: var(--primary);
    cursor: pointer;
    height: 6px;
}

.score-slider-val {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 2px;
}

/* ── Toggle buttons (英聽/APCS) ── */
.toggle-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.toggle-label {
    font-size: 14px;
    font-weight: 500;
    min-width: 80px;
}

@media(min-width:768px) {
    .toggle-label {
        font-size: 16px;
        min-width: 100px;
    }
}

.toggle-group {
    display: flex;
    gap: 4px;
}

.toggle-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text-dim);
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    transition: all .2s;
}

@media(min-width:768px) {
    .toggle-btn {
        padding: 8px 18px;
        font-size: 15px;
    }
}

.toggle-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ── Group chips ── */
.group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    margin-bottom: 20px;
}

@media(min-width:768px) {
    .group-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

.group-chip {
    padding: 10px;
    text-align: center;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all .2s;
    user-select: none;
    background: var(--bg);
}

@media(min-width:768px) {
    .group-chip {
        font-size: 14px;
        padding: 12px;
    }
}

.group-chip:hover {
    border-color: var(--primary);
}

.group-chip.selected {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    font-weight: 500;
}

.group-change-bar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

/* ── Keyword collapse panel ── */
.kw-collapse {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
    background: #fff;
}

.kw-collapse-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: linear-gradient(135deg, #667eea11, #764ba211);
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    font-size: 14px;
    transition: background .15s;
}

.kw-collapse-header:hover {
    background: linear-gradient(135deg, #667eea22, #764ba222);
}

.kw-arrow {
    transition: transform .2s;
    font-size: 12px;
}

.kw-collapse.collapsed .kw-arrow {
    transform: rotate(-90deg);
}

.kw-collapse-body {
    padding: 8px 12px 4px;
    max-height: 300px;
    overflow-y: auto;
    transition: max-height .3s ease, padding .3s ease;
}

.kw-collapse.collapsed .kw-collapse-body {
    max-height: 0;
    padding: 0 12px;
    overflow: hidden;
}

/* ── University panel ── */
.uni-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
    background: #fff;
}

.uni-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface);
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    font-size: 14px;
    transition: background .15s;
}

.uni-panel-header:hover {
    background: var(--surface2);
}

.uni-panel-header .arrow {
    transition: transform .2s;
    font-size: 12px;
}

.uni-panel.collapsed .uni-panel-header .arrow {
    transform: rotate(-90deg);
}

.uni-panel-body {
    padding: 12px 16px;
    max-height: 400px;
    overflow-y: auto;
    transition: max-height .3s ease, padding .3s ease;
}

.uni-panel.collapsed .uni-panel-body {
    max-height: 0;
    padding: 0 16px;
    overflow: hidden;
}

.uni-category {
    margin-bottom: 10px;
}

.uni-category-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-dark);
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.uni-category-title button {
    font-size: 11px;
    border: none;
    background: none;
    color: var(--primary);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}

.uni-category-title button:hover {
    background: var(--surface2);
}

.uni-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.uni-chip {
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 12px;
    cursor: pointer;
    background: var(--surface);
    color: var(--text-dim);
    transition: all .15s;
    white-space: nowrap;
}

.uni-chip.selected {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    font-weight: 500;
}

/* ── Results section ── */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 8px;
}

.combo-tag {
    display: inline-flex;
    align-items: center;
    background: #faf8f5;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 13px;
}

.combo-tag .score {
    font-weight: 700;
    color: var(--primary-dark);
    margin-left: 4px;
}

.free-hint {
    display: none;
    margin: 16px 0;
    padding: 16px;
    background: #fef9f0;
    border: 1px solid var(--primary-light);
    border-radius: 8px;
    text-align: center;
    font-size: 14px;
    color: var(--primary-dark);
}

.free-hint.show {
    display: block;
}

/* ── New dept collapsible section ── */
.new-dept-section {
    background: #e3f2fd;
    border: 1px solid #90caf9;
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
}

.new-dept-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    color: #1565c0;
    user-select: none;
}

.new-dept-header:hover {
    background: #bbdefb;
}

.collapse-arrow {
    transition: transform .2s;
    font-size: 12px;
}

.new-dept-section.collapsed .collapse-arrow {
    transform: rotate(-90deg);
}

.new-dept-section.collapsed .new-dept-list,
.new-dept-section.collapsed .new-dept-hint {
    display: none;
}

.new-dept-hint {
    padding: 0 16px 8px;
    font-size: 13px;
    color: #1976d2;
    opacity: 0.8;
}

.new-dept-list {
    padding: 0 12px 12px;
}

.new-dept-list .dept-card {
    border-color: #90caf9;
}

/* ── Department cards ── */
.dept-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    overflow: hidden;
    transition: all .2s;
}

.dept-card.expanded {
    box-shadow: 0 4px 16px rgba(0, 0, 0, .08);
}

.dept-main {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
}

.dept-hearts {
    font-size: 16px;
    min-width: 80px;
    cursor: pointer;
    white-space: nowrap;
}

.dept-info {
    flex: 1;
    cursor: pointer;
}

.dept-uni {
    font-size: 15px;
    color: var(--text-dim);
}

@media(min-width:768px) {
    .dept-uni {
        font-size: 17px;
    }
}

.dept-name {
    font-size: 15px;
    font-weight: 700;
}

@media(min-width:768px) {
    .dept-name {
        font-size: 17px;
    }
}

.dept-badges {
    display: flex;
    gap: 6px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
}

.badge-quota {
    background: #e8f4fd;
    color: var(--blue);
}

.badge-overage-HIGH {
    background: #fde8e5;
    color: var(--red);
}

.badge-overage-MEDIUM {
    background: #fef5e0;
    color: var(--yellow);
}

.badge-overage-LOW {
    background: #e8f5e8;
    color: var(--green);
}

.badge-overage-INFO {
    background: #e8f0f8;
    color: var(--blue);
}

.badge-keyword {
    background: linear-gradient(135deg, #667eea22, #764ba222);
    color: #5c4d9a;
    border: 1px solid #667eea44;
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all .2s;
}

.badge-keyword:hover {
    background: linear-gradient(135deg, #667eea44, #764ba244);
    transform: scale(1.05);
}

.badge-keyword.active {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border-color: transparent;
}

.dept-code {
    font-size: 11px;
    color: var(--primary);
    text-decoration: none;
    margin-right: 4px;
}

.dept-code:hover {
    text-decoration: underline;
}

.dept-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.action-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
}

.action-btn:hover {
    background: var(--surface2);
    border-color: var(--primary);
}

/* Premium text buttons (↑ 填這個, ↓ 移回) override fixed 32x32 */
#premiumConfirmed .action-btn,
#premiumWhitelist .action-btn {
    width: auto;
    height: auto;
    padding: 6px 12px;
    white-space: nowrap;
    flex-shrink: 0;
}

.action-btn.picked {
    background: var(--primary);
    border-color: var(--primary);
}

.dept-detail {
    display: none;
    padding: 0 16px 16px;
    border-top: 1px solid var(--border);
}

.dept-card.expanded .dept-detail {
    display: block;
}

.detail-subtitle {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-dim);
    margin: 12px 0 6px;
}

.round-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: fixed;
}

.round-table th {
    text-align: center;
    font-size: 12px;
    color: var(--text-dim);
    font-weight: 600;
    padding: 6px 4px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.round-table td {
    padding: 5px 4px;
    border-bottom: 1px solid #f0ece6;
    text-align: center;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Year heading between tables */
.year-heading {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin: 12px 0 4px;
    padding: 0;
}

/* Scrollable table wrapper */
.dept-detail .round-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Mobile: sticky first column */
@media (max-width: 767px) {

    .round-table th:first-child,
    .round-table td:first-child {
        position: sticky;
        left: 0;
        background: #fff;
        z-index: 1;
        box-shadow: 2px 0 4px rgba(0, 0, 0, .04);
    }

    .round-table tr:first-child th:first-child {
        z-index: 2;
    }

    .round-table {
        font-size: 12px;
    }

    .year-heading {
        font-size: 12px;
    }

    /* T2: Mobile RWD fixes */
    .dept-main {
        padding: 10px 12px;
        gap: 8px;
    }

    .dept-hearts {
        min-width: 50px;
        font-size: 14px;
    }

    .dept-uni {
        font-size: 13px;
    }

    .dept-name {
        font-size: 13px;
    }

    .action-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .dept-actions {
        gap: 4px;
    }

    .badge {
        font-size: 10px;
        padding: 1px 6px;
    }

    /* Premium buttons stack on small screens */
    .analyze-btn {
        font-size: 13px;
        padding: 8px 14px;
    }

    /* Round tables min-width for horizontal scroll */
    .round-table {
        min-width: 480px;
    }
}

/* Desktop: larger fonts */
@media (min-width: 768px) {
    .round-table {
        font-size: 14px;
    }

    .round-table th {
        font-size: 13px;
        padding: 7px 6px;
    }

    .round-table td {
        font-size: 14px;
        padding: 7px 6px;
    }

    .year-heading {
        font-size: 14px;
    }
}

/* Teacher view: extra large for readability */
.teacher-view .round-table {
    font-size: 15px;
}

.teacher-view .round-table th {
    font-size: 13px;
}

.teacher-view .round-table td {
    font-size: 14px;
    padding: 8px 10px;
}

.teacher-view .year-heading {
    font-size: 15px;
}

.result-HIGH {
    color: var(--green);
    font-weight: 700;
}

.result-MEDIUM {
    color: var(--yellow);
    font-weight: 700;
}

.result-LOW {
    color: var(--red);
    font-weight: 700;
}

.overage-note {
    margin-top: 10px;
    padding: 8px 12px;
    background: #fef9f0;
    border: 1px solid #f0e0c0;
    border-radius: 6px;
    font-size: 13px;
    color: var(--primary-dark);
}

/* ── Department search bar ── */
.dept-search-bar {
    display: none;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.dept-search-bar.show {
    display: flex;
}

.dept-search-bar label {
    font-size: 13px;
    color: var(--text-dim);
    white-space: nowrap;
}

.dept-search-bar input {
    flex: 1;
    min-width: 100px;
    max-width: 160px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

.dept-search-bar input:focus {
    outline: none;
    border-color: var(--primary);
}

.dept-search-bar button {
    padding: 6px 12px;
    border: 1px solid var(--primary);
    border-radius: 6px;
    background: none;
    color: var(--primary);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
}

.dept-search-bar button:hover {
    background: var(--primary);
    color: #fff;
}

@keyframes highlightNew {
    0% {
        background: #fff3cd;
    }

    100% {
        background: #fff;
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-6px);
    }

    40% {
        transform: translateX(6px);
    }

    60% {
        transform: translateX(-4px);
    }

    80% {
        transform: translateX(4px);
    }
}

/* ── Volunteer panel ── */
.vol-panel {
    position: fixed;
    right: 20px;
    top: 80px;
    width: 260px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 20px rgba(0, 0, 0, .12);
    z-index: 90;
    display: none;
    max-height: 70vh;
    overflow-y: auto;
}

.vol-panel.show {
    display: block;
}

.vol-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
}

.vol-list {
    padding: 8px;
}

.vol-item {
    padding: 6px 10px;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f0ece6;
}

.vol-item .vol-remove {
    cursor: pointer;
    color: var(--red);
    font-size: 14px;
}

.vol-toggle {
    position: fixed;
    right: 20px;
    bottom: 20px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
    z-index: 80;
    display: none;
}

.vol-toggle.show {
    display: block;
}

/* ── 我的決定 button ── */
.btn-decision {
    padding: 6px 14px;
    border: 2px solid var(--primary);
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: all .2s;
    display: none;
}

.btn-decision:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(176, 141, 87, .3);
}

.btn-decision.show {
    display: inline-block;
}

/* ── 我的志願 button ── */
.btn-wishlist {
    padding: 4px 12px;
    border: 1px solid var(--primary-light);
    border-radius: 6px;
    background: #faf8f5;
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all .2s;
    display: none;
}

.btn-wishlist:hover {
    background: var(--surface2);
}

.btn-wishlist.show {
    display: inline-block;
}

/* ── Premium checkbox ── */
.premium-chk {
    accent-color: var(--primary);
}

/* ── Entry bottom CTA ── */
.entry-bottom-cta {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    margin-top: 24px;
}

/* ── V7: Expand search button ── */
.expand-btn {
    display: inline-block;
    padding: 14px 32px;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.expand-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.expand-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.expand-btn.expand-up {
    background: linear-gradient(135deg, #ef4444, #f97316);
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.3);
}

.expand-btn.expand-up:hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.expand-btn.expand-down {
    background: linear-gradient(135deg, #22c55e, #06b6d4);
    box-shadow: 0 4px 14px rgba(34, 197, 94, 0.3);
}

.expand-btn.expand-down:hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.4);
}

/* ── V7: Expand marker (divider between batches) ── */
.expand-marker {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 24px 0 16px;
    color: var(--primary);
    font-size: 14px;
    font-weight: 600;
}

.expand-marker::before,
.expand-marker::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
}

/* ── V7: FadeSlideIn animation ── */
@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}