/* ============================================================
   main.css — shared styles for the telehealth platform (Phase 0)
   Palette adapted from townhealth.com (teal-cyan + deep navy).
   Elderly-friendly: 18px body, large targets, AA contrast.
   Mobile-first (576px), desktop max-width 960px.
   ============================================================ */

:root {
  /* brand */
  --brand-primary:       #019fba;   /* teal-cyan — decorative accents */
  --brand-primary-strong:#007c95;   /* darker teal — buttons (AA on white) */
  --brand-dark:          #01479d;   /* deep navy — header, footer, headings */
  --brand-blue:          #1d4ed8;   /* interactive blue — links (AA) */
  --brand-light-bg:      #ebf7fa;   /* light teal tint */
  /* functionals */
  --whatsapp:  #128c7e;
  --whatsapp-bright: #25d366;
  --danger:    #dc2626;
  --ok:        #15803d;
  /* neutrals */
  --text:       #111827;
  --text-muted: #4b5563;
  --bg:         #f3f3f5;
  --card-bg:    #ffffff;
  --border:     #e5e7eb;
  --border-mid: #cbd5e1;
  /* focus ring */
  --focus-ring: 3px solid rgba(1, 159, 186, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang HK",
               "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 18px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-blue); }
a:hover { text-decoration: underline; }

.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px; }

h1 { font-size: 28px; color: var(--brand-dark); line-height: 1.3; }
h2 { font-size: 24px; color: var(--brand-dark); margin: 24px 0 12px; }
h3 { font-size: 18px; color: var(--brand-dark); margin-top: 14px; }
p  { margin: 8px 0; }

/* ---------- Skip link (a11y) ---------- */
.skip-link {
  position: absolute;
  top: -48px;
  left: 12px;
  z-index: 200;
  background: var(--brand-dark);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 8px 8px;
  font-weight: 700;
  transition: top 0.15s;
}
.skip-link:focus { top: 0; color: #fff; text-decoration: none; }

/* ---------- Header ---------- */
.site-header { background: #006d77; color: #fff; padding: 14px 0; }
.site-header .inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; letter-spacing: 0.5px; }
.brand-logo { height: 42px; width: auto; flex: none; border-radius: 8px; }
.brand .en { display: block; font-size: 16.5px; font-weight: 400; opacity: 0.85; }
.header-contact { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 13px; line-height: 1.5; }
.header-contact a { color: #6ee7b7; font-weight: 700; text-decoration: none; }
.header-contact .contact-item { display: inline-flex; align-items: center; gap: 6px; }
.header-contact .ic { width: 15px; height: 15px; fill: currentColor; flex: none; }

/* ---------- Hero ---------- */
.hero {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  min-height: 240px;
  padding: 20px 0;
  background-color: #f0f4f8;
  background-image:
    linear-gradient(90deg, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.78) 42%, rgba(255,255,255,0.15) 62%, rgba(255,255,255,0) 78%),
    url('../images/hero_mobile.jpg');
  background-size: cover;
  background-position: right top;
}
.hero .hero-text { max-width: 240px; }
.hero h1 { color: var(--brand-dark); margin-bottom: 8px; }
.hero .tagline { font-size: 18px; color: #1f2937; }
.hero .cta { margin-top: 16px; max-width: 180px; }

/* Tighter left edge on mobile/tablet for face room */
.hero .wrap { width: 100%; padding-left: 12px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin: 16px 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* ---------- Queue status ---------- */
.queue-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.queue-stat {
  background: var(--brand-light-bg);
  border: 1px solid #cfe9ee;
  border-radius: 10px;
  text-align: center;
  padding: 16px 10px;
}
.queue-stat .value { font-size: 32px; font-weight: 800; color: var(--brand-dark); line-height: 1.1; }
.queue-stat .label { font-size: 14px; color: var(--text-muted); margin-top: 2px; }
/* 預計等候為「~A 至 B 分鐘」區間，字體縮細以免兩欄爆框 */
#q-est { font-size: 20px; }
.queue-note { font-size: 14px; color: var(--text-muted); }

/* ---------- Queue line (walking figure) ---------- */
.queue-line {
  position: relative;
  height: 74px;
  margin: 8px 0 14px;
  overflow: hidden;
  border-radius: 10px;
  background: linear-gradient(180deg, #f7fbfc 0%, #edf5f7 100%);
}
.queue-line .ql-ground {
  position: absolute;
  left: 0; right: 0; bottom: 12px;
  height: 3px;
  background: #d2e4e9;
  border-radius: 2px;
}
.queue-line .ql-person {
  position: absolute;
  bottom: 15px;
  width: 32px;
  height: 58px;
  overflow: visible;
}
.queue-line .ql-static { fill: #b7d3da; }
.queue-line .ql-walker {
  fill: var(--brand-primary-strong);
  left: 100%;
  animation: ql-walk 12s linear infinite;
}
.queue-line .ql-walker .limb {
  transform-box: fill-box;
  transform-origin: 50% 0;
}
.queue-line .ql-walker .walker-body { animation: ql-bob 0.55s ease-in-out infinite; }
.queue-line .ql-walker .leg-l,
.queue-line .ql-walker .arm-r { animation: ql-swing 0.55s ease-in-out infinite alternate; }
.queue-line .ql-walker .leg-r,
.queue-line .ql-walker .arm-l { animation: ql-swing 0.55s ease-in-out infinite alternate-reverse; }

@keyframes ql-walk {
  from { left: -44px; }
  to   { left: 100%; }
}
@keyframes ql-swing {
  from { transform: rotate(-17deg); }
  to   { transform: rotate(17deg); }
}
@keyframes ql-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-2px); }
}

/* ---------- Queue live indicator ---------- */
.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ok);
  vertical-align: middle;
  margin-left: 8px;
}
.live-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--ok);
  animation: live-pulse 1.6s ease-in-out infinite;
}
@keyframes live-pulse {
  0%, 100% { transform: scale(1); opacity: 1; box-shadow: 0 0 0 0 rgba(21,128,61,0.45); }
  50%      { transform: scale(1.35); opacity: 0.7; box-shadow: 0 0 0 5px rgba(21,128,61,0); }
}

/* live number breathing */
.value.live { animation: value-breathe 2.4s ease-in-out infinite; }
@keyframes value-breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.72; }
}

/* ---------- Queue closed state ---------- */
.queue-closed {
  text-align: center;
  padding: 22px 14px;
  background: var(--brand-light-bg);
  border: 1px solid #cfe9ee;
  border-radius: 10px;
  margin: 14px 0;
}
.queue-closed .qc-icon { font-size: 30px; line-height: 1; }
.queue-closed .qc-title { font-size: 18px; font-weight: 700; color: var(--brand-dark); margin: 8px 0 2px; }
.queue-closed .qc-desc { font-size: 14px; color: var(--text-muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  width: 100%;
  padding: 16px 24px;
  border: none;
  border-radius: 10px;
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  line-height: 1.2;
  transition: background-color 0.15s, opacity 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--brand-primary-strong); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #006a80; }
.btn-whatsapp { background: var(--whatsapp); color: #fff; }
.btn-outline { background: var(--card-bg); color: var(--brand-dark); border: 2px solid var(--brand-dark); }
.btn-outline:hover { background: var(--brand-light-bg); }

/* ---------- Spinner (loading state) ---------- */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 3px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -4px;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Service grid ---------- */
.service-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.service-card {
  display: block;
  width: 100%;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 14px;
  font-size: 16px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
.service-card:hover { border-color: var(--brand-primary); box-shadow: 0 2px 8px rgba(1,159,186,0.12); }
.service-card .title { font-weight: 700; color: var(--brand-dark); }
.service-card .desc { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.service-card.selected { border-color: var(--brand-primary); background: var(--brand-light-bg); }

/* ---------- Form ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 16px; font-weight: 700; margin-bottom: 6px; color: var(--brand-dark); }
.form-group .req { color: var(--danger); }
.form-group .hint { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 13px 14px;
  font-size: 18px;
  border: 1px solid var(--border-mid);
  border-radius: 8px;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(1,159,186,0.15);
}
.form-group textarea { min-height: 80px; resize: vertical; }
.form-error {
  display: none;
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #991b1b;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 14px;
}
.form-error.show { display: block; }

/* ---------- Result ---------- */
.result-box {
  background: var(--brand-light-bg);
  border: 1px solid #cfe9ee;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}
.result-box .token { font-size: 30px; font-weight: 800; color: var(--brand-dark); }

/* ---------- Hidden helper ---------- */
.hidden { display: none !important; }

/* ---------- WhatsApp FAB ---------- */
.wa-fab {
  position: fixed;
  bottom: 20px; right: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--whatsapp-bright);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(37,211,102,0.4);
  z-index: 99;
}
.wa-fab svg { width: 28px; height: 28px; fill: #fff; }

/* ---------- Footer ---------- */
.site-footer {
  background: #006d77;
  color: #cfdcee;
  text-align: center;
  padding: 24px 16px;
  margin-top: 32px;
  font-size: 14px;
}
.site-footer a { color: #6ee7b7; }

/* ---------- Emergency notice ---------- */
.emergency {
  background: #fef2f2;
  border: 1px solid #f5c6c6;
  border-left: 4px solid var(--danger);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 15px;
  color: #7b241c;
  margin: 16px 0;
}
.emergency strong { display: block; }

/* ---------- Focus visibility (a11y) ---------- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}
.btn:focus-visible,
.service-card:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

/* ---------- Reduced motion (a11y) ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
  .live-dot { animation: live-pulse 1.6s ease-in-out infinite !important; }
  .value.live { animation: value-breathe 2.4s ease-in-out infinite !important; }
  .queue-line .ql-walker { animation: ql-walk 12s linear infinite !important; }
  .queue-line .ql-walker .walker-body { animation: ql-bob 0.55s ease-in-out infinite !important; }
  .queue-line .ql-walker .leg-l,
  .queue-line .ql-walker .arm-r { animation: ql-swing 0.55s ease-in-out infinite alternate !important; }
  .queue-line .ql-walker .leg-r,
  .queue-line .ql-walker .arm-l { animation: ql-swing 0.55s ease-in-out infinite alternate-reverse !important; }
}

/* ---------- Very small screens ---------- */
@media (max-width: 400px) {
  .site-header .inner { gap: 8px; }
  .brand { font-size: 18px; }
  h1 { font-size: 26px; }
}

/* ---------- Desktop ---------- */
@media (min-width: 577px) {
  h1 { font-size: 34px; }
  .service-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 577px) and (max-width: 1024px) {
  .hero { min-height: 280px;
    background-image:
      linear-gradient(90deg, rgba(255,255,255,0.6) 0%, rgba(255,255,255,0) 50%),
      url('../images/hero_tablet.jpg');
    background-position: right top; }
  .hero .hero-text { max-width: 320px; }
}

@media (min-width: 577px) {
  .hero h1 br, .hero .tagline br { display: none; }
  .hero .tagline .l2::before { content: " · "; }
  .hero .cta { max-width: 260px; }
  .hero .hero-text {
    background: rgba(255,255,255,0.4);
    border-radius: 14px;
    padding: 14px 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  }
}

@media (min-width: 1025px) {
  .hero { min-height: 295px; padding: 20px 0;
    background-image:
      linear-gradient(180deg, rgba(255,255,255,0) 38%, rgba(255,255,255,0.55) 66%, rgba(255,255,255,0.92) 100%),
      url('../images/hero_desktop.jpg');
    background-position: center top; }
  .hero .hero-text { max-width: 480px; }
  .hero .wrap { padding-left: 16px; }
}
