:root {
  --green: #008069;
  --green-btn: #0f766e;
  --green-light: #e7f6ef;
  --green-bubble: #d9fdd3;
  --bg: #efeae2;
  --text: #111b21;
  --muted: #667781;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; color: var(--text); }

.hidden { display: none !important; }

/* ========== 門禁頁 ========== */
.gate-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 16px 24px;
  background:
    radial-gradient(circle at 20% 10%, rgba(15, 118, 110, 0.06), transparent 40%),
    #f3f5f7;
  background-image:
    radial-gradient(rgba(0,0,0,0.04) 1px, transparent 1px);
  background-size: 18px 18px;
}

.gate-card {
  width: min(100%, 360px);
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

.gate-card__head {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid #eef2f4;
}

.gate-card__icon {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--green-light); font-size: 22px;
}

.gate-card__title { font-weight: 700; font-size: 16px; }
.gate-card__sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.gate-card__body {
  padding: 28px 22px 22px;
  text-align: center;
}

.gate-shield {
  width: 72px; height: 72px; margin: 0 auto 16px;
  border-radius: 16px; background: var(--green-light);
  display: grid; place-items: center; font-size: 36px;
}

.gate-card__body h1 {
  margin: 0 0 10px;
  font-size: 22px;
  line-height: 1.35;
}

.gate-card__body p {
  margin: 0 0 20px;
  color: #54656f;
  font-size: 14px;
  line-height: 1.6;
}

.gate-btn {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 14px;
  background: var(--green-btn);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.gate-note {
  margin: 14px 0 0 !important;
  font-size: 11px !important;
  color: #8696a0 !important;
}

/* ========== 聊天主界面 ========== */
.chat-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: #fff;
  border-bottom: 1px solid #e9edef;
}

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

.topbar__logo {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--green); color: #fff;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 800;
}

.topbar__name { font-weight: 700; font-size: 15px; }
.topbar__status {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--muted); margin-top: 2px;
}
.topbar__status .dot {
  width: 7px; height: 7px; border-radius: 50%; background: #25d366;
}

.topbar__badges {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-end;
}
.badge {
  font-size: 9px; color: #008069;
  background: #e7f6ef; border-radius: 999px;
  padding: 3px 7px; white-space: nowrap;
}
.lang-switch {
  display: flex; gap: 2px; background: #f0f2f5; border-radius: 999px; padding: 2px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.lang-switch--global {
  position: fixed;
  top: max(10px, env(safe-area-inset-top, 10px));
  right: max(10px, env(safe-area-inset-right, 10px));
  z-index: 10000;
  padding: 3px;
}
.lang-switch__btn {
  border: 0; background: transparent; font-size: 11px; padding: 6px 10px;
  border-radius: 999px; color: #54656f; cursor: pointer; line-height: 1.2;
  min-height: 32px; min-width: 34px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.lang-switch__btn.is-active {
  background: #fff; font-weight: 700; color: #008069;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.chat-main {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 6px;
  -webkit-overflow-scrolling: touch;
}

.chat-date {
  width: fit-content; margin: 6px auto 12px;
  padding: 4px 10px; border-radius: 6px;
  background: rgba(255,255,255,0.9);
  font-size: 12px; color: #54656f;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.06);
}

.msg-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  align-items: flex-end;
}
.msg-row--out { justify-content: flex-end; }

.msg-avatar {
  width: 32px; height: 32px; flex: 0 0 32px;
  border-radius: 50%; background: #dfece8;
  display: grid; place-items: center; font-size: 16px;
}

.msg-bubble {
  max-width: 88%;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 0.5px rgba(11,20,26,0.13);
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
}
.msg-row--out .msg-bubble {
  background: var(--green-bubble);
  border-top-right-radius: 0;
}
.msg-row--in .msg-bubble { border-top-left-radius: 0; }

.msg-bubble__text { padding: 8px 10px 4px; }
.msg-bubble__time {
  padding: 0 8px 6px;
  text-align: right;
  font-size: 11px;
  color: #8696a0;
}

/* 富文本卡片 */
.card-hero {
  background: linear-gradient(180deg, #f7f3ea 0%, #fff 45%);
  padding: 12px;
  text-align: center;
  border-bottom: 1px solid #f0f2f5;
}
.card-hero__title { font-weight: 800; font-size: 15px; margin-top: 6px; }
.card-hero__sub { font-size: 11px; color: var(--muted); margin-top: 4px; }
.card-icons {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 4px; padding: 10px 8px; font-size: 10px; color: #008069; text-align: center;
}
.card-body { padding: 12px; font-size: 13px; line-height: 1.55; color: #3b4a54; }
.card-body strong { color: #111; }
.card-cta {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px; border-top: 1px solid #eef2f4;
  color: var(--green); font-weight: 700; font-size: 14px;
  cursor: pointer; background: #fafafa;
}
.card-cta:active { background: #f0f2f5; }

/* 電話表單卡片 */
.phone-card { padding: 12px; }
.phone-card h3 { margin: 0 0 4px; font-size: 15px; }
.phone-card p { margin: 0 0 12px; font-size: 12px; color: var(--muted); }
.phone-row { display: flex; gap: 8px; }
.phone-row select,
.phone-row input {
  height: 42px; border: 1px solid #d1d7db; border-radius: 8px;
  font-size: 15px; padding: 0 10px; background: #fff;
}
.phone-row select { width: 88px; flex: 0 0 88px; }
.phone-row input { flex: 1; min-width: 0; }
.phone-submit {
  width: 100%; margin-top: 10px; height: 42px;
  border: 0; border-radius: 8px;
  background: var(--green); color: #fff;
  font-weight: 700; font-size: 15px;
}

/* 步驟指引 */
.steps-card { padding: 12px; }
.steps-card h3 { margin: 0 0 4px; font-size: 14px; }
.steps-card p { margin: 0 0 10px; font-size: 12px; color: var(--muted); }
.steps-strip {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px;
}
.step-thumb {
  aspect-ratio: 9/16; border-radius: 6px;
  background: linear-gradient(180deg, #e8f5e9, #fff);
  border: 1px solid #dfe5e7;
  font-size: 9px; color: #008069;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 4px; text-align: center;
}
.step-list { display: grid; gap: 6px; }
.step-item {
  display: flex; gap: 8px; align-items: flex-start;
  background: #f0fdf4; border-radius: 8px; padding: 8px;
  font-size: 12px; line-height: 1.4;
}
.step-item span {
  width: 20px; height: 20px; flex: 0 0 20px;
  border-radius: 6px; background: #008069; color: #fff;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
}

/* 驗證碼卡片 */
.code-card {
  margin: 8px 10px 4px;
  padding: 12px;
  border-radius: 10px;
  background: #ecfdf5;
  border: 1px solid #bbf7d0;
}
.code-card__label { font-size: 12px; color: #047857; margin-bottom: 6px; }
.code-card__row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.code-card__value {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 26px; font-weight: 800; letter-spacing: 0.08em;
  color: #065f46;
}
.code-card__copy {
  border: 0; border-radius: 8px; padding: 8px 12px;
  background: #fff; color: #047857; font-weight: 700; font-size: 13px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.code-card__timer { margin-top: 8px; font-size: 12px; color: #059669; }
.code-card__action {
  display: block; width: 100%; margin-top: 10px;
  text-align: center; padding: 10px;
  border-radius: 8px; background: #dbeafe; color: #1d4ed8;
  font-weight: 700; text-decoration: none; border: 0; font-size: 14px;
}

.fail-human-card {
  padding: 12px 14px;
  background: #fff;
  border-left: 3px solid #ef4444;
  font-size: 13px;
  line-height: 1.55;
  color: #374151;
}
.fail-human-card .cs-human-link,
.tips-box .cs-human-link {
  color: #2563eb;
  text-decoration: underline;
  font-weight: 600;
}

.tips-box {
  padding: 10px 12px;
  background: #fff;
  border-left: 3px solid #f59e0b;
  font-size: 12px; line-height: 1.55; color: #4b5563;
}

.wa-typing {
  display: inline-flex; gap: 4px; padding: 10px 12px;
  background: #fff; border-radius: 8px;
  box-shadow: 0 1px 0.5px rgba(11,20,26,0.13);
}
.wa-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: #90a4ae;
  animation: dot 1.2s infinite ease-in-out;
}
.wa-typing span:nth-child(2) { animation-delay: .15s; }
.wa-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes dot {
  0%,80%,100% { transform: translateY(0); opacity: .5; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.chat-footer {
  background: #f0f2f5;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid #d1d7db;
}
.chat-footer__row { display: flex; align-items: center; gap: 8px; }
.chat-footer__emoji { font-size: 22px; color: #8696a0; }
.chat-footer__input {
  flex: 1; height: 42px; border: 0; border-radius: 24px;
  padding: 0 14px; font-size: 15px; outline: none;
}
.chat-footer__send {
  width: 42px; height: 42px; border: 0; border-radius: 50%;
  background: var(--green); color: #fff; font-size: 18px;
  display: grid; place-items: center; cursor: pointer;
}
.chat-footer__legal {
  margin: 6px 4px 0;
  font-size: 10px; color: #8696a0; text-align: center;
}
.chat-footer__legal a { color: #027eb5; text-decoration: none; }
.chat-footer__hint {
  margin: 4px 0 0; text-align: center; font-size: 10px; color: #8696a0;
}
.chat-footer__hint.online { color: #008069; }
.chat-footer__hint.offline { color: #dc2626; }

.toast {
  position: fixed; z-index: 100; left: 50%; bottom: 90px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 14px; border-radius: 8px;
  background: rgba(17,27,33,.92); color: #fff; font-size: 13px;
}
