:root {
  --crimson: #DC143C;
  --blue: #003893;
  --cyan: #25F4EE;
  --pink: #FE2C55;
  --ink: #15181d;
  --muted: #8a8f98;
  --text-2: #4b5560;
  --bg: #f4f5f8;
  --card: #ffffff;
  --line: #e7e9ee;
  --ok: #16a34a;
  --radius: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
/* Lock the outer page: only #views scrolls. Without this, hard scrolls
 * rubber-band the whole shell on iOS and the tab bar rides out of view. */
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  font-size: 15px;
  line-height: 1.4;
  background: #d9dce3;
  color: var(--ink);
}

.phone {
  max-width: 430px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
@media (min-width: 500px) {
  .phone { box-shadow: 0 0 40px rgba(0,0,0,.25); }
}

/* ---------- app bar ---------- */
.appbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  /* iPhone notch / rounded corners: env() is 0 wherever there is no inset */
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

/* iOS-PWA-only back button (shown by app.js when installed on iPhone) */
#te-back-btn {
  flex: none; width: 34px; height: 34px; margin-right: 10px;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--bg); color: var(--ink);
  font-size: 24px; line-height: 1; cursor: pointer;
  display: grid; place-items: center; padding-bottom: 3px;
}
#te-back-btn[hidden] { display: none; }
#te-back-btn:active { transform: scale(0.94); }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-logo { height: 34px; width: auto; flex: none; }
.brand-name { font-weight: 800; font-size: 17px; }
.brand-name small { color: var(--muted); font-weight: 600; }
.icon-btn {
  position: relative; border: none; background: none; color: var(--ink);
  width: 36px; height: 36px; cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }
.badge {
  position: absolute; top: 2px; right: 2px;
  background: var(--pink); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: grid; place-items: center;
}

/* ---------- views ---------- */
#views { flex: 1; overflow-y: auto; padding: 16px; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; }
.view { display: none; }
.view.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } }

.greet { font-size: 15px; margin-bottom: 12px; }
.greet-sub { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 2px; }

/* destination focus pill + picker sheet */
.dest-pill {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1.5px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 999px; padding: 7px 14px; margin-bottom: 12px;
  font-size: 13px; font-weight: 700; cursor: pointer;
}
.dest-pill.focused { border-color: var(--blue); color: var(--blue); background: rgba(10, 79, 192, .06); }
.dest-caret { font-size: 11px; opacity: .65; }
.focus-rows { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.focus-row {
  display: flex; align-items: center; gap: 12px;
  border: 1.5px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 12px; padding: 12px 14px;
  font-size: 15px; font-weight: 700; cursor: pointer; text-align: left;
}
.focus-row:active { border-color: var(--blue); background: rgba(10, 79, 192, .06); }
.focus-row[hidden] { display: none !important; } /* our flex display would defeat [hidden] */

/* ---------- live online classes ---------- */
.class-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card, #fff); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; margin-bottom: 10px; cursor: pointer;
}
.class-card .cls-main { flex: 1; min-width: 0; }
.class-card h4 { font-size: 15px; margin: 0 0 2px; }
.class-card .muted { font-size: 12.5px; }
.cls-next { font-size: 12.5px; margin-top: 6px; }
.cls-until { color: var(--blue, #0a4fc0); font-weight: 700; }
.cls-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.cls-price { font-size: 12px; font-weight: 800; color: var(--blue, #0a4fc0); }
.cls-session {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font-size: 13px; margin-bottom: 8px;
}
.cls-session.past { opacity: .75; }
.cls-h4 { font-size: 13px; margin: 14px 0 8px; }
.cls-badge {
  display: inline-block; font-size: 10.5px; font-weight: 800; letter-spacing: .3px;
  color: var(--blue, #0a4fc0); background: rgba(10, 79, 192, .08);
  border: 1px solid rgba(10, 79, 192, .25); border-radius: 999px;
  padding: 2px 8px; margin-bottom: 4px;
}
.my-sched {
  background: var(--card, #fff); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 12px;
}
.my-sched .cls-h4 { margin: 0 0 8px; }
.my-sched .cls-session:last-child { margin-bottom: 0; }
#class-sheet-body h3 { margin-bottom: 4px; }

/* ---------- voice doctor (missing Android TTS voice pack) ---------- */
.crs-voicedoc {
  background: rgba(192, 57, 43, .07); border: 1.5px solid rgba(192, 57, 43, .35);
  border-radius: 14px; padding: 14px; margin-bottom: 14px; font-size: 13.5px;
}
.crs-voicedoc p { margin: 8px 0; }
.crs-voicedoc-head { font-size: 15px; }
.crs-voicedoc-btns { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 2px; }
.crs-voicedoc-btns a { text-decoration: none; display: inline-flex; align-items: center; }
.crs-voicedoc-steps { font-size: 12.5px; color: var(--muted, #8a8f98); }

/* ---------- document desk v2 ---------- */
.doc-hint { display: block; font-size: 11.5px; color: var(--muted, #8a8f98); margin: 1px 0 2px; }
.doc-due { color: #c0392b; font-weight: 700; }
.section-title { font-size: 15px; margin: 18px 0 8px; }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }
.ok { color: var(--ok); font-weight: 700; font-size: 13px; }
.hint { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.demo-note { font-size: 11px; color: var(--muted); text-align: center; margin: 18px 0 8px; }

/* ---------- hero ---------- */
.hero-card {
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--blue), #0a4fc0);
  color: #fff; border-radius: var(--radius);
  padding: 18px 16px;
}
.hero-tag {
  display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: .08em;
  background: rgba(255,255,255,.18); border-radius: 6px; padding: 3px 8px;
  margin-bottom: 8px;
}
.hero-text h2 { font-size: 18px; margin-bottom: 6px; }
.hero-text p { font-size: 12.5px; opacity: .9; margin-bottom: 12px; }
.hero-flag { font-size: 44px; }

.btn-primary {
  border: none; cursor: pointer;
  background: var(--crimson); color: #fff;
  font-weight: 700; font-size: 14px;
  padding: 10px 16px; border-radius: 10px;
}
.btn-primary.wide { width: 100%; margin-top: 14px; padding: 13px; }
.btn-ghost {
  display: block; width: 100%; margin-top: 16px;
  background: none; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px; color: var(--muted); font-weight: 600; cursor: pointer;
}

/* ---------- quick grid ---------- */
.quick-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  margin-top: 14px;
}
.quick {
  border: none; cursor: pointer;
  background: var(--card); border-radius: 12px;
  padding: 12px 4px; font-size: 12px; font-weight: 600; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.quick span { font-size: 20px; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.card h4 { font-size: 15px; margin-bottom: 4px; }
.card p { font-size: 13.5px; color: var(--text-2); }
.card .meta {
  display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px;
  font-size: 12.5px; font-weight: 500; color: var(--text-2);
}
.card .meta .seats { color: var(--ok); font-weight: 700; }
.card .tag {
  font-size: 10px; font-weight: 800; letter-spacing: .05em;
  color: var(--crimson); margin-bottom: 4px; display: inline-block;
}

/* ---------- explore ---------- */
.searchbar {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 10px;
  border: 1px solid var(--line);
}
.searchbar svg { width: 17px; height: 17px; color: var(--muted); flex: none; }
.searchbar input { border: none; outline: none; flex: 1; font-size: 14px; background: none; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 7px 13px;
  font-size: 12.5px; font-weight: 600; color: var(--ink); cursor: pointer;
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- stepper ---------- */
.stepper { list-style: none; }
.stepper li {
  position: relative; padding: 0 0 18px 28px; font-size: 13.5px; font-weight: 600;
}
.stepper li small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.stepper li::before {
  content: ""; position: absolute; left: 6px; top: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--line);
}
.stepper li::after {
  content: ""; position: absolute; left: 11px; top: 18px; bottom: 0;
  width: 2px; background: var(--line);
}
.stepper li:last-child::after { display: none; }
.stepper li.done::before { background: var(--ok); }
.stepper li.current::before {
  background: var(--crimson);
  box-shadow: 0 0 0 4px rgba(220,20,60,.18);
}
.stepper li.current { color: var(--crimson); }

/* ---------- social links (Me tab) ---------- */
.social-card {
  background: var(--card, #fff); border: 1px solid var(--line); border-radius: var(--radius, 14px);
  padding: 15px; margin-top: 14px;
}
.social-card h4 { margin: 0 0 10px; font-size: 14px; }
.social-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.social-btn {
  display: inline-flex; align-items: center; gap: 6px;
  color: #fff; font-size: 13px; font-weight: 800; text-decoration: none;
  border-radius: 999px; padding: 9px 15px;
}
.social-btn.fb { background: #1877F2; }
.social-btn.tt { background: #111; }
.social-btn.wa { background: #25D366; }
.social-btn:active { opacity: .85; }

/* ---------- notification center ---------- */
/* our display rules would defeat the [hidden] attribute — force it to win */
.notif-panel[hidden], .notif-backdrop[hidden], .icon-btn .badge[hidden] { display: none !important; }
.notif-backdrop { position: fixed; inset: 0; z-index: 48; background: rgba(15, 18, 25, .45); }
.notif-panel {
  position: fixed; top: calc(56px + env(safe-area-inset-top)); right: 10px; z-index: 49;
  width: min(370px, calc(100vw - 20px)); max-height: min(66vh, 520px);
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 18px 44px rgba(15, 18, 25, .18);
  display: flex; flex-direction: column; overflow: hidden;
}
.notif-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 15px 11px; border-bottom: 1px solid var(--line); font-size: 15px;
}
.notif-list { overflow-y: auto; }
.notif-item {
  display: flex; gap: 10px; width: 100%; text-align: left; cursor: pointer;
  border: none; background: none; padding: 12px 15px; border-bottom: 1px solid #f0f1f4;
  color: var(--ink); font: inherit;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:active { background: #fafbfd; }
.ni-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: transparent; margin-top: 6px; }
.notif-item.unread .ni-dot { background: var(--crimson); }
.notif-item.unread b { color: var(--ink); }
.ni-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ni-text b { font-size: 13.5px; }
.ni-body {
  font-size: 12.5px; color: var(--text-2); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ni-text small { font-size: 11px; color: var(--muted); margin-top: 2px; }
.notif-empty { text-align: center; padding: 34px 24px; font-size: 30px; }
.notif-empty p { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

/* ---------- document verification states ---------- */
.doc-ok { color: var(--ok); font-weight: 700; }
.doc-wait { color: #b9770a; font-weight: 700; }
.doc-bad { color: #c0392b; font-weight: 700; }
.doc-row.bad { border: 1.5px solid rgba(192, 57, 43, .35); border-radius: 10px; }

/* ---------- exam ticket (Track tab) ---------- */
.ticket {
  background: var(--card, #fff); border: 1.5px solid var(--line); border-radius: var(--radius, 14px);
  padding: 15px 15px 13px; margin-bottom: 12px;
}
.ticket.off { opacity: .65; }
.tk-head { display: flex; align-items: flex-start; gap: 10px; }
.tk-head h4 { font-size: 15px; margin: 0; }
.tk-head p { font-size: 12px; color: var(--muted); margin: 2px 0 0; }
.tk-level {
  margin-left: auto; flex: none; background: linear-gradient(135deg, var(--crimson), var(--blue));
  color: #fff; font-weight: 800; font-size: 13px; border-radius: 9px; padding: 6px 11px;
}
.tk-meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); margin: 8px 0 12px; }
.tk-count { font-weight: 700; color: var(--blue); }
.tk-count.hot { color: var(--crimson); }
.tk-line { display: flex; align-items: flex-start; margin: 2px 0 10px; }
.tk-st {
  display: flex; flex-direction: column; align-items: center; gap: 3px; flex: none;
  width: 58px; font-size: 12.5px; font-weight: 800; color: var(--muted);
}
.tk-st::first-line { line-height: 1; }
.tk-st small { font-size: 10px; font-weight: 600; text-align: center; }
.tk-st.done { color: var(--ok); }
.tk-join { flex: 1; height: 2px; background: var(--line); margin-top: 8px; }
.tk-next { font-size: 13px; font-weight: 600; margin: 0 0 10px; }
.tk-cancel { font-size: 13px; color: var(--muted); margin: 0; }
.tk-prep { border-top: 1px dashed var(--line); margin-top: 12px; padding-top: 10px; }
.tk-prep-line { display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; margin-bottom: 5px; }
.tk-prep-bar { height: 7px; border-radius: 99px; background: var(--line); overflow: hidden; margin-bottom: 9px; }
.tk-prep-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--crimson), var(--blue)); border-radius: 99px; }
.tk-fee { border-top: 1px dashed var(--line); margin-top: 12px; padding-top: 10px; font-size: 13px; }
.tk-fee b { display: block; margin-bottom: 3px; font-size: 13.5px; }
.tk-fee p { color: var(--text-2); margin: 0 0 9px; line-height: 1.5; }
.tk-fee.ok { color: var(--ok); font-weight: 700; }
.tk-fee.wait { color: #b9770a; font-weight: 700; }
.tk-fee.bad b { color: #c0392b; }
.tk-pay-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.tk-payline { cursor: pointer; }
.wa-line { display: block; text-align: center; margin-top: 12px; font-size: 13.5px; font-weight: 700; color: #128C7E; }
.jc-empty h4 { margin: 0 0 4px; }
.jc-empty p { font-size: 13px; color: var(--text-2); margin: 0 0 10px; }
#journey-cta { margin-top: 4px; }
.noc-fold { margin-top: 16px; }
.noc-fold summary, .track-guide summary { list-style: none; cursor: pointer; }
.noc-fold summary::-webkit-details-marker, .track-guide summary::-webkit-details-marker { display: none; }
.noc-fold summary .section-title, .track-guide summary .section-title { display: inline-block; margin: 0 0 8px; }
.noc-fold summary .section-title::after, .track-guide summary .section-title::after { content: " ▸"; color: var(--muted); font-size: 12px; }
.noc-fold[open] summary .section-title::after, .track-guide[open] summary .section-title::after { content: " ▾"; }

/* the journey explainer on Track */
.track-guide { margin-bottom: 14px; }
.tg-body {
  background: var(--card, #fff); border: 1.5px solid var(--line); border-radius: var(--radius, 14px);
  padding: 15px 15px 11px; margin-top: 2px;
}
.tg-step { padding: 9px 0; border-bottom: 1px dashed var(--line); }
.tg-step:last-of-type { border-bottom: none; }
.tg-step b { display: block; font-size: 13.5px; margin-bottom: 3px; }
.tg-step p { font-size: 13px; color: var(--text-2); line-height: 1.55; margin: 0; }
.tg-note { font-size: 12.5px; font-weight: 700; text-align: center; margin: 10px 0 4px; }
.dest-pill[hidden] { display: none !important; }

/* ---------- checklist ---------- */
.checklist { list-style: none; }
.checklist li {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: 10px;
  padding: 11px 12px; margin-bottom: 6px; font-size: 13px;
  cursor: pointer; user-select: none;
}
.checklist li .box {
  width: 19px; height: 19px; border-radius: 6px;
  border: 2px solid var(--line); flex: none;
  display: grid; place-items: center; color: #fff; font-size: 12px;
}
.checklist li.checked .box { background: var(--ok); border-color: var(--ok); }
.checklist li.checked { color: var(--muted); text-decoration: line-through; }

/* ---------- profile ---------- */
.profile-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.avatar {
  width: 54px; height: 54px; border-radius: 50%;
  background: linear-gradient(135deg, var(--crimson), var(--blue));
  color: #fff; font-weight: 800; display: grid; place-items: center;
}
.list-card { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.list-card .row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 13px 14px; font-size: 13.5px; font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.list-card .row:last-child { border-bottom: none; }

/* ---------- TikTok-style tab bar ---------- */
.tabbar {
  display: flex; align-items: stretch;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 6px calc(4px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(4px + env(safe-area-inset-left));
}
.tab {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-size: 11px; font-weight: 600;
}
.tab svg { width: 23px; height: 23px; }
.tab.active { color: var(--ink); }
.tab.active span { font-weight: 800; }

/* center create/apply button — TikTok layered pill */
.tab-apply { justify-content: center; }
.plus-pill {
  position: relative; z-index: 0;
  width: 46px; height: 31px; border-radius: 9px;
  background: var(--ink); color: #fff;
  display: grid; place-items: center;
}
.plus-pill svg { width: 17px; height: 17px; }
.plus-pill::before, .plus-pill::after {
  content: ""; position: absolute; inset: 0;
  border-radius: 9px; z-index: -1;
}
.plus-pill::before { background: var(--cyan); transform: translateX(-4px); }
.plus-pill::after { background: var(--pink); transform: translateX(4px); }

/* ---------- sheet & toast ---------- */
.backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,.45); z-index: 8;
}
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 9;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  animation: slideup .22s ease;
}
@keyframes slideup { from { transform: translateY(40%); opacity: .4; } }
.sheet-grip {
  width: 42px; height: 4px; border-radius: 2px;
  background: var(--line); margin: 2px auto 12px;
}
.sheet h3 { font-size: 16px; margin-bottom: 12px; }
.sheet label {
  display: block; font-size: 12px; font-weight: 700; color: var(--muted);
  margin-bottom: 10px;
}
.sheet select, .sheet input {
  display: block; width: 100%; margin-top: 4px;
  padding: 11px 12px; font-size: 14px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  outline: none;
}
.toast {
  position: absolute; left: 50%; bottom: 86px; transform: translateX(-50%);
  z-index: 10; max-width: 86%;
  background: var(--ink); color: #fff;
  font-size: 12.5px; font-weight: 600;
  padding: 11px 16px; border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
  animation: fadein .2s ease;
  text-align: center;
}

.empty { padding: 10px 2px; }

/* ---------- v0.2: auth + booking ---------- */
.btn-sm { margin-top: 10px; padding: 8px 14px; font-size: 12.5px; }
.btn-row { display: flex; gap: 8px; margin-top: 4px; }
.btn-row .btn-primary, .btn-row .btn-outline { flex: 1; padding: 11px; }
.btn-outline {
  border: 1.5px solid var(--ink); background: none; color: var(--ink);
  border-radius: 10px; font-weight: 700; font-size: 14px; cursor: pointer;
}
#auth-card h4 { font-size: 15px; margin-bottom: 4px; }
#auth-card label {
  display: block; font-size: 12px; font-weight: 700; color: var(--muted);
  margin-bottom: 10px;
}
#auth-card input {
  display: block; width: 100%; margin-top: 4px;
  padding: 11px 12px; font-size: 14px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  outline: none;
}
#profile-card .btn-primary.wide { margin-top: 14px; }

/* WhatsApp OTP login */
.btn-wa { background: #25D366; margin-top: 6px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-wa .wa-ic { font-size: 16px; }
.otp-sent { font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.linkbtn { border: none; background: none; color: var(--blue); font-weight: 700; font-size: 13px; cursor: pointer; padding: 0; text-decoration: underline; }
.otp-input { text-align: center; font-size: 26px; font-weight: 700; letter-spacing: 10px; }
.otp-resend { margin-top: 12px; font-size: 13px; text-align: center; }
.otp-dev { margin-top: 12px; padding: 9px 12px; background: #fef3e2; color: #b9770a; border-radius: 8px; font-size: 12.5px; text-align: center; }

/* ---------- focused plan / 100% online counsellor ---------- */
.resume-banner {
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  background: linear-gradient(135deg, var(--blue), #0a4fc0); color: #fff;
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px;
}
.resume-banner .rb-icon { font-size: 22px; }
.resume-banner h4 { font-size: 14px; margin: 0; }
.resume-banner p { font-size: 12px; opacity: .92; margin: 0; }
.resume-banner .rb-go { margin-left: auto; font-size: 22px; opacity: .9; }

.plan-screen {
  position: absolute; inset: 0; z-index: 7;
  background: var(--bg); display: flex; flex-direction: column;
}
.plan-screen[hidden] { display: none; }
.plan-top {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; background: var(--card); border-bottom: 1px solid var(--line);
}
.plan-back {
  border: none; background: none; cursor: pointer;
  font-size: 26px; line-height: 1; color: var(--ink); width: 30px;
}
.plan-head-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.plan-head-text strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plan-head-text span { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plan-change {
  border: 1px solid var(--line); background: none; cursor: pointer;
  border-radius: 8px; padding: 6px 10px; font-size: 12px; font-weight: 600; color: var(--text-2);
}
.plan-progress { height: 6px; background: var(--line); }
.plan-progress-fill { height: 100%; background: var(--ok); width: 0; transition: width .3s ease; }
.plan-next {
  padding: 12px 16px; background: #eef4ff; color: var(--blue);
  font-size: 13px; font-weight: 700; border-bottom: 1px solid var(--line);
}
.plan-next small { display: block; color: var(--text-2); font-weight: 400; font-size: 11.5px; margin-top: 2px; }
.plan-body { flex: 1; overflow-y: auto; padding: 14px 16px; }
.plan-foot {
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.plan-complete {
  text-align: center; padding: 18px; margin-bottom: 10px;
  background: #eafaf0; border-radius: 12px; color: var(--ok); font-weight: 700;
}

.pstep { background: var(--card); border-radius: 12px; margin-bottom: 10px; overflow: hidden; border: 1px solid var(--line); }
.pstep-head { display: flex; align-items: center; gap: 12px; padding: 13px 14px; cursor: pointer; }
.pstep-dot {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  background: var(--line); color: var(--text-2);
}
.pstep.done .pstep-dot { background: var(--ok); color: #fff; }
.pstep.current .pstep-dot { background: var(--crimson); color: #fff; box-shadow: 0 0 0 4px rgba(220,20,60,.18); }
.pstep-ttl { flex: 1; font-size: 13.5px; font-weight: 600; }
.pstep.done .pstep-ttl { color: var(--text-2); }
.pstep.locked .pstep-head { opacity: .55; }
.pstep-chev { color: var(--muted); font-size: 11px; }
.pstep-body { padding: 0 14px 14px 52px; font-size: 13px; color: var(--text-2); }
.pstep-body .what { margin-bottom: 8px; line-height: 1.5; }
.pstep-body .do { color: var(--ink); font-weight: 600; margin-bottom: 10px; }
.pstep-body .checklist { margin: 4px 0 10px; }
.pstep-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pstep-cta { border: none; cursor: pointer; background: var(--crimson); color: #fff; font-weight: 700; font-size: 12.5px; padding: 8px 14px; border-radius: 9px; }
.pstep-done-btn { border: 1px solid var(--ok); cursor: pointer; background: none; color: var(--ok); font-weight: 700; font-size: 12.5px; padding: 8px 14px; border-radius: 9px; }

/* document upload list */
.doc-list { margin: 4px 0 12px; }
.doc-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.doc-row:last-child { border-bottom: none; }
.doc-info { flex: 1; min-width: 0; }
.doc-name { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink); }
.doc-meta { display: block; font-size: 11.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-row.has .doc-meta { color: var(--ok); font-weight: 600; }
.doc-btn { flex: none; cursor: pointer; border: 1px solid var(--crimson); color: var(--crimson); font-weight: 700; font-size: 12px; padding: 6px 12px; border-radius: 8px; }
.doc-row.has .doc-btn { border-color: var(--line); color: var(--text-2); }
.doc-login { font-size: 12.5px; color: var(--text-2); }
.doc-login .pstep-cta { margin-top: 8px; }

/* Visa Readiness Agent card */
.agent-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.agent-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.agent-emoji { font-size: 18px; }
.agent-head strong { font-size: 14px; flex: 1; }
.agent-band { font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 999px; }
.agent-band.ok { background: #eafaf0; color: var(--ok); }
.agent-band.warn { background: #fef3e2; color: #b9770a; }
.agent-band.risk { background: #fdecec; color: #c0392b; }
.agent-score { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.agent-pct { font-size: 30px; font-weight: 800; line-height: 1; }
.agent-pct span { font-size: 15px; font-weight: 700; color: var(--muted); }
.agent-bar { flex: 1; height: 9px; border-radius: 999px; background: var(--line); overflow: hidden; }
.agent-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.agent-fill.ok { background: var(--ok); }
.agent-fill.warn { background: #e8951b; }
.agent-fill.risk { background: #d8453c; }
.agent-sub { font-size: 12px; color: var(--text-2); font-weight: 600; margin-bottom: 10px; }
.agent-factors { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.afactor { display: flex; gap: 9px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.afactor:last-child { border-bottom: none; }
.af-ic { font-size: 14px; flex: none; line-height: 1.3; }
.af-text { display: flex; flex-direction: column; }
.af-label { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.afactor.ok .af-label { color: var(--text-2); font-weight: 500; }
.af-fix { font-size: 11.5px; color: var(--text-2); margin-top: 2px; }
.agent-note { font-size: 11px; color: var(--muted); line-height: 1.5; margin-top: 6px; }
.agent-note .pstep-cta { margin-top: 8px; }

/* File Coach (friendly student view of the readiness engine) */
.coach-count {
  font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 999px;
  background: #eafaf0; color: var(--ok); white-space: nowrap;
}
.coach-todos { margin-top: 4px; }
.coach-next { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin-bottom: 6px; }
.coach-todo {
  display: flex; gap: 8px; align-items: flex-start;
  background: var(--bg); border-radius: 10px; padding: 9px 11px; margin-bottom: 6px;
}
.coach-todo b { font-size: 13px; display: block; }
.coach-todo small { font-size: 12px; color: var(--text-2); line-height: 1.4; display: block; margin-top: 1px; }

/* exam result step (the journey gate) */
.res-form { display: grid; gap: 8px; margin-top: 10px; }
.res-form label { font-size: 11px; font-weight: 700; color: var(--muted); display: block; }
.res-form input, .res-form select {
  width: 100%; margin-top: 3px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
  background: var(--card); color: var(--ink); font-family: inherit;
}
.res-note { border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.5; margin-top: 8px; }
.res-note.ok { background: #eafaf0; }
.res-note.wait { background: #fef3e2; }
.res-note.support { background: #eef2fb; }
.res-note.bad { background: #fdecec; }
.pstep-cta.ghost { background: var(--bg); color: var(--ink); border: 1px solid var(--line); margin-top: 8px; }

/* referral card (Me tab) */
.ref-card {
  background: linear-gradient(135deg, var(--crimson), var(--blue));
  border-radius: var(--radius); padding: 16px; margin: 14px 0;
  color: #fff;
}
.ref-head { font-size: 15px; font-weight: 800; margin-bottom: 6px; }
.ref-sub { font-size: 12.5px; line-height: 1.5; color: rgba(255,255,255,.88); margin-bottom: 12px; }
.ref-link {
  background: rgba(0,0,0,.25); border: 1px dashed rgba(255,255,255,.4);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 10px;
  font-family: Consolas, "Courier New", monospace; font-size: 12.5px;
  word-break: break-all; color: #fff;
}
.ref-btns { display: flex; gap: 8px; }
.ref-btn {
  flex: 1; border: 1px solid rgba(255,255,255,.5); border-radius: 10px;
  background: rgba(255,255,255,.14); color: #fff;
  padding: 10px 8px; font-size: 13px; font-weight: 800; cursor: pointer;
  font-family: inherit;
}
.ref-btn.solid { background: #fff; color: var(--crimson); border-color: #fff; }
.ref-btn:active { transform: scale(.97); }
.ref-count { font-size: 12.5px; font-weight: 700; margin-top: 10px; color: #FFD98E; }

/* document preview lightbox */
.doc-lightbox {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(10, 12, 18, .92);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.doc-lightbox[hidden] { display: none; }
.doc-lightbox img {
  max-width: 100%; max-height: 90vh;
  border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.5);
  object-fit: contain;
}
.dl-close {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 16px;
  width: 38px; height: 38px; border-radius: 999px; border: none;
  background: rgba(255,255,255,.14); color: #fff; font-size: 17px; font-weight: 700;
  cursor: pointer;
}
.doc-view-btn {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 8px; padding: 7px 12px; font-size: 12.5px; font-weight: 700;
  cursor: pointer; margin-right: 6px; font-family: inherit;
}

/* course card buttons */
.card-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* home revision promo */
.rev-promo {
  display: flex; align-items: center; gap: 12px; margin-top: 14px;
  background: linear-gradient(135deg, #6b21a8, #9333ea); color: #fff;
  border-radius: var(--radius); padding: 14px 16px;
}
.rev-promo-text { flex: 1; }
.rev-promo-text h3 { font-size: 15px; margin: 6px 0 4px; }
.rev-promo-text p { font-size: 12px; opacity: .92; }
.rev-promo-btns { display: flex; flex-direction: column; gap: 6px; flex: none; }
.rev-promo-btns .btn-outline { border-color: #fff; color: #fff; }

/* revision study screen */
.rev-screen { position: absolute; inset: 0; z-index: 8; background: var(--bg); display: flex; flex-direction: column; }
.rev-screen[hidden] { display: none; }
.rev-top { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--card); border-bottom: 1px solid var(--line); }
.rev-back { border: none; background: none; cursor: pointer; font-size: 26px; line-height: 1; color: var(--ink); width: 30px; }
.rev-head { display: flex; flex-direction: column; min-width: 0; }
.rev-head strong { font-size: 15px; }
.rev-head span { font-size: 11.5px; color: var(--text-2); }
.rev-controls { padding: 10px 14px; background: var(--card); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.rev-levels, .rev-cats, .rev-modes { display: flex; gap: 6px; }
.rev-controls button {
  flex: 1; border: 1px solid var(--line); background: var(--bg); cursor: pointer;
  border-radius: 8px; padding: 8px 6px; font-size: 12.5px; font-weight: 600; color: var(--ink);
}
.rev-controls .rev-levels button.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.rev-controls .rev-cats button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.rev-controls .rev-modes button.active { background: #6b21a8; color: #fff; border-color: #6b21a8; }
.rev-cats button, .rev-modes button { display: flex; flex-direction: column; align-items: center; gap: 1px; line-height: 1.2; }
.rev-cats button small, .rev-modes button small { font-size: 10px; font-weight: 600; opacity: .8; }
.rev-lang { display: flex; gap: 6px; }
.rev-lang button { flex: 1; font-size: 12px; padding: 6px; }
.rev-lang button.active { background: #0f6e56; color: #fff; border-color: #0f6e56; }

.rev-audio { border: none; background: none; cursor: pointer; font-size: 18px; padding: 0 4px; line-height: 1; vertical-align: middle; }
.rev-front-audio { margin-top: 10px; }
.rev-front-audio .rev-audio { font-size: 26px; }

.rev-testbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-size: 13px; font-weight: 700; color: var(--text-2); }
.rev-timer { background: #6b21a8; color: #fff; padding: 4px 12px; border-radius: 999px; font-size: 14px; }
.rev-timer-done { font-size: 18px; font-weight: 700; color: #6b21a8; margin-bottom: 8px; }

.rev-weakbar { width: 100%; }
.rev-weak-btn {
  width: 100%; border: 1px solid #e8951b; background: #fef3e2; color: #b9770a;
  cursor: pointer; border-radius: 8px; padding: 9px 10px; font-size: 12.5px; font-weight: 700;
}
.rev-weak-btn.active { background: #e8951b; color: #fff; border-color: #e8951b; }

.rev-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; }
.rev-progress { font-size: 12px; color: var(--text-2); font-weight: 600; margin-bottom: 12px; text-align: center; }

.rev-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  min-height: 200px; padding: 20px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.rev-card.flipped { border-color: var(--blue); }
.rev-front { font-size: 52px; font-weight: 700; line-height: 1.2; }
.rev-tap { font-size: 11px; color: var(--muted); margin-top: 14px; }
.rev-reading { font-size: 26px; font-weight: 700; }
.rev-romaji { font-size: 14px; color: var(--text-2); margin-top: 2px; }
.rev-mean { font-size: 18px; font-weight: 600; margin-top: 10px; color: var(--blue); }
.rev-ex { font-size: 18px; margin-top: 12px; }
.rev-exen { font-size: 13px; color: var(--text-2); margin-top: 4px; }

.rev-nav { display: flex; gap: 8px; margin-top: 14px; }
.rev-nav button { flex: 1; border: 1px solid var(--line); background: var(--card); cursor: pointer; border-radius: 10px; padding: 11px 6px; font-size: 13px; font-weight: 600; color: var(--ink); }
.rev-nav #rev-known.on { background: #eafaf0; border-color: var(--ok); color: var(--ok); }

.rev-q { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 26px; text-align: center; font-size: 46px; font-weight: 700; margin-bottom: 14px; }
.rev-qsub { display: block; font-size: 15px; font-weight: 400; color: var(--text-2); margin-top: 8px; }
.rev-opts { display: flex; flex-direction: column; gap: 8px; }
.rev-opt { border: 1px solid var(--line); background: var(--card); cursor: pointer; border-radius: 10px; padding: 13px; font-size: 14px; font-weight: 600; color: var(--ink); text-align: left; }
.rev-opt.correct { background: #eafaf0; border-color: var(--ok); color: var(--ok); }
.rev-opt.wrong { background: #fdecec; border-color: #d8453c; color: #c0392b; }
.rev-result { text-align: center; padding: 30px 16px; }
.rev-score { font-size: 44px; font-weight: 800; color: var(--blue); }
.rev-result p { font-size: 14px; color: var(--text-2); margin: 8px 0 18px; }
.rev-empty { text-align: center; color: var(--muted); padding: 30px; }

/* ============ JLPT N5 FULL COURSE ============ */
.crs-progress { height: 6px; background: var(--line); flex: none; }
.crs-progress-fill { height: 100%; background: var(--ok); width: 0; transition: width .3s ease; }
.crs-body { flex: 1; overflow-y: auto; padding: 14px 16px 24px; }
.crs-hint { font-size: 12px; color: var(--text-2); margin: 0 0 10px; text-align: center; }
.crs-h4 { font-size: 13px; margin: 14px 0 8px; }
.crs-h4 small { color: var(--text-2); font-weight: 400; }

.crs-kana-row { display: flex; gap: 10px; margin-bottom: 10px; }
.crs-kana-card {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 14px 8px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); cursor: pointer; font-size: 13px;
}
.crs-kana-big { font-size: 34px; line-height: 1.1; }
.crs-kana-card small { font-size: 10.5px; color: var(--text-2); }

.crs-mock {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px; margin-bottom: 12px; border: 1px solid #6b21a8; border-radius: 14px;
  background: #6b21a8; color: #fff; font-weight: 700; font-size: 14px; cursor: pointer;
}
.crs-mock small { font-size: 11px; font-weight: 500; opacity: .9; }

.crs-list { display: flex; flex-direction: column; gap: 8px; }
.crs-row {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); cursor: pointer;
}
.crs-row.done { border-color: var(--ok); }
.crs-row-icon { font-size: 22px; flex: none; }
.crs-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.crs-row-text strong { font-size: 13.5px; }
.crs-row-text small { font-size: 11px; color: var(--text-2); }
.crs-row-mark { flex: none; font-size: 14px; font-weight: 700; color: var(--ok); }

.crs-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.crs-cell {
  display: flex; flex-direction: column; align-items: center; gap: 0;
  padding: 8px 2px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); cursor: pointer;
}
.crs-cell span { font-size: 20px; line-height: 1.2; }
.crs-cell small { font-size: 9.5px; color: var(--text-2); }
.crs-body .btn-primary.wide { margin-top: 14px; }

.crs-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.crs-tabs button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 4px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); cursor: pointer; font-size: 12.5px; line-height: 1.2;
}
.crs-tabs button small { font-size: 10px; color: var(--text-2); }
.crs-tabs button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.crs-tabs button.active small { color: #eee; }

.crs-items { display: flex; flex-direction: column; gap: 8px; }
.crs-item { padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.crs-item-jp { font-size: 18px; font-weight: 700; }
.crs-item-kana { font-size: 13px; font-weight: 500; color: var(--text-2); margin-left: 4px; }
.crs-item-roma { font-size: 11.5px; color: var(--muted); }
.crs-item-mean { font-size: 13px; color: var(--blue); font-weight: 600; margin-top: 2px; }
.crs-item-ex { font-size: 14px; margin-top: 6px; }
.crs-item-ex small { display: block; font-size: 11.5px; color: var(--text-2); }
.crs-note-body { font-size: 14px; line-height: 1.6; margin-top: 6px; color: var(--text-2); }
.crs-note-body b { color: var(--ink); }
.crs-audio { border: none; background: none; cursor: pointer; font-size: 16px; padding: 0 2px; line-height: 1; vertical-align: middle; }
.crs-passed { text-align: center; font-size: 13px; font-weight: 700; color: var(--ok); margin-top: 10px; }

.crs-qbar { font-size: 12px; color: var(--text-2); font-weight: 600; margin-bottom: 12px; text-align: center; }
.crs-q {
  border: 1px solid var(--line); border-radius: 14px; background: var(--card);
  padding: 24px 14px; text-align: center; font-size: 34px; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; gap: 4px; margin-bottom: 12px;
}
.crs-qsub { font-size: 15px; font-weight: 500; color: var(--text-2); }
.crs-opts { display: flex; flex-direction: column; gap: 8px; }
.crs-opt {
  padding: 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); cursor: pointer; font-size: 13.5px; text-align: left;
}
.crs-opt.correct { border-color: var(--ok); background: #e8f7ef; }
.crs-opt.wrong { border-color: #d33; background: #fdeaea; }

.crs-result { text-align: center; padding-top: 30px; }
.crs-score { font-size: 52px; font-weight: 800; color: #d33; }
.crs-score.pass { color: var(--ok); }
.crs-verdict { font-size: 14px; margin: 10px 0 18px; }
.crs-result .btn-ghost.wide { width: 100%; margin-top: 8px; }

/* course level switch (N5 / N4) */
.crs-levels { display: flex; gap: 6px; margin-bottom: 10px; }
.crs-levels button {
  flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); cursor: pointer; font-size: 13px; font-weight: 700;
}
.crs-levels button.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---------- counsellor chat (live support) ---------- */
.quick { position: relative; }
#counsel-badge { top: 6px; right: 6px; }

.chat-panel {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.chat-panel[hidden] { display: none !important; }

.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  padding-left: calc(8px + env(safe-area-inset-left));
  padding-right: calc(14px + env(safe-area-inset-right));
  background: linear-gradient(135deg, var(--crimson), #b01030);
  color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.chat-back {
  border: none; background: none; color: #fff;
  font-size: 30px; line-height: 1; padding: 0 6px; cursor: pointer;
}
.chat-who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-who strong { font-size: 15px; display: block; }
.chat-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255,255,255,.2); display: grid; place-items: center;
  font-weight: 800; font-size: 13px; flex: none;
}
.chat-sub { font-size: 11.5px; opacity: .85; }

.chat-log {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 14px 12px; display: flex; flex-direction: column; gap: 8px;
}
.chat-empty {
  margin: auto; text-align: center; color: var(--muted);
  font-size: 13px; max-width: 240px; line-height: 1.5;
}
.cmsg { max-width: 78%; display: flex; flex-direction: column; }
.cmsg.them { align-self: flex-start; align-items: flex-start; }
.cmsg.me { align-self: flex-end; align-items: flex-end; }
.cmsg .bubble {
  padding: 8px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4;
  word-wrap: break-word; white-space: pre-wrap;
}
.cmsg.them .bubble {
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-bottom-left-radius: 4px;
}
.cmsg.me .bubble {
  background: var(--crimson); color: #fff; border-bottom-right-radius: 4px;
}
.cmsg.me.pending .bubble { opacity: .6; }
.cmsg .cmeta { font-size: 10px; color: var(--muted); margin: 2px 4px 0; }
/* AI auto-reply bubbles: counsellor side, dashed edge + label = clearly a bot */
.cmsg.ai .bubble { border-style: dashed; }
.ai-tag { font-size: 10px; font-weight: 700; color: var(--muted); margin-bottom: 3px; letter-spacing: .2px; }

.chat-compose {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  padding-left: calc(12px + env(safe-area-inset-left));
  padding-right: calc(12px + env(safe-area-inset-right));
  background: var(--card); border-top: 1px solid var(--line);
}
/* min-width:0 lets the field shrink — without it the input keeps its intrinsic
 * width and shoves the 🎤 / send buttons off a narrow phone screen */
#chat-input {
  flex: 1 1 auto; min-width: 0; width: 100%;
  border: 1px solid var(--line); border-radius: 22px;
  padding: 10px 14px; font-size: 14px; background: var(--bg); color: var(--ink);
  outline: none;
}
#chat-input:focus { border-color: var(--crimson); }
.chat-send {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  border: none; background: var(--crimson); color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
.chat-send svg { width: 20px; height: 20px; }
.chat-send:disabled { opacity: .5; cursor: default; }

/* attach buttons (photo / mic) in the compose row */
.chat-attach {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  border: none; background: none; font-size: 20px; cursor: pointer;
  display: grid; place-items: center; color: var(--ink);
}
.chat-attach:active { background: var(--line); }
.chat-attach.recording { background: #fdecec; animation: recpulse 1s infinite; }

/* reply-to context bar above the compose row */
.chat-replybar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: var(--card); border-top: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted);
}
.chat-replybar[hidden] { display: none !important; }
.chat-replybar .crb-ico { flex: none; color: var(--crimson); font-size: 15px; }
.chat-replybar .crb-text {
  flex: 1 1 auto; min-width: 0; line-height: 1.35;
  border-left: 3px solid var(--crimson); padding-left: 8px;
}
.chat-replybar .crb-text span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-replybar b { display: block; color: var(--ink); font-size: 12px; }
#crb-cancel { flex: none; }
#crb-cancel {
  border: none; background: none; font-size: 20px; color: var(--muted);
  cursor: pointer; padding: 0 4px; line-height: 1;
}

/* voice recording bar */
.chat-recbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--card); border-top: 1px solid var(--line);
  font-size: 13px; color: var(--ink);
}
.chat-recbar[hidden] { display: none !important; }
.rec-dot {
  width: 10px; height: 10px; border-radius: 50%; background: #e11d48;
  animation: recpulse 1s infinite;
}
@keyframes recpulse { 50% { opacity: .3; } }
.rec-btn {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 16px; padding: 6px 14px; font-size: 13px; cursor: pointer;
}
.rec-btn.rec-go { background: var(--crimson); color: #fff; border-color: var(--crimson); margin-left: auto; }

/* quoted message block inside a bubble — wraps to 2 lines instead of running
 * under the bubble edge, and never inherits the bubble's pre-wrap */
.cquote {
  display: block; width: 100%; text-align: left; cursor: pointer;
  border: none; border-left: 3px solid rgba(255,255,255,.65);
  background: rgba(0,0,0,.14); color: inherit;
  border-radius: 8px; padding: 5px 8px; margin: 0 0 6px;
  font-family: inherit; font-size: 12px; line-height: 1.35; opacity: .92;
  overflow: hidden;
}
.cmsg.them .cquote { border-left-color: var(--crimson); background: rgba(0,0,0,.05); }
.cquote b { display: block; font-size: 11px; margin-bottom: 1px; }
.cquote span {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; white-space: normal; overflow-wrap: anywhere;
}

/* photo message */
.cimg { border-radius: 10px; overflow: hidden; margin: 0 -4px 4px; }
.cimg:only-child { margin-bottom: -2px; }
.cimg img { display: block; max-width: 100%; max-height: 260px; cursor: zoom-in; }
.cimg-ph {
  min-width: 140px; min-height: 90px; display: grid; place-items: center;
  font-size: 12px; color: var(--muted); background: rgba(0,0,0,.08);
}

/* voice message */
.cvoice audio { display: block; width: 210px; max-width: 100%; height: 36px; }
.cvoice-ph { font-size: 12px; opacity: .8; }

/* reply affordance in the meta row */
.creply {
  border: none; background: none; color: var(--muted); font-size: 10px;
  cursor: pointer; padding: 0 2px;
}

/* flash the original when a quote is tapped */
/* outline-offset keeps the ring inside the bubble so it can't paint over the
 * neighbouring message */
.cmsg.flash .bubble { outline: 2px solid var(--crimson); outline-offset: -2px; transition: outline-color .2s; }

/* full-size photo overlay */
.cimg-overlay {
  position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.92);
  display: grid; place-items: center; cursor: zoom-out;
}
.cimg-overlay img { max-width: 96vw; max-height: 92vh; }

/* AI SOP Writer overlay */
.sop-panel { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: var(--bg); }
.sop-panel[hidden] { display: none !important; }
.sop-head {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: linear-gradient(135deg, var(--blue), #0a4fc0); color: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.sop-head strong { font-size: 15px; display: block; }
.sop-head .chat-sub { color: #fff; opacity: .85; }
.sop-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.sop-l { display: block; font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 12px; }
.sop-l input, .sop-l textarea {
  display: block; width: 100%; margin-top: 5px; font-weight: 400;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  background: var(--card); color: var(--ink); font-size: 14px; box-sizing: border-box;
}
.sop-l input:focus, .sop-l textarea:focus { outline: none; border-color: var(--blue); }
#sop-text {
  width: 100%; box-sizing: border-box; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; font-size: 14px; line-height: 1.55; background: var(--card); color: var(--ink);
  font-family: inherit; resize: vertical;
}
.sop-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.sop-actions button { margin-top: 0; flex: 1; min-width: 46%; }
.sop-generating { text-align: center; color: var(--muted); font-size: 13px; padding: 30px 10px; }
.sop-st { border-radius: 10px; padding: 10px 12px; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.sop-st.wait { background: #fef3e2; color: #b9770a; }
.sop-st.ok { background: #eafaf0; color: var(--ok); }
.sop-st.bad { background: #fdecec; color: var(--crimson); }
.sop-promo { background: linear-gradient(135deg, var(--blue), #0a4fc0); }

/* AI document pre-check line on doc cards */
.doc-ai { display: block; font-size: 11.5px; font-weight: 600; margin-top: 3px; line-height: 1.35; }
.doc-ai.checking { color: var(--muted); }
.doc-ai.ok { color: var(--ok); }
.doc-ai.warn { color: #b9770a; }
.doc-ai.bad { color: var(--crimson); }
