:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--tg-theme-text-color, #e9eef5);
  background: var(--tg-theme-bg-color, #11161d);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --bg: var(--tg-theme-bg-color, #11161d);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #18202a);
  --section-bg: var(--tg-theme-section-bg-color, #18202a);
  --text: var(--tg-theme-text-color, #e9eef5);
  --hint: var(--tg-theme-hint-color, #8e9aa7);
  --link: var(--tg-theme-link-color, #55a8f5);
  --button: var(--tg-theme-button-color, #3390ec);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --separator: var(--tg-theme-section-separator-color, rgba(255,255,255,.08));
  --own-bubble: color-mix(in srgb, var(--button) 72%, #18202a);
  --other-bubble: var(--section-bg);
}
* { box-sizing: border-box; }
html, body, #root { width: 100%; height: 100%; margin: 0; }
body { overflow: hidden; background: var(--bg); color: var(--text); }
button { font: inherit; }
.center-screen { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.state-card { width: min(420px,100%); text-align: center; padding: 30px 24px; border: 1px solid var(--separator); border-radius: 22px; background: var(--section-bg); }
.state-card h1 { margin: 12px 0 8px; font-size: 22px; }
.state-card p { margin: 6px 0; color: var(--hint); line-height: 1.45; }
.state-icon { width: 48px; height: 48px; margin: auto; display: grid; place-items: center; border-radius: 50%; background: rgba(255,82,82,.16); color: #ff6969; font-size: 24px; font-weight: 700; }
.hint { font-size: 13px; }
.loader { width: 34px; height: 34px; border: 3px solid var(--separator); border-top-color: var(--button); border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.chat-list-page, .chat-page { height: 100%; display: flex; flex-direction: column; background: var(--bg); }
.app-header, .chat-header { flex: 0 0 auto; padding: calc(14px + env(safe-area-inset-top)) 16px 14px; background: color-mix(in srgb,var(--secondary-bg) 94%,transparent); border-bottom: 1px solid var(--separator); backdrop-filter: blur(16px); z-index: 10; }
.app-header h1, .chat-header h1 { margin: 0; font-size: 19px; }
.app-header p, .chat-header p { margin: 3px 0 0; color: var(--hint); font-size: 13px; }
.chat-list { overflow-y: auto; padding: 8px 0 calc(12px + env(safe-area-inset-bottom)); }
.chat-card { width: 100%; display: flex; gap: 12px; align-items: center; border: 0; background: transparent; color: var(--text); text-align: left; padding: 10px 14px; cursor: pointer; }
.chat-card:active { background: var(--secondary-bg); }
.avatar { flex: 0 0 auto; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; background: linear-gradient(145deg,#6b7cff,#3390ec); }
.avatar.small { width: 38px; height: 38px; font-size: 15px; }
.chat-card-body { min-width: 0; flex: 1; padding-bottom: 10px; border-bottom: 1px solid var(--separator); }
.chat-card-line { display: flex; gap: 12px; justify-content: space-between; align-items: baseline; }
.chat-card-line strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 16px; }
.chat-card-line time { color: var(--hint); font-size: 12px; white-space: nowrap; }
.chat-card-line.secondary { margin-top: 4px; color: var(--hint); font-size: 14px; }
.chat-card-line.secondary span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-card-line.secondary small { min-width: 24px; text-align: right; }
.chat-header { display: flex; align-items: center; gap: 10px; padding-bottom: 10px; }
.back-button { width: 34px; height: 38px; border: 0; background: transparent; color: var(--link); font-size: 34px; line-height: 30px; cursor: pointer; padding: 0; }
.chat-title { min-width: 0; flex: 1; }
.chat-header .icon-button {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  font-size: 18px;
}
.chat-title h1 { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.message-scroller { min-height: 0; flex: 1; overflow-y: auto; overscroll-behavior: contain; background: radial-gradient(circle at 12% 18%,rgba(51,144,236,.07),transparent 24%), radial-gradient(circle at 88% 72%,rgba(87,195,153,.05),transparent 26%), var(--bg); }
.message-column { width: min(860px,100%); min-height: 100%; margin: 0 auto; padding: 12px 10px calc(18px + env(safe-area-inset-bottom)); }
.load-older { display: block; margin: 2px auto 14px; padding: 8px 14px; border: 0; border-radius: 16px; background: var(--secondary-bg); color: var(--link); cursor: pointer; }
.load-older:disabled { opacity: .6; }
.date-divider { text-align: center; margin: 12px 0 8px; }
.date-divider span { display: inline-block; padding: 5px 10px; border-radius: 14px; background: color-mix(in srgb,var(--secondary-bg) 88%,transparent); color: var(--hint); font-size: 12px; }
.message-row { display: flex; margin: 3px 0; }
.message-row.own { justify-content: flex-end; }
.message-row.other { justify-content: flex-start; }
.message-bubble { width: fit-content; max-width: min(76%,650px); padding: 8px 10px 6px; border-radius: 16px; background: var(--other-bubble); box-shadow: 0 1px 1px rgba(0,0,0,.14); overflow-wrap: anywhere; }
.own .message-bubble { background: var(--own-bubble); border-bottom-right-radius: 5px; }
.other .message-bubble { border-bottom-left-radius: 5px; }
.message-bubble.deleted { opacity: .58; filter: saturate(.7); }
.sender-name { margin-bottom: 3px; color: var(--link); font-weight: 650; font-size: 13px; }
.message-text { white-space: pre-wrap; line-height: 1.38; font-size: 15px; }
.media-placeholder { padding: 8px 10px; border: 1px dashed color-mix(in srgb,var(--hint) 42%,transparent); border-radius: 10px; color: var(--hint); font-size: 14px; }
.deleted-label { margin-top: 7px; font-size: 12px; font-weight: 650; color: var(--hint); }
.message-meta { display: flex; justify-content: flex-end; gap: 5px; margin-top: 3px; color: color-mix(in srgb,var(--hint) 85%,transparent); font-size: 10px; }
.versions { margin-top: 8px; padding-top: 7px; border-top: 1px solid color-mix(in srgb,var(--separator) 90%,transparent); }
.versions summary { color: var(--link); font-size: 12px; cursor: pointer; line-height: 1.35; }
.versions-list { margin-top: 7px; display: grid; gap: 6px; }
.version { padding: 7px 8px; border-radius: 9px; background: rgba(0,0,0,.13); }
.version-number { font-size: 10px; color: var(--hint); margin-bottom: 3px; }
.version-text { white-space: pre-wrap; font-size: 13px; line-height: 1.35; }
.version time { display: block; margin-top: 4px; color: var(--hint); font-size: 9px; text-align: right; }
.muted, .empty { color: var(--hint); }
.empty { padding: 30px 18px; text-align: center; }
@media (min-width:760px) { .message-column { padding-left: 24px; padding-right: 24px; } .message-bubble { max-width: 68%; } }
.header-with-action { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.icon-button { width: 42px; height: 42px; border: 0; border-radius: 50%; background: var(--secondary-bg); color: var(--link); font-size: 24px; cursor: pointer; }
.media-placeholder { display: grid; gap: 4px; }
.media-placeholder span, .media-placeholder small { display: block; color: var(--hint); }
.archived-image, .archived-video { display: block; max-width: 100%; max-height: 520px; border-radius: 11px; object-fit: contain; background: rgba(0,0,0,.12); }
.sticker-image { width: min(220px, 70vw); background: transparent; }
.round-video { width: min(300px, 72vw); aspect-ratio: 1; border-radius: 50%; object-fit: cover; }
.audio-wrapper { min-width: min(280px, 68vw); }
.audio-wrapper audio { width: 100%; margin-top: 5px; }
.media-title { font-size: 13px; margin-bottom: 3px; }
.media-block { display: grid; gap: 7px; max-width: 100%; justify-items: start; }
.media-download-button { display: inline-flex; align-items: center; justify-content: center; min-height: 34px; padding: 7px 11px; border-radius: 10px; background: color-mix(in srgb,var(--link) 18%,transparent); color: var(--link); text-decoration: none; font-size: 13px; font-weight: 650; }
.audio-wrapper .media-download-button { margin-top: 6px; }
.file-link { display: flex; align-items: center; gap: 10px; padding: 9px; border-radius: 11px; background: color-mix(in srgb,var(--secondary-bg) 72%,transparent); color: var(--text); text-decoration: none; }
.file-icon { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--link); color: var(--button-text); font-size: 20px; }
.file-link-body { min-width: 0; display: grid; }
.file-link-body strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.file-link-body small { color: var(--hint); }
.message-text:not(:first-child) { margin-top: 7px; }
.storage-page { height: 100%; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: 0 12px calc(20px + env(safe-area-inset-bottom)); }
.storage-stats { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; margin: 4px 0 14px; }
.storage-stat { padding: 12px; border-radius: 13px; background: var(--secondary-bg); display: grid; gap: 4px; }
.storage-stat small { color: var(--hint); }
.storage-stat strong { font-size: 17px; overflow-wrap: anywhere; }
.storage-list { display: grid; gap: 8px; }
.storage-item { display: flex; gap: 10px; align-items: center; padding: 12px; border-radius: 13px; background: var(--secondary-bg); }
.storage-item-body { flex: 1; min-width: 0; display: grid; gap: 4px; }
.storage-item-body strong, .storage-item-body span, .storage-item-body small { overflow-wrap: anywhere; }
.storage-item-body span, .storage-item-body small { color: var(--hint); font-size: 12px; }
.storage-error { color: var(--destructive-text, #d14b4b) !important; }
.storage-actions { flex: 0 0 auto; }
.primary-button, .danger-button { border: 0; border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.storage-actions .media-download-button { min-height: auto; padding: 8px 10px; background: color-mix(in srgb,var(--link) 18%,transparent); }
.primary-button { background: var(--link); color: var(--button-text); }
.danger-button { background: color-mix(in srgb,#d14b4b 18%,transparent); color: var(--destructive-text,#d14b4b); }
.primary-button:disabled, .danger-button:disabled { opacity: .55; }
@media (min-width:760px) { .storage-stats { grid-template-columns: repeat(4,minmax(0,1fr)); } .storage-page { width: min(900px,100%); margin: 0 auto; } }
.storage-actions { display: flex; flex-wrap: wrap; gap: 7px; justify-content: flex-end; }
a.primary-button { display: inline-flex; align-items: center; text-decoration: none; }

/* Storage card: metadata on top, actions below */
.storage-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 14px;
}

.storage-item-body {
    width: 100%;
    min-width: 0;
}

.storage-item-body strong {
    font-size: 17px;
    line-height: 1.25;
}

.storage-item-body span,
.storage-item-body small {
    font-size: 14px;
    line-height: 1.35;
}

.storage-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.storage-actions .primary-button,
.storage-actions .danger-button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 9px 7px;
    justify-content: center;
    text-align: center;
    font-size: 14px;
}

@media (max-width: 390px) {
    .storage-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .storage-actions .danger-button {
        grid-column: 1 / -1;
    }
}

/* Stage 9: Mini App administration */
.header-actions { display: flex; align-items: center; gap: 8px; }
.admin-page {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 0 12px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.admin-header {
  position: sticky;
  top: 0;
  margin: 0 -12px 14px;
}
.admin-section { width: min(920px,100%); margin: 0 auto 18px; }
.admin-section-heading { margin: 0 2px 9px; }
.admin-section-heading h2 { margin: 0; font-size: 18px; }
.admin-section-heading p { margin: 4px 0 0; color: var(--hint); font-size: 13px; line-height: 1.4; }
.admin-list { display: grid; gap: 9px; }
.admin-card {
  display: grid;
  gap: 7px;
  padding: 13px;
  border: 1px solid var(--separator);
  border-radius: 14px;
  background: var(--secondary-bg);
}
.admin-card p { margin: 0; color: var(--hint); font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.admin-card small { color: var(--hint); }
.admin-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.admin-card-top strong { min-width: 0; overflow-wrap: anywhere; }
.admin-status {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  background: color-mix(in srgb,var(--link) 16%,transparent);
  color: var(--link);
  font-size: 11px;
  font-weight: 650;
  text-align: center;
}
.admin-owner-card { border-color: color-mix(in srgb,var(--link) 45%,var(--separator)); }
.admin-warning-card { border-color: color-mix(in srgb,#d99628 48%,var(--separator)); }
.blacklist-card { grid-template-columns: 1fr auto; align-items: center; }
.compact-admin-list { gap: 7px; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.admin-actions .primary-button,
.admin-actions .secondary-button,
.admin-actions .danger-button { min-height: 40px; }
.secondary-button {
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  background: color-mix(in srgb,var(--hint) 18%,transparent);
  color: var(--text);
}
.secondary-button:disabled { opacity: .55; }
.admin-form {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 10px;
  padding: 13px;
  border: 1px solid var(--separator);
  border-radius: 14px;
  background: var(--secondary-bg);
}
.admin-field { display: grid; gap: 6px; color: var(--hint); font-size: 12px; }
.admin-field input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--separator);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.admin-field input:disabled { opacity: .5; }
.admin-checkbox { display: flex; align-items: center; gap: 8px; color: var(--hint); font-size: 13px; }
.admin-checkbox input { width: 18px; height: 18px; }
.admin-submit { min-height: 44px; }
.created-promo-card { margin-bottom: 10px; border-color: color-mix(in srgb,#4aba79 52%,var(--separator)); }
.promo-full-code {
  display: block;
  padding: 10px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  overflow-wrap: anywhere;
  user-select: all;
}
@media (max-width: 680px) {
  .admin-form { grid-template-columns: 1fr; }
  .admin-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); }
  .admin-actions .danger-button:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .blacklist-card { grid-template-columns: 1fr; }
}

/* Text input dialog */
.text-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .48);
  backdrop-filter: blur(4px);
}

.text-dialog {
  width: min(400px, 100%);
  padding: 18px;
  border: 1px solid var(--separator);
  border-radius: 16px;
  background: var(--section-bg);
  color: var(--text);
}

.text-dialog h2 {
  margin: 0;
  font-size: 18px;
}

.text-dialog p {
  margin: 7px 0 14px;
  color: var(--hint);
  font-size: 13px;
  line-height: 1.4;
}

.text-dialog-input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--separator);
  border-radius: 10px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.text-dialog-input:focus {
  border-color: var(--link);
}

.text-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.text-dialog-button {
  min-height: 38px;
  padding: 8px 13px;
  border: 0;
  border-radius: 10px;
  background: var(--secondary-bg);
  color: var(--text);
  cursor: pointer;
}

.text-dialog-button.primary {
  background: var(--button);
  color: var(--button-text);
}

/* Chat settings */
.dialog-preline {
  white-space: pre-line;
}

.text-dialog-button.danger {
  background: color-mix(
    in srgb,
    #d14b4b 22%,
    var(--secondary-bg)
  );
  color: var(
    --destructive-text,
    #ff6b6b
  );
}

.chat-settings-dialog {
  padding-bottom: 12px;
}

.chat-settings-list {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.chat-settings-option {
  width: 100%;
  display: grid;
  gap: 3px;
  padding: 12px;
  border: 0;
  border-radius: 11px;
  background: var(--secondary-bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.chat-settings-option strong {
  font-size: 15px;
}

.chat-settings-option span {
  color: var(--hint);
  font-size: 12px;
  line-height: 1.4;
}

.chat-settings-option.danger strong {
  color: var(
    --destructive-text,
    #ff6b6b
  );
}

.chat-settings-option:active {
  opacity: .75;
}

/* Stage 10.3: browser login through OrbitLink */
.archive-auth-page {
  width: 100%;
  min-height: 100%;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: calc(28px + env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 50% 0%, color-mix(in srgb, var(--button) 13%, transparent), transparent 34%),
    var(--bg);
}

.archive-auth-card {
  width: min(440px, 100%);
  display: grid;
  gap: 24px;
  padding: 30px;
  border: 1px solid var(--separator);
  border-radius: 24px;
  background: color-mix(in srgb, var(--section-bg) 96%, transparent);
  box-shadow: 0 18px 60px rgba(0, 0, 0, .2);
}

.archive-auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.archive-auth-logo {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #6b7cff, var(--button));
  color: #fff;
  font-size: 22px;
  font-weight: 800;
}

.archive-auth-brand > div:last-child {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.archive-auth-brand strong { font-size: 17px; }
.archive-auth-brand span { color: var(--hint); font-size: 13px; }
.archive-auth-heading { display: grid; gap: 8px; }
.archive-auth-heading h1 { margin: 0; font-size: 27px; line-height: 1.15; }
.archive-auth-heading p,
.archive-auth-note { margin: 0; color: var(--hint); line-height: 1.5; }

.archive-auth-primary {
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  border: 0;
  border-radius: 14px;
  background: var(--button);
  color: var(--button-text);
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
}

.archive-auth-error {
  padding: 11px 13px;
  border: 1px solid color-mix(in srgb, #ff6969 35%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, #ff6969 10%, transparent);
  color: #ff8585;
  line-height: 1.4;
  font-size: 14px;
}

.archive-auth-note { font-size: 12px; text-align: center; }
.archive-selection-card { width: min(520px, 100%); }
.archive-account-list { display: grid; gap: 10px; }

.archive-account-button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 13px;
  border: 1px solid var(--separator);
  border-radius: 15px;
  background: var(--secondary-bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.archive-account-button:hover {
  border-color: color-mix(in srgb, var(--link) 45%, var(--separator));
}
.archive-account-button:disabled { opacity: .55; cursor: default; }

.archive-account-avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, #6b7cff, var(--button));
  color: #fff;
  font-weight: 750;
}

.archive-account-text {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 3px;
}
.archive-account-text strong,
.archive-account-text span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.archive-account-text span { color: var(--hint); font-size: 12px; }
.archive-account-arrow { flex: 0 0 auto; color: var(--hint); font-size: 28px; line-height: 1; }

@media (max-width: 520px) {
  .archive-auth-card { padding: 24px 20px; border-radius: 20px; }
  .archive-auth-heading h1 { font-size: 24px; }
}

