* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 0 48px;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: #f4f6f8;
  color: #1f2937;
}

header {
  padding: 20px 28px 14px;
  background: #1e3a5f;
  color: #fff;
}
header h1 { margin: 0; font-size: 22px; }
header .sub { margin: 6px 0 0; font-size: 13px; opacity: .8; }
header code { background: rgba(255,255,255,.15); padding: 1px 5px; border-radius: 3px; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 28px;
  background: #1e3a5f;
}
.tab {
  padding: 10px 20px;
  background: #2c4f7c;
  color: #cfe0f5;
  text-decoration: none;
  border-radius: 6px 6px 0 0;
  font-size: 15px;
}
.tab:hover { background: #3a639b; color: #fff; }
.tab.active { background: #f4f6f8; color: #1e3a5f; font-weight: 700; }

main { padding: 20px 28px; max-width: 1180px; }

.card {
  background: #fff;
  border: 1px solid #e2e6eb;
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 17px; color: #1e3a5f; }

.flash {
  margin: 16px 28px 0;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
}
.flash.ok   { background: #e6f6ec; border: 1px solid #a9d9bc; color: #14623a; }
.flash.err  { background: #fdecec; border: 1px solid #efb4b4; color: #9b1c1c; }
.flash.warn { background: #fff7e3; border: 1px solid #e8cf92; color: #7a5a10; }
.card .flash { margin: 0 0 14px; }

header .bar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
header .who { font-size: 13px; display: flex; align-items: center; gap: 12px; white-space: nowrap; }
header .who span::before { content: "👤 "; }
a.logout {
  color: #fff;
  background: rgba(255,255,255,.18);
  padding: 5px 12px;
  border-radius: 5px;
  text-decoration: none;
}
a.logout:hover { background: rgba(255,255,255,.3); }

.hint { margin: 0 0 14px; font-size: 14px; color: #475569; }
.hint.note { margin: 14px 0 0; font-size: 13px; color: #64748b; line-height: 1.6; }

.quick { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; }
a.btnlink {
  display: inline-block;
  padding: 9px 18px;
  background: #eef2f7;
  color: #1e3a5f;
  border: 1px solid #cfd8e3;
  border-radius: 5px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
a.btnlink:hover { background: #1e3a5f; color: #fff; border-color: #1e3a5f; }

/* ---- 登入頁 ---- */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: #1e3a5f;
}
.login-box {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 10px;
  padding: 28px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.login-box h1 { margin: 0; font-size: 19px; color: #1e3a5f; }
.login-sub { margin: -8px 0 0; font-size: 13px; color: #6b7280; }
.login-box .flash { margin: 0; }
.login-box button { margin-top: 4px; padding: 11px; font-size: 15px; }
.login-hint { margin: 0; font-size: 12px; color: #92400e; background: #fff7e3; padding: 8px 10px; border-radius: 5px; }

form.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px 18px;
}
/* label 用 block，標題文字與必填星號才會留在同一行 */
form.grid label,
form.inline label { display: block; font-size: 14px; }
form.grid label > input, form.grid label > select,
form.inline label > input, form.inline label > select {
  display: block;
  width: 100%;
  margin-top: 5px;
}
form.grid .actions { grid-column: 1 / -1; }

form.inline { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }

input, select {
  padding: 8px 10px;
  border: 1px solid #cbd3dc;
  border-radius: 5px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
input:focus, select:focus { outline: 2px solid #3a639b; outline-offset: -1px; }
input:disabled { background: #f0f2f5; color: #6b7280; }

.req { color: #c0392b; }

button {
  padding: 9px 22px;
  background: #1e3a5f;
  color: #fff;
  border: 0;
  border-radius: 5px;
  font-size: 14px;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
}
button:hover { background: #2c4f7c; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; border-bottom: 1px solid #e6eaef; text-align: left; }
th { background: #eef2f7; color: #334155; font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: #f8fafc; }
tbody tr.hit { background: #eaf3ff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; background: #eef2f7; text-align: right; }
table.compact td, table.compact th { padding: 7px 10px; }

td a { color: #1d4ed8; text-decoration: none; font-weight: 600; }
td a:hover { text-decoration: underline; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

a.tel { color: #1d4ed8; text-decoration: none; }

td.act, th.act { width: 1%; text-align: center; white-space: nowrap; }
td.act form { display: inline; }
button.del {
  padding: 5px 14px;
  background: #fff;
  color: #b91c1c;
  border: 1px solid #e0b4b4;
  border-radius: 4px;
  font-size: 13px;
  white-space: nowrap;   /* 瀏覽器預設樣式會覆寫繼承值，必須直接指定 */
  min-width: 4.5em;
  line-height: 1.4;
}
button.del:hover { background: #b91c1c; color: #fff; border-color: #b91c1c; }

.total { margin: 0 0 14px; font-size: 15px; }
.total strong { font-size: 20px; color: #1e3a5f; }

.empty { color: #6b7280; font-size: 14px; margin: 0; }

/* ===================== 行動裝置 ===================== */

/* 平板：縮排距、表格可左右滑動 */
@media (max-width: 900px) {
  header { padding: 16px 16px 12px; }
  .tabs  { padding: 0 16px; }
  main   { padding: 16px; }
  .flash { margin: 12px 16px 0; }
  .card  { padding: 16px 14px; }
}

/* 手機：表格改為卡片式堆疊，每格自己帶欄位名 */
@media (max-width: 640px) {
  header h1 { font-size: 18px; }
  header .sub { display: none; }
  header .bar { align-items: center; }

  /* 分頁可橫向滑動，不換行擠壓 */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 10px 14px; font-size: 14px; white-space: nowrap; }

  main { padding: 12px; }
  .flash { margin: 10px 12px 0; }
  .card { padding: 14px 12px; border-radius: 6px; }
  .card h2 { font-size: 16px; }

  /* 表單單欄，輸入框放大好點 */
  form.grid { grid-template-columns: 1fr; gap: 12px; }
  form.inline { flex-direction: column; align-items: stretch; }
  input, select { padding: 11px 12px; font-size: 16px; }  /* 16px 可避免 iOS 自動放大 */
  button { width: 100%; padding: 13px; font-size: 16px; }

  /* 表格 → 卡片 */
  .table-wrap { overflow-x: visible; }
  table, thead, tbody, tfoot, tr, th, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tbody tr {
    border: 1px solid #e2e6eb;
    border-radius: 7px;
    margin-bottom: 10px;
    padding: 4px 0;
    background: #fff;
  }
  tbody tr.hit { background: #eaf3ff; border-color: #9cc3f0; }
  tbody td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    border: 0;
    padding: 7px 12px;
    text-align: right;
  }
  tbody td::before {
    content: attr(data-label);
    color: #64748b;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    flex: 0 0 auto;
  }
  tbody td:empty, tbody td[data-label]:empty { display: none; }
  tbody td.num { text-align: right; }
  tbody tr:hover { background: #fff; }

  /* 卡片第一列（學號／紀錄編號）當標題用 */
  tbody td:first-child {
    background: #f1f5f9;
    border-radius: 6px 6px 0 0;
    font-weight: 700;
    margin-bottom: 2px;
  }

  /* 刪除鈕獨立一列；td.act 要蓋掉 tbody td 的 flex，否則按鈕會被壓成內容寬度 */
  td.act { display: block; width: auto; padding: 8px 12px 10px; }  /* 需覆寫桌機的 width:1% */
  td.act::before { content: none; }
  td.act form { display: flex; justify-content: flex-end; }
  button.del { width: auto; min-width: 92px; padding: 10px 18px; font-size: 14px; }

  /* 合計列 */
  tfoot tr { display: flex; justify-content: space-between; padding: 10px 12px; border-radius: 7px; }
  tfoot td { padding: 0; background: none; }
  tfoot td[colspan] { text-align: left; }
  tfoot td:empty { display: none; }

  .total strong { font-size: 18px; }
  .login-box { padding: 22px 18px; }
}

@media (max-width: 640px) {
  .quick { flex-direction: column; }
  a.btnlink { text-align: center; padding: 12px 18px; }
}
