:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #182229;
  --border: #24333d;
  --text: #e9edef;
  --muted: #8696a0;
  --primary: #00a884;
  --primary-hover: #06cf9c;
  --bubble-out: #005c4b;
  --bubble-in: #202c33;
  --danger: #e55353;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.divider-top { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 14px; }

/* Buttons & inputs */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-2);
  transition: background 0.15s ease, opacity 0.15s ease;
}
.btn:hover:not(:disabled) { opacity: 0.92; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #05201a; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.subtle { background: #1f2c34; color: var(--text); }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.danger { background: rgba(229, 83, 83, 0.18); color: #ff8c8c; }
.btn.small { padding: 6px 10px; font-size: 0.82rem; border-radius: 8px; }
.btn.full { width: 100%; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; padding: 8px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; }
.field span { color: var(--muted); }
input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
input[type="search"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0d171d;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}
input:focus { border-color: var(--primary); }

.alert {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.86rem;
  line-height: 1.4;
}
.alert.info { background: rgba(0, 168, 132, 0.15); border: 1px solid rgba(0, 168, 132, 0.35); color: #9cf2de; }
.alert.error { background: rgba(229, 83, 83, 0.16); border: 1px solid rgba(229, 83, 83, 0.38); color: #ffb4b4; }

/* Auth screen */
.auth-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.brand-badge {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--primary);
  color: #05201a;
  display: grid;
  place-items: center;
  font-size: 1.7rem;
  font-weight: bold;
}
.auth-card h1 { margin: 0; font-size: 1.35rem; }
.tg-native-card { max-width: 440px; }
.auth-card-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-spacer { flex: 1; }
.icon-circle-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-circle-btn:hover { border-color: #2aabee; color: #2aabee; }
.brand-badge.tg-blue {
  background: linear-gradient(135deg, #2aabee, #229ed9);
  color: #ffffff;
  border-radius: 50%;
  width: 64px;
  height: 64px;
  font-size: 2rem;
  margin: 0 auto;
}
.tg-step-center { align-items: center; text-align: center; }
.tg-step-center .field { text-align: left; }
.full-width { width: 100%; }
.small-text { font-size: 0.8rem; }
.api-config-box {
  background: #0d171d;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.api-config-box a { color: #56c2f6; text-decoration: underline; }
.country-select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0d171d;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}
.country-select:focus { border-color: #2aabee; }
.tg-phone-row {
  width: 100%;
  display: grid;
  grid-template-columns: 94px 1fr;
  gap: 10px;
}
.tg-code-wrap {
  display: flex;
  align-items: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0d171d;
  padding-left: 10px;
}
.tg-code-wrap:focus-within { border-color: #2aabee; }
.tg-code-wrap .plus-sign { color: var(--muted); font-weight: 700; font-size: 1rem; }
.tg-code-wrap input {
  border: none !important;
  background: transparent !important;
  padding-left: 4px !important;
  font-weight: 600;
}
.tg-otp-input {
  text-align: center;
  font-size: 1.65rem !important;
  font-weight: 700;
  letter-spacing: 0.45em;
  padding: 12px 16px !important;
}
.tg-fab-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
}
.tg-arrow-fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #2aabee, #229ed9);
  color: #ffffff;
  font-size: 1.55rem;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 6px 18px rgba(42, 171, 238, 0.35);
  transition: transform 0.12s ease, opacity 0.15s ease;
}
.tg-arrow-fab:hover:not(:disabled) { transform: scale(1.04); }
.tg-arrow-fab:disabled { opacity: 0.55; cursor: not-allowed; }
.auth-alt-links {
  width: 100%;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 4px;
}

/* App shell */
.app-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.topbar {
  height: 56px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-dot {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--primary);
  color: #05201a;
  display: grid;
  place-items: center;
  font-weight: bold;
}
.tabs { display: flex; gap: 6px; margin-left: 8px; }
.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active {
  background: rgba(0, 168, 132, 0.2);
  color: #79f2d4;
}
.badge {
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--panel-2);
  padding: 5px 10px;
  border-radius: 999px;
}

.main-area {
  flex: 1;
  min-height: 0;
  display: flex;
}
.center-panel {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
}
.login-tg-card {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-tg-card h2 { margin: 0; font-size: 1.25rem; }
.card-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.alert a { color: #79f2d4; text-decoration: underline; }
.check-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--muted);
  cursor: pointer;
}
.check-inline input[type="checkbox"] { width: auto; accent-color: var(--primary); }
.auth-mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 10px;
  background: #0d171d;
  border: 1px solid var(--border);
}
.mode-tab {
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.88rem;
  font-weight: 600;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.mode-tab.active {
  background: rgba(0, 168, 132, 0.22);
  color: #79f2d4;
}
.btn-row { display: flex; gap: 8px; }
.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-radius: 12px;
  background: #0d171d;
  border: 1px solid var(--border);
  text-align: center;
}
.qr-img {
  width: 240px;
  height: 240px;
  border-radius: 12px;
  background: #ffffff;
  padding: 8px;
}

/* Telegram Desktop-style Folders, Message Actions & VPS Rules Panel */
.folder-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.folder-pill {
  border: 1px solid var(--border);
  background: #0d171d;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.folder-pill.active {
  background: rgba(42, 171, 238, 0.22);
  border-color: #2aabee;
  color: #8fdcff;
}
.reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: #15222a;
  border-top: 1px solid var(--border);
  border-left: 3px solid #2aabee;
}
.reply-bar-info { min-width: 0; flex: 1; }
.reply-bar-info strong { font-size: 0.8rem; color: #79d2ff; display: block; }
.bubble-reply-tag {
  font-size: 0.74rem;
  color: #8fdcff;
  border-left: 2px solid #2aabee;
  padding-left: 6px;
  margin-bottom: 4px;
}
.bubble-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 4px;
}
.bubble-actions {
  display: inline-flex;
  gap: 4px;
  opacity: 0.72;
}
.bubble:hover .bubble-actions { opacity: 1; }
.bubble-act-btn {
  border: none;
  background: transparent;
  color: rgba(233, 237, 239, 0.8);
  font-size: 0.74rem;
  padding: 1px 4px;
  border-radius: 4px;
  cursor: pointer;
}
.bubble-act-btn:hover { background: rgba(255, 255, 255, 0.12); color: #ffffff; }
.vps-rules-card {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.vps-rules-card h2 { margin: 0; font-size: 1.2rem; }
.vps-rules-card h3 { margin: 0; font-size: 0.96rem; color: #79f2d4; }
.storage-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stat-box {
  background: #0d171d;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-box strong { font-size: 1.05rem; color: #e9edef; }
@media (max-width: 640px) {
  .storage-grid { grid-template-columns: 1fr; }
}

/* Split chat layout */
.split-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 350px 1fr;
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.tg-account-bar {
  padding: 12px 14px;
  background: rgba(0, 168, 132, 0.12);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.account-name { font-weight: 600; font-size: 0.95rem; }
.account-sub { font-size: 0.8rem; }

.sidebar-tools {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tool-row { display: flex; gap: 6px; flex-wrap: wrap; }

.chat-list {
  flex: 1;
  overflow-y: auto;
}
.chat-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 12px 14px;
  border-bottom: 1px solid rgba(36, 51, 61, 0.55);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: #20303a; }
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #1d3540;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}
.chat-meta { flex: 1; min-width: 0; }
.chat-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.chat-name {
  font-weight: 600;
  font-size: 0.94rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-time { font-size: 0.74rem; color: var(--muted); flex-shrink: 0; }
.chat-row-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
}
.chat-preview {
  font-size: 0.84rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.unread-pill {
  background: var(--primary);
  color: #05201a;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  flex-shrink: 0;
}

/* Chat pane */
.chat-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #0b141a;
}
.empty-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 6px;
}
.empty-icon { font-size: 2.6rem; }
.room {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.room-header {
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.room-title-wrap { flex: 1; min-width: 0; }
.room-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-sub { font-size: 0.8rem; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bubble {
  max-width: 75%;
  padding: 9px 12px;
  border-radius: 12px;
  line-height: 1.42;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.bubble.in {
  align-self: flex-start;
  background: var(--bubble-in);
  border-top-left-radius: 4px;
}
.bubble.out {
  align-self: flex-end;
  background: var(--bubble-out);
  border-top-right-radius: 4px;
}
.bubble-sender {
  font-size: 0.78rem;
  font-weight: 600;
  color: #79f2d4;
  margin-bottom: 3px;
}
.bubble-time {
  font-size: 0.7rem;
  color: rgba(233, 237, 239, 0.65);
  text-align: right;
  margin-top: 4px;
}
.media-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
}
.composer {
  padding: 10px 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Modal & Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-card {
  width: 100%;
  max-width: 440px;
  max-height: 80vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head h3 { margin: 0; font-size: 1rem; }
.modal-body {
  padding: 14px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.list-option {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
.list-option:hover { border-color: var(--primary); }

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2c34;
  border: 1px solid var(--primary);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  z-index: 60;
}

.mobile-only { display: none; }

@media (max-width: 820px) {
  .grid-2 { grid-template-columns: 1fr; }
  .split-layout { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex; }
  .badge { display: none; }
  .split-layout.chat-open .sidebar { display: none; }
  .split-layout:not(.chat-open) .chat-pane { display: none; }
}
