/* Reset, colour tokens, page background and wallpaper, sign-in / setup screens, form fields. */
*, *::before, *::after { box-sizing: border-box; }
html {
  --text-scale: 1;
  /* The bottom inset: the iPhone home indicator, or the Android app's navigation
     bar (MainActivity sets --android-bottom; the page reaches under the bar). */
  --sab: max(env(safe-area-inset-bottom, 0px), var(--android-bottom, 0px));
  /* The top inset: the status bar / notch. env() is 0 in the Android app, so
     MainActivity sets --android-top. Only for what the app's own rules don't
     already push down (the profile card, the call window) — else it counts twice. */
  --sat: max(env(safe-area-inset-top, 0px), var(--android-top, 0px));
  --avatar-opacity: 1;
  --bubble-opacity: 1;
  --pill-color: #1a1d26;
  --pill-opacity: 0.55;
  --bubble-peer-text: #1a1d26;
  --avatar-bg: #7939f2;
  --wallpaper-color: #d0e7f5;
  --wallpaper-gradient: none;
  --wallpaper-pattern-ink: #6b8fa8;
  --wallpaper-tile: 280px;
  --wallpaper-pattern: none;
  /* Frosted glass: chrome floats light; sheets need more milk so chat doesn't grey them out. */
  --glass-bg: rgba(255, 255, 255, 0.48);
  --glass-panel-bg: rgba(255, 255, 255, 0.78);
  --glass-chip-bg: rgba(255, 255, 255, 0.62);
  --glass-tools-bg: rgba(255, 255, 255, 0.88);
  --glass-window-bg: rgba(255, 255, 255, 0.55);
  --glass-text-mix: 100%;
  --glass-menu-mix: 86%;
  --glass-blur: 16px;
  --glass-border: 1px solid rgba(216, 216, 220, 0.75);
  --glass-dim: rgba(15, 23, 42, 0.14);
  --chrome-icon-scale: 1;
  --chrome-icon-btn: calc(36px * var(--chrome-icon-scale));
  --chrome-icon-svg: calc(22px * var(--chrome-icon-scale));
  --card-rail-icon-scale: 1;
  --sidebar-rail-btn: calc(40px * var(--card-rail-icon-scale));
  --profile-rail-btn: calc(44px * var(--card-rail-icon-scale));
  --channel-rail-btn: calc(36px * var(--card-rail-icon-scale));
  --card-rail-svg: calc(22px * var(--card-rail-icon-scale));
  --chat-tool-btn-w: calc(32px * var(--card-rail-icon-scale));
  --chat-tool-btn-h: calc(28px * var(--card-rail-icon-scale));
  --chat-tool-svg: calc(18px * var(--card-rail-icon-scale));
  --card-rail-bar-min-h: calc(52px * var(--card-rail-icon-scale));
}
html, body {
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  margin: 0;
  /* Same paint as chat wallpaper: keyboard overlay must never flash sidebar blue/white. */
  background-color: var(--wallpaper-color, #d0e7f5);
  background-image: var(--wallpaper-gradient, none);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center top;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  /* Stop iOS rubber-band / back-swipe from exposing the blank WebView edge. */
  overscroll-behavior-x: none;
}
html.shell-booting,
html.shell-booting body {
  background-color: #1e325c !important;
  background-image: none !important;
}
html[data-wallpaper="custom"],
html[data-wallpaper="custom"] body {
  background-image: var(--wallpaper-image-mobile, none);
  background-size: var(--wallpaper-size-mobile, cover);
  background-position: var(--wallpaper-pos-mobile, center center);
}
html[data-wallpaper="space"],
html[data-wallpaper="space"] body {
  background-image:
    var(--wallpaper-image-mobile, none),
    var(--wallpaper-space-gradient, linear-gradient(135deg, #fff2ff 0%, #eed5f0 25%, #dbcdf8 50%, #81d1f5 75%, #72cbf1 100%));
  background-size: var(--wallpaper-size-mobile, cover), cover;
  background-position: var(--wallpaper-pos-mobile, center center), center;
  background-repeat: no-repeat, no-repeat;
}
/* Pattern mode is solid color by default; doodle overlay stays off unless --wallpaper-pattern is set. */
html[data-wallpaper="pattern"] body::before {
  content: none;
  display: none;
}
html[data-wallpaper="custom"] body::before {
  content: none;
  display: none;
}
body {
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #3f4350;
}
@supports (min-height: -webkit-fill-available) {
  html, body { min-height: -webkit-fill-available; }
}
:root,
html[data-theme="blue"] {
  --rail: #15284a;
  --sidebar: #1e325c;
  --sidebar-head: #192a4d;
  --accent: #1c58d9;
  --accent-hover: #154ab8;
  --accent-soft: #eef3ff;
  --accent-mark: #8eb4ff;
  --action: #1c58d9;
  --action-hover: #154ab8;
  --action-soft: #eef3ff;
  --action-text: #ffffff;
  --mention-bg: #e8f1ff;
  --login-glow: rgba(87, 158, 255, .35);
  --login-bg: #14264d;
  --text-strong: #1e325c;
}
html[data-theme="purple"] {
  --rail: #2a1550;
  --sidebar: #3b1d6e;
  --sidebar-head: #31185c;
  --accent: #7939f2;
  --accent-hover: #6529d6;
  --accent-soft: #f3ecff;
  --accent-mark: #c4a6ff;
  --mention-bg: #efe6ff;
  --login-glow: rgba(168, 120, 255, .35);
  --login-bg: #241242;
  --text-strong: #3b1d6e;
}
html[data-theme="green"] {
  --rail: #14352c;
  --sidebar: #1b4d3e;
  --sidebar-head: #174436;
  --accent: #3db887;
  --accent-hover: #2f9a6f;
  --accent-soft: #eaf8f1;
  --accent-mark: #8fd9b8;
  --mention-bg: #e4f7ee;
  --login-glow: rgba(61, 184, 135, .35);
  --login-bg: #102820;
  --text-strong: #1b4d3e;
}
html[data-theme="red"] {
  --rail: #4a1a1c;
  --sidebar: #6a2428;
  --sidebar-head: #5a1f22;
  --accent: #d24b4e;
  --accent-hover: #b53c3f;
  --accent-soft: #fdeeee;
  --accent-mark: #f0a0a2;
  --mention-bg: #fce4e5;
  --login-glow: rgba(210, 75, 78, .32);
  --login-bg: #351012;
  --text-strong: #6a2428;
}
html[data-theme="orange"] {
  --rail: #4a2f0f;
  --sidebar: #6b4514;
  --sidebar-head: #5a3a11;
  --accent: #e0941a;
  --accent-hover: #c07d12;
  --accent-soft: #fff5e6;
  --accent-mark: #f0c27a;
  --mention-bg: #ffefd6;
  --login-glow: rgba(224, 148, 26, .32);
  --login-bg: #35210a;
  --text-strong: #6b4514;
}
html[data-theme="navy"] {
  --rail: #0f1a2e;
  --sidebar: #16233d;
  --sidebar-head: #121c33;
  --accent: #3a6fd8;
  --accent-hover: #2f5cb8;
  --accent-soft: #eaf0fb;
  --accent-mark: #8eade8;
  --mention-bg: #e4ecfa;
  --login-glow: rgba(58, 111, 216, .32);
  --login-bg: #0c1424;
  --text-strong: #16233d;
}
button, input, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
[hidden] { display: none !important; }
/* Visually hidden but still "shown" so mobile WebViews open the picker on .click(). */
.file-input-hidden {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  z-index: -1;
  pointer-events: none;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

/* Kept in DOM for paintAllTeamMarks ids; never shown as a wallpaper splash. */
.boot {
  display: none !important;
}
.team-mark {
  width: 42px; height: 42px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 18px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25);
  overflow: hidden;
  flex-shrink: 0;
}
.team-mark img {
  width: 100%; height: 100%; object-fit: contain; display: block;
}
.team-mark.has-logo {
  background: transparent;
  box-shadow: none;
  border-radius: 50%;
}
.team-mark.is-clickable { cursor: pointer; }
.settings-logo-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin: 4px 0 16px;
}
.settings-logo-wrap {
  position: relative;
  width: 56px;
  height: 56px;
}
.settings-logo-wrap .team-mark {
  width: 56px;
  height: 56px;
  font-size: 22px;
}
.settings-logo-wrap .settings-avatar-edit {
  position: absolute;
  right: -4px;
  bottom: -4px;
}
.settings-logo-wrap .avatar-clear {
  position: absolute;
  top: -6px;
  right: -6px;
}
.settings-logo-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted, #6b7280);
}
.settings-logo-reset {
  align-self: flex-start;
  padding: 6px 12px;
  font-size: 13px;
}
.logo-crop-editor {
  width: 100%;
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.logo-crop-editor.hidden { display: none !important; }
.logo-crop-stage-wrap {
  display: flex;
  justify-content: center;
  padding: 14px;
  border: 1px solid #e8eaef;
  border-radius: 14px;
  background: #f3f5f8;
}
.logo-crop-frame {
  position: relative;
  width: 168px;
  height: 168px;
  overflow: hidden;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,.08), 0 8px 24px rgba(16,24,40,.12);
  background: #e8ecf2;
  touch-action: none;
  cursor: grab;
  user-select: none;
}
.logo-crop-frame.avatar-crop-frame { background: #233259; }
.logo-crop-frame.is-dragging { cursor: grabbing; }
.logo-crop-img {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-repeat: no-repeat;
  background-size: 100%;
  background-position: 50% 50%;
  pointer-events: none;
}
.logo-crop-zoom-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 48px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  color: #5c6270;
}
.logo-crop-zoom-row input[type="range"] { width: 100%; }
.logo-crop-zoom-row span { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; color: #1a1d26; }
.logo-crop-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  color: #8b8e98;
}
.logo-crop-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(900px 420px at 50% -10%, var(--login-glow), transparent 55%), var(--login-bg);
  padding: 24px;
  box-sizing: border-box;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.login-screen > .auth-card { margin: auto; }
/* Soft keyboard open: top-align + bottom pad so the focused field can scroll above the IME. */
.login-screen.is-kb-open {
  align-items: flex-start;
  justify-content: center;
  padding-bottom: calc(24px + var(--kb-field-inset, 0px) + var(--sab));
}
@media (max-width: 600px) {
  .login-screen { padding: 56px 16px 16px; }
  .login-screen.is-kb-open {
    padding-top: max(12px, env(safe-area-inset-top, 0px));
    padding-bottom: calc(16px + var(--kb-field-inset, 0px) + var(--sab));
  }
  .auth-card { padding: 20px 20px 16px; border-radius: 12px; }
  .auth-card .logo { width: 56px; height: 56px; margin-bottom: 8px; }
  .auth-card h1 { font-size: 22px; }
  .auth-card label { margin: 10px 0 4px; }
  .auth-card .btn.wide { margin-top: 8px; }
  .auth-card .auth-switch { margin-top: 12px; }
}
/* Generic mobile forms (settings panels, sheets): room under the keyboard. */
html.kb-field-open #admin-screen:not(.hidden),
html.kb-field-open #profile-screen:not(.hidden),
html.kb-field-open #feature-screen:not(.hidden),
html.kb-field-open #rhs:not(.hidden) {
  padding-bottom: max(12px, var(--kb-field-inset, 0px));
  scroll-padding-bottom: calc(16px + var(--kb-field-inset, 0px));
}
.login-lang {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .12);
  backdrop-filter: blur(6px);
}
.login-lang-btn {
  min-width: 40px;
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: rgba(255, 255, 255, .72);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  cursor: pointer;
}
.login-lang-btn:hover { color: #fff; }
.login-lang-btn.is-active {
  background: rgba(255, 255, 255, .92);
  color: #1a2333;
}
.auth-card {
  width: 420px; max-width: 100%; background: #fff; border-radius: 8px;
  box-shadow: 0 16px 48px rgba(0,0,0,.28); padding: 28px 28px 20px;
}
.logo {
  width: 72px; height: 72px; border-radius: 50%;
  background: #1e325c;
  display: grid; place-items: center; margin: 0 auto 12px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(15, 30, 60, .22);
}
.logo img {
  width: 86%; height: 86%; object-fit: contain; display: block;
  border-radius: 50%;
}
.auth-card .logo { overflow: hidden; }
.auth-card .logo img { object-fit: contain; border-radius: 50%; }
.auth-card h1 { text-align: center; margin: 0; font-size: 26px; }
.lede, .hint { text-align: center; color: #6b7080; font-size: 14px; }
.lede { margin: 6px 0 0; }
.hint { margin: 16px 0 0; line-height: 1.4; }
.auth-switch { text-align: center; margin: 16px 0 0; }
.auth-switch a { color: var(--accent); font-weight: 700; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.auth-setup-toggle {
  display: block;
  width: 100%;
  margin: 10px 0 0;
  padding: 0;
  border: 0;
  background: none;
  color: #8b8e98;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.auth-setup-toggle:hover { color: #6b7080; text-decoration: underline; }
#form-setup { position: relative; }
.setup-edit-btn {
  position: absolute;
  top: 14px;
  right: 16px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.setup-edit-btn:hover { text-decoration: underline; }
.setup-edit-btn:disabled {
  color: #8b8e98;
  cursor: default;
  text-decoration: none;
}
#form-setup.is-locked input,
#form-setup.is-locked select {
  background: #f0f2f6;
  color: #6b7080;
  pointer-events: none;
}
#form-setup.is-locked #setup-db-test,
#form-setup.is-locked #setup-submit {
  pointer-events: none;
  opacity: .55;
}
#setup-step-db .req { color: #d24b4e; font-weight: 700; }
.setup-db-status {
  min-height: 1.2em;
  margin: 10px 0 0;
  font-size: 13px;
  font-weight: 600;
}
.setup-db-status.is-ok { color: #1f8a4c; }
.setup-db-status.is-fail { color: #d24b4e; }
#setup-db-test {
  margin-top: 12px;
  background: #fff;
  border: 1px solid #d7dbe3;
  color: #3a3f4b;
}
#setup-db-test:hover { background: #f0f2f6; }
#setup-submit:disabled {
  opacity: .55;
  cursor: not-allowed;
}
label { display: block; font-size: 13px; font-weight: 700; margin: 12px 0 6px; }
input[type="text"], input[type="password"], input[type="url"], input[type="email"], input[type="tel"], input:not([type]) {
  width: 100%; border: 1px solid #d0d4dc; border-radius: 4px; padding: 10px 12px;
  box-sizing: border-box;
  background: #fff;
  color: inherit;
  font: inherit;
  appearance: none;
  -webkit-appearance: none;
}
.form-error { color: #d24b4e; min-height: 1.2em; font-size: 13px; margin-top: 8px; }

/* Under the sign-in card: the author */
.login-copyright { position: absolute; left: 0; right: 0; bottom: max(14px, var(--sab)); margin: 0; text-align: center;
  padding: 0 12px; font-size: 12.5px; color: rgba(214, 222, 245, .62); letter-spacing: .01em; pointer-events: none; }
.login-copyright a { color: rgba(232, 237, 255, .9); text-decoration: none; font-weight: 600; pointer-events: auto; }
.login-copyright a:hover { color: #fff; text-decoration: underline; }
.login-screen.is-kb-open .login-copyright { display: none; }
@media (max-height: 560px) { .login-copyright { display: none; } }
