/* ============== Base ============== */
:root {
  --brand: #05c7a0;          /* Hahow 風 mint */
  --brand-dark: #04a687;
  --brand-soft: #e6faf5;
  --accent: #ff8f4c;
  --ink: #1d2a32;
  --ink-2: #3c4b55;
  --muted: #6b7884;
  --line: #e9edf1;
  --bg: #f7f9fb;
  --card: #ffffff;
  --danger: #e55353;
  --warn: #f5a524;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.05);
  --shadow-md: 0 8px 24px rgba(16,24,40,.08);
  --shadow-lg: 0 20px 48px rgba(16,24,40,.14);
  --r: 14px;
  --r-sm: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--brand-dark); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--brand); }
img { max-width: 100%; display: block; }
h1,h2,h3,h4 { color: var(--ink); letter-spacing: .01em; }
h2 { font-size: 26px; margin: 0 0 18px; }
h3 { font-size: 17px; margin: 0 0 8px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* ============== Header ============== */
.header {
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(1.6) blur(10px);
  -webkit-backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 14px 28px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.header .brand {
  font-size: 20px; font-weight: 800; color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}
.header .brand::before {
  content: ""; width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), #00a3ff);
  box-shadow: 0 4px 12px rgba(5,199,160,.35);
}
.header .nav { display: flex; align-items: center; gap: 6px; }
.header .nav a {
  color: var(--ink-2); padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.header .nav a:hover { background: var(--brand-soft); color: var(--brand-dark); }
.header .nav a.cta {
  background: var(--ink); color: #fff;
}
.header .nav a.cta:hover { background: var(--brand-dark); }

/* --- user menu dropdown --- */
.user-menu { position: relative; }
.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 14px 5px 5px; border-radius: 999px;
  background: #fff; border: 1px solid var(--line); color: var(--ink);
  cursor: pointer; font-size: 14px; font-weight: 500; font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.user-chip:hover { border-color: #c8d3dc; box-shadow: 0 2px 8px rgba(16,24,40,.06); background: #fafcfe; }
.user-chip[aria-expanded="true"] { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(5,199,160,.12); }
.user-chip .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), #00a3ff);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.user-chip .uname { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .caret { color: var(--muted); font-size: 10px; transition: transform .2s ease; }
.user-chip[aria-expanded="true"] .caret { transform: rotate(180deg); }
.user-chip .mini-badge {
  font-size: 10px; padding: 2px 6px; border-radius: 999px;
  background: #fff4d8; color: #8a5a00; font-weight: 700; letter-spacing: .04em;
}

.user-dropdown {
  position: absolute; top: calc(100% + 10px); right: 0;
  min-width: 240px; background: #fff;
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 8px; z-index: 100;
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: opacity .18s ease, transform .18s ease, visibility .18s ease;
}
.user-menu.open .user-dropdown {
  opacity: 1; visibility: visible; transform: translateY(0);
}
.user-dropdown-head {
  padding: 10px 12px 12px; border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}
.user-dropdown-head .uname-lg { font-weight: 700; color: var(--ink); }
.user-dropdown-head .uemail { font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-all; }
.user-dropdown a {
  display: flex !important; align-items: center; gap: 10px;
  padding: 10px 12px !important; border-radius: 8px !important;
  color: var(--ink) !important; font-size: 14px;
  background: transparent !important;
  margin: 0 !important;
}
.user-dropdown a:hover { background: var(--brand-soft) !important; color: var(--brand-dark) !important; text-decoration: none; }
.user-dropdown a.danger { color: #b11e1e !important; }
.user-dropdown a.danger:hover { background: #fdecec !important; color: #b11e1e !important; }
.user-dropdown-sep { height: 1px; background: var(--line); margin: 6px 4px; }

/* ============== Hero ============== */
.hero {
  background:
    radial-gradient(900px 400px at 85% -20%, rgba(5,199,160,.25), transparent 60%),
    radial-gradient(800px 340px at 10% 0%, rgba(0,163,255,.18), transparent 60%),
    linear-gradient(180deg, #ffffff, var(--bg));
  padding: 56px 28px 48px;
  border-bottom: 1px solid var(--line);
}
.hero-inner { max-width: 1100px; margin: 0 auto; }
.hero h1 {
  font-size: clamp(28px, 4vw, 42px); line-height: 1.25; margin: 0 0 12px;
  font-weight: 800; letter-spacing: .01em;
}
.hero h1 .grad {
  background: linear-gradient(90deg, var(--brand), #00a3ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { color: var(--muted); font-size: 16px; max-width: 640px; margin: 0 0 20px; }
.hero .chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: #fff; border: 1px solid var(--line); color: var(--ink-2);
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }

/* ============== Container ============== */
.container { max-width: 1100px; margin: 32px auto; padding: 0 20px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; }
.section-title small { color: var(--muted); font-size: 13px; }

/* ============== Flash ============== */
.flash {
  padding: 12px 16px; border-radius: var(--r-sm); margin-bottom: 14px;
  font-size: 14px; border: 1px solid transparent;
  animation: slideDown .3s ease;
}
.flash.ok  { background: #e9fbf5; color: #0a7d5b; border-color: #b8ecd8; }
.flash.err { background: #fdecec; color: #b11e1e; border-color: #f4c2c2; }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============== Grid & Cards ============== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 20px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: transform .25s cubic-bezier(.2,.7,.3,1), box-shadow .25s ease, border-color .2s ease;
  position: relative;
  overflow: hidden;
}
.card.clickable:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: #d8eae3;
}
.card.course-card { padding: 0; display: flex; flex-direction: column; }
.card.course-card .cover {
  aspect-ratio: 16/9;
  background: linear-gradient(135deg, var(--brand) 0%, #00a3ff 60%, #8f7bff 100%);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,.9); font-size: 40px; font-weight: 800; letter-spacing: .05em;
  position: relative; overflow: hidden;
}
.card.course-card .cover img { width: 100%; height: 100%; object-fit: cover; }
.card.course-card .cover::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0) 55%, rgba(0,0,0,.25) 100%);
}
.card.course-card .body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card.course-card h3 a { color: var(--ink); }
.card.course-card h3 a:hover { color: var(--brand-dark); }
.card.course-card .foot {
  margin-top: auto; padding-top: 12px; border-top: 1px dashed var(--line);
  display: flex; justify-content: space-between; align-items: center;
  color: var(--muted); font-size: 13px;
}

.meta { color: var(--muted); font-size: 13px; margin: 2px 0; display: flex; align-items: center; gap: 6px; }
.meta .ico { opacity: .8; }

/* ============== Badges ============== */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  margin-right: 4px; letter-spacing: .02em;
}
.badge.hci      { background: #fff4d8; color: #8a5a00; }
.badge.course   { background: var(--brand-soft); color: var(--brand-dark); }
.badge.activity { background: #eaf2ff; color: #1760d6; }
.badge.closed   { background: #eef0f2; color: #6b7884; }
.badge.signed   { background: #e4f8ef; color: #0a7d5b; }

/* ============== Buttons ============== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; background: var(--brand); color: #fff; border: 0; border-radius: 999px;
  cursor: pointer; font-size: 14px; font-weight: 600; letter-spacing: .02em;
  transition: transform .12s ease, box-shadow .2s ease, background .15s ease;
  box-shadow: 0 4px 12px rgba(5,199,160,.25);
}
.btn:hover { background: var(--brand-dark); color: #fff; text-decoration: none; transform: translateY(-1px); box-shadow: 0 6px 16px rgba(5,199,160,.35); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: #1d2a32; box-shadow: 0 4px 12px rgba(29,42,50,.25); }
.btn.secondary:hover { background: #000; }
.btn.danger    { background: var(--danger); box-shadow: 0 4px 12px rgba(229,83,83,.25); }
.btn.danger:hover { background: #c43535; }
.btn.ghost     { background: transparent; color: var(--ink); border: 1px solid var(--line); box-shadow: none; }
.btn.ghost:hover { background: #f1f4f7; color: var(--ink); border-color: #d6dde4; }
.btn.accent    { background: #ffb300; color: #3b2600; box-shadow: 0 4px 12px rgba(255,179,0,.35); }
.btn.accent:hover { background: #ffa600; color: #2e1d00; }
.btn.block { display: flex; width: 100%; }
.btn.lg { padding: 12px 22px; font-size: 15px; }

/* ============== Tables ============== */
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 12px 14px; text-align: left; font-size: 14px; vertical-align: middle; border-bottom: 1px solid var(--line); }
th { background: #f7fafc; color: var(--ink-2); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #fafcfe; }

/* ============== Forms ============== */
.form {
  background: #fff; padding: 24px;
  border-radius: var(--r); border: 1px solid var(--line);
  max-width: 760px; box-shadow: var(--shadow-sm);
}
.form h3 { margin-top: 0; }
.form label { display: block; margin-top: 12px; font-weight: 600; font-size: 13px; color: var(--ink-2); }
.form input[type=text], .form input[type=email], .form input[type=password],
.form input[type=date], .form input[type=time], .form input[type=number],
.form select, .form textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #d5dde4; border-radius: 10px;
  font-size: 14px; margin-top: 6px; font-family: inherit; background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(5,199,160,.15);
}
.form textarea { min-height: 120px; resize: vertical; }
.form .row { display: flex; gap: 14px; flex-wrap: wrap; }
.form .row > * { flex: 1; min-width: 160px; }

/* ============== Login box ============== */
.login-box {
  max-width: 440px; margin: 64px auto;
  background: #fff; padding: 32px;
  border-radius: var(--r); border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  animation: fadeUp .35s ease;
}
.login-box h2 { margin-top: 0; text-align: center; }
.login-box p.sub { color: var(--muted); text-align: center; margin-top: -6px; margin-bottom: 20px; font-size: 14px; }
.divider {
  height: 1px; background: var(--line); margin: 22px 0; position: relative; text-align: center;
}
.divider span {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  background: #fff; color: var(--muted); padding: 0 10px; font-size: 12px;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============== Detail page ============== */
.detail {
  display: grid; grid-template-columns: 1.6fr 1fr; gap: 28px;
}
@media (max-width: 860px) { .detail { grid-template-columns: 1fr; } }
.detail .lead {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden;
}
.detail .lead .cover {
  aspect-ratio: 21/9;
  background: linear-gradient(135deg, var(--brand), #00a3ff 60%, #8f7bff);
  color: #fff; display: flex; align-items: flex-end; padding: 24px;
  font-size: 28px; font-weight: 800;
}
.detail .lead .body { padding: 24px; }
.detail .side {
  position: sticky; top: 90px; align-self: start;
  background: #fff; border: 1px solid var(--line); border-radius: var(--r);
  padding: 22px; box-shadow: var(--shadow-sm);
}
.detail .side .price { font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.detail .side .meta { font-size: 14px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.detail .side .meta:last-of-type { border-bottom: 0; }

/* ============== Content (HTML from admin) ============== */
.rte { font-size: 15px; color: var(--ink-2); line-height: 1.9; }
.rte p { margin: 0 0 12px; }
.rte h4 { margin: 18px 0 8px; }

/* ============== Admin layout ============== */
.admin-layout { display: flex; min-height: 100vh; }
.admin-side {
  width: 236px; background: #0f172a; color: #cbd5e1; padding: 22px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.admin-side .brand {
  color: #fff; font-weight: 800; font-size: 16px; padding: 0 10px 14px;
  border-bottom: 1px solid #1e293b; margin-bottom: 12px; display: flex; gap: 8px; align-items: center;
}
.admin-side .brand::before {
  content: ""; width: 24px; height: 24px; border-radius: 6px;
  background: linear-gradient(135deg, var(--brand), #00a3ff);
}
.admin-side a {
  display: flex; align-items: center; gap: 10px;
  color: #cbd5e1; padding: 10px 12px; border-radius: 10px; margin-bottom: 4px;
  font-size: 14px; transition: background .15s ease, color .15s ease, transform .15s ease;
}
.admin-side a:hover { background: #1e293b; color: #fff; text-decoration: none; }
.admin-side a.active {
  background: linear-gradient(135deg, rgba(5,199,160,.2), rgba(0,163,255,.2));
  color: #fff;
}
.admin-side .foot { margin-top: 20px; padding: 12px 10px 0; border-top: 1px solid #1e293b; }
.admin-side .foot .who { color: #94a3b8; font-size: 12px; margin-bottom: 6px; }

.admin-main { flex: 1; padding: 28px 32px; background: var(--bg); min-width: 0; }
.admin-main h2 { display: flex; align-items: center; gap: 10px; }

/* ============== Stat cards ============== */
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r);
  padding: 18px 20px; display: flex; flex-direction: column; gap: 4px;
  box-shadow: var(--shadow-sm);
  transition: transform .2s ease, box-shadow .2s ease;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .num { font-size: 28px; font-weight: 800; color: var(--ink); }
.stat .sub { color: var(--muted); font-size: 12px; }
.stat.brand  { background: linear-gradient(135deg, var(--brand-soft), #fff); }
.stat.accent { background: linear-gradient(135deg, #fff3e6, #fff); }

/* ============== Utilities ============== */
.center { text-align: center; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.row-gap { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.footer-bar { text-align: center; padding: 28px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); background: #fff; margin-top: 40px; }

/* ============== Reveal animation ============== */
.reveal { opacity: 0; transform: translateY(12px); transition: opacity .5s ease, transform .5s ease; }
.reveal.in { opacity: 1; transform: translateY(0); }

/* ============== Skeleton / empty ============== */
.empty {
  text-align: center; padding: 48px 20px; color: var(--muted);
  border: 1px dashed var(--line); border-radius: var(--r); background: #fff;
}
.empty .big { font-size: 48px; opacity: .5; margin-bottom: 8px; }

/* ============== RWD：手機與平板（Hahow 風） ============== */

/* 平板 (≤1024px) */
@media (max-width: 1024px) {
  .container { padding: 0 18px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 18px; }
  .admin-side { width: 200px; }
  .admin-main { padding: 22px 22px; }
}

/* 手機 (≤768px) */
@media (max-width: 768px) {
  body { line-height: 1.6; }
  h2 { font-size: 22px; }
  h3 { font-size: 16px; }

  /* Header：縮小+垂直排列 */
  .header { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .header .brand { font-size: 16px; }
  .header .brand::before { width: 22px; height: 22px; }
  .header .nav { gap: 2px; }
  .header .nav a { padding: 6px 10px; font-size: 13px; }
  .header .nav a.cta { padding: 8px 14px; }

  /* User chip 收合：手機只顯示頭像 */
  .user-chip .uname { display: none; }
  .user-chip .mini-badge { display: none; }
  .user-dropdown { right: 0; left: auto; min-width: 220px; }

  /* Hero：字級縮小、padding 縮小 */
  .hero { padding: 28px 0 18px; }
  .hero-inner { padding: 0 18px; }
  .hero h1 { font-size: 28px; line-height: 1.3; }
  .hero p { font-size: 14px; }
  .chips { gap: 6px; }
  .chip { font-size: 12px; padding: 4px 10px; }

  /* Grid 卡片：單欄 */
  .grid { grid-template-columns: 1fr; gap: 14px; }
  .card .cover { aspect-ratio: 16/9; }

  /* Section title */
  .section-title { flex-direction: column; align-items: flex-start; gap: 4px; }
  .section-title h2 { font-size: 20px; }

  /* Detail page */
  .detail { gap: 18px; }
  .detail .lead .cover { aspect-ratio: 16/9; padding: 16px; font-size: 22px; }
  .detail .lead .body { padding: 18px; }
  .detail .side { position: static; padding: 18px; }
  .detail .side .price { font-size: 18px; }

  /* Forms */
  .form { padding: 18px; }
  .form .row { flex-direction: column; gap: 0; }
  .form .row > div { width: 100%; }

  /* Tables：橫向滾動 */
  .table-wrap, table { display: block; }
  table { overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  table th, table td { padding: 8px 10px; font-size: 13px; }

  /* Admin layout：側邊欄變上方 */
  .admin-layout { flex-direction: column; }
  .admin-side {
    width: 100%; height: auto; position: static; padding: 12px;
    display: flex; flex-wrap: wrap; gap: 4px;
  }
  .admin-side .brand { width: 100%; padding: 4px 8px 10px; margin-bottom: 6px; }
  .admin-side a { padding: 6px 10px; font-size: 13px; margin: 0; }
  .admin-side .foot { width: 100%; margin-top: 8px; padding-top: 8px; }
  .admin-main { padding: 18px 16px; }

  /* Buttons */
  .btn { padding: 8px 14px; font-size: 14px; }
  .btn.lg { padding: 12px 18px; font-size: 15px; }

  /* Learn page */
  .learn-wrap { gap: 16px; }
  .lesson-list { max-height: 360px; }

  /* Flash */
  .flash { padding: 10px 14px; font-size: 14px; }
}

/* 小型手機 (≤420px) */
@media (max-width: 420px) {
  .header .nav a { padding: 6px 8px; font-size: 12px; }
  .hero h1 { font-size: 24px; }
  .stat .num { font-size: 22px; }
}

/* 觸控優化 */
@media (hover: none) {
  .card:hover { transform: none; }
  .stat:hover { transform: none; }
  .btn:hover { transform: none; }
}
