:root {
  --bg: #f5f6f8;
  --panel: #fff;
  --ink: #1c2430;
  --muted: #6b7683;
  --line: #dfe3e8;
  --brand: #2c6fb5;
  --brand-dark: #1f5288;
  --danger: #d63b3b;
  --warn: #d98218;
  --ok: #2f9e5f;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 版頭 ---------- */
.site-header {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0 20px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.site-header .inner {
  max-width: 1600px; margin: 0 auto;
  display: flex; align-items: center; gap: 24px; height: 56px;
}
.site-header .logo { display: flex; align-items: center; gap: 12px; min-width: 0; }
.site-header .logo:hover { text-decoration: none; }
.logo-img { display: block; height: 32px; width: auto; }
.logo-sep { flex: none; width: 1px; height: 24px; background: var(--line); }
.logo-text {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; color: var(--ink); white-space: nowrap;
}
.logo-badge {
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 5px; background: var(--brand); color: #fff;
}
.site-header nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.site-header nav a {
  padding: 6px 12px; border-radius: 6px; color: var(--muted); font-weight: 500;
}
.site-header nav a:hover { background: #eef1f5; text-decoration: none; }
.site-header nav a.active { background: var(--brand); color: #fff; }

.wrap { max-width: 1600px; margin: 0 auto; padding: 20px; }

/* ---------- 篩選列 ---------- */
.filters {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.filters form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field select, .field input[type=date], .field input[type=text], .field input[type=number],
.field input[type=password], .field textarea, select, input[type=text], input[type=date] {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--ink);
  min-width: 130px;
}
.field select:focus, .field input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

.btn {
  display: inline-block; padding: 8px 16px; border-radius: 6px; border: 1px solid transparent;
  background: var(--brand); color: #fff; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit; text-align: center;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { background: #f0f3f7; color: var(--ink); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 13px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: #fff; cursor: pointer; font-size: 13px; user-select: none;
}
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- 檢視切換 ---------- */
.viewtabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.viewtabs a {
  padding: 7px 16px; border-radius: 999px; background: #fff;
  border: 1px solid var(--line); color: var(--muted); font-weight: 600;
}
.viewtabs a.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.viewtabs a:hover { text-decoration: none; }

/* ---------- 週導覽 ---------- */
.weeknav {
  display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.weeknav .range { font-size: 16px; font-weight: 700; }

/* ---------- 課表 ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.panel-head {
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-body { padding: 0; overflow-x: auto; }

table.grid { border-collapse: collapse; width: 100%; min-width: 900px; }
table.grid th, table.grid td {
  border: 1px solid var(--line); padding: 4px 6px; vertical-align: top; font-size: 13px;
}
table.grid thead th {
  background: #f0f3f7; position: sticky; top: 0; z-index: 5;
  font-size: 12px; color: var(--muted); text-align: center; padding: 8px 6px;
}
table.grid thead th.today { background: #e3f0ff; color: var(--brand-dark); }
table.grid td.rowhead, table.grid th.rowhead {
  background: #fafbfc; font-weight: 600; white-space: nowrap;
  position: sticky; left: 0; z-index: 4; text-align: left; vertical-align: middle;
  min-width: 100px;
}
table.grid thead th.rowhead { z-index: 6; }
table.grid td.slot { height: 34px; padding: 2px; }
table.grid td.weekend { background: #fbfbfc; }

/* 課程色塊 */
.ev {
  display: block; border-radius: 4px; padding: 3px 6px; margin-bottom: 2px;
  font-size: 12px; line-height: 1.35; cursor: pointer; border-left: 3px solid rgba(0,0,0,.18);
  overflow: hidden;
}
.ev:hover { filter: brightness(.95); text-decoration: none; }
.ev .t { font-weight: 600; display: block; }
.ev .m { opacity: .8; font-size: 11px; display: block; }
.ev.conflict { box-shadow: 0 0 0 2px var(--danger) inset; }

/* 圖例 */
.legend { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.legend .item { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.legend .sw { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,.12); }

/* ---------- 表格（清單） ---------- */
table.list { border-collapse: collapse; width: 100%; }
table.list th, table.list td { border-bottom: 1px solid var(--line); padding: 9px 12px; text-align: left; }
table.list th { background: #f7f9fb; font-size: 12px; color: var(--muted); font-weight: 600; }
table.list tbody tr:hover { background: #f9fbfd; }
table.list td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 徽章 ---------- */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge.blocker { background: #fde8e8; color: #a62222; }
.badge.warning { background: #fdf1de; color: #92600f; }
.badge.info    { background: #eaeef3; color: #55606d; }
.badge.ok      { background: #e3f6ea; color: #1e7043; }
.badge.cand    { background: #eef0ff; color: #4a4fa8; }

/* ---------- 統計卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat.alert .v { color: var(--danger); }
.stat.warn .v { color: var(--warn); }

/* ---------- 提示 ---------- */
.notice { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 13px; }
.notice.err  { background: #fdecec; border: 1px solid #f5c2c2; color: #982323; }
.notice.warn { background: #fdf4e6; border: 1px solid #f2ddb5; color: #8a5d10; }
.notice.ok   { background: #e8f7ee; border: 1px solid #b9e4c9; color: #1c6b40; }
.notice.info { background: #eaf2fb; border: 1px solid #c4dcf5; color: #23557f; }

.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

/* ---------- 彈窗 ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .45);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-bg.on { display: flex; }
.modal {
  background: #fff; border-radius: 10px; max-width: 560px; width: 100%;
  max-height: 88vh; overflow: auto; box-shadow: 0 12px 40px rgba(16,24,40,.2);
}
.modal h3 { margin: 0; padding: 16px 20px; border-bottom: 1px solid var(--line); font-size: 16px; }
.modal .body { padding: 18px 20px; }
.modal .foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.modal dl { margin: 0; display: grid; grid-template-columns: 90px 1fr; gap: 8px 14px; }
.modal dt { color: var(--muted); font-size: 13px; }
.modal dd { margin: 0; }

/* ---------- 表單 ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }
textarea { min-height: 70px; resize: vertical; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-family: inherit; font-size: 14px; }

.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; }

/* ---------- 列印 ---------- */
@media print {
  .filters, .viewtabs, .weeknav, .no-print { display: none !important; }
  .site-header { position: static; box-shadow: none; padding: 0; border-bottom: 1px solid #ccc; }
  .site-header nav, .logo-badge { display: none !important; }
  .site-header .inner { height: auto; padding: 0 0 8px; }
  .logo-img { height: 26px; }
  body { background: #fff; }
  .wrap { padding: 0; max-width: none; }
  .panel { border: none; box-shadow: none; }
  table.grid { min-width: 0; font-size: 10px; }
  .ev { font-size: 9px; }
}

@media (max-width: 720px) {
  .site-header .inner { height: auto; padding: 10px 0; flex-wrap: wrap; gap: 10px; }
  .site-header .logo { gap: 9px; }
  .logo-img { height: 30px; }
  .logo-text { font-size: 14px; }
  .wrap { padding: 12px; }
  .filters form { gap: 10px; }
  .field select, .field input { min-width: 110px; }
}
