:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface2: #f1f5f9;
    --border: rgba(0, 0, 0, 0.08);
    --accent: #4f46e5;      /* 飽和的科技藍靛色，白底下對比度佳 */
    --accent2: #6366f1;
    --green: #10b981;
    --text: #1e293b;        /* 深色文字確保易讀性 */
    --muted: #64748b;
    --card-glow: 0 4px 20px rgba(0, 0, 0, 0.02);
  }

  * { margin: 0; padding: 0; box-sizing: border-box; }

  body {
    font-family: 'Noto Sans TC', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
  }

  /* 背景格線 */
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
      linear-gradient(rgba(108,99,255,0.03) 1px, transparent 1px),
      linear-gradient(90deg, rgba(108,99,255,0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
  }

  /* 主版面 */
  main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 48px 32px;
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 32px;
  }

  /* 區塊標題 */
.section-label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

  .section-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
  }

  /* 卡片 */
  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--card-glow);
    transition: border-color 0.3s;
  }

  .card:hover { border-color: rgba(108,99,255,0.2); }

  /* 大樓按鈕列表 */
  .building-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
  }

  .building-btn {
    padding: 12px 14px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 13px;
    font-family: 'Noto Sans TC', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .building-btn::before {
    content: '🏢';
    font-size: 14px;
    flex-shrink: 0;
  }

  .building-btn:hover {
    background: rgba(108,99,255,0.12);
    border-color: rgba(108,99,255,0.4);
    color: var(--accent2);
    transform: translateY(-1px);
  }

  .building-btn.active {
    background: rgba(108,99,255,0.15);
    border-color: var(--accent);
    color: var(--accent2);
  }

  .building-btn.building-status-close,
  .building-btn:disabled {
    cursor: not-allowed;
    opacity: 0.58;
    color: var(--muted);
    background: #f8fafc;
    transform: none;
  }

  .building-btn.building-status-close:hover,
  .building-btn:disabled:hover {
    border-color: var(--border);
    color: var(--muted);
    background: #f8fafc;
    transform: none;
  }

  /* 校園地圖區塊 */
  .map-card {
    margin-top: 24px;
  }

  /* 校園地圖開合：仿 classroom_teachbuild_search 的 media-toggle 樣式 */
  .map-toggle {
    width: 100%;
    border: 1px solid #dbe3ef;
    background: #f8fafc;
    color: var(--text);
    border-radius: 8px;
    padding: 0.75rem 0.9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    font-family: 'Noto Sans TC', sans-serif;
    transition: background 0.2s, border-color 0.2s;
  }

  .map-toggle:hover {
    background: #eff6ff;
    border-color: #bfdbfe;
  }

  .map-toggle span {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
  }

  .map-toggle .fa-chevron-down {
    transition: transform 0.2s;
  }

  .map-card.expanded .map-toggle .fa-chevron-down {
    transform: rotate(180deg);
  }

  .map-body {
    display: none;
    margin-top: 0.85rem;
  }

  .map-card.expanded .map-body {
    display: block;
  }

  /* 教室代碼查詢 */
  .search-card {
    margin-bottom: 24px;
    /* 每張 .card 因 fadeUp 動畫殘留 transform 而各自成為堆疊環境，
       下拉選單(z-index:200)只在本卡內有效，會被下一張卡片蓋住；
       將整張搜尋卡提高層級，下拉才能蓋在後面的卡片之上。 */
    position: relative;
    z-index: 20;
  }

  .search-row {
    display: flex;
    gap: 10px;
  }

  .search-input {
    flex: 1;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
    color: var(--text);
    font-size: 14px;
    font-family: 'DM Mono', monospace;
    outline: none;
    transition: all 0.2s;
  }

  .search-input::placeholder { color: var(--muted); }

  .search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108,99,255,0.15);
  }

  .search-btn {
    padding: 12px 24px;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    font-family: 'Noto Sans TC', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
  }

  .search-btn:hover {
    background: var(--accent2);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(108,99,255,0.4);
  }

  /* 右側欄 */
  .sidebar { display: flex; flex-direction: column; gap: 20px; }

  .quick-links {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .quick-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    color: var(--text);
    text-decoration: none;
    font-size: 13.5px;
    transition: all 0.2s;
    border: 1px solid transparent;
  }

  .quick-link:hover {
    background: var(--surface2);
    border-color: var(--border);
    color: var(--accent2);
  }

  .quick-link-icon {
    width: 28px; height: 28px;
    border-radius: 6px;
    display: grid;
    place-items: center;
    font-size: 14px;
    flex-shrink: 0;
  }

  .ql-blue  { background: rgba(59,130,246,0.15); }
  .ql-green { background: rgba(52,211,153,0.15); }
  .ql-purple{ background: rgba(108,99,255,0.15); }
  .ql-amber { background: rgba(251,191,36,0.15); }

  /* 統計資訊 */
  .stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
  }

  .stat-num {
    font-size: 26px;
    font-weight: 700;
    font-family: 'DM Mono', monospace;
    color: var(--accent2);
    line-height: 1;
  }

  .stat-label {
    font-size: 11px;
    color: var(--muted);
    margin-top: 6px;
    letter-spacing: 0.05em;
  }

  /* 系統狀態 */
  .status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
  }

  .status-ok {
    background: rgba(52,211,153,0.12);
    color: var(--green);
    border: 1px solid rgba(52,211,153,0.2);
  }

  .status-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 2s infinite;
  }

  @keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
  }

  /* 分隔線 */
  .divider { height: 1px; background: var(--border); }

  /* 頁尾 */
  footer {
    text-align: center;
    padding: 24px;
    color: var(--muted);
    font-size: 12px;
    border-top: 1px solid var(--border);
    letter-spacing: 0.05em;
  }

  /* 標籤 */
  .tag {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(108,99,255,0.1);
    border: 1px solid rgba(108,99,255,0.2);
    border-radius: 4px;
    font-size: 11px;
    color: var(--accent2);
    margin-left: 6px;
  }

  /* 校園地圖圖片 */

  .map-viewport {
    position: relative;
    width: 100%;
    overflow: visible;
    border-radius: 12px;
    cursor: zoom-in;
    user-select: none;
  }

  .map-canvas {
    position: static;
    width: 100%;
    height: auto;
  }


  /* 大樓外觀快速跳轉 */
  .bld-search-wrap {
    position: relative;
  }

  .bld-search-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px 12px;
    transition: all 0.2s;
  }

  .bld-search-input-row:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108,99,255,0.15);
  }

  .bld-search-icon { font-size: 14px; flex-shrink: 0; }

  .bld-search-input-row input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 13px;
    font-family: 'Noto Sans TC', sans-serif;
  }

  .bld-search-input-row input::placeholder { color: var(--muted); }

  .bld-clear-btn {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    display: none;
    line-height: 1;
    transition: color 0.15s;
  }
  .bld-clear-btn:hover { color: var(--text); }

  .bld-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0; right: 0;
    background: var(--surface);
    border: 1px solid rgba(108,99,255,0.25);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 16px 40px rgba(0,0,0,0.5);
    display: none;
    z-index: 200;
    max-height: 280px;
    overflow-y: auto;
  }

  .bld-dropdown.open { display: block; animation: fadeUp 0.15s ease; }

  .bld-dropdown::-webkit-scrollbar { width: 4px; }
  .bld-dropdown::-webkit-scrollbar-track { background: transparent; }
  .bld-dropdown::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

  .bld-dropdown-header {
    padding: 8px 14px 6px;
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
  }

  .bld-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 13px;
  }

  .bld-option:hover {
    background: rgba(108,99,255,0.1);
    color: var(--accent2);
  }

  .bld-option .bld-name { flex: 1; }

  .bld-option .bld-campus {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--surface2);
    color: var(--muted);
  }

  .bld-num-code {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(108,99,255,0.10);
    color: var(--accent2);
    letter-spacing: .03em;
    flex-shrink: 0;
  }

  .building-num-code {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(108,99,255,0.10);
    color: var(--accent2);
    letter-spacing: .03em;
    pointer-events: none;
  }

  .bld-option.campus-up .bld-campus {
    background: rgba(108,99,255,0.12);
    color: var(--accent2);
  }

  .bld-option.building-exterior-close {
    cursor: not-allowed;
    opacity: 0.55;
    color: var(--muted);
  }

  .bld-option.building-exterior-close:hover {
    background: none;
    color: var(--muted);
  }

  .bld-no-photo {
    font-size: 10px;
    color: var(--muted);
    margin-left: auto;
    flex-shrink: 0;
  }

  .bld-no-result {
    padding: 20px 14px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
  }

  .bld-exterior-message {
    display: none;
    margin-top: 10px;
    padding: 10px 12px;
    border: 1px solid rgba(245,158,11,0.28);
    border-radius: 10px;
    background: rgba(245,158,11,0.08);
    color: #92400e;
    font-size: 13px;
    line-height: 1.5;
  }

  /* 動畫 */
  @keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .card, .sidebar > * {
    animation: fadeUp 0.4s ease both;
  }
  .card:nth-child(2) { animation-delay: 0.08s; }
  .card:nth-child(3) { animation-delay: 0.16s; }

  @media (max-width: 1100px) {

    main { grid-template-columns: 1fr; padding: 24px 16px; }
  }


  /* 校園地圖改為直接圖片點擊放大 */

  #campusImg {
    width: 100% !important;
    height: auto !important;
    display: block !important;
    border-radius: 12px;
    border: 1px solid var(--border);
    pointer-events: auto !important;
    cursor: zoom-in;
  }

  .image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(15, 23, 42, 0.82);
  }

  .image-lightbox.open { display: flex; }

  .image-lightbox-inner {
    position: relative;
    display: inline-flex;
    max-width: min(96vw, 1280px);
    max-height: 92vh;
  }

  .image-lightbox img {
    max-width: min(96vw, 1280px);
    max-height: 92vh;
    width: auto;
    height: auto;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 24px 80px rgba(0,0,0,.35);
  }

  .image-lightbox-close {
    position: absolute;
    top: -14px;
    right: -14px;
    width: 38px;
    height: 38px;
    border: 1px solid rgba(255,255,255,.75);
    border-radius: 50%;
    background: rgba(15,23,42,.72);
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
  }

