:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --bg: #f6f7fb;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-sub: #6b7280;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
               "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

/* ---------- 按鈕 ---------- */
.btn {
  border: none; border-radius: 8px; cursor: pointer;
  font-size: 14px; padding: 9px 16px; font-family: inherit;
  transition: background .15s, box-shadow .15s;
}
.btn.small { padding: 7px 13px; font-size: 13.5px; }
.btn.wide { width: 100%; padding: 11px; font-size: 15px; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn.outline:hover { background: var(--primary-soft); }
.btn.ghost { background: transparent; color: var(--text-sub); border: 1px solid var(--border); }
.btn.ghost:hover { background: #f3f4f6; }
.btn.danger-outline { background: #fff; color: var(--danger); border: 1px solid #fca5a5; }
.btn.danger-outline:hover { background: #fef2f2; }
.btn.icon {
  background: #fff; border: 1px solid var(--border); width: 34px; height: 34px;
  border-radius: 8px; font-size: 18px; line-height: 1; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center;
}
.btn.icon:hover { background: #f3f4f6; }

/* ---------- 登入 ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #eef2ff 0%, #f6f7fb 55%, #fdf4ff 100%);
}
.login-card {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  padding: 40px 36px; width: 100%; max-width: 400px; text-align: center;
}
.login-logo { font-size: 42px; }
.login-card h1 { margin: 8px 0 6px; font-size: 24px; }
.login-sub { color: var(--text-sub); font-size: 13.5px; margin: 0 0 24px; }
.login-card label { display: block; text-align: left; font-size: 13.5px; color: var(--text-sub); margin-bottom: 16px; }
.login-card input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 15px; font-family: inherit;
}
.login-card input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.line-steps {
  text-align: left; font-size: 14px; color: var(--text);
  margin: 18px 0; padding-left: 22px; line-height: 1.7;
}
.line-steps li { margin-bottom: 10px; }
.line-steps code {
  background: #f3f4f6; border-radius: 4px; padding: 1px 5px;
  font-size: 12px; display: inline-block; margin-top: 3px;
}

/* ---------- 版面 ---------- */
.topbar {
  background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 17px; }
.user-area { display: flex; align-items: center; gap: 10px; }
.user-chip {
  background: var(--primary-soft); color: var(--primary-dark);
  border-radius: 999px; padding: 5px 14px; font-size: 13px; font-weight: 600;
}

.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px; padding: 14px 20px 4px;
  max-width: 1200px; margin: 0 auto; width: 100%;
}
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-label { font-size: 18px; font-weight: 700; min-width: 120px; text-align: center; }
.toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.view-toggle {
  display: inline-flex; background: #e9eaf0; border-radius: 8px; padding: 3px;
}
.view-toggle button {
  border: none; background: transparent; padding: 5px 14px; border-radius: 6px;
  font-size: 13.5px; cursor: pointer; color: var(--text-sub); font-family: inherit;
}
.view-toggle button.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.1); font-weight: 600; }

main { max-width: 1200px; margin: 0 auto; padding: 10px 20px 40px; }

/* ---------- 月曆 ---------- */
.weekday-row {
  display: grid; grid-template-columns: repeat(7, 1fr);
  text-align: center; font-size: 12.5px; color: var(--text-sub);
  padding: 8px 0 6px; font-weight: 600;
}
.month-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.day-cell {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  min-height: 96px; padding: 6px; cursor: pointer; overflow: hidden;
  transition: box-shadow .15s;
}
.day-cell:hover { box-shadow: var(--shadow); }
.day-cell.other { background: transparent; border-color: transparent; cursor: default; }
.day-cell .dnum {
  font-size: 12.5px; color: var(--text-sub); font-weight: 600;
  width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
}
.day-cell.today .dnum { background: var(--primary); color: #fff; }
.event-chip {
  border-radius: 6px; padding: 3px 6px; font-size: 11.5px; line-height: 1.35;
  margin-top: 4px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.event-chip .t { opacity: .85; font-size: 10.5px; }
.more-chip { font-size: 11px; color: var(--text-sub); margin-top: 3px; }

/* ---------- 清單 ---------- */
#list-view { display: flex; flex-direction: column; gap: 14px; padding-top: 6px; }
.list-day { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list-day-head {
  padding: 9px 16px; font-size: 13.5px; font-weight: 700;
  background: #fafafa; border-bottom: 1px solid var(--border); color: var(--text-sub);
}
.list-day-head.today-head { background: var(--primary-soft); color: var(--primary-dark); }
.list-item {
  display: flex; align-items: center; gap: 14px; padding: 12px 16px; cursor: pointer;
}
.list-item + .list-item { border-top: 1px solid var(--border); }
.list-item:hover { background: #fafaff; }
.list-bar { width: 4px; align-self: stretch; border-radius: 4px; flex: none; }
.list-time { font-size: 13px; color: var(--text-sub); min-width: 92px; flex: none; }
.list-main { flex: 1; min-width: 0; }
.list-name { font-weight: 600; }
.list-meta { font-size: 12.5px; color: var(--text-sub); margin-top: 2px; }
.empty-note { text-align: center; color: var(--text-sub); padding: 60px 0; }

.tag {
  display: inline-block; font-size: 11px; border-radius: 5px; padding: 1px 6px;
  margin-left: 6px; vertical-align: 1px; font-weight: 600;
}
.tag.req { background: #fee2e2; color: #b91c1c; }
.tag.elective { background: #dbeafe; color: #1d4ed8; }

/* ---------- Modal ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(17,24,39,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow);
  width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
}
.modal.wide { max-width: 680px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 0;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-close {
  border: none; background: transparent; font-size: 26px; line-height: 1;
  color: var(--text-sub); cursor: pointer; padding: 0 4px;
}
.modal-body { padding: 14px 20px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px; padding: 4px 20px 18px;
  flex-wrap: wrap;
}

.detail-rows { display: grid; grid-template-columns: 88px 1fr; gap: 8px 12px; font-size: 14px; }
.detail-rows dt { color: var(--text-sub); }
.detail-rows dd { margin: 0; }

/* ---------- 表單 ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid label { font-size: 13px; color: var(--text-sub); display: block; }
.form-grid input, .form-grid select, textarea {
  display: block; width: 100%; margin-top: 5px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14.5px;
  font-family: inherit; background: #fff; color: var(--text);
}
.form-grid input:focus, .form-grid select:focus, textarea:focus {
  outline: 2px solid var(--primary-soft); border-color: var(--primary);
}
.hint-inline { font-size: 12px; color: #9ca3af; display: block; margin-top: 26px; }
.date-adder { display: flex; gap: 8px; margin-top: 5px; }
.date-adder input { flex: 1; margin-top: 0; }
.date-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.date-chip {
  background: var(--primary-soft); color: var(--primary-dark);
  border-radius: 999px; padding: 4px 10px; font-size: 12.5px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.date-chip button {
  border: none; background: transparent; cursor: pointer; color: var(--primary-dark);
  font-size: 14px; padding: 0; line-height: 1;
}

textarea { resize: vertical; min-height: 120px; }
.hint { font-size: 12.5px; color: var(--text-sub); margin: 0 0 10px; }
.hint code { background: #f3f4f6; border-radius: 4px; padding: 1px 5px; font-size: 12px; }
.batch-year { display: flex; align-items: end; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.batch-year label { font-size: 13px; color: var(--text-sub); }
.batch-year input { width: 110px; margin-top: 5px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14.5px; font-family: inherit; display: block; }
.batch-result { margin-top: 14px; font-size: 13.5px; display: flex; flex-direction: column; gap: 6px; }
.batch-result .ok { color: #15803d; }
.batch-result .fail { color: var(--danger); }
.error { color: var(--danger); font-size: 13px; margin: 4px 0 0; }
.req { color: var(--danger); }

/* ---------- 手機 ---------- */
@media (max-width: 720px) {
  .topbar { padding: 10px 14px; }
  .brand { font-size: 15.5px; }
  .toolbar { padding: 10px 12px 2px; }
  .month-label { font-size: 16px; min-width: 100px; }
  main { padding: 8px 10px 30px; }
  .month-grid { gap: 3px; }
  .day-cell { min-height: 74px; padding: 4px; border-radius: 8px; }
  .event-chip { font-size: 9.5px; padding: 2px 4px; }
  .event-chip .t { display: none; }
  .list-time { min-width: 78px; font-size: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: span 1; }
  .hint-inline { display: none; }
  .modal { max-height: 88vh; }
}
