.sc-root {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 16px;
}

.sc-root[hidden] {
  display: none !important;
}

/* Dashboard ichida — modal emas, oddiy sahifa; footer pastga yopishadi */
.app-main:has(#page-support:not(.hidden)) {
  padding: 0;
  max-width: none;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

#page-support:not(.hidden) {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0 !important;
  margin: 0;
}

#page-support .sc-page-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-width: none;
  margin: 0;
}

.sc-root.sc-page {
  position: relative;
  inset: auto;
  z-index: 1;
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 0;
  height: 100%;
  min-height: 0;
}

.sc-root.sc-page .sc-backdrop {
  display: none;
}

.sc-root.sc-page .sc-panel {
  width: 100%;
  height: 100%;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: 0;
  border: none;
  animation: none;
  box-shadow: none;
}

.sc-root.sc-page .sc-close {
  display: inline-flex;
}

.sc-root.sc-page .sc-head {
  border-radius: 0;
  flex-shrink: 0;
}

.sc-root.sc-page .sc-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.sc-root.sc-page .sc-foot {
  margin-top: auto;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 2;
}

@media (max-width: 900px) {
  #page-support:not(.hidden) {
    min-height: calc(100dvh - 64px);
  }
  .app-main:has(#page-support:not(.hidden)) {
    min-height: calc(100dvh - 64px);
  }
}

.sc-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(2px);
}

.sc-panel {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  height: min(720px, calc(100vh - 32px));
  height: min(720px, calc(100dvh - 32px));
  background: var(--d-card, #fff);
  color: var(--d-text, #0a0c10);
  border: 1px solid var(--d-border, #d7dde7);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: scIn 0.22s ease;
}

@keyframes scIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.sc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--d-border, #d7dde7);
  background: var(--d-soft, #f5f7fa);
  flex-shrink: 0;
}

.sc-head-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sc-bot {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #7c3aed, #5b21b6);
  color: #fff;
  flex-shrink: 0;
  font-size: 22px;
  line-height: 1;
}

.sc-avatar {
  overflow: hidden;
}

.sc-title {
  display: block;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
  color: #f5f5f5;
}

.sc-status {
  margin-top: 3px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: #22c55e;
}

.sc-status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45);
  animation: scPulse 1.6s ease infinite;
}

@keyframes scPulse {
  70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
}

.sc-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.sc-pill {
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(29, 78, 216, 0.1);
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.sc-uname {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--d-muted, #1f2937);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sc-close {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: #2a2a32;
  color: #f87171;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 10px;
}

.sc-close:hover {
  background: #3a3a45;
}

.sc-close svg {
  color: #ef4444;
}

.sc-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--d-bg, #f1f4f8);
}

.sc-msg {
  max-width: min(78%, 420px);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sc-msg.is-user {
  align-self: flex-end;
}

.sc-msg.is-ai,
.sc-msg.is-operator,
.sc-msg.is-system {
  align-self: flex-start;
}

.sc-bubble {
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  word-break: break-word;
}

.sc-msg.is-user .sc-bubble {
  background: #7c3aed;
  color: #fff;
  border-bottom-right-radius: 5px;
}

.sc-msg.is-ai .sc-bubble,
.sc-msg.is-operator .sc-bubble {
  background: var(--d-card, #fff);
  border: 1px solid var(--d-border, #d7dde7);
  color: var(--d-text, #0a0c10);
  border-bottom-left-radius: 5px;
}

.sc-msg.is-system .sc-bubble {
  background: rgba(232, 107, 15, 0.1);
  border: 1px solid rgba(232, 107, 15, 0.25);
  color: var(--d-text, #0a0c10);
  font-size: 13px;
}

.sc-meta {
  font-size: 11px;
  font-weight: 700;
  color: var(--d-dim, #6b7280);
  padding: 0 4px;
}

.sc-msg.is-user .sc-meta {
  text-align: right;
}

.sc-foot {
  border-top: 1px solid var(--d-border, #d7dde7);
  background: var(--d-card, #fff);
  padding: 12px 14px 14px;
  flex-shrink: 0;
}

.sc-escalate {
  margin-bottom: 10px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(29, 78, 216, 0.05);
  border: 1px solid rgba(29, 78, 216, 0.12);
}

.sc-escalate[hidden] {
  display: none !important;
}

.sc-escalate p {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--d-muted, #1f2937);
  margin-bottom: 8px;
  line-height: 1.4;
}

.sc-op-btn {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(29, 78, 216, 0.35);
  background: rgba(29, 78, 216, 0.08);
  color: #1d4ed8;
  font: inherit;
  font-size: 13.5px;
  font-weight: 800;
  cursor: pointer;
}

.sc-op-btn:hover {
  background: rgba(29, 78, 216, 0.14);
}

.sc-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sc-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--d-border, #d7dde7);
  background: var(--d-input, #fff);
  color: var(--d-text, #0a0c10);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  outline: none;
}

.sc-input:focus {
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
}

.sc-send {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: #7c3aed;
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.sc-send:hover {
  background: #6d28d9;
}

.sc-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

html[data-theme="dark"] .sc-panel,
[data-theme="dark"] .sc-panel,
:root:not([data-theme="light"]) .sc-panel {
  background: #141414;
  border-color: #2a2a2a;
}

html[data-theme="dark"] .sc-head,
html[data-theme="dark"] .sc-foot,
[data-theme="dark"] .sc-head,
[data-theme="dark"] .sc-foot,
:root:not([data-theme="light"]) .sc-head,
:root:not([data-theme="light"]) .sc-foot {
  background: #141414;
  border-color: #2a2a2a;
}

html[data-theme="dark"] .sc-body,
[data-theme="dark"] .sc-body,
:root:not([data-theme="light"]) .sc-body {
  background: #0b0b0b;
}

html[data-theme="dark"] .sc-msg.is-ai .sc-bubble,
html[data-theme="dark"] .sc-msg.is-operator .sc-bubble,
[data-theme="dark"] .sc-msg.is-ai .sc-bubble,
[data-theme="dark"] .sc-msg.is-operator .sc-bubble,
:root:not([data-theme="light"]) .sc-msg.is-ai .sc-bubble,
:root:not([data-theme="light"]) .sc-msg.is-operator .sc-bubble {
  background: #1a1a1a;
  border-color: #2a2a2a;
  color: #fff;
}

html[data-theme="dark"] .sc-title,
html[data-theme="dark"] .sc-status,
html[data-theme="dark"] .sc-uname,
html[data-theme="dark"] .sc-escalate p,
[data-theme="dark"] .sc-title,
:root:not([data-theme="light"]) .sc-title {
  color: #e5e5e5;
}

html[data-theme="dark"] .sc-input,
[data-theme="dark"] .sc-input,
:root:not([data-theme="light"]) .sc-input {
  background: #1a1a1a;
  border-color: #2a2a2a;
  color: #fff;
}

@media (max-width: 640px) {
  .sc-root {
    padding: 0;
    place-items: stretch;
  }

  .sc-panel {
    width: 100%;
    height: 100%;
    height: 100dvh;
    border-radius: 0;
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .sc-page-wrap {
    height: 100%;
    min-height: 0;
  }

  .sc-close {
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
  }

  .sc-close span {
    display: inline;
  }

  .sc-uname {
    display: none;
  }

  .sc-form {
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  }

  .sc-input,
  .sc-send {
    min-height: 44px;
  }
}

/* Telegram WebApp — faqat chat (sidebar yo‘q) */
body.support-only {
  background: #0b0b0f !important;
}

body.support-only .app-sidebar,
body.support-only .sidebar-toggle,
body.support-only .mobile-topbar {
  display: none !important;
}

body.support-only #view-app {
  display: block !important;
}

body.support-only .app-main {
  margin: 0 !important;
  padding: 0 !important;
  max-width: none !important;
  width: 100% !important;
  min-height: 100vh;
  min-height: 100dvh;
}

body.support-only #page-support:not(.hidden),
body.support-only .app-main:has(#page-support:not(.hidden)) {
  min-height: 100vh;
  min-height: 100dvh;
}

body.support-only .sc-head {
  background: #16161c;
  border-bottom-color: #2a2a35;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
}

body.support-only .sc-body {
  background: #0b0b0f;
}

body.support-only .sc-foot {
  background: #121218;
  border-top-color: #2a2a35;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}

body.support-only .sc-input {
  border-radius: 999px;
  background: #1c1c24;
  border-color: #2e2e3a;
  padding: 13px 18px;
}

body.support-only .sc-msg.is-user .sc-bubble {
  background: #7c3aed;
}

body.support-only .sc-escalate {
  display: none !important;
}
