:root {
  --primary: #3E5C50;
  --primary-dark: #2C4339;
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --user-bubble: #E2EAE5;
  --bot-bubble: #FFFFFF;
  --text: #2C3A33;
  --muted: #8C9A92;
  --accent: #C49A6C;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app { height: 100%; display: flex; flex-direction: column; }

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px;
  overflow-y: auto;
}
.screen.center { align-items: center; justify-content: center; text-align: center; gap: 18px; }

.muted { color: var(--muted); }

/* --- login --- */
.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.brand-mark {
  font-size: 56px; line-height: 1; color: var(--primary);
  width: 96px; height: 96px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); box-shadow: 0 6px 24px rgba(0,0,0,.08); margin-bottom: 8px;
}
.brand h1 { margin: 8px 0 0; font-size: 26px; font-weight: 650; }
.tagline { margin: 0; color: var(--muted); }

/* --- buttons --- */
.btn-primary {
  border: none; background: var(--primary); color: #fff;
  font-size: 16px; font-weight: 600; padding: 14px 32px; border-radius: 999px;
  cursor: pointer; transition: background .15s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost {
  border: none; background: transparent; color: var(--primary);
  font-size: 15px; padding: 6px 10px; cursor: pointer; border-radius: 8px;
}
.btn-ghost:hover { background: rgba(0,0,0,.04); }

/* --- top bar --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--surface);
  border-bottom: 1px solid rgba(0,0,0,.06); flex: 0 0 auto;
}
.topbar-title { font-weight: 650; font-size: 17px; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }

/* --- modal (account / change password) --- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.42);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 14px; padding: 22px;
  width: 100%; max-width: 360px; box-shadow: 0 14px 44px rgba(0,0,0,.28);
}
.modal h2 { margin: 0 0 16px; font-size: 18px; color: var(--text); }
.modal label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 13px; color: var(--muted); margin-bottom: 12px;
}
.modal input {
  padding: 10px 12px; border: 1px solid rgba(0,0,0,.14); border-radius: 9px;
  font-size: 15px; color: var(--text); background: var(--bg);
}
.modal input:focus { outline: none; border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.modal-msg { min-height: 18px; font-size: 13px; margin: 2px 0 8px; }
.modal-msg.error { color: #C0392B; }
.modal-msg.ok { color: #2E7D32; }

/* --- persona picker --- */
.picker-hint { color: var(--muted); margin: 8px 0 18px; }
.persona-grid { display: flex; flex-direction: column; gap: 14px; max-width: 480px; width: 100%; margin: 0 auto; }
.persona-card {
  display: flex; flex-direction: column; gap: 4px; text-align: left;
  border: 1px solid rgba(0,0,0,.08); border-left: 5px solid var(--card-accent, var(--primary));
  background: var(--surface); border-radius: 16px; padding: 18px 20px;
  cursor: pointer; transition: transform .12s, box-shadow .12s;
}
.persona-card:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(0,0,0,.08); }
.persona-name { font-size: 18px; font-weight: 650; }
.persona-tagline { color: var(--muted); font-size: 14px; }
.signed-as { color: var(--muted); font-size: 13px; text-align: center; margin-top: 24px; }

/* --- chat --- */
.messages {
  flex: 1; overflow-y: auto; padding: 18px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.bubble {
  max-width: 80%; padding: 10px 14px; border-radius: 18px;
  font-size: 15px; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,.05);
}
.bubble.user { align-self: flex-end; background: var(--user-bubble); border-bottom-right-radius: 5px; }
.bubble.bot { align-self: flex-start; background: var(--bot-bubble); border-bottom-left-radius: 5px; }

.bubble.typing { display: flex; gap: 4px; align-items: center; }
.bubble.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite both;
}
.bubble.typing span:nth-child(2) { animation-delay: .2s; }
.bubble.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.system-line { align-self: center; color: var(--muted); font-size: 13px; text-align: center; max-width: 90%; padding: 4px 0; }
.system-line.error { color: #C0392B; }
.error-msg { color: #C0392B; max-width: 420px; }

/* --- composer --- */
.composer {
  flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid rgba(0,0,0,.06);
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid rgba(0,0,0,.12); border-radius: 20px;
  padding: 10px 14px; font-size: 15px; font-family: inherit; line-height: 1.35;
  max-height: 140px; outline: none; background: var(--bg); color: var(--text);
}
.composer textarea:focus { border-color: var(--primary); }
.btn-send {
  flex: 0 0 auto; width: 40px; height: 40px; border: none; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 18px; cursor: pointer;
}
.btn-send:disabled { opacity: .5; cursor: default; }

/* --- spinner --- */
.spinner {
  width: 38px; height: 38px; border: 3px solid rgba(0,0,0,.1);
  border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- persona-site landing (branded single-persona front door) --- */
.landing {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px 24px; overflow-y: auto; position: relative; width: 100%;
}
.landing-inner {
  max-width: 380px; width: 100%; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}
.landing-copy, .landing-bullets { width: 100%; overflow-wrap: break-word; }
.landing .brand h1 { font-size: 34px; }
.landing-copy { color: var(--text); line-height: 1.55; }
.landing-copy p { margin: 0 0 12px; }
.landing-bullets {
  list-style: none; padding: 0; margin: 0; text-align: left;
  display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 360px;
}
.landing-bullets li { position: relative; padding-left: 22px; color: var(--text); }
.landing-bullets li::before {
  content: "◐"; position: absolute; left: 0; top: 0; color: var(--primary);
}
.landing-footer { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.lang-toggle {
  position: absolute; top: 16px; right: 16px; display: flex; gap: 2px;
  background: var(--surface); border-radius: 999px; padding: 3px;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
}
.lang-opt {
  border: none; background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 600; padding: 5px 12px; border-radius: 999px; cursor: pointer;
}
.lang-opt.active { background: var(--primary); color: #fff; }
.landing-org {
  margin-top: 10px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding-top: 18px; border-top: 1px solid rgba(0,0,0,.08); width: 100%;
}
.landing-logo { height: 52px; width: auto; opacity: .92; }
.landing-org-caption { margin: 0; font-size: 12px; color: var(--muted); }

/* --- course hub (logged-in: intro video + curriculum) --- */
.lang-toggle.inline { position: static; box-shadow: none; background: transparent; padding: 0; }
.course-scroll { flex: 1; overflow-y: auto; padding: 24px 18px calc(28px + env(safe-area-inset-bottom)); }
.course-inner { max-width: 720px; margin: 0 auto; width: 100%; }
.course-intro { color: var(--text); line-height: 1.55; margin: 0 0 20px; }
.course-video {
  border-radius: 14px; overflow: hidden; background: #000;
  box-shadow: 0 8px 28px rgba(0,0,0,.12); margin: 0 0 16px;
}
.course-video.portrait { max-width: 360px; margin-left: auto; margin-right: auto; }
.course-video video { display: block; width: 100%; height: auto; background: #000; }
.course-video-label {
  margin: 0; padding: 10px 14px; font-size: 13px; color: var(--muted);
  background: var(--surface);
}
.course-talk {
  display: block; width: 100%; max-width: 320px; margin: 22px auto 8px; text-align: center;
}
.course-modules-h { font-size: 16px; font-weight: 650; color: var(--text); margin: 28px 0 12px; }
.course-modules { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.course-module {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid rgba(0,0,0,.07); border-radius: 12px;
  padding: 12px 14px;
}
.cm-num {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%;
  background: var(--bg); color: var(--primary); font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.cm-title { flex: 1; font-size: 14px; color: var(--text); line-height: 1.35; }
.cm-soon { flex: 0 0 auto; font-size: 11px; color: var(--muted); font-style: italic; }

/* --- access flow (register / pending / approved) + admin panel ----------- */
.screen.access { align-items: center; }
.access-card {
  width: 100%; max-width: 440px; background: var(--surface);
  border-radius: 14px; padding: 24px 22px; box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.access-card h2 { margin: 0 0 12px; font-size: 20px; color: var(--text); }
.access-intro { color: var(--text); line-height: 1.55; margin: 0 0 18px; font-size: 14px; }
.access-card form { display: flex; flex-direction: column; gap: 14px; }
.access-card label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; color: var(--muted);
}
.access-card input, .access-card textarea {
  padding: 10px 12px; border: 1px solid #d9d2c7; border-radius: 9px;
  font: inherit; color: var(--text); background: var(--bg); resize: vertical;
}
.access-card input:focus, .access-card textarea:focus {
  outline: none; border-color: var(--primary); background: var(--surface);
}
.access-card .btn-primary { margin-top: 4px; }

.admin-scroll { overflow-y: auto; padding: 16px; }
.admin-list { width: 100%; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.admin-item {
  background: var(--surface); border-radius: 12px; padding: 16px 16px 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05); display: flex; flex-direction: column; gap: 8px;
}
.admin-who { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.admin-name { font-weight: 600; color: var(--text); }
.admin-persona { font-size: 11px; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.admin-meta { font-size: 13px; color: var(--muted); }
.admin-why { font-size: 13px; color: var(--text); line-height: 1.5; background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.admin-phone-l { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.admin-phone { padding: 8px 10px; border: 1px solid #d9d2c7; border-radius: 8px; font: inherit; color: var(--text); background: var(--bg); }
.admin-phone:focus { outline: none; border-color: var(--primary); }
.admin-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; align-items: center; }
.admin-done { color: #2E7D32; font-size: 14px; text-align: center; padding: 6px 0; }

/* --- admin hub: tabs + persona switcher --- */
.admin-tabs { display: flex; gap: 4px; padding: 8px 16px 0; border-bottom: 1px solid rgba(0,0,0,.06); }
.admin-tab {
  border: none; background: transparent; color: var(--muted); font: inherit; font-size: 14px;
  padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.admin-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.admin-persona-sel {
  font: inherit; font-size: 15px; font-weight: 600; color: var(--text);
  border: none; background: transparent; max-width: 60vw;
}
.center-p { text-align: center; padding: 24px 0; }

/* --- members --- */
/* Member rows: stacked cards on mobile; single-line grid + wider container on
   desktop (the admin hub is a management view, not the phone-width chat). */
.member-item {
  width: 100%; max-width: 560px; margin: 0 auto; background: var(--surface);
  border: 1px solid rgba(0,0,0,.08); border-radius: 12px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.member-item.removed { opacity: .55; }
.member-name { font-weight: 600; color: var(--text); }
.member-email { font-size: 13px; color: var(--text); overflow-wrap: anywhere; }
.member-email-none { color: var(--muted); font-style: italic; }
.member-phone { font-size: 13px; color: var(--muted); }
.member-last { font-size: 13px; color: var(--muted); }
.member-section {
  max-width: 560px; margin: 20px auto 8px; font-size: 14px; font-weight: 650; color: var(--text);
}
.member-count { color: var(--muted); font-weight: 400; }
.member-hint { color: var(--muted); font-size: 12px; font-weight: 400; }
.member-tier { display: flex; align-items: center; gap: 4px; }
.member-controls { display: flex; align-items: center; gap: 8px; }
.member-msg { min-height: 0; }
.role-badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700;
  padding: 2px 7px; border-radius: 999px; background: var(--bg); color: var(--muted);
}
.role-badge.role-admin { background: #E2EAE5; color: var(--primary-dark); }
.role-badge.role-superadmin { background: var(--accent); color: #fff; }
.member-fixed { font-size: 10px; color: var(--muted); font-style: italic; }
.member-role { font: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid #d9d2c7;
  border-radius: 8px; background: var(--bg); color: var(--text); }

@media (min-width: 768px) {
  /* Widen the whole admin hub on a real screen. */
  .admin-list, .member-section { max-width: 1080px; }
  .member-item {
    max-width: 1080px;
    display: grid;
    grid-template-columns: minmax(140px, 1.4fr) minmax(170px, 1.6fr) minmax(120px, 1fr) max-content max-content max-content;
    align-items: center; column-gap: 18px; row-gap: 2px;
    padding: 10px 18px;
  }
  .member-email, .member-phone, .member-last { font-size: 14px; }
  .member-controls { justify-self: end; }
  /* status line drops to its own row under the cells, only when populated */
  .member-msg { grid-column: 1 / -1; }
  .member-msg:empty { display: none; }
}

/* --- usage dashboard --- */
.tile-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; max-width: 560px; margin: 0 auto 8px; }
.tile { background: var(--surface); border: 1px solid rgba(0,0,0,.08); border-radius: 12px; padding: 14px; text-align: center; }
.tile-val { font-size: 24px; font-weight: 700; color: var(--primary); }
.tile-label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.usage-h { max-width: 560px; margin: 18px auto 6px; font-size: 14px; color: var(--text); }
.barchart { width: 100%; max-width: 560px; display: block; margin: 0 auto; height: 90px; }
.barchart .bar { fill: var(--primary); }
.channel-mix { max-width: 560px; margin: 0 auto; }
.splitbar { height: 14px; border-radius: 7px; overflow: hidden; background: var(--accent); }
.splitbar .seg-web { display: block; height: 100%; background: var(--primary); }
.channel-legend { font-size: 13px; color: var(--muted); margin-top: 8px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: middle; margin-right: 3px; }
.dot-web { background: var(--primary); }
.dot-wa { background: var(--accent); }
.usage-note { max-width: 560px; margin: 16px auto 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
