/* NexoGram Telegram Accounts.
   A read-only Telegram Web ("Night") style client over the server archive:
   account rail → chat list → message thread. Shares its palette with the
   standalone console (console/styles.css). */

.nexogram-accounts-console {
  --tg-bg: #0e1621;
  --tg-panel: #17212b;
  --tg-panel-2: #232e3c;
  --tg-hover: #202b36;
  --tg-active: #2b5278;
  --tg-line: rgba(255, 255, 255, .08);
  --tg-line-soft: rgba(255, 255, 255, .05);
  --tg-text: #ffffff;
  --tg-muted: #7d8b99;
  --tg-faint: #5e6f7e;
  --tg-accent: #6ab7ff;
  --tg-accent-solid: #3390ec;
  --tg-in: #182533;
  --tg-out: #2b5278;
  --tg-green: #4dcd5e;
  --tg-red: #f2818a;
  --tg-amber: #e6b45c;

  margin: 14px clamp(12px, 2vw, 22px) 20px;
  color: var(--tg-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  isolation: isolate;
}

.nexogram-accounts-console * { box-sizing: border-box; }
.nexogram-accounts-console button,
.nexogram-accounts-console input,
.nexogram-accounts-console select { font: inherit; }

.nexogram-accounts-console ::-webkit-scrollbar { width: 8px; height: 8px; }
.nexogram-accounts-console ::-webkit-scrollbar-thumb { border-radius: 8px; background: rgba(255, 255, 255, .12); }
.nexogram-accounts-console ::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, .2); }

/* ---- Shell: rail | chat list | conversation --------------------------- */

.tg-shell {
  display: grid;
  grid-template-columns: 68px minmax(280px, 340px) minmax(0, 1fr);
  height: min(78vh, 820px);
  min-height: 520px;
  overflow: hidden;
  border: 1px solid var(--tg-line);
  border-radius: 12px;
  background: var(--tg-bg);
}

/* ---- Account rail ----------------------------------------------------- */

.tg-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  background: #141e29;
  border-right: 1px solid var(--tg-line-soft);
}

.tg-rail-logo {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-bottom: 6px;
  border-radius: 12px;
  background: var(--tg-accent-solid);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
}

.tg-rail-accounts {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  width: 100%;
  overflow-y: auto;
  padding: 2px 0;
}

.tg-rail-account {
  position: relative;
  width: 46px;
  height: 46px;
  border: 0;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  background: transparent;
  transition: border-radius .15s ease;
}

.tg-rail-account .tg-avatar { width: 46px; height: 46px; font-size: 16px; }

.tg-rail-account::after {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  width: 3px;
  height: 0;
  border-radius: 0 3px 3px 0;
  background: var(--tg-accent);
  transform: translateY(-50%);
  transition: height .15s ease;
}

.tg-rail-account:hover .tg-avatar { filter: brightness(1.08); }
.tg-rail-account.active::after { height: 26px; }
.tg-rail-account.active .tg-avatar { border-radius: 16px; }

.tg-rail-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #141e29;
  background: var(--tg-faint);
}
.tg-rail-dot.online { background: var(--tg-green); }

.tg-rail-refresh {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: var(--tg-muted);
  background: transparent;
  font-size: 18px;
  transition: background .15s ease, color .15s ease;
}
.tg-rail-refresh:hover { background: var(--tg-hover); color: var(--tg-text); }
.tg-rail-refresh:disabled { opacity: .5; cursor: default; }

/* ---- Avatars (shared) ------------------------------------------------- */

.tg-avatar {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: #fff;
  font-weight: 600;
  letter-spacing: -.01em;
  text-transform: uppercase;
  overflow: hidden;
}

/* ---- Chat list -------------------------------------------------------- */

.tg-sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0; /* allow .tg-chats to scroll instead of growing the column */
  background: var(--tg-panel);
  border-right: 1px solid var(--tg-line-soft);
}

.tg-sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--tg-line-soft);
}

.tg-account-id { min-width: 0; flex: 1; }
.tg-account-id strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
}
.tg-account-id span {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--tg-muted);
  font-size: 12px;
}
.tg-account-id .on { color: var(--tg-green); }
.tg-account-id .warn { color: var(--tg-amber); }

.tg-icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: var(--tg-muted);
  background: transparent;
  font-size: 18px;
  transition: background .15s ease, color .15s ease;
}
.tg-icon-btn:hover { background: var(--tg-hover); color: var(--tg-text); }

/* Account menu popover */
.tg-menu {
  position: relative;
  border-bottom: 1px solid var(--tg-line-soft);
  background: var(--tg-panel-2);
}
.tg-menu-inner { padding: 12px 14px; display: grid; gap: 12px; }
.tg-menu-toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.tg-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border: 1px solid var(--tg-line);
  border-radius: 8px;
  cursor: pointer;
  color: var(--tg-muted);
  font-size: 12px;
}
.tg-toggle input { accent-color: var(--tg-accent-solid); margin: 0; }
.tg-toggle.on { color: var(--tg-text); border-color: rgba(106, 183, 255, .4); }
.tg-menu-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.tg-contact-sync {
  display: grid;
  gap: 7px;
  padding-bottom: 11px;
  border-bottom: 1px solid var(--tg-line-soft);
}
.tg-contact-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tg-contact-head > div { min-width: 0; }
.tg-contact-head strong { display: block; font-size: 13px; font-weight: 600; }
.tg-contact-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: var(--tg-accent);
  background: rgba(106, 183, 255, .12);
  font-size: 16px;
}
.tg-contact-state,
.tg-contact-meta { display: block; color: var(--tg-muted); font-size: 11px; line-height: 1.4; }
.tg-contact-state.ready { color: var(--tg-green); }
.tg-contact-state.syncing { color: var(--tg-accent); }
.tg-contact-state.error { color: var(--tg-red); }
.tg-contact-path {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--tg-faint);
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.tg-contact-error { margin: 0; color: var(--tg-red); font-size: 11px; line-height: 1.4; }

.tg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--tg-line);
  border-radius: 8px;
  cursor: pointer;
  color: var(--tg-text);
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s ease, border-color .15s ease;
}
.tg-btn:hover:not(:disabled) { background: var(--tg-hover); }
.tg-btn:disabled { opacity: .5; cursor: default; }
.tg-btn.primary { border-color: transparent; background: var(--tg-accent-solid); color: #fff; }
.tg-btn.primary:hover:not(:disabled) { background: #4aa0f2; }
.tg-btn.danger { border-color: rgba(239, 85, 85, .5); color: #ff8b8b; }
.tg-btn.danger:hover:not(:disabled) { border-color: var(--tg-red); background: rgba(239, 85, 85, .12); }
.tg-btn.sm { min-height: 30px; padding: 0 11px; font-size: 12px; }

/* Needs-second-login banner */
.tg-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 10px 12px 0;
  padding: 11px 12px;
  border: 1px solid rgba(230, 180, 92, .3);
  border-radius: 10px;
  background: rgba(230, 180, 92, .08);
}
.tg-banner p { margin: 0; color: #ecd6ac; font-size: 12px; line-height: 1.45; }
.tg-banner p strong { display: block; margin-bottom: 2px; color: var(--tg-amber); font-weight: 600; }
.tg-banner button {
  flex: none;
  align-self: center;
  padding: 5px 10px;
  border: 1px solid rgba(230, 180, 92, .4);
  border-radius: 7px;
  cursor: pointer;
  color: #ecd6ac;
  background: transparent;
  font-size: 12px;
}

.tg-search { padding: 8px 10px; }
.tg-search input {
  width: 100%;
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 19px;
  outline: none;
  color: var(--tg-text);
  background: var(--tg-panel-2);
  font-size: 14px;
}
.tg-search input::placeholder { color: var(--tg-faint); }

.tg-chats { flex: 1; overflow-y: auto; padding: 2px 6px 8px; }

.tg-chat-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  color: var(--tg-text);
  background: transparent;
  transition: background .12s ease;
}
.tg-chat-row:hover { background: var(--tg-hover); }
.tg-chat-row.active { background: var(--tg-active); }
.tg-chat-row .tg-avatar { width: 48px; height: 48px; font-size: 17px; }

.tg-chat-body { min-width: 0; align-self: center; }
.tg-chat-line { display: flex; align-items: baseline; gap: 6px; }
.tg-chat-line strong {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 500;
}
.tg-chat-preview {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--tg-muted);
  font-size: 13px;
}
.tg-chat-row.active .tg-chat-preview { color: rgba(255, 255, 255, .72); }

.tg-chat-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 5px;
}
.tg-chat-time { color: var(--tg-faint); font-size: 11px; white-space: nowrap; }
.tg-chat-row.active .tg-chat-time { color: rgba(255, 255, 255, .7); }
.tg-chat-badges { display: flex; gap: 4px; }
.tg-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}
.tg-badge.del { background: rgba(242, 129, 138, .22); color: #f2a6ac; }
.tg-badge.edit { background: rgba(230, 180, 92, .22); color: #ecc987; }
.tg-badge.count { background: rgba(255, 255, 255, .1); color: var(--tg-muted); }
.tg-chat-row.active .tg-badge.count { background: rgba(255, 255, 255, .2); color: #fff; }

/* ---- Conversation ----------------------------------------------------- */

.tg-chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0; /* let .tg-messages scroll within the fixed shell height so all edits/deletions are reachable */
  background:
    linear-gradient(rgba(14, 22, 33, .86), rgba(14, 22, 33, .86)),
    var(--tg-bg);
}

.tg-chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
  min-height: 58px;
  border-bottom: 1px solid var(--tg-line-soft);
  background: var(--tg-panel);
}
.tg-back { display: none; flex: none; font-size: 24px; }
.tg-chat-peer { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 1; }
.tg-chat-peer .tg-avatar { width: 40px; height: 40px; font-size: 15px; }
.tg-chat-peer-text { min-width: 0; }
.tg-chat-peer-text strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
}
.tg-chat-peer-text span {
  display: block;
  margin-top: 1px;
  color: var(--tg-muted);
  font-size: 12px;
}

.tg-chat-filters { display: flex; gap: 8px; align-items: center; }
.tg-chat-filters select,
.tg-chat-filters input {
  min-height: 34px;
  border: 1px solid var(--tg-line);
  border-radius: 8px;
  outline: none;
  color: var(--tg-text);
  background: var(--tg-panel-2);
  font-size: 13px;
}
.tg-chat-filters select { padding: 0 8px; }
.tg-chat-filters input { width: 170px; padding: 0 11px; }
.tg-chat-filters input::placeholder { color: var(--tg-faint); }

.tg-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 16px clamp(16px, 6%, 90px);
}

.tg-day { align-self: center; margin: 10px 0; }
.tg-day span {
  padding: 4px 12px;
  border-radius: 14px;
  background: rgba(0, 0, 0, .38);
  color: #cfe0f0;
  font-size: 12px;
  font-weight: 500;
}

.tg-msg { display: flex; max-width: 100%; }
.tg-msg.out { justify-content: flex-end; }
.tg-msg.in { justify-content: flex-start; }

.tg-bubble {
  position: relative;
  max-width: min(70%, 560px);
  padding: 7px 11px 6px;
  border-radius: 12px;
  background: var(--tg-in);
  font-size: 14px;
  line-height: 1.4;
}
.tg-msg.in .tg-bubble { border-bottom-left-radius: 4px; }
.tg-msg.out .tg-bubble { background: var(--tg-out); border-bottom-right-radius: 4px; }

/* Event tags carry the state without adding a decorative side stripe. */

.tg-sender {
  display: block;
  margin-bottom: 2px;
  color: var(--tg-accent);
  font-size: 13px;
  font-weight: 600;
}
.tg-msg.out .tg-sender { color: #9fd0ff; }

.tg-tag {
  display: inline-block;
  margin-bottom: 3px;
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.tg-tag.deleted, .tg-tag.cleared, .tg-tag.chat_removed { background: rgba(242, 129, 138, .2); color: #f2a6ac; }
.tg-tag.edited { background: rgba(230, 180, 92, .2); color: #ecc987; }
.tg-tag.service { background: rgba(168, 149, 231, .2); color: #c3b6f2; }

.tg-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.tg-text-empty { color: var(--tg-muted); font-style: italic; }

.tg-quote {
  margin: 6px 0 2px;
  padding: 4px 9px;
  border-left: 2px solid var(--tg-amber);
  border-radius: 0 6px 6px 0;
  background: rgba(230, 180, 92, .1);
  color: #ecd6ac;
  font-size: 13px;
  line-height: 1.4;
}
.tg-quote b {
  display: block;
  margin-bottom: 1px;
  color: var(--tg-amber);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.tg-media {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  padding: 6px 11px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  color: #d9ecfb;
  background: rgba(255, 255, 255, .08);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
}
.tg-media:hover { background: rgba(255, 255, 255, .14); }

.tg-time {
  float: right;
  margin: 4px 0 -2px 10px;
  color: rgba(255, 255, 255, .45);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.tg-msg.out .tg-time { color: rgba(255, 255, 255, .6); }

.tg-chat-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 16px;
  border-top: 1px solid var(--tg-line-soft);
  background: var(--tg-panel);
  color: var(--tg-muted);
  font-size: 12px;
}
.tg-chat-foot div { display: flex; gap: 8px; }

/* ---- Empty / loading states ------------------------------------------ */

.tg-empty {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 30px;
  text-align: center;
  color: var(--tg-muted);
}
.tg-empty-pill {
  padding: 8px 16px;
  border-radius: 16px;
  background: rgba(0, 0, 0, .3);
  font-size: 13px;
}
.tg-list-empty { padding: 32px 16px; text-align: center; color: var(--tg-muted); font-size: 13px; line-height: 1.5; }

/* ---- Notice toast ----------------------------------------------------- */

.tg-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 40;
  transform: translateX(-50%);
  max-width: min(440px, 90vw);
  padding: 11px 16px;
  border-radius: 10px;
  color: #fff;
  background: #1c2b3a;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
  font-size: 13px;
}
.tg-toast.error { background: #4a2530; }

/* ---- In-app media download button (React bubbles, outside our root) --- */

.nova-media-shell { position: relative !important; }
.nova-media-download {
  position: absolute;
  top: 7px;
  right: 7px;
  z-index: 8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
  padding: 0 9px;
  border-radius: 8px;
  color: #fff;
  background: rgba(0, 0, 0, .55);
  font-size: 15px;
  line-height: 1;
  text-decoration: none;
  opacity: .25;
  transition: opacity .14s ease, background .14s ease;
  backdrop-filter: blur(6px);
}
.nova-media-shell:hover .nova-media-download,
.nova-media-download:focus-visible { opacity: 1; }
.nova-media-download:hover { background: rgba(0, 0, 0, .78); }
.nova-media-download span {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- Responsive ------------------------------------------------------- */

@media (max-width: 900px) {
  .tg-shell {
    grid-template-columns: 56px minmax(0, 1fr);
    height: auto;
    min-height: 0;
  }
  .tg-rail { padding: 10px 0; }
  .tg-rail-logo { width: 36px; height: 36px; }
  /* Collapse to list OR thread: whichever the user is in. */
  .tg-shell[data-view="chat"] .tg-sidebar { display: none; }
  .tg-shell[data-view="list"] .tg-chat { display: none; }
  .tg-sidebar { height: min(74vh, 640px); }
  .tg-chat { height: min(78vh, 720px); }
  .tg-back { display: grid; }
  .tg-chat-filters input { width: 120px; }
}
