:root {
  --ink: #172026;
  --muted: #687783;
  --line: #d7dee4;
  --soft: #f4f7f8;
  --panel: #fff;
  --blue: #2d6cdf;
  --blue-dark: #1f55b8;
  --blue-soft: #e7eefc;
  --green: #2f8f5b;
  --green-soft: #dff3e7;
  --red: #c94d42;
  --red-soft: #fae8e6;
  --yellow: #9a6700;
  --yellow-soft: #fff1c9;
  --shadow: 0 12px 32px rgba(23, 32, 38, .07);
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--soft);
  font-family: "Microsoft JhengHei", "Noto Sans TC", Arial, sans-serif;
  line-height: 1.55;
}
body.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef3f6;
}
.auth-card {
  width: min(440px, 100%);
  padding: 30px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 8px; font-size: 25px; }
.auth-card p { margin: 0 0 22px; color: var(--muted); }
.auth-form { display: grid; gap: 14px; }
.auth-form .field + .field { margin-top: 0; }
.auth-form .btn { width: 100%; }
.auth-link {
  color: var(--blue);
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 28px;
  color: #fff;
  background: #172026;
  border-bottom: 1px solid #2b363d;
}
.brand {
  display: flex;
  gap: 11px;
  align-items: center;
  min-width: max-content;
  font-weight: 800;
  text-decoration: none;
}
.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: #172026;
  background: #fff;
  border-radius: 6px;
}
.brand-mark svg { width: 19px; }
.schedule-chip {
  margin-left: auto;
  color: #d8e0e5;
  font-size: 13px;
}
.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.topbar-actions a,
.topbar-actions button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid #495861;
  border-radius: 6px;
  color: #e7edf1;
  background: transparent;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}
.topbar-actions a:hover,
.topbar-actions button:hover { background: #25313a; }
.menu-button {
  display: none;
  width: 38px;
  height: 38px;
  border: 0;
  color: #fff;
  background: transparent;
}

.workspace { display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  padding: 20px 14px;
  background: #fff;
  border-right: 1px solid var(--line);
}
.nav-label {
  margin: 2px 12px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.nav {
  display: grid;
  gap: 4px;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 42px;
  padding: 0 12px;
  color: #45535c;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}
.nav a:hover { background: var(--soft); }
.nav a.active { color: var(--blue); background: var(--blue-soft); }
.nav svg { width: 18px; height: 18px; flex: 0 0 auto; }

.main { min-width: 0; padding: 28px; }
.page-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin: 0 auto 20px;
  max-width: 1180px;
}
.page-header h1 { margin: 0 0 4px; font-size: 25px; letter-spacing: 0; }
.page-header p { margin: 0; color: var(--muted); font-size: 14px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.content { max-width: 1180px; margin: 0 auto; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: minmax(280px, .8fr) minmax(0, 1.2fr); }
.grid-sidebar { grid-template-columns: 220px minmax(0, 1fr); }

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  min-height: 58px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 17px; letter-spacing: 0; }
.panel-head p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.panel-body { padding: 18px; }

.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: #f8fafb; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { color: #fff; background: var(--blue); border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-green { color: #fff; background: var(--green); border-color: var(--green); }
.btn-danger { color: var(--red); border-color: #efc9c5; background: #fff; }
.btn-icon { width: 38px; padding: 0; }
.btn svg { width: 17px; height: 17px; }

.field { display: grid; gap: 7px; }
.field + .field { margin-top: 14px; }
.field label, .label { font-size: 13px; font-weight: 800; }
.field small { color: var(--muted); }
.input, .select, .textarea {
  width: 100%;
  min-height: 42px;
  padding: 8px 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #bcc8d0;
  border-radius: 6px;
  outline: none;
}
.textarea { min-height: 82px; resize: vertical; }
.textarea-tall { min-height: 120px; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(45, 108, 223, .13);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check-row { display: flex; gap: 9px; align-items: center; color: #45535c; font-size: 14px; }
.check-row input { width: 18px; height: 18px; accent-color: var(--blue); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.form-actions .import-result {
  margin-right: auto;
  align-self: center;
  color: var(--muted);
  font-size: 13px;
}
.import-panel { margin-bottom: 18px; }
.import-form { display: grid; gap: 14px; }
.import-form .field + .field { margin-top: 0; }
.checkbox-grid.compact {
  max-height: 138px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
.word-preview {
  margin-top: 16px;
  display: grid;
  gap: 14px;
}
.word-preview-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.word-preview-grid > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}
.word-preview h3 {
  margin: 0 0 8px;
  font-size: 16px;
}
.word-preview ul {
  margin: 0;
  padding-left: 20px;
}
.word-month-note pre {
  white-space: pre-wrap;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}
.people-grid { align-items: start; }

.stepper {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-bottom: 20px;
}
.step {
  min-width: 0;
  padding: 9px 8px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: center;
  text-decoration: none;
  font-size: 12px;
  font-weight: 800;
}
.step.active { color: var(--blue); border-color: #9fb9ec; background: var(--blue-soft); }
.step.done { color: var(--green); border-color: #abd8bd; background: var(--green-soft); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat { padding: 15px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.stat strong { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; }

.list { display: grid; gap: 8px; }
.list-item {
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: left;
  cursor: pointer;
}
.list-item:hover, .list-item.active { border-color: #9fb9ec; background: var(--blue-soft); }
.list-item.activity { border-color: #abd8bd; background: var(--green-soft); }
.list-item strong { display: block; font-size: 14px; }
.list-item small { display: block; color: var(--muted); margin-top: 2px; }

.filters { display: grid; gap: 7px; }
.filter-button {
  min-height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: #45535c;
  background: transparent;
  text-align: left;
  font-weight: 700;
  cursor: pointer;
}
.filter-button:hover { background: var(--soft); }
.filter-button.active { color: var(--blue); background: var(--blue-soft); }

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.search-field { flex: 1; max-width: 420px; }
.toolbar small { color: var(--muted); white-space: nowrap; }
.review-filters {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 180px auto;
  gap: 12px;
  align-items: end;
  border-bottom: 1px solid var(--line);
}
.review-filters .field + .field { margin-top: 0; }
.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}
.pagination-pages { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; }
.btn-page { min-width: 36px; padding-inline: 10px; }
.btn-page.active { color: var(--blue); border-color: #9fb9ec; background: var(--blue-soft); }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  padding: 10px 11px;
  color: var(--muted);
  background: #f8fafb;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 12px;
  white-space: nowrap;
}
td { padding: 11px; border-bottom: 1px solid #e8edef; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfd; }
tr.activity td { background: var(--green-soft); }
tr.error td { background: var(--red-soft); }
tr.warning td { background: var(--yellow-soft); }
.table-select { min-width: 128px; min-height: 36px; padding: 5px 8px; border: 1px solid #bcc8d0; border-radius: 5px; background: #fff; }
.table-static { min-width: 128px; min-height: 36px; padding: 7px 10px; border: 1px solid #abd8bd; border-radius: 5px; background: #fff; color: #1d6e45; display: inline-flex; align-items: center; }
.table-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 2px 9px;
  border-radius: 999px;
  color: #45535c;
  background: #edf1f3;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.badge-blue { color: var(--blue); background: var(--blue-soft); }
.badge-green { color: #1d6e45; background: var(--green-soft); }
.badge-red { color: var(--red); background: var(--red-soft); }
.badge-yellow { color: var(--yellow); background: var(--yellow-soft); }

.empty { padding: 42px 18px; color: var(--muted); text-align: center; }
.empty svg { width: 38px; margin-bottom: 10px; color: #9aa7b1; }
.hint {
  padding: 12px 14px;
  color: #45535c;
  background: var(--blue-soft);
  border-left: 3px solid var(--blue);
  border-radius: 4px;
  font-size: 13px;
}
.hint-green { background: var(--green-soft); border-color: var(--green); }
.hint-yellow { background: var(--yellow-soft); border-color: var(--yellow); }
.hint-red { background: var(--red-soft); border-color: var(--red); }
.rule-list { display: grid; gap: 10px; }
.rule {
  display: flex;
  gap: 11px;
  align-items: start;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.rule-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--green);
  background: var(--green-soft);
  border-radius: 50%;
  font-weight: 900;
}
.rule strong { display: block; font-size: 14px; }
.rule small { color: var(--muted); }

.activity-card, .issue-card {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.activity-card { border-color: #abd8bd; background: var(--green-soft); }
.issue-card.error { border-color: #efc9c5; background: var(--red-soft); }
.issue-card.warning { border-color: #ebd18d; background: var(--yellow-soft); }
.issue-card.info { border-color: #b9c9ee; background: var(--blue-soft); }
.issue-card + .issue-card, .activity-card + .activity-card { margin-top: 8px; }
.issue-card strong, .activity-card strong { display: block; font-size: 13px; }
.issue-card small, .activity-card small { color: #56636c; }

.calendar-preview { display: grid; gap: 8px; }
.date-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  min-height: 46px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
.date-row.activity { color: #1d6e45; border-color: #abd8bd; background: var(--green-soft); }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  max-width: min(380px, calc(100% - 44px));
  padding: 12px 16px;
  color: #fff;
  background: #172026;
  border-radius: 6px;
  box-shadow: 0 14px 34px rgba(0,0,0,.22);
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--red); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(23, 32, 38, .48);
}
.modal.open { display: grid; }
.dialog {
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(0,0,0,.22);
}
.dialog-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-body { padding: 18px; }
.checkbox-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.line-message {
  padding: 13px 15px;
  margin-bottom: 10px;
  color: #26343c;
  background: #eef8e8;
  border: 1px solid #c8e5bd;
  border-radius: 8px;
  white-space: pre-line;
}
.excel-preview { border: 1px solid var(--line); }
.excel-preview td, .excel-preview th { border: 1px solid var(--line); }
.excel-preview th { color: #fff; background: var(--blue); }

.loading { opacity: .55; pointer-events: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  .topbar { padding: 0 16px; }
  .menu-button { display: grid; place-items: center; order: -1; }
  .workspace { display: block; }
  .sidebar {
    position: fixed;
    top: 64px;
    left: 0;
    z-index: 30;
    width: 240px;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 12px 0 30px rgba(23,32,38,.16);
  }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 22px 16px; }
  .grid-2, .grid-sidebar { grid-template-columns: 1fr; }
  .word-preview-grid { grid-template-columns: 1fr; }
  .stepper { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 620px) {
  .brand span:last-child { display: none; }
  .schedule-chip { font-size: 12px; }
  .page-header { align-items: start; }
  .page-header, .page-actions { flex-direction: column; }
  .page-actions, .page-actions .btn { width: 100%; }
  .form-row, .stats { grid-template-columns: 1fr; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .import-result { width: 100%; }
  .review-filters { grid-template-columns: 1fr; }
  .stepper { grid-template-columns: repeat(2, 1fr); }
  .checkbox-grid { grid-template-columns: 1fr; }
}
