/* 表格在手機上改成一列一張卡(public/table-cards.js;表格加 class「rt-cards」就套用)。
 * 只在窄螢幕(700px 以下)生效,寬螢幕完全照各頁原本的表格樣式。
 * 每一格的欄名寫在 data-l(table-cards.js 從表頭抄過來),畫在格子左邊一欄,值在右邊、太長就照字換行。
 * 這裡蓋過各頁表格的寬度、不換行、最小寬度等設定(用 !important),各頁不用自己再寫手機版。
 * 商米舊 WebView 守則同 report-drill.css:不靠 flex gap;不用 grid、inset、:has()、:is()、min()、clamp()。 */
@media (max-width: 700px) {
  table.rt-cards { display: block !important; width: 100% !important; min-width: 0 !important; border: 0; }
  table.rt-cards > thead { display: none !important; }
  table.rt-cards > tbody, table.rt-cards > tfoot { display: block !important; width: 100% !important; }
  /* 一列 = 一張卡 */
  table.rt-cards > tbody > tr, table.rt-cards > tfoot > tr {
    display: block !important; width: auto !important; box-sizing: border-box; position: relative;
    margin: 0 0 8px; padding: 6px 10px; border: 1px solid var(--line, #e3e6ec); border-radius: 10px; background: var(--panel, #fff);
  }
  table.rt-cards > tbody > tr > td, table.rt-cards > tbody > tr > th, table.rt-cards > tfoot > tr > td, table.rt-cards > tfoot > tr > th {
    display: block !important; width: auto !important; min-width: 0 !important; max-width: none !important; box-sizing: border-box; position: relative;
    padding: 4px 0 4px 96px !important; border: 0 !important; text-align: left !important;
    white-space: normal !important; word-break: normal; word-wrap: break-word; overflow-wrap: break-word;
  }
  /* 欄名:左邊固定寬的一欄 */
  table.rt-cards > tbody > tr > [data-l]::before, table.rt-cards > tfoot > tr > [data-l]::before {
    content: attr(data-l); position: absolute; left: 0; top: 4px; width: 88px;
    color: var(--muted); font-size: 12.5px; font-weight: 700; line-height: 1.5; white-space: normal; word-wrap: break-word;
  }
  /* 沒有欄名的格子(放按鈕的那一欄、對不到表頭的合併格):整寬,不留左邊那一欄 */
  table.rt-cards > tbody > tr > td:not([data-l]), table.rt-cards > tbody > tr > th:not([data-l]),
  table.rt-cards > tbody > tr > [data-l=""], table.rt-cards > tfoot > tr > td:not([data-l]), table.rt-cards > tfoot > tr > [data-l=""] { padding-left: 0 !important; }
  table.rt-cards > tbody > tr > [data-l=""]::before, table.rt-cards > tfoot > tr > [data-l=""]::before { content: none; }
  /* 第一格 = 卡片標題 */
  table.rt-cards:not(.rt-notitle) > tbody > tr > :first-child { padding-left: 0 !important; font-size: 15px; font-weight: 700; }
  table.rt-cards:not(.rt-notitle) > tbody > tr > :first-child::before { content: none; }
  table.rt-cards:not(.rt-notitle) > tbody > tr > :first-child small, table.rt-cards:not(.rt-notitle) > tbody > tr > :first-child .hint { font-weight: 400; }
  /* 按鈕:橫排、字不拆開 */
  table.rt-cards > tbody > tr > * button, table.rt-cards > tfoot > tr > * button { white-space: nowrap; max-width: 100%; vertical-align: middle; margin: 2px 6px 2px 0; }
  table.rt-cards > tbody > tr > * select, table.rt-cards > tbody > tr > * input:not([type=checkbox]):not([type=radio]) { max-width: 100%; }
  /* 一列只有一格、橫跨好幾欄(展開的明細、「沒有資料」):接在上一張卡下面,不另外框一張 */
  table.rt-cards > tbody > tr.rt-full { margin-top: -8px; border-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; }
  table.rt-cards > tbody > tr.rt-full:first-child { margin-top: 0; border-top: 1px solid var(--line, #e3e6ec); border-radius: 10px; }
  table.rt-cards > tbody > tr.rt-full > :first-child { padding-left: 0 !important; font-size: inherit; font-weight: inherit; }
  /* 表頭裡有排序鈕之類的:表頭不藏,改成一排小鈕(空的表頭格不顯示) */
  table.rt-cards.rt-head-live > thead { display: block !important; margin: 0 0 6px; }
  table.rt-cards.rt-head-live > thead > tr { display: block !important; }
  table.rt-cards.rt-head-live > thead > tr > th { display: inline-block !important; width: auto !important; min-width: 0 !important; padding: 0 !important; margin: 0 6px 6px 0; border: 1px solid var(--line, #e3e6ec) !important; border-radius: 999px; background: var(--panel, #fff); }
  table.rt-cards.rt-head-live > thead > tr > th:empty { display: none !important; }
  table.rt-cards.rt-head-live > thead > tr > th > button { padding: 0 12px; }
}
