:root {
  --primary: #0b78b6;
  --primary-dark: #075985;
  --primary-soft: #e0f2fe;
  --accent: #2563eb;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f4f7fb;
  --card: rgba(255,255,255,.92);
  --danger: #dc2626;
  --success: #059669;
  --shadow: 0 18px 45px rgba(15,23,42,.10);
  --shadow-sm: 0 10px 25px rgba(15,23,42,.07);
  --radius: 22px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', 'Microsoft JhengHei', Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(14,165,233,.14), transparent 32rem),
    radial-gradient(circle at top right, rgba(37,99,235,.10), transparent 28rem),
    var(--bg);
  color: var(--ink);
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; }
.container { max-width: 1120px; margin: 0 auto; padding: 0 18px; }
.main { padding: 34px 0 64px; }

/* Public header */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255,255,255,.90);
  color: var(--ink);
  padding: 14px 0;
  border-bottom: 1px solid rgba(226,232,240,.9);
  box-shadow: 0 8px 25px rgba(15,23,42,.06);
  backdrop-filter: blur(14px);
}
.header-inner { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.brand-logo { display: inline-flex; align-items: center; transition: transform .22s ease; }
.brand-logo:hover { transform: translateY(-2px); }
.brand-logo img { display: block; max-height: 78px; max-width: min(440px, 66vw); }
.nav { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 15px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(37,99,235,.18);
  transition: transform .18s ease, box-shadow .18s ease, filter .18s ease;
}
.nav a:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(37,99,235,.26); filter: brightness(1.03); }

/* Public hero and cards */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: 30px;
  background: linear-gradient(135deg, #0b78b6 0%, #2563eb 52%, #4338ca 100%);
  color: #fff;
  padding: 38px;
  box-shadow: var(--shadow);
  margin-bottom: 26px;
}
.hero::after {
  content: '';
  position: absolute;
  width: 310px;
  height: 310px;
  right: -120px;
  top: -120px;
  border-radius: 999px;
  background: rgba(255,255,255,.16);
}
.hero h1 { margin: 0 0 10px; font-size: clamp(30px, 5vw, 48px); letter-spacing: .02em; }
.hero p { max-width: 720px; margin: 0; line-height: 1.8; color: rgba(255,255,255,.88); }
.section-title { margin: 0 0 18px; font-size: clamp(26px, 3vw, 38px); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 20px; }
.card {
  background: var(--card);
  border: 1px solid rgba(226,232,240,.95);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  animation: fadeUp .42s ease both;
}
.card h1, .card h2, .card h3 { margin-top: 0; line-height: 1.25; }
.activity-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 270px;
  transition: transform .22s ease, box-shadow .22s ease, border-color .22s ease;
}
.activity-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; right: 0;
  height: 5px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}
.activity-card:hover { transform: translateY(-5px); box-shadow: var(--shadow); border-color: rgba(14,116,144,.28); }
.activity-card .btn { margin-top: auto; align-self: flex-start; }
.meta { color: var(--muted); line-height: 1.85; font-size: 15px; }
.meta-row { display: flex; gap: 8px; align-items: flex-start; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 900;
  background: #dcfce7;
  color: #166534;
}
.badge::before { content: ''; width: 8px; height: 8px; border-radius: 999px; background: currentColor; box-shadow: 0 0 0 5px rgba(22,101,52,.10); }
.badge.closed { background: #fee2e2; color: #991b1b; }
.event-layout { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 22px; align-items: start; }
.event-info { position: sticky; top: 126px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

/* Forms, buttons, tables */
.form { display: grid; gap: 16px; }
.form label { display: block; font-weight: 850; margin-bottom: 6px; }
.input, textarea, select {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  padding: 12px 13px;
  font-size: 16px;
  background: rgba(255,255,255,.95);
  color: var(--ink);
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}
textarea { min-height: 130px; resize: vertical; }
.input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(37,99,235,.13); }
.choice { display:block; margin:.45rem 0; font-weight:600; color: #334155; }
.choice input { margin-right: 7px; transform: translateY(1px); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn {
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 17px;
  min-height: 43px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(37,99,235,.18);
  transition: transform .18s ease, box-shadow .18s ease, filter .18s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(37,99,235,.26); filter: brightness(1.03); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: linear-gradient(135deg, #475569, #334155); }
.btn.danger { background: linear-gradient(135deg, #dc2626, #b91c1c); }
.btn.light { background: #eef2f7; color: #0f172a; box-shadow: none; }
.notice { padding: 14px 16px; border-radius: 16px; margin-bottom: 18px; background: #ecfeff; border: 1px solid #a5f3fc; color: #155e75; }
.notice.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.notice.success { background:#ecfdf5; color:#065f46; border:1px solid #a7f3d0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 18px; overflow: hidden; }
th, td { padding: 13px 15px; border-bottom: 1px solid #e5e7eb; text-align: left; vertical-align: top; white-space: normal; }
th { background: #f1f5f9; font-size: 14px; color: #334155; }
tr:hover td { background: #f8fafc; }
.table-wrap textarea { min-height:72px; }
.table-wrap input.input, .table-wrap select, .table-wrap textarea { width:100%; min-width:150px; }

/* Countdown */
.countdown {
  display: inline-flex;
  align-items: center;
  font-weight: 900;
  color: #b91c1c;
  background: #fff1f2;
  border: 1px solid #fecdd3;
  border-radius: 999px;
  padding: 5px 11px;
  animation: softPulse 1.6s ease-in-out infinite;
}
.countdown.expired { color: #475569; background: #f1f5f9; border-color: #cbd5e1; animation: none; }

/* Admin */
.admin-layout { display: grid; grid-template-columns: 246px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: linear-gradient(180deg, #075985, #0b78b6 58%, #1d4ed8);
  color: #fff;
  padding: 24px 20px;
  box-shadow: 12px 0 35px rgba(15,23,42,.12);
  z-index: 30;
}
.sidebar h1 { font-size: 22px; margin: 0 0 24px; letter-spacing: .03em; }
.sidebar a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 11px 13px;
  border-radius: 14px;
  margin-bottom: 9px;
  background: rgba(255,255,255,.12);
  font-weight: 850;
  transition: background .18s ease, transform .18s ease;
}
.sidebar a:hover { background: rgba(255,255,255,.22); transform: translateX(4px); }
.admin-main { padding: 30px; min-width: 0; }
.admin-topbar { display: none; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { background: #fff; border-radius: 18px; padding: 20px; border: 1px solid #e5e7eb; box-shadow: var(--shadow-sm); }
.stat strong { font-size: 34px; display: block; color: var(--primary-dark); }
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at top, rgba(14,165,233,.16), transparent 36rem), var(--bg);
}
.login-box { max-width: 430px; width: 100%; margin: 0 auto; }
.login-logo { display: block; max-height: 74px; margin: 0 auto 18px; }

/* Footer */
.site-footer {
  margin-top: 28px;
  background: linear-gradient(135deg, #0f172a, #1e293b);
  color: #e5e7eb;
  font-size: 14px;
  line-height: 1.7;
  padding: 20px 0;
}
.site-footer .container { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes softPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,.15); } 50% { box-shadow: 0 0 0 7px rgba(220,38,38,0); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media (max-width: 980px) {
  .event-layout { grid-template-columns: 1fr; }
  .event-info { position: static; }
}
@media (max-width: 760px) {
  .container { padding: 0 14px; }
  .main { padding: 22px 0 48px; }
  .header { position: static; padding: 12px 0; }
  .header-inner { align-items: flex-start; flex-direction: column; }
  .brand-logo img { max-width: 100%; max-height: 70px; }
  .nav { width: 100%; }
  .nav a, .btn { width: 100%; }
  .hero { padding: 26px 20px; border-radius: 24px; }
  .grid { grid-template-columns: 1fr; }
  .card { padding: 20px; border-radius: 20px; }
  .site-footer .container { align-items: flex-start; flex-direction: column; }
  .admin-layout { grid-template-columns: 1fr; }
  .admin-topbar {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 40;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    color: #fff;
    background: linear-gradient(135deg, #075985, #2563eb);
    box-shadow: 0 8px 24px rgba(15,23,42,.15);
  }
  .menu-toggle { border: 0; color: #fff; background: rgba(255,255,255,.16); border-radius: 12px; padding: 9px 12px; font-weight: 900; }
  .sidebar { position: fixed; transform: translateX(-105%); transition: transform .22s ease; width: 250px; height: 100vh; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .admin-main { padding: 20px 14px 34px; }
  th, td { padding: 11px 12px; }
}
@media (max-width: 520px) {
  .meta { font-size: 14px; }
  .input, textarea, select { font-size: 16px; }
  .hero h1 { font-size: 30px; }
}


/* Desktop activity-card nowrap refinement */
@media (min-width: 900px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(430px, 1fr));
  }

  .activity-card h2,
  .activity-card h3 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.18;
  }

  .activity-card .meta {
    font-size: 15px;
  }

  .activity-card .meta-row {
    display: grid;
    grid-template-columns: 62px minmax(0, 1fr);
    align-items: start;
    gap: 10px;
  }

  .activity-card .meta-row strong {
    white-space: nowrap;
  }

  .activity-card .meta-row span {
    min-width: 0;
  }

  .activity-card .meta-row span,
  .event-info .meta-row span {
    white-space: nowrap;
  }

  .event-info .meta-row {
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr);
    gap: 12px;
  }

  .event-info .meta-row strong {
    white-space: nowrap;
  }
}

/* Medium desktop: keep event title cleaner while avoiding huge cards */
@media (min-width: 900px) and (max-width: 1180px) {
  .activity-card h2,
  .activity-card h3 {
    font-size: clamp(25px, 2.5vw, 34px);
  }
}

/* Mobile remains readable and may wrap naturally */
@media (max-width: 899px) {
  .activity-card h2,
  .activity-card h3 {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .activity-card .meta-row,
  .event-info .meta-row {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr);
    gap: 8px;
  }
}


/* Desktop home layout density refinement */
@media (min-width: 1200px) {
  .container {
    max-width: 1280px;
  }

  .hero {
    max-width: none;
  }

  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
  }

  .activity-card {
    min-height: 500px;
  }

  .activity-card h2,
  .activity-card h3 {
    font-size: clamp(22px, 1.35vw, 28px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .activity-card .meta-row {
    grid-template-columns: 52px minmax(0, 1fr);
  }

  .activity-card .meta-row span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .activity-card p {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

@media (min-width: 1600px) {
  .container {
    max-width: 1400px;
  }

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

/* Keep two columns on medium desktop without making cards too narrow */
@media (min-width: 900px) and (max-width: 1199px) {
  .container {
    max-width: 1040px;
  }

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


/* Admin event create/edit compact form layout */
.admin-event-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 22px;
}

.admin-event-form .full {
  grid-column: 1 / -1;
}

.admin-event-form label {
  display: block;
  margin-bottom: 7px;
  font-weight: 900;
  color: #334155;
}

.admin-event-form input,
.admin-event-form textarea,
.admin-event-form select {
  width: 100%;
}

.admin-event-form textarea {
  min-height: 128px;
  resize: vertical;
}

.admin-event-form .actions {
  margin-top: 6px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

@media (min-width: 1200px) {
  .admin-event-form {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .admin-event-form .full {
    grid-column: 1 / -1;
  }

  .admin-event-form .actions.full {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .admin-event-form {
    grid-template-columns: 1fr;
  }
}

/* Public target audience badge-like row */
.activity-card .meta-row strong,
.event-info .meta-row strong {
  white-space: nowrap;
}


/* Restore public activity cover images */
.activity-cover {
  margin: -24px -24px 18px;
  height: 210px;
  overflow: hidden;
  border-radius: var(--radius) var(--radius) 0 0;
  background: #e2e8f0;
}

.activity-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Cards with images need slightly tighter content spacing */
.activity-card .activity-cover + .badge {
  margin-top: 0;
}

@media (min-width: 1200px) {
  .activity-cover {
    height: 190px;
  }

  .activity-card {
    min-height: 560px;
  }
}

@media (max-width: 899px) {
  .activity-cover {
    margin: -24px -24px 18px;
    height: 210px;
  }
}


/* Success page restored layout */
.success-card {
  max-width: 980px;
  margin: 0 auto;
  padding: 34px;
}

.success-card h1 {
  margin: 0 0 12px;
  font-size: clamp(28px, 3vw, 42px);
}

.success-card > .meta {
  margin: 0 0 24px;
  color: var(--muted);
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.summary-grid > div {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(248,250,252,.85);
}

.summary-grid strong {
  color: #475569;
  font-weight: 1000;
  white-space: nowrap;
}

.summary-grid span {
  color: var(--ink);
  font-weight: 800;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.qr-box {
  margin-top: 24px;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 22px;
  align-items: center;
  padding: 22px;
  border-radius: 22px;
  background: linear-gradient(135deg, #eff6ff, #f8fafc);
  border: 1px solid #dbeafe;
}

.qr-box img {
  width: 220px;
  height: 220px;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
}

.qr-box strong {
  display: block;
  color: #1e3a8a;
  font-size: 1.2rem;
  margin-bottom: 6px;
}

.qr-box span {
  color: #64748b;
  font-weight: 700;
  line-height: 1.6;
}

.success-card .actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

@media (max-width: 760px) {
  .success-card {
    padding: 22px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .summary-grid > div {
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .qr-box {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .qr-box img {
    width: 190px;
    height: 190px;
  }
}


/* Success summary overlap fix */
.summary-grid > div {
  grid-template-columns: minmax(150px, 34%) minmax(0, 1fr);
  align-items: start;
}

.summary-grid strong {
  white-space: normal;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

.summary-grid span {
  min-width: 0;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (max-width: 900px) {
  .summary-grid > div {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}


/* Public form inline validation */
.field-error {
  display: none;
  color: #dc2626;
  font-size: 13px;
  font-weight: 900;
  margin: 0 0 6px;
  line-height: 1.45;
}

.input-error,
.public-register-form .input-error,
.public-register-form input.input-error,
.public-register-form textarea.input-error,
.public-register-form select.input-error {
  border-color: #dc2626 !important;
  box-shadow: 0 0 0 3px rgba(220,38,38,.12) !important;
}

.public-register-form .field-wrap {
  min-width: 0;
}


/* Public form server-side inline error banner */
.form-error-banner {
  display: none;
  color: #dc2626;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.5;
  margin: 0 0 14px;
}

.public-register-form button[disabled] {
  opacity: .7;
  cursor: wait;
}

/* Manual admission action buttons */
.registration-table td.actions form,
table td.actions form {
  display: inline-block;
  margin: 2px 3px 2px 0;
}


/* Manual admission pending review status */
.status-pill.pending-review {
  background: #eef2ff;
  color: #3730a3;
}



/* Phase 44: render rich activity description on frontend */
.activity-rich-description{
  line-height:1.85;
  color:#0f172a;
  word-break:break-word;
}
.activity-rich-description p,
.activity-rich-description div{
  margin:0 0 14px;
}
.activity-rich-description h2,
.activity-rich-description h3,
.activity-rich-description h4{
  margin:18px 0 10px;
  line-height:1.35;
  color:#0f2f6f;
}
.activity-rich-description h2{font-size:1.55em;}
.activity-rich-description h3{font-size:1.35em;}
.activity-rich-description h4{font-size:1.18em;}
.activity-rich-description ul,
.activity-rich-description ol{
  margin:10px 0 14px 1.4em;
  padding:0;
}
.activity-rich-description li{
  margin:5px 0;
}
.activity-rich-description blockquote{
  margin:14px 0;
  padding:12px 16px;
  border-left:4px solid #60a5fa;
  border-radius:12px;
  background:#eff6ff;
  color:#1e3a8a;
}
.activity-rich-description span[style*="font-size"],
.activity-rich-description .rich-custom-font-size{
  line-height:1.35;
}



/* Phase 60: frontend rich color rendering */
.activity-rich-description .rich-force-style,
.activity-rich-description span[style*="font-family"],
.activity-rich-description span[style*="font-size"],
.activity-rich-description span[style*="color"]{
  display:inline !important;
  line-height:1.35 !important;
}



/* Phase 61: frontend rich text color/font rendering */
.activity-rich-description .rich-force-style,
.activity-rich-description span[style*="font-family"],
.activity-rich-description span[style*="font-size"],
.activity-rich-description span[style*="color"]{
  display:inline !important;
  line-height:1.35 !important;
}



/* Phase 62: frontend rich text font/color rendering */
.activity-rich-description .rich-force-style,
.activity-rich-description span[style*="font-family"],
.activity-rich-description span[style*="font-size"],
.activity-rich-description span[style*="color"]{display:inline!important;line-height:1.35!important}



/* Phase 64: frontend rich text style rendering */
.activity-rich-description .rich-force-style,
.activity-rich-description span[style*="font-family"],
.activity-rich-description span[style*="font-size"],
.activity-rich-description span[style*="color"]{
  display:inline !important;
  line-height:1.35 !important;
}



/* Phase 70: frontend status badge colors */
.status-pill.status-waitlist,
.activity-status.status-waitlist,
.badge.status-waitlist{
  background:#fff3d6 !important;
  color:#b45309 !important;
  border-color:#fed7aa !important;
  box-shadow:0 10px 24px rgba(245,158,11,.18) !important;
}

.status-pill.status-waitlist::before,
.activity-status.status-waitlist::before,
.badge.status-waitlist::before{
  background:#f59e0b !important;
}

.status-pill.status-upcoming,
.activity-status.status-upcoming,
.badge.status-upcoming{
  background:#dbeafe !important;
  color:#1d4ed8 !important;
  border-color:#bfdbfe !important;
  box-shadow:0 10px 24px rgba(37,99,235,.16) !important;
}

.status-pill.status-upcoming::before,
.activity-status.status-upcoming::before,
.badge.status-upcoming::before{
  background:#2563eb !important;
}
