/* ──────────────────────────────────────────────────────────
   學測申請入學校系查詢工具 — 樣式表
   ────────────────────────────────────────────────────────── */

/* ── 全域 ─────────────────────────────────────────────────── */
:root {
  --color-pass: #16a34a;
  --color-fail: #dc2626;
  --color-neutral: #78716c;
  --color-badge: #f97316;
  --color-card-hover: #fef9c3;
  --radius: 12px;

  /* Warm palette */
  --bg-base: #fffbf0;
  --bg-surface: #fff7ed;
  --bg-muted: #fef3c7;
  --border-warm: #fed7aa;
  --text-primary: #1c1917;
  --text-muted: #a8a29e;

  /* Pico CSS overrides */
  --pico-background-color: var(--bg-base);
  --pico-color: var(--text-primary);
  --pico-primary: #f97316;
  --pico-primary-hover: #ea580c;
  --pico-primary-focus: rgba(249,115,22,0.25);
  --pico-border-color: var(--border-warm);
  --pico-card-background-color: var(--bg-surface);
  --pico-form-element-background-color: #fff;
  --pico-form-element-border-color: var(--border-warm);
  --pico-form-element-focus-color: var(--color-badge);
}

body {
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  padding-bottom: 8rem;
}

h1, h2, h3, h4, h5, h6 {
  color: #1c1917 !important;
}

/* ── Pico CSS 強制覆蓋（表單元素） ──────────────────────────── */
input[type="number"],
input[type="text"],
input[type="email"],
select,
textarea {
  background-color: #fff !important;
  color: var(--text-primary) !important;
  border-color: var(--border-warm) !important;
  border-radius: 8px !important;
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
  border-color: var(--color-badge) !important;
  box-shadow: 0 0 0 3px rgba(249,115,22,0.2) !important;
}

input::placeholder {
  color: var(--text-muted) !important;
}

/* ── 主要按鈕（查詢） ─────────────────────────────────────── */
button[type="submit"],
#query-btn {
  background: var(--color-badge) !important;
  border-color: var(--color-badge) !important;
  color: #fff !important;
  border-radius: 10px !important;
}

button[type="submit"]:hover,
#query-btn:hover {
  background: #ea580c !important;
  border-color: #ea580c !important;
}

/* ── fieldset / legend ──────────────────────────────────── */
fieldset {
  border-color: var(--border-warm) !important;
  border-radius: var(--radius) !important;
}

legend {
  color: #92400e !important;
  font-weight: 600 !important;
  font-size: 0.9rem !important;
}

/* ── details / summary ──────────────────────────────────── */
details summary {
  cursor: pointer;
  color: var(--color-badge) !important;
}

/* ── outline 按鈕 ───────────────────────────────────────── */
button.outline, a.outline {
  border-color: var(--border-warm) !important;
  color: #92400e !important;
  background: transparent !important;
}

button.outline:hover {
  background: var(--bg-muted) !important;
  border-color: var(--color-badge) !important;
}

/* ── checkbox ───────────────────────────────────────────── */
input[type="checkbox"] {
  accent-color: var(--color-badge) !important;
}

.hidden { display: none !important; }

/* 觸控裝置不顯示 tooltip */
@media (hover: none) {
  #custom-tip { display: none !important; }
}

/* ── 自訂 Tooltip ──────────────────────────────────────────── */
#custom-tip {
  position: fixed;
  z-index: 9999;
  background: #1c1917;
  color: #fff;
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  pointer-events: none;
  max-width: 220px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  opacity: 0;
  transition: opacity 0.15s;
  white-space: normal;
}

/* ── 標頭 ─────────────────────────────────────────────────── */
header {
  padding: 1.25rem 1.5rem;
  background: linear-gradient(135deg, #fff7ed 0%, #fef3c7 100%);
  border-radius: var(--radius);
  border: 1px solid var(--border-warm);
  margin-bottom: 1.25rem;
}

header h1 {
  margin-bottom: 0.2rem;
  color: #c2410c !important;
}
header p {
  color: var(--color-neutral);
  margin-top: 0;
}

/* ── 錯誤橫幅 ────────────────────────────────────────────── */
.error-banner {
  background: #fff1f2;
  border: 1px solid #fecdd3;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.error-banner button {
  margin: 0;
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
  white-space: nowrap;
}

/* ── 成績輸入格線 ─────────────────────────────────────────── */
.score-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.score-field label {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  display: block;
}

.score-field input[type="number"],
.score-field select {
  width: 100%;
}

.field-error {
  color: var(--color-fail);
  font-size: 0.8rem;
  display: block;
  margin-top: 0.2rem;
}

/* ── APCS / 英聽區塊 ──────────────────────────────────────── */
#extra-scores-section {
  margin-top: 0.75rem;
  font-size: 0.875rem;
}

#extra-scores-section summary {
  cursor: pointer;
  color: var(--color-badge);
  font-weight: 500;
}

.extra-score-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  padding: 0.75rem 0 0.25rem;
}

/* ── 送出區 ───────────────────────────────────────────────── */
.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

/* ── 載入 spinner ────────────────────────────────────────── */
.spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 3px solid #fed7aa;
  border-top-color: var(--color-badge);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 篩選面板 ────────────────────────────────────────────── */
#filter-panel {
  margin: 1.5rem 0 0.5rem;
  padding: 1rem;
  background: var(--bg-surface);
  border-radius: var(--radius);
  border: 1px solid var(--border-warm);
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
}

.filter-row label {
  display: flex;
  flex-direction: column;
  font-size: 0.875rem;
  font-weight: 500;
  min-width: 150px;
}

.filter-row select {
  margin-top: 0.25rem;
}

/* ── 學門篩選 ────────────────────────────────────────────── */
.isced-filter-section {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  border-top: 1px solid var(--border-warm);
  padding-top: 0.75rem;
}

.isced-filter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.isced-filter-title {
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--color-badge);
}

.isced-filter-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.75rem 0 0.25rem;
}

.isced-loading {
  color: var(--text-muted);
  font-style: italic;
}

.isced-domain {
  min-width: 160px;
}

.isced-domain-header {
  margin-bottom: 0.3rem;
}

.isced-domain-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  cursor: pointer;
  color: #92400e;
}

.isced-fields {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding-left: 1.2rem;
}

.isced-field-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  color: #78716c;
}

.isced-actions {
  margin-top: 0.5rem;
}

.isced-btn {
  padding: 0.2rem 0.75rem;
  font-size: 0.8rem;
}

/* 學門標籤（卡片上） */
.field-tag {
  background: #fde68a;
  color: #92400e;
  border-radius: 6px;
  padding: 0 0.4rem;
  font-size: 0.72rem;
  white-space: nowrap;
}

/* 跨域方案標籤 */
.special-tag {
  background: #fee2e2;
  color: #b91c1c;
  border-radius: 6px;
  padding: 0 0.4rem;
  font-size: 0.72rem;
  white-space: nowrap;
}

/* 跨域特殊方案 toggle */
.specials-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
  font-size: 0.875rem;
  cursor: pointer;
}

.specials-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ── 顯示偏好 ────────────────────────────────────────────── */
.display-prefs {
  margin-top: 0.75rem;
  font-size: 0.875rem;
}

.display-prefs summary {
  cursor: pointer;
  color: var(--color-badge);
  font-weight: 500;
}

.prefs-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.5rem 0 0 0.5rem;
}

.prefs-options label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

/* ── 結果計數 ────────────────────────────────────────────── */
.results-count {
  margin: 0.75rem 0 0;
  font-weight: 600;
  color: var(--color-badge);
  font-size: 0.95rem;
}

/* ── 校系清單 ────────────────────────────────────────────── */
#results {
  display: flex;
  flex-direction: column;
  margin-top: 0.5rem;
  border: 1px solid var(--border-warm);
  border-radius: var(--radius);
  overflow: hidden;
}

.dept-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.875rem;
  border-bottom: 1px solid #fde68a;
  background: #fff;
  cursor: pointer;
  transition: background 0.15s;
  outline: none;
}

.dept-card:last-of-type {
  border-bottom: none;
}

.dept-card:hover,
.dept-card:focus {
  background: var(--color-card-hover);
}

/* 左欄：校名 + 系名 */
.card-title {
  display: flex;
  flex-direction: column;
  min-width: 10rem;
  flex-shrink: 0;
}

.school-name {
  font-weight: 700;
  font-size: 0.88rem;
  color: #1c1917;
  white-space: nowrap;
}

.dept-name {
  font-size: 0.82rem;
  color: #78716c;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 16rem;
}

/* 中欄：各標籤 */
.card-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  flex: 1;
  font-size: 0.78rem;
  color: #57534e;
}

.group-tag {
  background: #ffedd5;
  color: #c2410c;
  border-radius: 6px;
  padding: 0 0.4rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

.badge {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
  border-radius: 6px;
  padding: 0.1rem 0.35rem;
  font-size: 0.72rem;
  white-space: nowrap;
}

.exam-date-tag {
  font-size: 0.72rem;
  color: #7c3aed;
  background: #ede9fe;
  border: 1px solid #c4b5fd;
  border-radius: 6px;
  padding: 0.1rem 0.4rem;
  white-space: nowrap;
  font-weight: 600;
}

.gender-tag {
  background: #fce7f3;
  color: #9d174d;
  border-radius: 6px;
  padding: 0 0.4rem;
  font-size: 0.72rem;
  white-space: nowrap;
}

/* 右欄：機率 + 倍率 */
.card-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  flex-shrink: 0;
}

.comp-tag {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 20px;
  white-space: nowrap;
}
.comp-easy { background: #dcfce7; color: #15803d; }
.comp-mid  { background: #fef9c3; color: #92400e; }
.comp-hard { background: #fee2e2; color: #991b1b; }

/* 右欄：倍率 */
.multiplier-badge {
  background: var(--color-badge);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}

.prev-info {
  font-size: 0.75rem;
  color: var(--color-neutral);
}

/* ── 空結果 ──────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--color-neutral);
}

.empty-state p { margin: 0.25rem 0; }
.empty-state .hint { font-size: 0.875rem; }

/* ── 詳情面板 ────────────────────────────────────────────── */
#detail-panel {
  margin-top: 1rem;
}

#back-btn {
  margin-bottom: 1.5rem;
}

.detail-header h2 {
  margin-bottom: 0.1rem;
  color: #1c1917 !important;
}

.detail-dept-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.detail-dept-row h3 {
  margin: 0;
  color: #78716c;
  font-weight: 500;
}

.detail-header h3 {
  color: #78716c;
  font-weight: 500;
  margin-top: 0;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* ── 採計科目表格 ─────────────────────────────────────────── */
.subjects-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.subjects-table th {
  background: #fef3c7;
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 2px solid #fcd34d;
}

.subjects-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #fef9c3;
}

.pass { color: var(--color-pass); font-weight: 700; }
.fail { color: var(--color-fail); font-weight: 700; }
.na   { color: var(--text-muted); font-style: italic; }

.level-hint {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-left: 0.2rem;
}

.scoring-only td:first-child { color: #78716c; }

.section-label {
  margin: 1.2rem 0 0.4rem;
  font-size: 0.9rem;
  color: #c2410c;
}

.tiebreaker-section { background: #fff7ed; border-color: #fed7aa; }
.tiebreaker-section h4 { color: #c2410c; }
.tiebreaker-text {
  font-size: 0.85rem;
  color: var(--text-primary);
  margin: 0;
}

.stage2-section {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-top: 0.75rem;
  font-size: 0.875rem;
}

.stage2-section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: #15803d;
}

.stage2-section ul {
  margin: 0.3rem 0;
  padding-left: 1.2rem;
}

.stage2-section li { margin: 0.4rem 0; }

.item-name { font-weight: 600; color: var(--color-fail); }
.stage2-section .stage1-pct { font-weight: 600; color: var(--color-fail); margin: 0 0 0.4rem; }

.item-desc {
  margin-top: 0.25rem;
  font-size: 0.82rem;
  color: #166534;
  line-height: 1.6;
  padding-left: 0.5rem;
  border-left: 2px solid #bbf7d0;
}

.exam-desc {
  margin-top: 0.6rem;
  padding: 0.5rem 0.75rem;
  background: #f0fdf4;
  border-radius: 6px;
  font-size: 0.82rem;
  color: #1c1917;
  line-height: 1.6;
}

.exam-desc-label {
  display: block;
  font-weight: 600;
  font-size: 0.8rem;
  color: #15803d;
  margin-bottom: 0.25rem;
}

.date-info {
  margin: 0.2rem 0;
  color: #78716c;
}

.apcs-tag {
  display: inline-block;
  background: #ff6b35;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  margin-top: 0.35rem;
}

.apcs-section {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-top: 0.75rem;
  font-size: 0.875rem;
}

.apcs-section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: #ea580c;
}

.apcs-section ul {
  margin: 0;
  padding-left: 1.2rem;
}

.apcs-section li { margin: 0.15rem 0; }

/* ── 前一學年比較 ─────────────────────────────────────────── */
.prev-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-warm);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: #78716c;
}

.prev-section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--color-badge);
}

.prev-section p { margin: 0.2rem 0; }

.sieve-section { border-color: #c7d2fe; }
.sieve-section h4 { color: #4f46e5; }

.sieve-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin: 0.4rem 0 0.5rem;
}
.sieve-table th {
  background: #eef2ff;
  color: #4338ca;
  font-weight: 600;
  padding: 0.3rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid #c7d2fe;
}
.sieve-table td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  color: #374151;
}
.sieve-table tr:last-child td { border-bottom: none; }
.sieve-table td strong { color: #4f46e5; }
.sieve-user { font-weight: 600; text-align: center; }
.sieve-pass { color: #059669; }
.sieve-fail { color: #dc2626; }
.sieve-note {
  font-size: 0.75rem;
  color: #9ca3af;
  margin: 0;
}

/* ── 縣市 / 公私立標籤 ───────────────────────────────────── */
.city-tag {
  background: #fef3c7;
  color: #92400e;
  border-radius: 6px;
  padding: 0 0.4rem;
  font-size: 0.75rem;
}

.type-tag {
  border-radius: 6px;
  padding: 0 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.type-public {
  background: #dcfce7;
  color: #15803d;
}

.type-private {
  background: #ffedd5;
  color: #c2410c;
}

.dist-tag {
  font-size: 0.75rem;
  color: #78716c;
}

/* ── 地理定位狀態列 ──────────────────────────────────────── */
.geo-bar {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.825rem;
}

.geo-status {
  color: #78716c;
}

.geo-status.geo-error {
  color: var(--color-fail);
}

.geo-retry {
  padding: 0.15rem 0.6rem;
  font-size: 0.8rem;
}

/* ── 詳情：學校資訊區塊 ──────────────────────────────────── */
.school-info-block {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.825rem;
  color: #78716c;
  padding: 0.5rem 0.75rem;
  background: var(--bg-surface);
  border-radius: var(--radius);
  border: 1px solid var(--border-warm);
}

.school-address a,
.school-phone {
  color: #78716c;
  text-decoration: none;
}

.school-address a:hover {
  color: var(--color-badge);
  text-decoration: underline;
}

.school-dist {
  font-weight: 500;
  color: #15803d;
}

/* ── 詳情：學門標籤 ──────────────────────────────────────── */
.detail-isced {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin: 0.35rem 0 0.5rem;
}

.isced-domain-tag {
  background: #ffedd5;
  color: #c2410c;
  border-radius: 6px;
  padding: 0.1rem 0.5rem;
  font-size: 0.8rem;
}

.isced-field-tag-detail {
  background: #fef3c7;
  color: #92400e;
  border-radius: 6px;
  padding: 0.1rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
}

/* ── 詳情：通用資訊區塊 ──────────────────────────────────── */
.info-section {
  border: 1px solid var(--border-warm);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-top: 0.75rem;
  font-size: 0.875rem;
}

.info-section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
  color: #c2410c;
}

.info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.info-table td {
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid #fef9c3;
}

.info-table td:first-child {
  color: #78716c;
  white-space: nowrap;
  width: 7em;
}

.info-table tr:last-child td { border-bottom: none; }

.info-list {
  margin: 0;
  padding-left: 1.2rem;
}

.info-list li { margin: 0.15rem 0; }

.note-section { background: #fffbeb; border-color: #fcd34d; }
.note-section h4 { color: #b45309; }
.note-text { margin: 0; white-space: pre-wrap; line-height: 1.6; color: #78716c; }

/* ── 詳情：連結區 ─────────────────────────────────────────── */
.detail-links {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.cac-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--color-badge);
  color: #fff;
  border-radius: var(--radius);
  padding: 0.3rem 0.75rem;
  text-decoration: none;
  font-weight: 500;
  transition: opacity 0.15s;
}

.cac-link:hover { opacity: 0.85; }

.ref-link {
  color: var(--text-muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0;
}

.ref-link:hover {
  color: var(--color-badge);
  text-decoration: underline;
}

/* ── 顯示更多按鈕 ─────────────────────────────────────────── */
.show-more-wrap {
  grid-column: 1 / -1;
  text-align: center;
  padding: 0.75rem 0;
}
.show-more-btn {
  font-size: 0.875rem;
  padding: 0.4rem 1.5rem;
}

/* ── 我的最愛 ─────────────────────────────────────────────── */
.favorites-toggle-row {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.favorites-toggle-row .school-picker-trigger {
  max-width: 200px;
}

/* ── 申請清單 modal ─────────────────────────────────────── */
.applied-modal-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #fef9c3;
}

.applied-modal-row--empty {
  opacity: 0.45;
}

.applied-modal-row:last-child {
  border-bottom: none;
}

.applied-priority-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-badge);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.applied-priority-badge--empty {
  background: #e7e5e4;
  color: #a8a29e;
}

.applied-dept-name {
  flex: 1;
  font-size: 0.875rem;
}

.applied-empty-label {
  flex: 1;
  font-size: 0.875rem;
  color: #a8a29e;
}

.applied-remove-btn {
  background: none;
  border: none;
  color: #f87171;
  cursor: pointer;
  font-size: 0.8rem;
  min-height: unset;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: background 0.15s;
}

.applied-remove-btn:hover {
  background: #fee2e2;
}

.fav-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.1rem 0.25rem;
  color: #d4b8a0;
  border-radius: 4px;
  transition: color 0.15s, transform 0.1s;
  min-height: unset;
  flex-shrink: 0;
}

.fav-btn:hover { color: #e05a7a; transform: scale(1.2); }
.fav-btn.fav-active { color: #e05a7a; }

.dept-card--fav { background: #fff7ed; }
.dept-card--fav:hover,
.dept-card--fav:focus { background: #ffedd5; }

/* ── 申請順位 ─────────────────────────────────────────────── */
.apply-btn {
  background: #fff7ed;
  border: 1.5px solid var(--color-badge);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  width: 26px;
  height: 26px;
  min-height: unset;
  border-radius: 50%;
  color: var(--color-badge);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.apply-btn:hover {
  background: var(--color-badge);
  color: #fff;
  transform: scale(1.1);
}

.apply-btn.apply-active {
  background: var(--color-badge);
  border-color: var(--color-badge);
  color: #fff;
}

.apply-popover {
  position: fixed;
  background: #fff;
  border: 1px solid var(--border-warm);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  padding: 0.5rem;
  z-index: 200;
  min-width: 136px;
}

.apply-popover-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--color-badge);
  text-align: center;
  margin-bottom: 0.35rem;
}

.apply-popover-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
  margin-bottom: 0.4rem;
}

.apply-popover-cell {
  width: 36px;
  height: 36px;
  min-height: unset;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1.5px solid var(--border-warm);
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  transition: all 0.15s;
  padding: 0;
}

.apply-popover-cell:hover:not([disabled]) {
  background: var(--color-badge);
  border-color: var(--color-badge);
  color: #fff;
}

.apply-popover-cell--current {
  background: var(--color-badge);
  border-color: var(--color-badge);
  color: #fff;
}

.apply-popover-cell--disabled,
.apply-popover-cell[disabled] {
  background: #f5f5f4;
  color: #d4d4d0;
  cursor: not-allowed;
  border-color: #e7e5e4;
}

.apply-popover-remove {
  width: 100%;
  min-height: unset;
  padding: 0.3rem;
  font-size: 0.8rem;
  background: none;
  border: 1px solid #fecdd3;
  border-radius: 6px;
  color: #ef4444;
  cursor: pointer;
  transition: all 0.15s;
}

.apply-popover-remove:hover {
  background: #fee2e2;
}

/* ── 學門篩選觸發列 ───────────────────────────────────────── */
.isced-trigger-row {
  margin-top: 0.75rem;
  border-top: 1px solid var(--border-warm);
  padding-top: 0.75rem;
}

.isced-trigger-row .school-picker-trigger {
  max-width: 220px;
}

/* 學門 modal 寬一點以顯示領域/學門層級 */
.isced-picker-panel {
  width: min(640px, 95vw) !important;
}

.isced-picker-list {
  overflow-y: auto;
  padding: 0.75rem 1rem;
  flex: 1;
}

.isced-picker-list .isced-filter-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0;
}

/* ── 學校選擇器 modal ─────────────────────────────────────── */
.school-picker-trigger {
  width: 100%;
  text-align: left;
  background: var(--pico-background-color);
  border: 1px solid var(--pico-border-color);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
}
.school-picker-trigger:hover {
  border-color: var(--color-badge);
  background: var(--bg-muted);
}

.school-picker-trigger.active {
  background: var(--color-badge);
  border-color: var(--color-badge);
  color: #fff;
  font-weight: 600;
}

.school-picker-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}
.school-picker-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
}

.school-picker-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: var(--radius);
  width: min(480px, 92vw);
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(249,115,22,0.15);
  border: 1px solid var(--border-warm);
}
.school-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-warm);
  flex-shrink: 0;
}
.school-picker-title { font-weight: 700; font-size: 1rem; }
.school-picker-actions { display: flex; gap: 0.5rem; align-items: center; }
.school-picker-list {
  overflow-y: auto;
  padding: 0.5rem 0.25rem;
  flex: 1;
}
.school-picker-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}
.school-picker-item:hover { background: var(--color-card-hover); }
.picker-school-name { flex: 1; }
.picker-school-meta { font-size: 0.75rem; color: var(--text-muted); }
.picker-empty { color: var(--text-muted); text-align: center; padding: 1rem; }
.school-picker-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-warm);
  flex-shrink: 0;
  text-align: right;
}

/* ── 彈出式提示 modal ─────────────────────────────────────── */
.alert-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
}
.alert-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}
.alert-box {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  width: min(320px, 88vw);
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  text-align: center;
}
.alert-msg {
  margin: 0 0 1.25rem;
  font-size: 1rem;
  color: var(--color-fail);
  font-weight: 600;
}
.alert-ok {
  background: var(--color-badge);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: unset;
  width: 100%;
}
.alert-ok:hover { background: #ea580c; }

/* ── card-extra（桌面預設：子元素直接排在 flex 中）─────────── */
.card-extra { display: contents; }
.card-extra-toggle { display: none; }

/* ── 手機響應式（T030）────────────────────────────────────── */
@media (max-width: 768px) {
  .score-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .extra-score-grid {
    grid-template-columns: 1fr 1fr;
  }

  .filter-row {
    flex-direction: column;
  }

  .filter-row label {
    min-width: unset;
    width: 100%;
  }

  /* 手機：卡片字體加大 */
  .school-name { font-size: 1rem; }
  .dept-name   { font-size: 0.88rem; }

  /* 手機：卡片 grid 排版 */
  .dept-card {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    grid-template-rows: auto auto;
    gap: 0.3rem 0.5rem;
    align-items: start;
    padding: 0.6rem 0.75rem;
    min-height: unset;
  }

  .fav-btn {
    grid-column: 1;
    grid-row: 1;
    font-size: 1.5rem;
    margin-top: 0.05rem;
  }

  .card-title {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
  }

  .dept-name {
    white-space: normal;
    max-width: none;
  }

  .card-right {
    grid-column: 3;
    grid-row: 1;
    flex-direction: column;
    align-items: flex-end;
  }

  .card-info {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  /* 最小觸控目標 44px */
  button, input[type="submit"], select {
    min-height: 44px;
  }

  .apply-btn, .fav-btn {
    min-height: unset;
  }

  .apply-btn { width: 36px; height: 36px; font-size: 0.9rem; }

  /* 篩選條件收合（預設隱藏） */
  .card-extra {
    display: none;
    width: 100%;
  }
  .card-extra.open {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.15rem;
  }
  .card-extra-toggle {
    display: inline-flex;
    align-items: center;
    background: #fef9c3;
    border: 1px solid #fcd34d;
    border-radius: 20px;
    font-size: 0.7rem;
    color: #92400e;
    padding: 0.15rem 0.5rem;
    cursor: pointer;
    min-height: unset;
  }
}

@media (max-width: 480px) {
  .score-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .score-field label {
    font-size: 0.82rem;
  }

  header {
    padding: 0.75rem 1rem;
  }

  header h1 {
    font-size: 1.3rem !important;
  }

  header p {
    font-size: 0.82rem;
  }
}
