:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --mine: #2563eb;
  --theirs: #eef2ff;
  --danger: #b91c1c;
  --shadow: 0 20px 60px rgba(15, 23, 42, 0.12);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #dbeafe 0, transparent 34%), var(--bg);
  color: var(--text);
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.app-shell { min-height: 100vh; padding: 24px; display: grid; place-items: center; }
.auth-card {
  width: min(460px, 100%);
  background: rgba(255,255,255,.96);
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 24px;
  padding: 30px;
  box-shadow: var(--shadow);
}
.brand-block { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.logo { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--accent); color: white; font-size: 24px; font-weight: 800; }
h1, h2, p { margin-top: 0; }
.brand-block h1 { margin-bottom: 5px; font-size: 26px; }
.brand-block p { color: var(--muted); margin-bottom: 0; font-size: 14px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--panel-soft); border-radius: 12px; padding: 4px; margin-bottom: 22px; }
.tab { border: 0; background: transparent; padding: 10px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--panel); color: var(--text); box-shadow: 0 2px 8px rgba(15,23,42,.08); }
.form-stack { display: grid; gap: 16px; }
label span, .new-chat-box label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; }
input, textarea { width: 100%; border: 1px solid var(--border); border-radius: 12px; padding: 12px 13px; background: white; color: var(--text); outline: none; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.primary-btn, .send-btn, .inline-form button { border: 0; border-radius: 12px; background: var(--accent); color: white; font-weight: 700; padding: 12px 16px; }
.primary-btn:hover, .send-btn:hover, .inline-form button:hover { background: var(--accent-dark); }
button:disabled { cursor: not-allowed; opacity: .55; }
.helper-text { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 16px 0 0; }
.chat-layout { width: min(1180px, 100%); height: min(820px, calc(100vh - 48px)); background: var(--panel); border-radius: 24px; box-shadow: var(--shadow); overflow: hidden; display: grid; grid-template-columns: 340px 1fr; border: 1px solid rgba(255,255,255,.75); }
.sidebar { border-right: 1px solid var(--border); background: var(--panel-soft); display: flex; flex-direction: column; min-width: 0; }
.sidebar-header, .chat-header { min-height: 82px; padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; background: white; }
.eyebrow { margin-bottom: 4px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 10px; font-weight: 700; }
.sidebar-header h2, .chat-header h2 { margin: 0; font-size: 18px; }
.icon-btn, .mobile-back { border: 1px solid var(--border); background: white; border-radius: 10px; padding: 8px 10px; }
.new-chat-box { padding: 16px; border-bottom: 1px solid var(--border); }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.inline-form button { padding-inline: 14px; }
.conversation-heading { padding: 14px 16px 9px; display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.text-btn { border: 0; background: transparent; color: var(--accent); font-size: 12px; font-weight: 700; padding: 0; }
.conversation-list { overflow-y: auto; padding: 0 10px 14px; }
.conversation-item { width: 100%; border: 0; background: transparent; border-radius: 13px; display: flex; align-items: center; text-align: left; position: relative; overflow: hidden; }
.conversation-open { flex: 1; min-width: 0; border: 0; background: transparent; padding: 12px 4px 12px 12px; display: flex; align-items: center; gap: 11px; text-align: left; cursor: pointer; }
.conversation-more { flex: 0 0 42px; align-self: stretch; border: 0; background: transparent; color: var(--muted); font-size: 23px; cursor: pointer; border-radius: 10px; }
.conversation-more:hover { background: #f1f5f9; color: #0f172a; }
.conversation-item:hover, .conversation-item.active { background: white; box-shadow: 0 4px 16px rgba(15,23,42,.06); }
.avatar { flex: 0 0 42px; width: 42px; height: 42px; border-radius: 50%; background: #dbeafe; color: #1e40af; display: grid; place-items: center; font-weight: 800; text-transform: uppercase; }
.conversation-meta { min-width: 0; flex: 1; }
.conversation-name { font-weight: 700; margin-bottom: 3px; }
.conversation-preview { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-panel { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; background: white; }
.mobile-back { display: none; }
.message-list { overflow-y: auto; padding: 24px; background: linear-gradient(180deg, #f8fafc 0, #ffffff 100%); display: flex; flex-direction: column; gap: 11px; }
.message-row { display: flex; }
.message-row.mine { justify-content: flex-end; }
.message-bubble { max-width: min(72%, 560px); padding: 10px 13px; border-radius: 16px; background: var(--theirs); color: var(--text); line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-row.mine .message-bubble { background: var(--mine); color: white; border-bottom-right-radius: 5px; }
.message-row:not(.mine) .message-bubble { border-bottom-left-radius: 5px; }
.message-time { display: block; margin-top: 5px; font-size: 10px; opacity: .7; text-align: right; }
.message-composer { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 16px; border-top: 1px solid var(--border); background: white; align-items: end; }
.message-composer textarea { resize: none; min-height: 46px; max-height: 140px; }
.send-btn { min-height: 46px; }
.empty-state { margin: auto; color: var(--muted); text-align: center; padding: 24px; font-size: 14px; }
.empty-state.small { margin: 20px 0; }
.toast { position: fixed; top: 18px; left: 50%; transform: translate(-50%, -20px); opacity: 0; pointer-events: none; z-index: 20; background: #111827; color: white; padding: 11px 15px; border-radius: 10px; font-size: 13px; transition: .2s ease; box-shadow: 0 12px 30px rgba(0,0,0,.18); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }
@media (max-width: 760px) {
  .app-shell { padding: 0; }
  .chat-layout { height: 100vh; border-radius: 0; grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .chat-panel { display: none; }
  .chat-layout.mobile-chat-open .sidebar { display: none; }
  .chat-layout.mobile-chat-open .chat-panel { display: grid; }
  .mobile-back { display: inline-block; }
  .message-bubble { max-width: 84%; }
  .auth-card { min-height: 100vh; border-radius: 0; display: flex; flex-direction: column; justify-content: center; }
}

.attach-btn { min-width: 46px; min-height: 46px; border: 1px solid var(--border); border-radius: 12px; background: white; font-size: 25px; line-height: 1; color: var(--accent); }
.message-composer { grid-template-columns: auto 1fr auto; }
.attachment-preview { padding: 10px 16px 0; border-top: 1px solid var(--border); background: white; }
.attachment-preview-card { display: flex; align-items: center; gap: 10px; padding: 9px 11px; background: var(--panel-soft); border: 1px solid var(--border); border-radius: 12px; }
.attachment-preview-card span { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.remove-attachment { border: 0; background: transparent; color: var(--danger); font-weight: 700; }
.chat-media { display: block; max-width: 100%; max-height: 360px; border-radius: 12px; margin-bottom: 7px; background: #000; }
.media-link { display: inline-block; font-size: 12px; margin-bottom: 5px; color: inherit; }
.upload-progress { font-size: 12px; color: var(--muted); padding: 0 16px 8px; background: white; }
.name-label{font-size:11px;font-weight:700;opacity:.72;margin-bottom:4px}.status-text{margin:3px 0 0;color:var(--muted);font-size:12px}.status-text.online{color:#16a34a}.chat-person{display:flex;align-items:center;gap:11px}.header-avatar{width:42px;height:42px;border-radius:50%;display:grid;place-items:center;background:#ede9fe;color:#6d28d9;font-weight:800}.online-dot{width:9px;height:9px;border-radius:50%;background:#22c55e;display:inline-block;margin-right:5px}.record-btn{min-width:46px;min-height:46px;border:1px solid var(--border);border-radius:12px;background:white;font-size:18px}.record-btn.recording{background:#fee2e2;border-color:#ef4444}.recording-bar{display:flex;align-items:center;gap:9px;padding:10px 16px;border-top:1px solid var(--border);background:#fff7f7;font-size:13px}.recording-bar strong{margin-left:auto}.recording-bar button{border:0;background:transparent;color:var(--danger);font-weight:700}.recording-dot{width:10px;height:10px;border-radius:50%;background:#ef4444;animation:pulse 1s infinite}@keyframes pulse{50%{opacity:.35}}.voice-note{width:min(280px,65vw);height:38px}.message-composer{grid-template-columns:auto 1fr auto auto}.conversation-status{font-size:11px;color:var(--muted);margin-top:2px}.conversation-status.online{color:#16a34a}@media(max-width:420px){.send-btn{padding-inline:12px}.message-composer{gap:7px;padding:11px}.attach-btn,.record-btn{min-width:42px}}

.login-heading{font-size:1rem;font-weight:800;margin:1.4rem 0 .9rem;color:#182033}

/* ===== FIX: keep the composer visible when photos/videos are present ===== */
.chat-layout,
.sidebar,
.chat-panel {
  min-height: 0;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header,
.recording-bar,
.attachment-preview,
.message-composer {
  flex: 0 0 auto;
}

.message-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.conversation-list {
  flex: 1 1 auto;
  min-height: 0;
}

.chat-media {
  width: auto;
  max-width: 100%;
  max-height: min(360px, 45vh);
  object-fit: contain;
}

@media (max-width: 760px) {
  .chat-panel {
    display: none;
  }

  .chat-layout.mobile-chat-open .chat-panel {
    display: flex;
  }

  .chat-media {
    max-height: 42vh;
  }
}

/* Message actions, replies and clear-chat controls */
.chat-header{position:relative}.header-menu-btn{margin-left:auto;border:0;background:transparent;font-size:30px;line-height:1;padding:8px 12px;border-radius:12px;cursor:pointer;color:#334155}.header-menu-btn:hover{background:#eef2ff}.header-menu-btn:disabled{opacity:.35;cursor:not-allowed}
.message-row{position:relative}.message-wrap{display:flex;align-items:flex-start;gap:6px;max-width:min(78%,560px)}.message-row.mine .message-wrap{flex-direction:row-reverse}.message-more{border:0;background:transparent;color:#94a3b8;font-size:20px;line-height:1;padding:5px;border-radius:50%;cursor:pointer;opacity:0;transition:opacity .15s}.message-row:hover .message-more,.message-more:focus{opacity:1}.message-bubble{max-width:100%}
.reply-quote{border-left:3px solid #6366f1;background:rgba(255,255,255,.55);padding:7px 9px;margin:0 0 7px;border-radius:8px;font-size:12px;overflow:hidden}.message-row.mine .reply-quote{background:rgba(255,255,255,.2)}.reply-quote strong,.reply-quote span{display:block}.reply-quote span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;opacity:.8;margin-top:2px}
.reply-preview{flex:0 0 auto;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:9px 16px;border-top:1px solid #e2e8f0;background:#f8fafc}.reply-preview>div{min-width:0;border-left:3px solid #6366f1;padding-left:10px}.reply-preview strong,.reply-preview span{display:block}.reply-preview span{font-size:13px;color:#64748b;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:55vw}.reply-preview button{border:0;background:transparent;font-size:25px;cursor:pointer;color:#64748b}
.message-menu,.clear-menu,.conversation-menu{position:fixed;z-index:1000;min-width:180px;padding:6px;background:#fff;border:1px solid #e2e8f0;border-radius:14px;box-shadow:0 18px 50px rgba(15,23,42,.18)}.message-menu button,.clear-menu button,.conversation-menu button{width:100%;border:0;background:transparent;text-align:left;padding:11px 13px;border-radius:9px;font:600 14px Inter,sans-serif;cursor:pointer;color:#1e293b}.message-menu button:hover,.clear-menu button:hover,.conversation-menu button:hover{background:#f1f5f9}.message-menu button.danger,.clear-menu button.danger,.conversation-menu button.danger{color:#dc2626}.message-menu.hidden,.clear-menu.hidden,.conversation-menu.hidden{display:none!important}
.message-bubble.action-highlight{outline:3px solid rgba(99,102,241,.2)}
@media(max-width:760px){.message-wrap{max-width:88%}.message-more{opacity:1;font-size:18px}.header-menu-btn{font-size:27px}.reply-preview span{max-width:65vw}}

/* ===== Performance and responsive enhancements ===== */
:root { color-scheme: light; }
* { -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { touch-action: manipulation; }
.app-shell { min-height: 100dvh; }
.chat-layout { height: min(860px, calc(100dvh - 32px)); }
.message-list {
  contain: layout paint;
  scroll-behavior: auto;
  -webkit-overflow-scrolling: touch;
}
.message-row {
  content-visibility: auto;
  contain-intrinsic-size: 72px;
}
.chat-media {
  image-rendering: auto;
  transform: translateZ(0);
}
.message-composer textarea {
  field-sizing: content;
  overflow-y: auto;
}
.icon-btn, .mobile-back, .attach-btn, .record-btn, .send-btn, .header-menu-btn {
  min-height: 44px;
}
.loading-messages {
  margin: auto;
  color: var(--muted);
  font-size: 14px;
}
@media (max-width: 760px) {
  html, body { width: 100%; }
  .chat-layout { height: 100dvh; min-height: 100dvh; }
  .sidebar-header, .chat-header {
    padding-top: max(12px, env(safe-area-inset-top));
  }
  .message-composer {
    padding-bottom: max(11px, env(safe-area-inset-bottom));
  }
  .message-list { padding: 14px 12px; gap: 8px; }
  .message-bubble { font-size: 15px; }
  .chat-media { max-width: min(78vw, 380px); }
}
@media (max-width: 420px) {
  .sidebar-header, .chat-header { min-height: 68px; padding-inline: 12px; }
  .new-chat-box { padding: 12px; }
  .conversation-list { padding-inline: 6px; }
  .message-wrap { max-width: 94%; }
  .message-composer textarea { min-width: 0; }
  .send-btn { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Stable composer: prevents movement after each send */
.message-composer textarea {
  field-sizing: fixed !important;
  height: 46px;
  min-height: 46px;
  max-height: 46px;
  overflow-y: auto;
}
.message-list { overflow-anchor: none; }
.message-composer, .reply-preview, .attachment-preview { overflow-anchor: none; }

/* Final send stability: the new message is appended instead of rebuilding the list. */
.message-list { scroll-snap-type: none !important; }
.message-row { overflow-anchor: none; }
.message-composer { position: relative; z-index: 5; }


/* Secure close / logout controls */
.header-actions{margin-left:auto;display:flex;align-items:center;gap:4px;flex:0 0 auto}
.close-tab-btn{width:40px;height:40px;border:0;background:transparent;border-radius:12px;font-size:30px;line-height:1;color:#475569;cursor:pointer;display:grid;place-items:center}
.close-tab-btn:hover{background:#fee2e2;color:#b91c1c}
.closed-screen{min-height:100dvh;display:grid;place-items:center;padding:24px;background:#f8fafc;font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#0f172a}
.closed-screen section{width:min(420px,100%);text-align:center;background:#fff;border:1px solid #e2e8f0;border-radius:24px;padding:36px 26px;box-shadow:0 20px 60px rgba(15,23,42,.10)}
.closed-screen .closed-icon{width:58px;height:58px;margin:0 auto 16px;border-radius:50%;display:grid;place-items:center;background:#dcfce7;color:#15803d;font-size:28px;font-weight:800}
.closed-screen h1{margin:0 0 8px}.closed-screen p{margin:0 0 20px;color:#64748b}
.closed-screen button{border:0;border-radius:12px;padding:12px 18px;background:#4f46e5;color:#fff;font:inherit;font-weight:700;cursor:pointer}
.closed-screen small{display:block;margin-top:16px;color:#94a3b8;line-height:1.45}
@media(max-width:760px){.close-tab-btn{width:38px;height:38px;font-size:27px}.header-actions{gap:0}}

/* UPSC coaching portal inspired login */
.coaching-login{
  width:min(960px,calc(100% - 32px));
  max-width:960px;
  padding:0;
  display:grid;
  grid-template-columns:minmax(320px,1.05fr) minmax(320px,.95fr);
  overflow:hidden;
  border-radius:22px;
  border:1px solid #dbe4ef;
  box-shadow:0 24px 70px rgba(15,35,68,.18);
  background:#fff;
}
.coaching-banner{
  min-height:520px;
  padding:54px 48px;
  background:linear-gradient(145deg,#102a56 0%,#173d76 62%,#1d4f91 100%);
  color:#fff;
  display:flex;
  flex-direction:column;
  justify-content:center;
  position:relative;
  overflow:hidden;
}
.coaching-banner::before,.coaching-banner::after{content:"";position:absolute;border-radius:50%;border:1px solid rgba(255,255,255,.12)}
.coaching-banner::before{width:330px;height:330px;right:-120px;top:-100px}
.coaching-banner::after{width:220px;height:220px;left:-90px;bottom:-85px}
.academy-mark{width:78px;height:78px;border-radius:18px;background:#f59e0b;display:grid;place-items:center;margin-bottom:28px;box-shadow:0 12px 28px rgba(0,0,0,.18);position:relative;z-index:1}
.academy-wheel{font-size:38px;color:#102a56;line-height:1}
.portal-kicker{text-transform:uppercase;letter-spacing:.14em;font-size:12px;font-weight:800;color:#fcd34d;margin:0 0 10px;position:relative;z-index:1}
.coaching-banner h1{font-size:clamp(32px,4vw,48px);line-height:1.08;margin:0 0 14px;max-width:480px;position:relative;z-index:1}
.portal-subtitle{margin:0;max-width:430px;color:#dbeafe;font-size:16px;line-height:1.65;position:relative;z-index:1}
.login-panel{padding:58px 48px;display:flex;flex-direction:column;justify-content:center;background:#fff}
.coaching-login .login-heading{font-size:26px;margin:0 0 26px;color:#102a56;letter-spacing:-.02em}
.coaching-login .form-stack{gap:19px}
.coaching-login label>span{display:block;margin-bottom:8px;color:#334155;font-size:13px;font-weight:800}
.input-shell{display:flex;align-items:center;gap:10px;border:1px solid #cbd5e1;border-radius:10px;padding:0 13px;background:#f8fafc;transition:.18s ease}
.input-shell:focus-within{border-color:#1d4f91;background:#fff;box-shadow:0 0 0 4px rgba(29,79,145,.10)}
.input-shell>span{font-size:15px;opacity:.65}
.input-shell input{border:0!important;background:transparent!important;box-shadow:none!important;padding:14px 0!important;width:100%;outline:0;color:#0f172a}
.coaching-submit{margin-top:4px;background:#f59e0b;color:#102a56;border-radius:10px;min-height:50px;font-weight:900;box-shadow:0 8px 20px rgba(245,158,11,.24)}
.coaching-submit:hover{background:#fbbf24;transform:translateY(-1px)}
.coaching-login .helper-text{text-align:center;color:#64748b;margin:18px 0 0;font-size:12px}
.login-footer{grid-column:1/-1;background:#0b1f40;color:#bfdbfe;text-align:center;padding:12px 18px;font-size:11px;letter-spacing:.08em;text-transform:uppercase}
.close-tab-btn{font-size:22px;font-weight:800}
.close-tab-btn:disabled{opacity:.45;cursor:wait}
@media(max-width:760px){
  .coaching-login{width:100%;max-width:none;min-height:100dvh;border-radius:0;grid-template-columns:1fr;align-content:stretch}
  .coaching-banner{min-height:auto;padding:34px 24px 28px;justify-content:flex-start}
  .academy-mark{width:58px;height:58px;border-radius:14px;margin-bottom:18px}.academy-wheel{font-size:28px}
  .coaching-banner h1{font-size:30px}.portal-subtitle{font-size:14px}
  .login-panel{padding:34px 24px 30px;justify-content:flex-start}
  .coaching-login .login-heading{font-size:23px;margin-bottom:22px}
  .login-footer{align-self:end}
}


/* ===== UPSC coaching dashboard theme (inside login) ===== */
:root{
  --upsc-navy:#102a56;
  --upsc-blue:#173d76;
  --upsc-gold:#f59e0b;
  --upsc-paper:#f5f7fb;
}
body{background:#e9eef6}
.chat-layout{
  width:min(1240px,100%);
  height:min(850px,calc(100dvh - 40px));
  grid-template-columns:360px 1fr;
  border-radius:18px;
  border:1px solid #cfd9e7;
  box-shadow:0 22px 65px rgba(16,42,86,.16);
}
.dashboard-brand{
  min-height:92px;
  padding:18px 20px;
  display:flex;
  align-items:center;
  gap:13px;
  color:#fff;
  background:linear-gradient(135deg,var(--upsc-navy),var(--upsc-blue));
  border-bottom:3px solid var(--upsc-gold);
}
.dashboard-emblem{
  flex:0 0 48px;
  width:48px;height:48px;
  border-radius:13px;
  display:grid;place-items:center;
  background:var(--upsc-gold);
  color:var(--upsc-navy);
  font-size:25px;font-weight:900;
  box-shadow:0 8px 20px rgba(0,0,0,.18);
}
.dashboard-brand p{margin:0 0 3px;color:#bfdbfe;text-transform:uppercase;letter-spacing:.12em;font-size:9px;font-weight:800}
.dashboard-brand h1{margin:0;font-size:19px;line-height:1.15;letter-spacing:-.01em}
.sidebar{background:#f5f7fb;border-right-color:#dbe4ef}
.sidebar-header{min-height:74px;background:#fff;padding:14px 18px}
.sidebar-header h2{color:var(--upsc-navy)}
.icon-btn{border-color:#d6dfeb;color:var(--upsc-navy);font-weight:800;background:#fff}
.icon-btn:hover{background:#fff7e6;border-color:#f5c45f}
.new-chat-box{margin:14px 14px 5px;padding:14px;background:#fff;border:1px solid #dbe4ef;border-radius:13px;box-shadow:0 7px 20px rgba(16,42,86,.05)}
.new-chat-box label{color:var(--upsc-navy);font-weight:800}
.inline-form button{background:var(--upsc-gold);color:var(--upsc-navy);font-weight:900}
.inline-form button:hover{background:#fbbf24}
.conversation-heading{padding:16px 18px 9px;color:#52647d}
.text-btn{color:var(--upsc-blue)}
.conversation-item{border:1px solid transparent}
.conversation-item:hover,.conversation-item.active{background:#fff;border-color:#dbe4ef;box-shadow:0 6px 18px rgba(16,42,86,.07)}
.conversation-item.active{border-left:4px solid var(--upsc-gold)}
.avatar,.header-avatar{background:#e8eef8;color:var(--upsc-navy);border:1px solid #cfdaea}
.chat-panel{background:#fff}
.chat-header{background:linear-gradient(180deg,#fff,#fbfcfe);border-bottom-color:#dbe4ef}
.chat-header h2{color:var(--upsc-navy)}
.message-list{background:linear-gradient(rgba(245,247,251,.93),rgba(255,255,255,.96)),repeating-linear-gradient(0deg,transparent,transparent 31px,rgba(16,42,86,.035) 32px)}
.message-row.mine .message-bubble{background:var(--upsc-blue)}
.message-row:not(.mine) .message-bubble{background:#eef3fa;border:1px solid #dbe4ef}
.message-composer{border-top-color:#dbe4ef;background:#fbfcfe}
.send-btn{background:var(--upsc-gold);color:var(--upsc-navy);font-weight:900}
.send-btn:hover{background:#fbbf24}
.attach-btn{color:var(--upsc-blue)}
.record-btn{color:var(--upsc-blue)}
@media(max-width:760px){
  .chat-layout{height:100dvh;border-radius:0;grid-template-columns:1fr}
  .dashboard-brand{min-height:78px;padding:13px 15px}
  .dashboard-emblem{width:42px;height:42px;flex-basis:42px}
  .dashboard-brand h1{font-size:17px}
  .new-chat-box{margin:10px}
}


/* End-to-end encryption unlock */
.e2ee-modal{position:fixed;inset:0;z-index:10000;display:grid;place-items:center;padding:20px;background:rgba(5,15,35,.72);backdrop-filter:blur(10px)}
.e2ee-modal.hidden{display:none}
.e2ee-card{width:min(440px,100%);padding:30px;border-radius:20px;background:#fff;box-shadow:0 28px 90px rgba(0,0,0,.34);text-align:center;border-top:5px solid var(--upsc-gold,#f59e0b)}
.e2ee-lock{width:68px;height:68px;margin:0 auto 14px;display:grid;place-items:center;border-radius:20px;background:#edf3fb;font-size:34px}
.e2ee-card h2{margin:5px 0 9px;color:var(--upsc-navy,#102a56)}
.e2ee-card p:not(.portal-kicker){margin:0 auto 20px;max-width:360px;color:#5b687c;line-height:1.55}
.e2ee-card form{display:grid;gap:12px}.e2ee-input-row{display:flex;border:1px solid #cbd6e5;border-radius:12px;overflow:hidden;background:#fff}
.e2ee-input-row input{min-width:0;flex:1;border:0;padding:14px;font:inherit;outline:0}.e2ee-input-row button{border:0;background:#edf3fb;color:#173d76;padding:0 14px;font-weight:800;cursor:pointer}
.e2ee-card .primary-btn{width:100%}.e2ee-logout{margin:14px 0 8px;border:0;background:none;color:#52647d;font-weight:700;cursor:pointer}.e2ee-card small{display:block;color:#8792a3;line-height:1.45}

/* Reliable initial positioning at the newest message. */
.message-row {
  content-visibility: visible !important;
  contain: none !important;
}
.message-list {
  contain: none !important;
}
.status-text.typing{color:#2563eb;font-weight:700;animation:typingPulse 1.1s ease-in-out infinite}
@keyframes typingPulse{0%,100%{opacity:1}50%{opacity:.55}}


/* ===== Device-persistent dark mode ===== */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg:#070b14;
  --panel:#111827;
  --panel-soft:#0b1220;
  --text:#e5e7eb;
  --muted:#94a3b8;
  --border:#263244;
  --accent:#60a5fa;
  --accent-dark:#3b82f6;
  --mine:#1d4ed8;
  --theirs:#1e293b;
  --danger:#f87171;
  --shadow:0 20px 60px rgba(0,0,0,.48);
  --upsc-navy:#dbeafe;
  --upsc-blue:#60a5fa;
}
html[data-theme="dark"] body{background:radial-gradient(circle at top left,#172554 0,transparent 35%),#070b14;color:var(--text)}
html[data-theme="dark"] .auth-card,
html[data-theme="dark"] .login-panel,
html[data-theme="dark"] .chat-layout,
html[data-theme="dark"] .chat-panel,
html[data-theme="dark"] .sidebar-header,
html[data-theme="dark"] .chat-header,
html[data-theme="dark"] .new-chat-box,
html[data-theme="dark"] .message-composer,
html[data-theme="dark"] .attachment-preview,
html[data-theme="dark"] .upload-progress{background:#111827!important;border-color:#263244!important;color:#e5e7eb}
html[data-theme="dark"] .sidebar{background:#0b1220!important;border-color:#263244!important}
html[data-theme="dark"] .dashboard-brand{background:linear-gradient(135deg,#111c35,#172554)}
html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .input-shell,
html[data-theme="dark"] .e2ee-input-row{background:#0b1220!important;color:#e5e7eb!important;border-color:#334155!important}
html[data-theme="dark"] input::placeholder,html[data-theme="dark"] textarea::placeholder{color:#64748b}
html[data-theme="dark"] .message-list{background:linear-gradient(rgba(11,18,32,.96),rgba(15,23,42,.98)),repeating-linear-gradient(0deg,transparent,transparent 31px,rgba(148,163,184,.035) 32px)!important}
html[data-theme="dark"] .message-row:not(.mine) .message-bubble{background:#1e293b!important;border-color:#334155!important;color:#e5e7eb}
html[data-theme="dark"] .conversation-item:hover,
html[data-theme="dark"] .conversation-item.active{background:#172033!important;border-color:#334155!important;box-shadow:none}
html[data-theme="dark"] .conversation-more:hover{background:#1e293b;color:#e5e7eb}
html[data-theme="dark"] .avatar,html[data-theme="dark"] .header-avatar{background:#1e293b;color:#bfdbfe;border-color:#334155}
html[data-theme="dark"] .icon-btn,html[data-theme="dark"] .mobile-back,html[data-theme="dark"] .attach-btn,html[data-theme="dark"] .record-btn,html[data-theme="dark"] .close-tab-btn,html[data-theme="dark"] .header-menu-btn{background:#111827!important;color:#dbeafe!important;border-color:#334155!important}
html[data-theme="dark"] .message-menu,
html[data-theme="dark"] .clear-menu,
html[data-theme="dark"] .conversation-menu{background:#111827;border-color:#334155;box-shadow:0 18px 50px rgba(0,0,0,.5)}
html[data-theme="dark"] .message-menu button,
html[data-theme="dark"] .clear-menu button,
html[data-theme="dark"] .conversation-menu button{color:#e5e7eb}
html[data-theme="dark"] .message-menu button:hover,
html[data-theme="dark"] .clear-menu button:hover,
html[data-theme="dark"] .conversation-menu button:hover{background:#1e293b}
html[data-theme="dark"] .message-menu button.danger,
html[data-theme="dark"] .clear-menu button.danger,
html[data-theme="dark"] .conversation-menu button.danger{color:#f87171}
html[data-theme="dark"] .reply-preview,html[data-theme="dark"] .attachment-preview-card,html[data-theme="dark"] .recording-bar{background:#0f172a!important;border-color:#334155!important;color:#e5e7eb}
html[data-theme="dark"] .coaching-login{background:#111827!important}
html[data-theme="dark"] .login-heading,html[data-theme="dark"] .coaching-login label span,html[data-theme="dark"] .sidebar-header h2,html[data-theme="dark"] .chat-header h2{color:#e5e7eb!important}
html[data-theme="dark"] .helper-text,html[data-theme="dark"] .login-footer,html[data-theme="dark"] .portal-subtitle{color:#94a3b8!important}
html[data-theme="dark"] .e2ee-card{background:#111827;color:#e5e7eb}
html[data-theme="dark"] .e2ee-lock,html[data-theme="dark"] .e2ee-input-row button{background:#1e293b;color:#bfdbfe}
html[data-theme="dark"] .e2ee-card h2{color:#e5e7eb}
html[data-theme="dark"] .e2ee-card p:not(.portal-kicker),html[data-theme="dark"] .e2ee-card small{color:#94a3b8}


/* ===== Full-interface theme toggle beside Student account ===== */
.student-account-copy{min-width:0}
.account-actions{margin-left:auto;display:flex;align-items:center;gap:9px;flex:0 0 auto}
.account-theme-btn{
  min-height:44px;padding:0 12px;border:1px solid #d6dfeb;border-radius:12px;
  display:inline-flex;align-items:center;justify-content:center;gap:7px;
  background:#fff;color:#102a56;font:inherit;font-weight:800;cursor:pointer;
  transition:background .16s ease,border-color .16s ease,color .16s ease,transform .16s ease;
}
.account-theme-btn:hover{background:#fff7e6;border-color:#f5c45f;transform:translateY(-1px)}
.account-theme-btn .theme-icon{font-size:16px;line-height:1}
.account-theme-btn .theme-label{font-size:13px}

/* Full dashboard dark theme */
html[data-theme="dark"] body,
html[data-theme="dark"] main{background:#050914!important;color:#e8eef8!important}
html[data-theme="dark"] .chat-layout{background:#090f1c!important;border-color:#253249!important;box-shadow:0 26px 80px rgba(0,0,0,.62)!important}
html[data-theme="dark"] .sidebar{background:#090f1c!important;border-right-color:#26344a!important}
html[data-theme="dark"] .dashboard-brand{background:linear-gradient(135deg,#07152f,#102a56)!important;border-bottom-color:#f59e0b!important}
html[data-theme="dark"] .sidebar-header{background:#0f1726!important;border-bottom-color:#26344a!important}
html[data-theme="dark"] .sidebar-header .eyebrow{color:#93a4bd!important}
html[data-theme="dark"] .sidebar-header h2{color:#f8fafc!important}
html[data-theme="dark"] .account-theme-btn,
html[data-theme="dark"] .icon-btn{background:#172235!important;border-color:#34445f!important;color:#e8eef8!important}
html[data-theme="dark"] .account-theme-btn:hover,
html[data-theme="dark"] .icon-btn:hover{background:#22304a!important;border-color:#f59e0b!important;color:#fff!important}
html[data-theme="dark"] .new-chat-box{background:#111b2c!important;border-color:#2b3a52!important;box-shadow:none!important}
html[data-theme="dark"] .new-chat-box label{color:#f1f5f9!important}
html[data-theme="dark"] .inline-form input{background:#09111f!important;border-color:#33445f!important;color:#f8fafc!important}
html[data-theme="dark"] .inline-form input::placeholder{color:#718199!important}
html[data-theme="dark"] .inline-form button,
html[data-theme="dark"] .send-btn{background:#f59e0b!important;color:#102a56!important}
html[data-theme="dark"] .inline-form button:hover,
html[data-theme="dark"] .send-btn:hover{background:#fbbf24!important}
html[data-theme="dark"] .conversation-heading{color:#aebbd0!important;border-color:#26344a!important}
html[data-theme="dark"] .text-btn{color:#7db4ff!important}
html[data-theme="dark"] .conversation-list{background:#090f1c!important}
html[data-theme="dark"] .conversation-item{background:transparent!important;border-color:transparent!important;color:#e8eef8!important}
html[data-theme="dark"] .conversation-item:hover,
html[data-theme="dark"] .conversation-item.active{background:#142035!important;border-color:#31425e!important;box-shadow:none!important}
html[data-theme="dark"] .conversation-item.active{border-left-color:#f59e0b!important}
html[data-theme="dark"] .conversation-name{color:#f8fafc!important}
html[data-theme="dark"] .conversation-preview,
html[data-theme="dark"] .conversation-status,
html[data-theme="dark"] .empty-state{color:#93a4bd!important}
html[data-theme="dark"] .conversation-more{color:#aebbd0!important}
html[data-theme="dark"] .conversation-more:hover{background:#22304a!important;color:#fff!important}
html[data-theme="dark"] .avatar,
html[data-theme="dark"] .header-avatar{background:#182641!important;border-color:#375071!important;color:#bfdbfe!important}
html[data-theme="dark"] .chat-panel{background:#070d18!important}
html[data-theme="dark"] .chat-header{background:#0f1726!important;border-bottom-color:#26344a!important}
html[data-theme="dark"] .chat-header h2{color:#f8fafc!important}
html[data-theme="dark"] .status-text{color:#93a4bd!important}
html[data-theme="dark"] .status-text.typing{color:#60a5fa!important}
html[data-theme="dark"] .header-menu-btn,
html[data-theme="dark"] .close-tab-btn,
html[data-theme="dark"] .mobile-back{background:transparent!important;border-color:transparent!important;color:#cbd5e1!important}
html[data-theme="dark"] .header-menu-btn:hover,
html[data-theme="dark"] .close-tab-btn:hover,
html[data-theme="dark"] .mobile-back:hover{background:#1b2940!important;color:#fff!important}
html[data-theme="dark"] .message-list{
  background:linear-gradient(rgba(6,12,23,.97),rgba(9,15,28,.98)),repeating-linear-gradient(0deg,transparent,transparent 31px,rgba(148,163,184,.035) 32px)!important;
}
html[data-theme="dark"] .message-row.mine .message-bubble{background:#1d4f91!important;color:#fff!important}
html[data-theme="dark"] .message-row:not(.mine) .message-bubble{background:#172235!important;border-color:#30415c!important;color:#edf2f7!important}
html[data-theme="dark"] .message-name{color:inherit!important}
html[data-theme="dark"] .message-time,
html[data-theme="dark"] .seen-time{color:#a8b5c8!important}
html[data-theme="dark"] .quoted-message{background:rgba(5,10,20,.32)!important;border-left-color:#60a5fa!important;color:#dbeafe!important}
html[data-theme="dark"] .message-composer{background:#0f1726!important;border-top-color:#26344a!important}
html[data-theme="dark"] .message-composer textarea{background:#09111f!important;border-color:#34445f!important;color:#f8fafc!important;caret-color:#60a5fa!important}
html[data-theme="dark"] .message-composer textarea:focus{border-color:#60a5fa!important;box-shadow:0 0 0 3px rgba(96,165,250,.14)!important}
html[data-theme="dark"] .message-composer textarea::placeholder{color:#718199!important}
html[data-theme="dark"] .attach-btn,
html[data-theme="dark"] .record-btn{background:#111b2c!important;border-color:#34445f!important;color:#bfdbfe!important}
html[data-theme="dark"] .attach-btn:hover,
html[data-theme="dark"] .record-btn:hover{background:#1b2940!important}
html[data-theme="dark"] .reply-preview,
html[data-theme="dark"] .attachment-preview,
html[data-theme="dark"] .recording-bar{background:#101b2d!important;border-color:#30415c!important;color:#e8eef8!important}
html[data-theme="dark"] .message-menu,
html[data-theme="dark"] .clear-menu,
html[data-theme="dark"] .conversation-menu{background:#111b2c!important;border-color:#30415c!important;box-shadow:0 22px 58px rgba(0,0,0,.62)!important}
html[data-theme="dark"] .message-menu button,
html[data-theme="dark"] .clear-menu button,
html[data-theme="dark"] .conversation-menu button{color:#edf2f7!important}
html[data-theme="dark"] .message-menu button:hover,
html[data-theme="dark"] .clear-menu button:hover,
html[data-theme="dark"] .conversation-menu button:hover{background:#1d2a40!important}
html[data-theme="dark"] .message-menu button.danger,
html[data-theme="dark"] .clear-menu button.danger,
html[data-theme="dark"] .conversation-menu button.danger{color:#fca5a5!important}
html[data-theme="dark"] .toast{background:#172235!important;color:#f8fafc!important;border-color:#34445f!important}
html[data-theme="dark"] .upload-progress{background:#111b2c!important;border-color:#30415c!important;color:#e8eef8!important}
html[data-theme="dark"] ::-webkit-scrollbar{width:10px;height:10px}
html[data-theme="dark"] ::-webkit-scrollbar-track{background:#090f1c}
html[data-theme="dark"] ::-webkit-scrollbar-thumb{background:#35445c;border:2px solid #090f1c;border-radius:999px}
html[data-theme="dark"] ::-webkit-scrollbar-thumb:hover{background:#4b5f7c}
@media(max-width:760px){
  .account-actions{gap:6px}.account-theme-btn{padding:0 10px}.account-theme-btn .theme-label{display:none}
}
