:root {
  --accent: #5B4FE8;
  --accent-dark: #4038B0;
  --bg: #F6F5FB;
  --card: #FFFFFF;
  --text: #1E1B2E;
  --muted: #78748F;
  --border: #E6E4F2;
  --success: #1FA971;
  --danger: #E4483B;
  --coach-bubble: #EDEBFB;
  --asker-bubble: #5B4FE8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 76px; /* room for bottom nav */
  overflow-x: hidden; /* safety net: no single element (e.g. an unbroken long word) should ever force horizontal page scroll */
}

a { color: inherit; text-decoration: none; }

.container { max-width: 640px; margin: 0 auto; padding: 16px; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
}
.topbar .back { font-size: 20px; }
.topbar h1 { font-size: 17px; margin: 0; flex: 1; }
.topbar .lang-switch {
  font-size: 12px; font-weight: 700; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 9px;
}
.topbar .balance {
  font-size: 13px; font-weight: 600; color: var(--accent);
  background: var(--coach-bubble); padding: 4px 10px; border-radius: 999px;
}

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; padding: 8px 0 max(8px, env(safe-area-inset-bottom));
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--muted); padding: 4px 12px;
}
.bottom-nav a.active { color: var(--accent); font-weight: 600; }
.bottom-nav .icon { font-size: 20px; }

.category-block { margin-bottom: 24px; }
.category-title { font-size: 15px; font-weight: 700; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.room-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.room-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; display: flex; flex-direction: column; gap: 6px;
}
.room-card .icon { font-size: 26px; }
.room-card .name { font-weight: 600; font-size: 14px; }
.room-card .desc { font-size: 12px; color: var(--muted); }

.thread-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.thread-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; min-width: 0;
}
.thread-card .title { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; min-width: 0; }
.thread-card .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 999px; }
.pill.open { background: #FFF1D6; color: #9A6B00; }
.pill.resolved { background: #DFF6EA; color: var(--success); }

.fab {
  position: fixed; bottom: 88px; right: 20px; z-index: 15;
  background: var(--accent); color: white; border: none; border-radius: 999px;
  padding: 14px 22px; font-weight: 700; font-size: 14px; box-shadow: 0 6px 18px rgba(91,79,232,.4);
}

.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px; }

label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], textarea, select {
  width: 100%; padding: 13px 14px; border-radius: 10px; border: 1px solid var(--border);
  font-size: 15px; background: #fff; color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 14px; border-radius: 12px; border: none;
  font-size: 15px; font-weight: 700; cursor: pointer; margin-top: 14px;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:active { background: var(--accent-dark); }
.btn-secondary { background: var(--coach-bubble); color: var(--accent-dark); }
.btn-danger { background: #FBE4E1; color: var(--danger); }
.btn-sm { width: auto; padding: 8px 16px; font-size: 13px; margin-top: 0; }

.error-box { background: #FBE4E1; color: var(--danger); padding: 12px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 12px; }
.info-box { background: var(--coach-bubble); color: var(--accent-dark); padding: 12px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 12px; }
.success-box { background: #DFF6EA; color: var(--success); padding: 12px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 12px; }

.type-tabs { display: flex; gap: 8px; margin-top: 10px; }
.type-tab {
  flex: 1; text-align: center; padding: 10px; border-radius: 10px; border: 1px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--muted); background: #fff; cursor: pointer;
}
.type-tab.active { border-color: var(--accent); color: var(--accent); background: var(--coach-bubble); }
.type-tab .cost { display: block; font-size: 11px; font-weight: 400; margin-top: 2px; }

.coach-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.coach-check {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
}
.coach-check input { width: auto; }

.recorder-box { text-align: center; padding: 20px 10px; }
.record-btn {
  width: 84px; height: 84px; border-radius: 50%; border: none;
  background: var(--danger); color: white; font-size: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(228,72,59,.4);
}
.record-btn.recording { animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(228,72,59,.5); } 70% { box-shadow: 0 0 0 18px rgba(228,72,59,0); } 100% { box-shadow: 0 0 0 0 rgba(228,72,59,0); } }
.record-timer { margin-top: 10px; font-size: 14px; font-weight: 700; color: var(--muted); }
.record-hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
video.preview, audio.preview { width: 100%; margin-top: 12px; border-radius: 10px; }

.messages { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.msg { max-width: 82%; min-width: 0; padding: 10px 14px; border-radius: 14px; font-size: 14px; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg .sender { font-size: 11px; font-weight: 700; margin-bottom: 3px; opacity: .75; }
.msg.from-asker { align-self: flex-end; background: var(--asker-bubble); color: white; border-bottom-right-radius: 4px; }
.msg.from-coach { align-self: flex-start; background: var(--coach-bubble); color: var(--text); border-bottom-left-radius: 4px; }
.msg audio, .msg video { width: 100%; margin-top: 6px; border-radius: 8px; }
.msg .cost-tag { font-size: 10px; opacity: .7; margin-top: 4px; }

.composer { margin-top: 18px; }
.resolve-box { margin-top: 24px; padding: 16px; background: var(--coach-bubble); border-radius: 14px; }
.resolve-box h3 { margin: 0 0 8px; font-size: 14px; }

.preset-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.preset-btn {
  padding: 12px 4px; text-align: center; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; font-weight: 700; font-size: 13px; cursor: pointer;
}
.preset-btn.selected { border-color: var(--accent); background: var(--coach-bubble); color: var(--accent-dark); }

.wallet-balance { text-align: center; padding: 22px 0; }
.wallet-balance .num { font-size: 40px; font-weight: 800; color: var(--accent); }
.wallet-balance .label { font-size: 13px; color: var(--muted); }

.history-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.history-row .note { color: var(--muted); }
.history-row .amt.pos { color: var(--success); font-weight: 700; }
.history-row .amt.neg { color: var(--danger); font-weight: 700; }

table.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
table.admin-table th, table.admin-table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.stat-tile { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.stat-tile .label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-tile .value { font-size: 20px; font-weight: 800; color: var(--text); margin-top: 4px; }
.stat-tile .value.accent { color: var(--accent); }
.stat-tile .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat-tile .note { font-size: 11px; color: var(--faint, var(--muted)); margin-top: 6px; line-height: 1.4; }
.section-title { font-size: 15px; font-weight: 700; margin: 22px 0 4px; }

/* ── Elder Voices additions ───────────────────────────────────────── */
.hero { background: linear-gradient(135deg, var(--accent), #8B5CF6); color: #fff; border-radius: 16px; padding: 20px; margin-bottom: 20px; }
.hero h2 { margin: 0 0 6px; font-size: 20px; }
.hero p { margin: 0 0 4px; font-size: 14px; opacity: .95; line-height: 1.45; }
.hero .btn { background: #fff; color: var(--accent-dark); margin-top: 12px; }
.topbar .back { font-size: 20px; }
.topbar a.balance, .topbar a.lang-switch { white-space: nowrap; }
.avatar { border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--coach-bubble); }
.avatar.ph { display: inline-flex; align-items: center; justify-content: center; }
.grow { flex: 1; min-width: 0; }
.elder-card { flex-direction: row !important; align-items: center; gap: 12px !important; }
.profile-head { display: flex; gap: 14px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pill.paid, .pill.awaiting_confirmation, .pill.reschedule_needed, .pill.disputed { background: #FFF1D6; color: #9A6B00; }
.pill.released { background: #DFF6EA; color: var(--success); }
.pill.refunded, .pill.expired { background: #ECEAF5; color: var(--muted); }
.pill.pending_payment { background: #E8EEFF; color: #3A56C8; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; }
.stars { color: #E8A317; letter-spacing: 1px; }
.price-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.price-table td { padding: 6px 0; }
.price-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.price-table tr.total td { border-top: 1px solid var(--border); font-weight: 800; padding-top: 10px; }
.price-table tr.internal td { color: var(--muted); font-size: 12px; font-style: italic; }
.reply { background: var(--coach-bubble); border-radius: 10px; padding: 8px 12px; font-size: 13px; margin-top: 6px; overflow-wrap: anywhere; }
.rating-row { display: inline-flex; flex-direction: row-reverse; gap: 4px; }
.rating-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.rating-row label { font-size: 34px; color: #D9D6E8; cursor: pointer; margin: 0; line-height: 1; }
.rating-row input:checked ~ label, .rating-row label:hover, .rating-row label:hover ~ label { color: #E8A317; }
.rating-row input:focus-visible + label { outline: 2px solid var(--accent); border-radius: 6px; }
.call-card { text-align: center; }
.call-timer { font-size: 38px; font-weight: 800; margin: 14px 0; font-variant-numeric: tabular-nums; }
.call-actions { display: flex; justify-content: center; gap: 24px; margin: 8px 0 12px; }
.round-btn { width: 68px; height: 68px; border-radius: 50%; border: none; background: var(--coach-bubble); font-size: 28px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.round-btn.hangup { background: var(--danger); }
.quick-links { display: flex; flex-direction: column; gap: 0; }
.wallet-balance .num small { font-size: 16px; }
details > summary { cursor: pointer; font-weight: 700; font-size: 14px; padding: 8px 0; }
input[type=file], input[type=datetime-local], input[type=email] { max-width: 100%; }
