/* 由 GAS 版 mod_styles.html 移植；配色與版面維持一致 */
/*
   * 配色沿用既有營運中心的視覺：米色底、深藍頂列、橘色重點。
   * 刻意只做淺色一套——這是內部營運工具，與既有系統並排使用時
   * 顏色跟著使用者的系統偏好變反而不一致。
   */
  :root {
    --bg: #f1eee4;
    --surface: #ffffff;
    --surface-alt: #faf8f2;
    --topbar: #1b2b33;
    --dark-card: #22343c;
    --accent: #e8672c;
    --accent-hover: #cf551c;
    --ink: #17272e;
    --muted: #6d7c83;
    --line: #e4dfd2;
    --line-strong: #d3ccbb;
    --ok: #2f9e6a;
    --danger: #d64545;
    --radius: 14px;
  }

  * { box-sizing: border-box; }

  html, body { height: 100%; }

  body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
                 "PingFang TC", "Microsoft JhengHei", sans-serif;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
  }

  .hidden { display: none !important; }

  /* ===== 頂列 ===== */

  /* 頂列與分頁列一起固定在畫面上方，捲動時不會消失。
     兩者包在同一個容器裡 sticky，避免分開計算偏移量——頂列在手機上
     會因為隱藏單位名稱而變矮，寫死的偏移量就會露出縫隙。 */
  .sticky-head {
    position: sticky;
    top: 0;
    z-index: 50;
  }

  .topbar {
    background: var(--topbar);
    color: #fff;
    padding: 14px 0;
  }
  .topbar-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }
  .brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
  /* 公司 logo。球體本身是淺灰白，深色頂列上直接放就有對比；
     淺色登入頁上靠中央黑紅的 KH 標誌辨識，不另外加底色。 */
  .brand-logo {
    width: 34px; height: 34px;
    flex: none;
    object-fit: contain;
    display: block;
  }
  .brand-name {
    font-size: 17px; font-weight: 700; letter-spacing: .3px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  .topbar-right { display: flex; align-items: center; gap: 10px; }
  .who { text-align: right; line-height: 1.35; min-width: 0; }
  .who-name { font-size: 14px; font-weight: 700; }
  .who-meta { font-size: 12px; color: #a8b6bc; }

  .chip {
    padding: 7px 15px;
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 8px;
    background: transparent;
    color: #fff;
    font-size: 13.5px; font-weight: 600; font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s;
  }
  .chip:hover { background: rgba(255,255,255,.12); }
  .chip-active { background: #fff; color: var(--topbar); border-color: #fff; }

  /* ===== 版面 ===== */

  .shell { max-width: 1180px; margin: 0 auto; padding: 18px 20px 60px; }

  /* 分頁列的底色要不透明，否則捲動時內容會從底下透出來 */
  .tabs-bar {
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    padding: 12px 20px;
  }
  .tabs-bar .tabs { max-width: 1140px; margin: 0 auto; }

  /* ===== 分頁列 ===== */

  .tabs {
    display: flex;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }

  .tab {
    padding: 9px 16px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    font-size: 14.5px; font-weight: 600; font-family: inherit;
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, color .15s;
  }
  .tab:hover { background: var(--surface-alt); }
  .tab-active { background: var(--topbar); color: #fff; }
  .tab-active:hover { background: var(--topbar); }

  /* ===== 麵包屑與標題 ===== */

  .crumb {
    margin: 20px 0 0;
    font-size: 13px;
    color: var(--muted);
  }
  .crumb span + span::before { content: '›'; margin: 0 9px; color: var(--line-strong); }

  .eyebrow {
    margin: 22px 0 6px;
    font-size: 12.5px; font-weight: 700;
    letter-spacing: .16em;
    color: var(--accent);
    text-transform: uppercase;
  }
  h1.page-title {
    margin: 0 0 10px;
    font-size: 40px; font-weight: 800;
    letter-spacing: -.01em;
    line-height: 1.15;
  }
  .page-lead { margin: 0 0 26px; font-size: 15px; color: var(--muted); max-width: 62ch; }

  @media (max-width: 640px) {
    h1.page-title { font-size: 29px; }
    .who-meta { display: none; }
    /* 手機螢幕矮，固定區塊要盡量薄，否則內容可視範圍被吃掉太多 */
    .topbar { padding: 9px 0; }
    .topbar-inner { padding: 0 14px; }

    /*
       分頁列移到螢幕底部——單手拿手機時拇指構得到的是下緣，不是上緣。
       .tabs-bar 雖然是 sticky 容器的子元素，position:fixed 仍以視窗為基準
       （祖先沒有 transform／filter，不會產生新的包含區塊）。
       它脫離文件流之後，上方的 sticky-head 就只剩頂列。
    */
    .tabs-bar {
      position: fixed;
      left: 0; right: 0; bottom: 0;
      z-index: 60;
      /* 白底讓它與米色頁面分開，看起來像獨立的導覽列而不是頁面的一部分 */
      background: var(--surface);
      box-shadow: 0 -2px 12px rgba(23, 39, 46, .06);
      border-top: 1px solid var(--line);
      border-bottom: 0;
      /* iPhone 的home indicator 會蓋住最後幾像素 */
      padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    }
    .tabs-bar .tabs {
      border: 0;
      border-radius: 0;
      padding: 0;
      background: transparent;
      gap: 2px;
    }

    /* 底部導覽只有文字辨識度差，改成圖示在上、文字在下 */
    .tab {
      flex: 1 0 auto;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 3px;
      padding: 5px 10px;
      font-size: 11px;
      line-height: 1.2;
    }
    .tab::before {
      content: attr(data-icon);
      font-size: 19px;
      line-height: 1;
    }
    /* 底部導覽的選取狀態用顏色，不用深色色塊——那在下緣會顯得很重 */
    .tab-active, .tab-active:hover { background: transparent; color: var(--accent); }
    .tab:hover { background: transparent; }

    /* 內容要留出底部導覽的高度，否則最後一列會被蓋住 */
    .shell { padding: 14px 14px calc(84px + env(safe-area-inset-bottom, 0px)); }
  }

  /* ===== 卡片 ===== */

  .card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px 24px;
  }
  .card + .card { margin-top: 16px; }
  .card-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px; flex-wrap: wrap;
  }
  .card h2 { margin: 0 0 3px; font-size: 17px; font-weight: 700; }
  .card .hint { margin: 0; font-size: 13.5px; color: var(--muted); }

  .card-dark {
    background: var(--dark-card);
    border-color: var(--dark-card);
    color: #fff;
  }
  .card-dark h2 { color: #fff; }
  .card-dark .hint { color: #9fb0b7; }

  /* ===== 按鈕 ===== */

  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 9px;
    padding: 12px 20px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    font-size: 15px; font-weight: 600; font-family: inherit;
    text-decoration: none; cursor: pointer;
    transition: background .15s, border-color .15s, opacity .15s;
    -webkit-tap-highlight-color: transparent;
  }
  .btn:hover { border-color: var(--muted); }
  .btn[aria-disabled="true"] { opacity: .55; }
  .btn-primary {
    background: var(--accent); border-color: var(--accent); color: #fff;
  }
  .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
  .btn-block { display: flex; width: 100%; }
  .btn-block + .btn-block { margin-top: 12px; }
  .btn-sm { padding: 7px 14px; font-size: 13px; font-weight: 600; }
  .btn-danger { color: var(--danger); }
  .btn-danger:hover { border-color: var(--danger); }

  /* ===== 訊息 ===== */

  .msg {
    padding: 12px 15px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-size: 13.5px;
    margin-bottom: 16px;
    white-space: pre-wrap;
  }
  .msg-error { background: #fdecec; border-color: #f4c9c9; color: #a62c2c; }
  .msg-ok    { background: #e8f6ee; border-color: #bfe4d0; color: #1d7a4f; }
  .msg-info  { background: var(--surface-alt); border-color: var(--line); color: var(--muted); }
  .msg-warn  { background: #fdf3e3; border-color: #f0dcb4; color: #96631a; }

  /* ===== 其他元件 ===== */

  .spinner {
    width: 16px; height: 16px;
    border: 2px solid var(--line-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex: none;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  .loading-row {
    display: flex; align-items: center; gap: 12px;
    color: var(--muted); font-size: 14px;
  }

  .kv {
    display: grid;
    grid-template-columns: 96px 1fr;
    gap: 10px 16px;
    font-size: 14px;
    margin: 0;
  }
  .kv dt { color: var(--muted); }
  .kv dd { margin: 0; font-weight: 600; }

  .device {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    padding: 14px 0;
    border-top: 1px solid var(--line);
    font-size: 14px;
  }
  .device-name { font-weight: 700; }
  .device-meta { color: var(--muted); font-size: 12.5px; }

  .badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px; font-weight: 700;
  }
  .badge-off { background: #eeeae0; color: var(--muted); }

  /* ===== 載入進度 ===== */

  .progress {
    padding: 18px 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
  }
  .progress-row { display: flex; align-items: center; gap: 12px; }
  .progress-text { font-size: 14px; color: var(--ink); flex: 1; }
  .progress-time {
    font-size: 13px; color: var(--muted);
    font-variant-numeric: tabular-nums;
  }
  .progress-hint { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

  /* ===== 首頁功能格 ===== */

  /* 電腦一排六個、手機一排兩個。用 auto-fit 會依容器寬度自己決定數量，
     但那樣中間尺寸的螢幕會跑出三個、五個這種不規則的排法，
     所以直接指定欄數，只在斷點切換。 */
  .home-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 14px;
  }
  @media (max-width: 1000px) { .home-grid { grid-template-columns: repeat(3, 1fr); } }
  @media (max-width: 640px)  { .home-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; } }

  .home-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 26px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: border-color .15s, transform .12s, box-shadow .15s;
    -webkit-tap-highlight-color: transparent;
  }
  .home-tile:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(23, 39, 46, .08);
  }
  .home-tile:active { transform: translateY(0); }
  .home-icon { font-size: 30px; line-height: 1; }
  .home-label { font-size: 14.5px; font-weight: 700; text-align: center; }

  .home-tile.is-disabled {
    opacity: .55;
    cursor: not-allowed;
    background: var(--surface-alt);
  }
  .home-tile.is-disabled:hover {
    border-color: var(--line);
    transform: none;
    box-shadow: none;
  }
  .home-note {
    font-size: 11.5px;
    color: var(--muted);
    text-align: center;
    margin-top: -4px;
  }

  @media (max-width: 640px) {
    .home-tile { padding: 22px 10px; }
    .home-icon { font-size: 26px; }
    .home-label { font-size: 13.5px; }
  }

  /* 點標誌回首頁 */
  #view-app .brand { cursor: pointer; }

  /* 篩選用的小晶片 */
  .chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
  .filter-chip {
    padding: 6px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-size: 13px; font-weight: 600; font-family: inherit;
    cursor: pointer;
  }
  .filter-chip.on { background: var(--topbar); border-color: var(--topbar); color: #fff; }

  /* 可排序的表頭 */
  th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
  th.sortable:hover { color: var(--ink); }

  /* 表格裡當按鈕用的姓名欄 */
  .link-cell {
    border: 0; background: none; padding: 0;
    font: inherit; font-weight: 600;
    color: var(--ink); cursor: pointer; text-align: left;
  }
  .link-cell:hover { color: var(--accent); }

  /* 展開的明細列 */
  tr.detail-row td { background: var(--surface-alt); padding: 0; }
  .detail-box { padding: 16px 14px 20px; }
  .detail-title {
    font-size: 12px; font-weight: 700; color: var(--accent);
    letter-spacing: .08em; margin: 16px 0 6px;
  }
  .detail-box > .detail-title:first-child { margin-top: 0; }

  /* 安裝步驟 */
  ol.steps {
    margin: 16px 0 0;
    padding-left: 22px;
    font-size: 14px;
    line-height: 1.9;
  }
  ol.steps li::marker { color: var(--accent); font-weight: 700; }
  ol.steps .steps-warn { color: var(--danger); list-style: none; margin-left: -22px; margin-top: 8px; }

  /* 尚未開發的分頁 */
  .placeholder {
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface-alt);
    padding: 40px 26px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
  }
  .placeholder strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 6px; }

  /* ===== 戰況：篩選列與數據 ===== */

  .filters {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 18px;
  }
  .field { display: flex; flex-direction: column; gap: 5px; }
  .field label { font-size: 12px; font-weight: 600; color: var(--muted); }
  .field select, .field input {
    padding: 9px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    background: var(--surface);
    color: var(--ink);
    font-size: 14px; font-family: inherit;
    min-height: 40px;
  }

  .segmented { display: flex; gap: 3px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 9px; padding: 3px; }
  .segmented button {
    padding: 7px 15px; border: 0; border-radius: 7px;
    background: transparent; color: var(--ink);
    font-size: 13.5px; font-weight: 600; font-family: inherit; cursor: pointer;
  }
  .segmented button.on { background: var(--topbar); color: #fff; }

  .stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
  }
  .stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
  }
  .stat-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
  .stat-value { font-size: 30px; font-weight: 800; letter-spacing: -.02em; margin-top: 3px; line-height: 1.15; }
  .stat-value .unit { font-size: 14px; font-weight: 700; color: var(--muted); margin-right: 3px; }
  .stat-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
  .stat-hero { background: var(--dark-card); border-color: var(--dark-card); color: #fff; }
  .stat-hero .stat-label, .stat-hero .stat-sub { color: #9fb0b7; }
  .neg { color: var(--danger); }

  .table-wrap { overflow-x: auto; margin: 0 -4px; }
  table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 460px; }
  table.data th, table.data td { padding: 10px 12px; text-align: right; white-space: nowrap; }
  table.data th:first-child, table.data td:first-child { text-align: left; white-space: normal; min-width: 140px; }
  table.data thead th {
    font-size: 12px; color: var(--muted); font-weight: 700;
    border-bottom: 1px solid var(--line-strong);
  }
  table.data tbody tr + tr td { border-top: 1px solid var(--line); }
  table.data tbody tr:hover { background: var(--surface-alt); }
  .num { font-variant-numeric: tabular-nums; }
  td.strong { font-weight: 700; }
  /* 在名單裡標出自己那一列 */
  tr.row-total td {
    background: var(--surface-alt);
    border-top: 2px solid var(--line-strong);
  }
  tr.row-self td { background: #fdf3e3; }
  tr.row-self td:first-child { font-weight: 700; box-shadow: inset 3px 0 0 var(--accent); }

  /* 查詢中：內容變淡但留在原地，頂端跑一條進度條。
     整塊清空再重畫會讓畫面跳動，反而更像壞掉。 */
  .is-loading { opacity: .45; pointer-events: none; transition: opacity .15s; }

  .loading-bar {
    height: 3px;
    border-radius: 3px;
    background: var(--line);
    overflow: hidden;
    margin-bottom: 14px;
    position: relative;
  }
  .loading-bar::after {
    content: '';
    position: absolute;
    inset: 0;
    width: 40%;
    background: var(--accent);
    border-radius: 3px;
    animation: slide 1s ease-in-out infinite;
  }
  @keyframes slide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(250%); }
  }

  /* 門市選擇對話框 */
  .picker-actions {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 12px;
  }
  .picker-count { font-size: 13.5px; font-weight: 600; color: var(--muted); }

  .picker-list {
    max-height: 46vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
  }
  /* 部門標題：本身就是「整組切換」的按鈕，用底色與縮排跟門市列分開 */
  .picker-group {
    display: flex; align-items: center; gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: var(--surface-alt);
    color: var(--ink);
    font-size: 13.5px; font-family: inherit;
    text-align: left;
    cursor: pointer;
    position: sticky; top: 0; z-index: 1;
  }
  .picker-group:hover { background: #f1eee4; }
  .picker-group-name { font-weight: 700; flex: 1; }
  .picker-group-count { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
  /* 全選才填滿；部分選取顯示為半選狀態 */
  .picker-group.on .picker-check { background: var(--accent); border-color: var(--accent); }

  .picker-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%;
    padding: 11px 14px 11px 30px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    font-size: 14px; font-family: inherit;
    text-align: left;
    cursor: pointer;
  }
  .picker-item:last-child { border-bottom: 0; }
  .picker-item:hover { background: var(--surface-alt); }
  .picker-item.on { font-weight: 700; }
  .picker-check {
    width: 20px; height: 20px;
    flex: none;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--line-strong);
    border-radius: 5px;
    font-size: 13px; line-height: 1;
    color: #fff;
  }
  .picker-item.on .picker-check { background: var(--accent); border-color: var(--accent); }

  /* ===== 設定對話框 ===== */

  /*
   * 用 position:fixed 覆蓋整個檢視區。開啟時同時鎖住 body 捲動，
   * 否則背景內容會跟著滑動，在手機上會很錯亂。
   */
  .modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(18, 30, 36, .55);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 32px 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    animation: modal-fade .15s ease-out;
  }
  @keyframes modal-fade { from { opacity: 0; } }

  .modal {
    width: 100%;
    max-width: 540px;
    background: var(--bg);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 26px 64px rgba(0, 0, 0, .34);
    animation: modal-rise .2s cubic-bezier(.2, .8, .3, 1);
  }
  @keyframes modal-rise { from { transform: translateY(14px); opacity: 0; } }

  .modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 17px 20px;
    background: var(--topbar);
    color: #fff;
  }
  .modal-title { font-size: 16.5px; font-weight: 700; }
  .modal-sub { font-size: 12.5px; color: #a8b6bc; margin-top: 1px; }

  .modal-close {
    width: 32px; height: 32px;
    flex: none;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 8px;
    background: transparent;
    color: #fff;
    font-size: 19px; line-height: 1; font-family: inherit;
    cursor: pointer;
    transition: background .15s;
  }
  .modal-close:hover { background: rgba(255,255,255,.14); }

  .modal-body { padding: 18px; }
  .modal-body .card { border-color: var(--line); }

  body.modal-open { overflow: hidden; }

  @media (max-width: 640px) {
    .modal-backdrop { padding: 0; }
    .modal { max-width: none; min-height: 100%; border-radius: 0; }
  }

  /* ===== 登入頁 ===== */

  .login-wrap { max-width: 430px; margin: 0 auto; padding: 56px 20px 40px; }
  .login-brand { text-align: center; margin-bottom: 26px; }
  .login-brand .brand-logo { width: 52px; height: 52px; margin: 0 auto 14px; }
  .login-brand h1 { margin: 0 0 4px; font-size: 23px; font-weight: 800; }
  .login-brand p { margin: 0; font-size: 13px; color: var(--muted); letter-spacing: .06em; }

  .divider {
    display: flex; align-items: center; gap: 12px;
    margin: 18px 0; color: var(--muted); font-size: 12.5px;
  }
  .divider::before, .divider::after {
    content: ''; flex: 1; height: 1px; background: var(--line);
  }

/* ===== 學習護照 ===== */

.section-label {
  margin: 20px 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--muted);
  text-transform: uppercase;
}
.section-label:first-child { margin-top: 4px; }

.course-list { margin-top: 4px; }

.course-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.course-item:last-child { border-bottom: 0; }
.course-item.is-cancelled { opacity: .55; }
.course-item.is-cancelled .course-name { text-decoration: line-through; }

.course-main { flex: 1; min-width: 0; }
.course-name { font-size: 14.5px; font-weight: 700; }
.course-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.course-meta.warn { color: var(--danger); font-weight: 600; }

.status-pass { font-size: 13px; color: var(--ok); font-weight: 600; margin-top: 3px; }
.status-fail { font-size: 13px; color: var(--danger); font-weight: 600; margin-top: 3px; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
  vertical-align: middle;
}
.pill-ok     { background: #e4f5ec; color: #1e7a4f; }
.pill-danger { background: #fce8e8; color: #b13333; }
.pill-warn   { background: #fdf0dc; color: #96601a; }
.pill-muted  { background: var(--surface-alt); color: var(--muted); }

@media (max-width: 640px) {
  .course-item { flex-direction: column; align-items: stretch; gap: 10px; }
  .course-item .btn, .course-item .pill { align-self: flex-start; }
}

/* ===== 學習護照的大類選擇 ===== */

.module-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 4px;
}

.module-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.module-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(23, 39, 46, .08);
}
.module-card:active { transform: translateY(0); }

.module-icon { font-size: 28px; line-height: 1; flex-shrink: 0; }
.module-main { flex: 1; min-width: 0; }
.module-title { font-size: 15px; font-weight: 700; }
.module-stat { font-size: 12.5px; margin-top: 5px; line-height: 1.5; }
.module-stat.tone-todo { color: var(--danger); font-weight: 600; }
.module-stat.tone-done { color: var(--ok); font-weight: 600; }
.module-stat.tone-none { color: var(--muted); }

.module-arrow { font-size: 22px; color: var(--muted); flex-shrink: 0; }

@media (max-width: 900px) {
  .module-grid { grid-template-columns: 1fr; }
}

/* ===== 手機：表格改成一列一張卡片 =====

   大表格在手機上橫向捲是最難用的模式——滑到第五欄時已經忘了在看誰，
   標題列也早就捲出畫面外。這裡把每一列變成一張卡片，每個儲存格顯示成
   「欄位名稱　數值」，靠 JS 事後補上的 data-label 供應名稱。

   只在 .stacked 生效：沒套用的表格維持原本的橫向捲，不會因為漏改而壞掉。
*/
@media (max-width: 720px) {
  .table-wrap { overflow-x: visible; margin: 0; }

  table.data.stacked { min-width: 0; display: block; }
  table.data.stacked thead { display: none; }
  table.data.stacked tbody { display: block; }

  table.data.stacked tbody tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 14px;
    margin-bottom: 10px;
    background: var(--surface);
  }
  table.data.stacked tbody tr:hover { background: var(--surface); }
  table.data.stacked tbody tr + tr td { border-top: 0; }

  table.data.stacked td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    padding: 5px 0;
    text-align: right;
    white-space: normal;
    min-width: 0;
  }
  table.data.stacked td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    max-width: 55%;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
  }
  /* 沒有欄位名稱就不要留出左邊那一欄的空間 */
  table.data.stacked td[data-label=""]::before { content: none; }

  /* 第一欄當卡片標題：整行、粗體、底下畫一條分隔 */
  table.data.stacked tbody td:first-child {
    display: block;
    text-align: left;
    font-size: 15px;
    font-weight: 700;
    padding: 2px 0 8px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--line);
  }
  table.data.stacked tbody td:first-child::before { content: none; }

  /* 次要欄位在手機上收起來，資訊量太大的表才用得到 */
  table.data.stacked .col-secondary { display: none; }

  /* 展開列不是資料列，維持整塊寬度 */
  table.data.stacked tbody tr.detail-row {
    border: 0;
    padding: 0;
    margin: -6px 0 10px;
    background: transparent;
  }
  table.data.stacked tbody tr.detail-row td {
    display: block;
    padding: 0;
    text-align: left;
  }
  table.data.stacked tbody tr.detail-row td::before { content: none; }

  table.data.stacked tbody tr.row-self { border-color: var(--accent); }
  table.data.stacked tbody tr.row-self td:first-child { box-shadow: none; }
  table.data.stacked tbody tr.row-total { background: var(--surface-alt); }
  table.data.stacked tbody tr.row-total td { background: transparent; border-top: 0; }
}
