:root {
  --bg: transparent;
  --card: rgba(255, 255, 255, 0.9);
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #3b82f6;
  --accent-ink: #2563eb;
  --ok: #10b981;
  --danger: #ef4444;
  --scrim: rgba(15, 23, 42, .45);
}

* {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15.5px/1.65 "Inter", "Outfit", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-weight: 500;
  min-width: 0;
}

/* App bar（上方標題列） */
.appbar {
  position: sticky;
  top: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(15, 23, 42, .04)
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand h1 {
  font-size: 18px;
  margin: 0;
}

.brand-badge {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #9cd5ff);
}

.appbar-actions {
  margin-left: auto;
}

/* Layout */
.container {
  max-width: 1200px;
  /* 視覺收斂一點 */
  margin: 20px auto;
  padding: 0 16px;
  min-width: 0;
}

/* Hero 區塊（上面那塊簡介 + 按鈕） */
.hero {
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #ffffff, #f1f5f9);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px 24px;
  box-shadow: 0 8px 30px rgba(15, 23, 42, .03);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.hero:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(15, 23, 42, .06);
}

.hero-text h2 {
  margin: 0 0 6px;
}

.hero-text p {
  margin: 0;
}

.hero-cta .btn {
  min-width: 140px;
}

/* 區塊標題 */
.section-hd {
  margin: 20px 2px 10px;
}

.section-hd h3 {
  margin: 0 0 4px 0;
}

.section-hd .muted {
  margin: 0;
}

/* Card */
.card {
  background: var(--card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(15, 23, 42, .03);
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
  box-shadow: 0 10px 30px rgba(15, 23, 42, .06);
  transform: translateY(-2px);
}

.card-hd {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

.card-bd {
  padding: 20px;
}

/* Grid / Form */
.grid {
  display: grid;
  gap: 24px;
  min-width: 0;
}

.g-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-span-2 {
  grid-column: 1 / -1;
}

@media (max-width:840px) {
  .g-2 {
    grid-template-columns: 1fr;
  }

  .field-span-2 {
    grid-column: auto;
  }
}

.form .field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.lbl {
  display: block;
  margin-bottom: 0; /* Handled by field gap */
  font-weight: 600;
  color: #374151;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.req::after {
  content: " *";
  color: var(--danger);
}

input,
textarea,
select {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: var(--text);
  line-height: 1.4;
  transition: all 0.25s ease;
  min-width: 0;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.combo-box {
  position: relative;
}

.combo-box input {
  padding-right: 52px;
}

.combo-toggle {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.combo-toggle:hover {
  background: #f1f5f9;
  color: var(--accent);
}

.combo-caret {
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
}

.combo-list {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  display: none;
  max-height: 280px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.14);
  z-index: 20;
}

.combo-box.is-open .combo-list {
  display: block;
}

.combo-option {
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.combo-option:hover,
.combo-option.is-active {
  background: #eff6ff;
  color: var(--accent-ink);
}

.combo-empty {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 14px;
}

textarea {
  min-height: 140px;
  resize: vertical;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.row.wrap {
  flex-wrap: wrap;
}

/* ===== 活動時段 (Scheme A: Fixed Add Button Layout) ===== */
.time-slot-inline {
  display: flex;
  gap: 30px;
  align-items: flex-start; /* Fix to top */
  justify-content: flex-start;
  margin-top: 8px;
}

.time-slots {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.time-slot-row {
  display: flex;
  gap: 40px;
  align-items: center;
  background: transparent;
  min-width: 0;
}

.time-slot-date-group {
  flex: 0 0 220px;
}

.time-slot-date-group input[type="date"] {
  width: 100%;
}

.time-slot-time-group {
  flex: 1;
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.time-slot-time-group input[type="time"] {
  flex: 1;
  min-width: 0;
}

.time-slot-sep {
  color: var(--muted);
  font-weight: 500;
  padding: 0 4px;
}

.time-slot-add {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 12px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: #475569;
  font-size: 22px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-top: 0; /* Align with top row */
}

.time-slot-add:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
  color: var(--accent);
}

.btn.slot-remove {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
  color: #94a3b8;
  border: 1px solid transparent;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
}

.btn.slot-remove:hover {
  color: #ef4444;
  background: #fef2f2;
}

@media (max-width: 840px) {
  .time-slot-inline {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }
  .time-slot-row {
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
  }
  .time-slot-date-group, 
  .time-slot-time-group {
    flex: 1 1 100%;
  }
}

.choice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.radio-group input[type="radio"],
.choice input[type="radio"] {
  width: auto;
  min-width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  flex: 0 0 16px;
  transition: none;
  box-shadow: none;
}

.radio-group input[type="radio"]:focus,
.choice input[type="radio"]:focus {
  box-shadow: none;
}

.is-hidden {
  display: none !important;
}

/* Uploader & misc */
.uploader {
  border: 1px dashed #d6dae6;
  border-radius: 12px;
  padding: 12px;
  background: #fbfcff;
}

.file-list {
  margin: 8px 0 0 18px;
  padding-left: 0;
}

.file-list li {
  margin-bottom: 2px;
  min-width: 0;
}

.preview {
  white-space: pre-wrap;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 13px;
}

.note {
  background: #fbfcff;
  border: 1px dashed #e2e8f0;
  border-radius: 12px;
  padding: 8px 12px;
  margin-top: 8px;
}

.actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}

/* Buttons */
.btn {
  border: 1px solid #d6dae6;
  background: #fff;
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  transition: all 0.25s ease;
}

.btn:hover {
  border-color: #94a3b8;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, .05);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-ink));
  border: none;
  color: #fff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, .3);
}

.btn.primary:hover {
  background: linear-gradient(135deg, var(--accent-ink), #1d4ed8);
  box-shadow: 0 6px 16px rgba(59, 130, 246, .4);
  border-color: transparent;
}

/* 訊息 & 輔助文字 */
.msg {
  margin-top: 6px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
}

/* 匯出區 */
.export-actions {
  margin-top: 14px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: #fbfcff;
}

.export-actions .row .btn {
  min-width: 120px;
}

.important-tip {
  margin: 16px 2px 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--danger);
  background: rgba(251, 75, 75, 0.06);
  color: #ff0101;
  font-weight: 600;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.important-tip::before {
  content: "！";
  display: inline-flex;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 2px solid currentColor;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  margin-top: 1px;
}

/* ==== PDF 匯出版面 ==== */
#pdfForm {
  display: none;
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  padding: 12mm 10mm;
  background: #fff;
  color: #111;
  font-family: "Noto Sans TC", system-ui, -apple-system, "Segoe UI", sans-serif;
  box-sizing: border-box;
}

#pdfForm h2 {
  font-size: 18px;
  margin: 0 0 10px 0;
  text-align: center;
  font-weight: 800;
}

#pdfForm table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-top: 10px;
  font-size: 12px;
}

#pdfForm td {
  border: 1px solid #444;
  padding: 8px 10px;
  vertical-align: top;
  word-break: break-word;
}

#pdfForm td.label {
  background: #f1f3f6;
  font-weight: 700;
  width: 20%;
  white-space: nowrap;
}

/* ==== 去框化設計 & 區塊標題 ==== */
.unboxed-form {
  padding: 0 10px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-bottom: 48px;
  min-width: 0;
}

.group-title {
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin: 0; /* Handled by parent gap */
  position: relative;
  padding-left: 14px;
}

.group-title::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 5px;
  height: 22px;
  background-color: var(--accent);
  border-radius: 4px;
}

/* ==== 拖曳上傳區塊 ==== */
.file-drop-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: rgba(248, 250, 252, 0.5);
  padding: 30px 20px;
  text-align: center;
  position: relative;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.file-drop-zone:hover,
.file-drop-zone.drag-active {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.05);
}

.drop-zone-icon {
  color: var(--accent);
  margin-bottom: 4px;
}

.drop-zone-text {
  font-size: 15px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.file-drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* ==== 操作列 ==== */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.btn-large {
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
}

#pdfForm .sign-box {
  height: 58px;
}

.readonly-style {
  background-color: rgba(241, 245, 249, 0.6);
  color: var(--muted);
  cursor: not-allowed;
  border-color: #cbd5e1;
}

.readonly-style:focus {
  outline: none;
  border-color: #cbd5e1;
  box-shadow: none;
}

#pdfForm .relevance-box {
  height: 110px;
}

#pdf_files {
  white-space: pre-wrap;
}

#pdfForm .made-date {
  text-align: right;
  margin-top: 8px;
  font-size: 12px;
}

@media print {
  body {
    background: #fff !important;
  }

  body * {
    visibility: hidden !important;
  }

  #pdfForm,
  #pdfForm * {
    visibility: visible !important;
  }

  #pdfForm {
    display: block !important;
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 210mm !important;
    margin: 0 !important;
  }

  @page {
    size: A4;
    margin: 10mm;
  }

  .appbar {
    display: none !important;
  }
}

/* --- File Upload Success Styles --- */
.file-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-success-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  color: #475569;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13.5px;
  font-weight: 500;
  animation: fileFadeIn 0.2s ease-out forwards;
  width: fit-content;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
  max-width: 100%;
}

.file-success-item svg {
  flex-shrink: 0;
  color: #10b981;
  width: 16px;
  height: 16px;
}

.file-success-item .file-size {
  color: #94a3b8;
  font-size: 12px;
  margin-left: 2px;
  font-weight: 400;
}

.file-success-item > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

@keyframes fileFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.file-remove-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: #94a3b8;
  padding: 4px;
  margin-left: 4px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
}

.file-remove-btn:hover {
  background: #f1f5f9;
  color: #ef4444;
}

.file-remove-btn svg {
  color: currentColor;
  width: 14px !important;
  height: 14px !important;
}

.teacher-form-shell {
  min-width: 0;
}

.field-upload .muted {
  margin: 0;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.form-actions-sticky {
  position: static;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  padding-bottom: 0;
}

@media (max-width: 900px) {
  .container {
    margin: 12px auto 0;
    padding: 0 10px;
  }

  .teacher-form-shell {
    padding-bottom: 8px;
  }

  .section-hd {
    margin: 10px 2px 8px;
  }

  .section-hd h3 {
    font-size: 20px;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }

  .unboxed-form {
    padding: 0 4px;
  }

  .form-group {
    gap: 20px;
    margin-bottom: 36px;
  }

  .group-title {
    font-size: 17px;
    line-height: 1.4;
  }

  .row.radio-group {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 12px 18px;
  }

  .field-upload .file-drop-zone {
    padding: 24px 18px;
  }

  .form-actions {
    margin-top: 32px;
  }

  .form-actions-sticky {
    position: sticky;
    bottom: 0;
    z-index: 15;
    background: linear-gradient(180deg, rgba(248, 250, 252, 0), rgba(248, 250, 252, 0.94) 24px, rgba(248, 250, 252, 0.98) 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 600px) {
  .container {
    padding: 0 2px;
  }

  .section-hd h3 {
    font-size: 18px;
  }

  .form-group {
    gap: 18px;
    margin-bottom: 30px;
  }

  .group-title {
    font-size: 16px;
    padding-left: 12px;
  }

  .group-title::before {
    height: 18px;
  }

  .lbl,
  .muted {
    font-size: 14px;
  }

  input,
  textarea,
  select {
    padding: 13px 14px;
    font-size: 16px;
  }

  .combo-box input {
    padding-right: 48px;
  }

  .combo-toggle {
    right: 8px;
    width: 34px;
    height: 34px;
  }

  .combo-list {
    max-height: min(280px, 45vh);
  }

  .time-slot-inline {
    gap: 14px;
  }

  .time-slot-row {
    gap: 10px;
    padding: 14px;
  }

  .time-slot-time-group {
    flex-wrap: wrap;
    gap: 10px;
  }

  .time-slot-time-group input[type="time"] {
    flex: 1 1 calc(50% - 18px);
  }

  .time-slot-sep {
    flex: 0 0 auto;
  }

  .btn.slot-remove {
    width: 40px;
    height: 40px;
    margin-left: auto;
  }

  .time-slot-add {
    width: 100%;
    height: 46px;
    margin-top: 0;
    border-style: dashed;
  }

  .file-drop-zone {
    padding: 20px 16px;
    border-radius: 14px;
  }

  .drop-zone-text {
    font-size: 14px;
  }

  .file-list {
    gap: 10px;
  }

  .file-success-item {
    width: 100%;
    border-radius: 14px;
    padding: 10px 12px;
  }

  .file-remove-btn {
    margin-left: auto;
    flex-shrink: 0;
  }

  .form-actions {
    flex-direction: column-reverse;
    gap: 10px;
    margin-top: 28px;
    padding-top: 18px;
  }

  .form-actions .btn,
  .form-actions .btn-large {
    width: 100%;
    min-height: 48px;
  }
}

/* ===== 多選下拉（鏈結領域 & SDGs） ===== */
.multi-select {
  position: relative;
}

.ms-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #d6dae6;
  background: #fff;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, background .15s;
}

.ms-trigger:focus {
  outline: none;
  border-color: rgba(59, 130, 246, .65);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, .15);
}

.ms-placeholder {
  color: var(--muted);
}

.ms-value {
  font-weight: 700;
}

.ms-caret {
  margin-left: auto;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 7px solid #6b7280;
}

.multi-select.is-open .ms-caret {
  transform: rotate(180deg);
}

.ms-panel {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  background: #fff;
  border: 1px solid #d6dae6;
  border-radius: 12px;
  padding: 8px 10px;
  max-height: 240px;
  overflow: auto;
  box-shadow: 0 12px 24px rgba(15, 23, 42, .12);
}

.multi-select.is-open .ms-panel {
  display: block;
}

.ms-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}

.ms-option:hover {
  background: #f3f5fb;
}

.ms-option input {
  width: auto;
  margin: 0;
}
