/* CS Tuition brand: Royal Navy, Academic Navy, Heritage Gold, Champion Gold, Warm Ivory.
   Navy for authority, gold only for highlights and key actions. */
:root {
  --navy: #071C3D;
  --navy-2: #0E326B;
  --gold: #B88A2B;
  --gold-2: #D6AE4B;
  --ivory: #F8F5ED;
  --mist: #EAF0F8;

  --bg: var(--ivory);
  --panel: #FFFFFF;
  --panel-2: #F4F1E8;
  --text: var(--navy);
  --muted: #47617E;
  --line: #E7E1D2;
  --accent: var(--navy-2);
  --on-accent: #FFFFFF;
  --ok: #1F8A5B;
  --bad: #B83A33;
  --warn-soft: #FBF1DA;
  --warn: #8A6516;
  --bubble-customer: #FFFFFF;
  --bubble-bot: #FBF4E2;
  --bubble-staff: #E4ECF8;
  --chat-bg: #F1EEE4;
  --rail: var(--navy);
  --shadow: 0 1px 2px rgba(7, 28, 61, .04), 0 8px 24px rgba(7, 28, 61, .06);
  --shadow-lift: 0 2px 4px rgba(7, 28, 61, .06), 0 14px 34px rgba(7, 28, 61, .10);
  --radius: 22px;
  --radius-sm: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #061530;
    --panel: #0C2247;
    --panel-2: #10295A;
    --text: #F8F5ED;
    --muted: #A7B6CB;
    --line: #1B3767;
    --accent: #D6AE4B;
    --on-accent: #071C3D;
    --ok: #5BC995;
    --bad: #F08A80;
    --warn-soft: #3A2E12;
    --warn: #E9C46A;
    --bubble-customer: #12305F;
    --bubble-bot: #33290F;
    --bubble-staff: #173A73;
    --chat-bg: #081B3A;
    --rail: #040F24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, .35), 0 14px 34px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  --bg: #061530; --panel: #0C2247; --panel-2: #10295A; --text: #F8F5ED; --muted: #A7B6CB; --line: #1B3767;
  --accent: #D6AE4B; --on-accent: #071C3D; --ok: #5BC995; --bad: #F08A80; --warn-soft: #3A2E12; --warn: #E9C46A;
  --bubble-customer: #12305F; --bubble-bot: #33290F; --bubble-staff: #173A73; --chat-bg: #081B3A; --rail: #040F24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, .35), 0 14px 34px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 34px; font-weight: 700; }
h2 { font-size: 22px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 4px 0 12px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--bad); min-height: 1em; }
.lead { max-width: 760px; }
.grow { flex: 1; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.ico { width: 18px; height: 18px; }

/* ---------- Form controls ---------- */
input, textarea, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  margin-top: 5px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(214, 174, 75, .25); }
label { display: block; margin-bottom: 14px; font-size: 14px; font-weight: 500; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
label.check input { width: auto; margin: 0; accent-color: var(--gold); }

.btn {
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 9px 18px; border-radius: 999px;
  box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .15s, background .15s;
}
.btn:hover { box-shadow: var(--shadow-lift); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--navy-2); border-color: var(--navy-2); color: #fff; }
.btn.gold { background: linear-gradient(135deg, var(--gold-2), var(--gold)); border-color: var(--gold); color: var(--navy); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.small { padding: 6px 14px; font-size: 13px; }
.btn.block { width: 100%; padding: 12px; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; margin: 0; box-shadow: var(--shadow); font-size: 14px;
}
.pill.soft { box-shadow: none; background: var(--panel-2); }
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); }

/* Language + light/dark buttons (top-right) */
.pill-btn {
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; color: var(--text);
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; height: 38px; padding: 0 14px; box-shadow: var(--shadow);
}
.pill-btn:hover, .icon-btn:hover { border-color: var(--gold); }
.topbar .icon-btn, .corner-toggles .icon-btn { box-shadow: var(--shadow); }
.corner-toggles { position: fixed; top: 16px; right: 16px; display: flex; gap: 8px; z-index: 30; }

/* ---------- Cards & layout helpers ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: center; }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; gap: 12px; }
.row.gap { gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0 20px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 22px; align-items: start; }
.pair { display: flex; gap: 8px; align-items: center; }
.narrow { max-width: 620px; }
.section-title { font-size: 18px; margin-top: 4px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 14px; margin: 6px 0 20px; }
.page-head h1 { margin: 0; }
.eyebrow { margin: 0 0 4px; color: var(--gold); font-weight: 700; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-shell {
  width: 100%; max-width: 980px; display: grid; grid-template-columns: 1.1fr 1fr;
  background: var(--panel); border-radius: 28px; overflow: hidden; box-shadow: var(--shadow-lift); border: 1px solid var(--line);
}
.auth-hero {
  position: relative; padding: 36px 36px 0; color: var(--navy);
  background: radial-gradient(circle at 85% 0%, rgba(214, 174, 75, .16), transparent 45%), #FFFFFF;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.auth-hero h1 { font-size: 34px; color: var(--navy); margin-top: 18px; }
.auth-hero p { color: var(--muted); max-width: 360px; }
.hero-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; }
.hero-brand img { width: 46px; height: 46px; background: #fff; border-radius: 14px; padding: 4px; border: 1px solid var(--line); }
.hero-mascot { width: 62%; max-width: 280px; align-self: center; margin-top: 8px; border-radius: 24px 24px 0 0; display: block; }
.hero-foot {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 10px; text-align: center;
  background: var(--ivory); border-top: 1px solid var(--line); color: var(--gold); font-weight: 700; font-size: 12px; letter-spacing: .16em; text-transform: uppercase;
}
/* Dark mode: the login box stays navy */
:root[data-theme="dark"] .auth-hero { color: #F8F5ED; border-right: 0; background: radial-gradient(circle at 85% 0%, rgba(214, 174, 75, .14), transparent 45%), linear-gradient(160deg, var(--navy) 10%, var(--navy-2) 100%); }
:root[data-theme="dark"] .auth-hero h1 { color: #fff; }
:root[data-theme="dark"] .auth-hero p { color: #C9D4E5; }
:root[data-theme="dark"] .hero-foot { background: rgba(7, 28, 61, .85); border-top: 0; color: var(--gold-2); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .auth-hero { color: #F8F5ED; border-right: 0; background: radial-gradient(circle at 85% 0%, rgba(214, 174, 75, .14), transparent 45%), linear-gradient(160deg, var(--navy) 10%, var(--navy-2) 100%); }
  :root:not([data-theme="light"]) .auth-hero h1 { color: #fff; }
  :root:not([data-theme="light"]) .auth-hero p { color: #C9D4E5; }
  :root:not([data-theme="light"]) .hero-foot { background: rgba(7, 28, 61, .85); border-top: 0; color: var(--gold-2); }
}
.auth-card { padding: 44px 40px; align-self: center; }
.auth-card h2 { font-size: 28px; }

/* ---------- App shell: navy icon rail + top bar ---------- */
.app { display: flex; min-height: 100vh; }
.rail {
  width: 92px; flex-shrink: 0; background: var(--rail); color: #C9D4E5;
  display: flex; flex-direction: column; align-items: center; padding: 18px 0;
  position: sticky; top: 0; height: 100vh;
}
.rail-logo { width: 54px; height: 54px; background: #fff; border-radius: 16px; padding: 5px; margin-bottom: 22px; }
#nav { display: flex; flex-direction: column; gap: 6px; flex: 1; width: 100%; align-items: center; }
#nav button {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px;
  width: 70px; padding: 10px 0 8px; border: 0; border-radius: 18px; cursor: pointer;
  background: transparent; color: inherit; font: inherit; font-size: 11px; font-weight: 600;
  transition: background .15s, color .15s;
}
#nav button svg { width: 22px; height: 22px; }
#nav button:hover { background: rgba(255, 255, 255, .07); color: #fff; }
#nav button.active { background: linear-gradient(135deg, var(--gold-2), var(--gold)); color: var(--navy); box-shadow: 0 6px 18px rgba(184, 138, 43, .35); }
#nav button:disabled { opacity: .35; cursor: default; }
#nav .nav-bottom { margin-top: auto; }
.badge {
  position: absolute; top: 4px; right: 10px; min-width: 18px; height: 18px; padding: 0 5px;
  background: #E2483D; color: #fff; border-radius: 99px; font-size: 11px; line-height: 18px; font-weight: 700;
}

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 18px 28px; position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
}
.number-pill { padding: 4px 6px 4px 14px; font-weight: 600; }
.number-pill select {
  width: auto; min-width: 180px; border: 0; background: transparent; margin: 0; padding: 6px 8px; font-weight: 600; box-shadow: none; cursor: pointer;
}
.number-pill select:focus { box-shadow: none; }
.number-pill.connected .ico { color: var(--ok); }
.number-pill.off .ico { color: var(--muted); }
.faces { display: flex; align-items: center; }
.faces .avatar { margin-left: -10px; border: 2px solid var(--bg); }
.faces .avatar:first-child { margin-left: 0; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  background: linear-gradient(135deg, var(--navy-2), var(--navy)); color: #fff; font-weight: 700; font-size: 13px;
}
.avatar.more { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.me-pill {
  display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow);
}
.me-pill .avatar { background: linear-gradient(135deg, var(--gold-2), var(--gold)); color: var(--navy); }
.me-name { font-size: 13px; line-height: 1.25; padding-right: 4px; }
.me-name b { display: block; font-size: 14px; }
main { padding: 4px 28px 40px; max-width: 1360px; width: 100%; }

/* ---------- Home ---------- */
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 22px; align-items: start; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.stat { margin: 0; display: flex; flex-direction: column; gap: 6px; padding: 18px 20px; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat .big { font-size: 30px; font-weight: 800; line-height: 1.1; }
#waStatus { font-size: 22px; white-space: nowrap; padding-top: 6px; }
.stat-gold { background: linear-gradient(135deg, #F3D98E, var(--gold-2)); border-color: var(--gold-2); color: var(--navy); }
.stat-gold .stat-label { color: rgba(7, 28, 61, .7); }
.ok { color: var(--ok); }
.bad { color: var(--bad); }

.buddy {
  position: sticky; top: 92px;
  border-radius: 28px; overflow: hidden; color: var(--navy); box-shadow: var(--shadow-lift);
  background: radial-gradient(circle at 50% 0%, rgba(214, 174, 75, .14), transparent 55%), #FFFFFF;
  border: 1px solid var(--line);
}
.buddy-mascot {
  display: block; width: calc(100% - 28px); margin: 14px 14px 0; border-radius: 22px;
  aspect-ratio: 1 / 1; object-fit: cover; object-position: center 30%;
}
.buddy-body { padding: 4px 22px 22px; text-align: center; }
.buddy-body h2 { color: var(--navy); font-size: 24px; margin-top: 10px; }
.buddy-body p { color: var(--muted); }
.buddy-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 14px 0 18px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--navy);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px;
}
.chip svg { width: 16px; height: 16px; }
.chip:hover { background: #FBF1DA; border-color: var(--gold-2); }
.buddy-tips { text-align: left; background: var(--ivory); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; font-size: 13px; }
.tips-title { display: flex; gap: 8px; align-items: center; color: var(--gold); font-weight: 700; margin-bottom: 6px; }
.tips-title svg { width: 18px; height: 18px; }
.buddy-tips ul { margin: 0; padding-left: 18px; color: var(--muted); }
.buddy-tips li { margin: 3px 0; }

/* Dark mode: the mascot panel stays navy */
:root[data-theme="dark"] .buddy { color: #F8F5ED; border-color: transparent; background: linear-gradient(180deg, #0B2550 0%, var(--navy) 70%); }
:root[data-theme="dark"] .buddy-mascot { width: 100%; margin: 0; border-radius: 0; }
:root[data-theme="dark"] .buddy-body h2 { color: #fff; }
:root[data-theme="dark"] .buddy-body p, :root[data-theme="dark"] .buddy-tips ul { color: #C9D4E5; }
:root[data-theme="dark"] .chip { color: #F8F5ED; background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .16); }
:root[data-theme="dark"] .chip:hover { background: rgba(214, 174, 75, .22); border-color: var(--gold-2); }
:root[data-theme="dark"] .buddy-tips { background: rgba(255, 255, 255, .06); border-color: transparent; }
:root[data-theme="dark"] .tips-title { color: var(--gold-2); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .buddy { color: #F8F5ED; border-color: transparent; background: linear-gradient(180deg, #0B2550 0%, var(--navy) 70%); }
  :root:not([data-theme="light"]) .buddy-mascot { width: 100%; margin: 0; border-radius: 0; }
  :root:not([data-theme="light"]) .buddy-body h2 { color: #fff; }
  :root:not([data-theme="light"]) .buddy-body p, :root:not([data-theme="light"]) .buddy-tips ul { color: #C9D4E5; }
  :root:not([data-theme="light"]) .chip { color: #F8F5ED; background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .16); }
  :root:not([data-theme="light"]) .chip:hover { background: rgba(214, 174, 75, .22); border-color: var(--gold-2); }
  :root:not([data-theme="light"]) .buddy-tips { background: rgba(255, 255, 255, .06); border-color: transparent; }
  :root:not([data-theme="light"]) .tips-title { color: var(--gold-2); }
}

/* Switch */
.switch { position: relative; width: 54px; height: 31px; margin: 0; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::before {
  content: ""; position: absolute; width: 25px; height: 25px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}
.switch input:checked + span { background: linear-gradient(135deg, var(--gold-2), var(--gold)); }
.switch input:checked + span::before { transform: translateX(23px); }
.switch input:disabled + span { opacity: .5; cursor: default; }

/* Linking */
.link-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.option { border: 1px solid var(--line); background: var(--panel-2); border-radius: 18px; padding: 16px; }
.option p { margin: 2px 0 12px; font-size: 14px; }
.notice { background: var(--warn-soft); color: var(--warn); padding: 9px 14px; border-radius: 12px; }
.qr-wrap { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.qr-wrap img { width: 230px; height: 230px; background: #fff; padding: 10px; border-radius: 18px; border: 1px solid var(--line); }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 8px; }
.pair-code {
  font: 800 38px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 6px;
  background: var(--navy); color: var(--gold-2); border-radius: 18px;
  padding: 16px; text-align: center; margin-bottom: 14px; word-break: break-all;
}

/* Lists (scheduled, activity, numbers) */
.log { list-style: none; margin: 0; padding: 0; }
.log li { padding: 12px 0; border-bottom: 1px solid var(--line); display: flex; gap: 14px; align-items: center; font-size: 14px; }
.log li:last-child { border-bottom: 0; }
.log .when { color: var(--muted); width: 120px; flex-shrink: 0; font-size: 13px; }

/* ---------- Chats ---------- */
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px; box-shadow: var(--shadow); }
.seg button { font: inherit; font-size: 14px; font-weight: 600; border: 0; background: transparent; color: var(--muted); padding: 7px 16px; border-radius: 999px; cursor: pointer; }
.seg button.active { background: var(--navy-2); color: #fff; }
.chats { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 18px; }
.chat-list { padding: 8px; height: calc(100vh - 230px); min-height: 420px; overflow-y: auto; margin: 0; }
.chat-item { padding: 12px 14px; border-radius: 16px; cursor: pointer; display: block; width: 100%; text-align: left; border: 0; background: none; color: inherit; font: inherit; }
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--mist); }
:root[data-theme="dark"] .chat-item.active { background: var(--panel-2); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chat-item.active { background: var(--panel-2); } }
.chat-item .top { display: flex; justify-content: space-between; gap: 8px; }
.chat-item .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.chat-item .last { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 99px; margin: 3px 4px 0 0; }
.tag.need { background: var(--warn-soft); color: var(--warn); }
.tag.paused { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.chat-view { display: flex; flex-direction: column; height: calc(100vh - 230px); min-height: 420px; margin: 0; padding: 0; overflow: hidden; }
.chat-view > .muted.center { margin: auto; }
.chat-head { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.msgs { flex: 1; overflow-y: auto; padding: 18px; background: var(--chat-bg); display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 72%; padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 1px 2px rgba(7, 28, 61, .06); }
.msg.customer { background: var(--bubble-customer); align-self: flex-start; border-bottom-left-radius: 6px; }
.msg.bot, .msg.staff { align-self: flex-end; border-bottom-right-radius: 6px; }
.msg.bot { background: var(--bubble-bot); border: 1px solid rgba(214, 174, 75, .4); }
.msg.staff { background: var(--bubble-staff); }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.msg .sender { font-size: 12px; font-weight: 700; color: var(--gold); margin-bottom: 2px; }
.msg img.photo, .msg video.photo { display: block; max-width: 100%; max-height: 320px; border-radius: 12px; margin-bottom: 4px; }
.msg img.sticker { display: block; width: 120px; height: 120px; object-fit: contain; }
.msg audio { display: block; width: 260px; max-width: 100%; margin-bottom: 4px; }
.media-note { font-size: 13px; color: var(--muted); font-style: italic; }
.composer { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { margin: 0; resize: none; border-radius: 18px; }

/* ---------- Auto replies ---------- */
.rules-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 0 18px; }
.rule .rule-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.rule .rule-head input[name=name] { font-weight: 700; flex: 1; margin: 0; }
.rule .reply-row { display: flex; gap: 8px; align-items: flex-start; }
.rule .reply-row textarea { flex: 1; resize: vertical; overflow-y: auto; }
.rule .reply-row .btn { margin-top: 6px; box-shadow: none; }
.rule.off { opacity: .55; }
.test-box { background: var(--mist); border-color: transparent; }
:root[data-theme="dark"] .test-box { background: var(--panel-2); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .test-box { background: var(--panel-2); } }
.test-box #testResult { margin: 0; white-space: pre-wrap; }

/* English version of a reply + staff note */
.en-replies { margin: 6px 0 12px; border: 1px dashed var(--line); border-radius: 14px; padding: 8px 12px; }
.en-replies summary { cursor: pointer; font-size: 13px; color: var(--muted); font-weight: 600; }
.en-replies[open] summary { margin-bottom: 8px; }
.rule-note { font-size: 13px; background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 8px 12px; white-space: pre-wrap; }

.site-card .card-head .pill { font-size: 12px; }

/* Hours */
.hours { display: grid; grid-template-columns: 110px 1fr 1fr; gap: 6px 12px; align-items: center; margin-bottom: 16px; }
.hours input { margin: 0; }

/* ---------- Team ---------- */
.add-row { margin-top: 14px; }
.add-row input { flex: 1; min-width: 180px; margin: 0; }
.user-row { padding: 16px 18px; margin-bottom: 12px; }
.user-row.off { opacity: .55; }
.role-pick { width: auto; margin: 0; padding: 5px 10px; border-radius: 999px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 6px; }
.checks .check { margin: 0; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 11px 20px; border-radius: 999px; z-index: 20;
  box-shadow: var(--shadow-lift); border: 1px solid var(--gold);
}

/* ---------- Insights ---------- */
.pill-select { width: auto; margin: 0; border-radius: 999px; padding: 8px 14px; background: var(--panel); box-shadow: var(--shadow); font-weight: 600; font-size: 14px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.kpi { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.kpi b { font-size: 34px; font-weight: 800; line-height: 1.1; }
.kpi-navy { background: linear-gradient(135deg, var(--navy-2), var(--navy)); color: #F8F5ED; border-color: var(--navy-2); }
.kpi-navy .stat-label { color: var(--gold-2); }
.ins-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 18px; }
.ins-grid .card { min-width: 0; }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.lg { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 8px; }
.lg-a, .tb-a { background: var(--navy-2); }
.lg-b, .tb-b { background: var(--gold-2); }
:root[data-theme="dark"] .lg-a, :root[data-theme="dark"] .tb-a { background: #5E86C9; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .lg-a, :root:not([data-theme="light"]) .tb-a { background: #5E86C9; } }
.trend { display: flex; align-items: stretch; gap: 4px; height: 190px; margin-top: 12px; }
.trend-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.trend-bars { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; border-bottom: 1px solid var(--line); }
.tb { width: 42%; max-width: 16px; border-radius: 5px 5px 0 0; min-height: 0; }
.trend-x { font-size: 10px; color: var(--muted); text-align: center; height: 16px; margin-top: 4px; white-space: nowrap; }
.bars { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 38%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 99px; background: var(--navy-2); }
.bar-val { font-size: 13px; white-space: nowrap; }
.f-new { background: #8FA6C4; }
.f-trial { background: var(--gold-2); }
.f-reg { background: var(--navy-2); }
.f-lost { background: #C9B8A8; }
:root[data-theme="dark"] .f-reg { background: #5E86C9; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .f-reg { background: #5E86C9; } }
.heat { display: grid; grid-template-columns: 34px repeat(24, minmax(0, 1fr)); gap: 3px; margin-top: 10px; }
.heat-h { font-size: 10px; color: var(--muted); text-align: center; }
.heat-d { font-size: 11px; color: var(--muted); align-self: center; }
.heat-cell { aspect-ratio: 1; border-radius: 4px; background-color: var(--panel-2); background-image: linear-gradient(rgba(var(--heat-rgb), var(--a)), rgba(var(--heat-rgb), var(--a))); }
:root { --heat-rgb: 184, 138, 43; }
:root[data-theme="dark"] { --heat-rgb: 127, 166, 230; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --heat-rgb: 127, 166, 230; } }
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.stage-pick { padding: 6px 12px; font-size: 13px; }
.tag.stage-trial, .stage-pick.stage-trial { background: #FBF1DA; color: #8A6516; }
.tag.stage-registered, .stage-pick.stage-registered { background: var(--navy-2); color: #fff; }
.tag.stage-lost, .stage-pick.stage-lost { background: var(--panel-2); color: var(--muted); }


/* ---------- CRM ---------- */
.chat-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.search-box { width: auto; flex: 1; min-width: 200px; margin: 0; border-radius: 999px; padding: 9px 16px; background: var(--panel); box-shadow: var(--shadow); }
.chat-item.unread .name { font-weight: 800; }
.item-tags { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 5px; }
.item-tags .tag { margin: 0; }
.chip-tag {
  display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px;
  background: color-mix(in srgb, var(--c) 18%, transparent); color: color-mix(in srgb, var(--c) 80%, var(--text)); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
}
.chip-tag button { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 0 0 2px; font-size: 13px; line-height: 1; }
.unread-badge { background: #1F8A5B; color: #fff; border-radius: 99px; font-size: 11px; font-weight: 800; padding: 1px 7px; }
.owner-dot { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10px; font-weight: 800; background: linear-gradient(135deg, var(--gold-2), var(--gold)); color: var(--navy); margin-left: auto; }

.chat-view { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.head-controls { gap: 8px; }
.head-controls .pill-select { padding: 5px 10px; font-size: 13px; box-shadow: none; }
label.mini { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 12px; color: var(--muted); font-weight: 600; }
.status-closed { opacity: .75; }
.collision { background: var(--warn-soft); color: var(--warn); font-size: 13px; font-weight: 600; padding: 7px 16px; border-bottom: 1px solid var(--line); }
.chat-body { display: grid; grid-template-columns: minmax(0, 1fr) 320px; min-height: 0; }
.chat-view.no-panel .chat-body { grid-template-columns: minmax(0, 1fr); }
.chat-view.no-panel .panel-slot { display: none; }
.chat-body .msgs { min-height: 0; }
.panel-slot { border-left: 1px solid var(--line); overflow-y: auto; min-height: 0; }
.panel-toggle { display: none; }
.profile-panel { padding: 14px 16px 24px; }
.profile-panel h4 { margin: 14px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--gold); }
.profile-panel h4:first-child { margin-top: 0; }
.profile-panel label { font-size: 13px; margin-bottom: 10px; }
.profile-panel input, .profile-panel select, .profile-panel textarea { padding: 7px 10px; font-size: 14px; }
.student-box { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px 2px; margin-bottom: 8px; background: var(--panel-2); }
.auto-chip { margin-left: 6px; font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 99px; background: var(--mist); color: var(--navy-2); text-transform: uppercase; letter-spacing: .04em; }
:root[data-theme="dark"] .auto-chip { background: var(--panel-2); color: var(--gold-2); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .auto-chip { background: var(--panel-2); color: var(--gold-2); } }
.add-tag { width: auto; margin: 0; padding: 2px 8px; font-size: 12px; border-radius: 99px; }
.fu-row { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.fu-row input { width: auto; margin: 3px 0 0; accent-color: var(--gold); }
.fu-row.due b { color: var(--bad); }
.fu-add { display: grid; gap: 6px; margin-top: 8px; }
.fu-add input, .fu-add select { margin: 0; }

.msg.note { align-self: stretch; max-width: 100%; background: var(--warn-soft); border: 1px dashed var(--gold); box-shadow: none; }
.note-head { font-size: 12px; font-weight: 700; color: var(--warn); margin-bottom: 2px; }
.composer-wrap { border-top: 1px solid var(--line); }
.composer-wrap .composer { border-top: 0; position: relative; }
.compose-mode { margin: 10px 14px 0; box-shadow: none; }
.compose-mode button { padding: 4px 12px; font-size: 13px; }
.composer-wrap.note-mode textarea { background: var(--warn-soft); border-color: var(--gold); }
.qr-popup {
  position: absolute; left: 14px; right: 90px; bottom: calc(100% - 4px); max-height: 260px; overflow-y: auto; z-index: 5;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lift); padding: 6px;
}
.qr-popup button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: left; border: 0; background: none; color: var(--text); font: inherit; padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.qr-popup button:hover, .qr-popup button:first-child { background: var(--panel-2); }

.bell-wrap { position: relative; }
.bell-wrap .badge { top: -4px; right: -4px; }
.bell-panel {
  position: absolute; right: 0; top: calc(100% + 8px); width: min(380px, 90vw); max-height: 60vh; overflow-y: auto; z-index: 40;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lift); padding: 12px 14px;
}
.clickable { cursor: pointer; }
.clickable:hover { background: var(--panel-2); }
.log li.unread-note { font-weight: 600; }
.log li.overdue .when { color: var(--bad); font-weight: 700; }

.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.board .col { background: var(--panel-2); border: 1px solid var(--line); border-radius: 20px; padding: 10px; min-height: 300px; display: flex; flex-direction: column; gap: 8px; }
.board .col.over { outline: 2px dashed var(--gold); }
.col-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 6px; }
.stage-col-trial .col-head b { color: #8A6516; }
.stage-col-registered .col-head b { color: var(--ok); }
.stage-col-lost .col-head b { color: var(--muted); }
.board-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; cursor: grab; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.board-card:active { cursor: grabbing; }
.card-stage { width: auto; margin: 4px 0 0; padding: 3px 8px; font-size: 12px; border-radius: 99px; display: none; }

.feature-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.feature-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; background: var(--panel-2); }
.tag-edit, .quick-edit { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.tag-edit input[type=color] { width: 42px; height: 36px; padding: 2px; margin: 0; flex-shrink: 0; }
.tag-edit input, .quick-edit input, .quick-edit textarea { margin: 0; }
.quick-edit input { max-width: 160px; }

@media (max-width: 1180px) {
  .chat-body { grid-template-columns: minmax(0, 1fr); }
  .panel-slot { display: none; border-left: 0; }
  .chat-view.show-panel .panel-slot { display: block; }
  .chat-view.show-panel .msgs { display: none; }
  .panel-toggle { display: inline-flex; }
}
@media (max-width: 800px) {
  .board { grid-template-columns: repeat(4, 82vw); }
  .card-stage { display: inline-block; }
  .search-box { min-width: 100%; }
}

.safety-card { border-left: 4px solid var(--gold); }
.safety-list { margin: 0; padding-left: 20px; columns: 2; column-gap: 32px; }
.safety-list li { margin: 0 0 8px; break-inside: avoid; font-size: 14px; }
@media (max-width: 900px) { .safety-list { columns: 1; } }

/* ---------- Smaller screens ---------- */
@media (max-width: 1180px) {
  .home-grid { grid-template-columns: 1fr; }
  .buddy { position: static; display: grid; grid-template-columns: 220px 1fr; align-items: center; }
  .buddy-mascot { height: 100%; aspect-ratio: auto; }
  .buddy-body { text-align: left; padding: 18px 22px; }
  .buddy-actions { justify-content: flex-start; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ins-grid { grid-template-columns: 1fr 1fr; }
  .span3 { grid-column: span 2; }
}
@media (max-width: 800px) {
  .app { flex-direction: column; }
  .rail {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; width: 100%; z-index: 10;
    flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .rail-logo { display: none; }
  #nav { flex-direction: row; justify-content: space-between; gap: 2px; overflow-x: auto; }
  #nav button { width: auto; min-width: 54px; flex: 1; padding: 7px 4px 6px; border-radius: 14px; font-size: 10px; }
  #nav .nav-bottom { margin-top: 0; }
  .topbar { padding: 12px 16px; gap: 8px; }
  .number-pill select { min-width: 0; max-width: 46vw; }
  .me-name, .faces { display: none; }
  main { padding: 0 16px 96px; }
  h1 { font-size: 26px; }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-hero { padding: 24px 24px 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .hero-mascot { width: 46%; }
  .auth-card { padding: 28px 24px; }
  .auth { padding-top: 68px; }
  .buddy { grid-template-columns: 1fr; }
  .buddy-mascot { aspect-ratio: 4 / 3; height: auto; object-position: center 12%; }
  .chats { grid-template-columns: 1fr; }
  .chat-list { height: 38vh; min-height: 0; }
  .chat-view { height: 70vh; min-height: 0; }
  .rules-grid { grid-template-columns: 1fr; }
  .ins-grid { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: auto; }
  .kpi b { font-size: 26px; }
  .heat { gap: 2px; grid-template-columns: 28px repeat(24, minmax(0, 1fr)); }
  .msg { max-width: 88%; }
  .log .when { width: 84px; }
  .page-head { margin-bottom: 14px; }
}
