@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");

:root {
  --bg: #0f1116;
  --sidebar: #141821;
  --panel: #0c0f14;
  --border: #1c212d;
  --accent: #3da6ff;
  --accent-strong: #1f86ff;
  --text: #eef1f5;
  --muted: #9aa2b2;
  --danger: #ff5f87;
  --bubble-self: #13314b;
  --bubble-other: #151a23;
}

* { box-sizing: border-box; }

body.telegram {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  justify-content: center;
}

.tg-root {
  width: min(1600px, 100%);
  height: 100vh;
  display: grid;
  grid-template-columns: 360px 1fr;
  background: var(--bg);
}

/* Sidebar */
.tg-sidebar {
  background: var(--sidebar);
  padding: 0.8rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  overflow: visible;
}
.sidebar-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; }
.header-stack { display: flex; flex-direction: column; gap: 0.6rem; }
.title-row { display: flex; align-items: center; gap: 0.5rem; }
.app-title-large { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.08em; }
.menu-wrapper { display: flex; gap: 0.35rem; align-items: center; position: relative; }
.icon-button {
  width: 36px; height: 36px;
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  display: grid; place-items: center;
  cursor: pointer;
}
.profile-chip { display: flex; align-items: center; gap: 0.6rem; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg,#252b3a,#191d29); display: grid; place-items: center; font-weight: 700; }
.profile-text { display: flex; flex-direction: column; gap: 0.1rem; }
.profile-name { font-weight: 700; }
.profile-status { color: #4ade80; font-size: 0.85rem; }
.ghost { border: 1px solid var(--border); background: transparent; color: var(--text); border-radius: 0.7rem; padding: 0.45rem 0.8rem; cursor: pointer; }
.ghost.mini { padding: 0.35rem 0.7rem; }

.app-menu {
  position: absolute;
  top: 110%;
  right: 0;
  background: #101622;
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  min-width: 160px;
  z-index: 10;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}
.app-menu[hidden] { display: none; }
.app-menu button {
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-radius: 0.6rem;
  cursor: pointer;
}
.app-menu button:hover { background: rgba(255,255,255,0.06); }

.sidebar-tabs { display: flex; gap: 0.4rem; }
.sidebar-tabs .tab {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  padding: 0.55rem 0.8rem;
  cursor: default;
}

.sidebar-search form { display: flex; gap: 0.45rem; }
.sidebar-search input {
  flex: 1; padding: 0.65rem 0.85rem;
  border-radius: 0.85rem; border: 1px solid var(--border);
  background: #101622; color: var(--text);
}
.sidebar-search button {
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: rgba(255,255,255,0.05);
  color: var(--text);
  padding: 0.65rem 0.9rem;
  cursor: pointer;
}

.token-card {
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 0.75rem;
  background: #111622;
  font-size: 0.9rem;
  color: var(--muted);
}
.token-box {
  margin-top: 0.45rem;
  background: #0d111a;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  padding: 0.65rem;
  word-break: break-all;
  color: var(--text);
}

.chat-list-wrapper { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-list { flex: 1; overflow-y: auto; padding-right: 0.2rem; display: flex; flex-direction: column; gap: 0.2rem; }
.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.chat-item {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 0.85rem;
  padding: 0.6rem 0.7rem;
  display: grid; grid-template-columns: 48px 1fr auto; gap: 0.6rem; align-items: center;
  cursor: pointer;
}
.chat-item:hover { background: rgba(255,255,255,0.04); }
.chat-item--active { background: linear-gradient(135deg, rgba(61,166,255,0.2), rgba(28,130,255,0.2)); border-color: rgba(61,166,255,0.4); }
.chat-item__avatar { width: 48px; height: 48px; border-radius: 50%; background: linear-gradient(135deg,#252b3a,#191d29); display: grid; place-items: center; font-weight: 700; }
.chat-item__body { display: flex; flex-direction: column; gap: 0.15rem; }
.chat-item__name { font-weight: 700; }
.chat-item__preview { color: var(--muted); font-size: 0.9rem; }
.chat-item__time { color: var(--muted); font-size: 0.82rem; }
.badge { background: var(--accent); color: #06101f; border-radius: 999px; padding: 0.1rem 0.5rem; font-size: 0.75rem; }

/* Dialog */
.tg-dialog { background: var(--panel); display: flex; flex-direction: column; }
.dialog-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.8rem 0;
}
.dialog-header.hidden { display: none; }
.dialog-header h2 { margin: 0; font-size: 1.05rem; }
.dialog-header p { margin: 0; font-size: 0.9rem; color: #4ade80; }
.status-dot { color: var(--muted); }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.chat-log--empty {
  justify-content: center;
  align-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 1.1rem;
}
.chat-log::-webkit-scrollbar { width: 6px; }
.chat-log::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

.message {
  max-width: 78%;
  padding: 0.65rem 0.85rem 0.55rem;
  border-radius: 0.95rem;
  background: var(--bubble-other);
  border: 1px solid rgba(255,255,255,0.04);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  position: relative;
  color: var(--text);
  margin-right: auto;
  align-self: flex-start;
}
.message--self {
  margin-left: auto;
  margin-right: 0;
  align-self: flex-end;
  align-items: flex-end;
  padding-right: 1rem; /* место под галочки */
  background: var(--bubble-self);
  border-color: rgba(61,166,255,0.3);
}
.message__meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.82rem; }
.message__media { background: #0a0d12; border-radius: 0.8rem; padding: 0.35rem; }
.message__media img, .message__media video, .message__media audio { width: 100%; max-width: 420px; border-radius: 0.7rem; border: 1px solid var(--border); background: #0c0f16; }
.message__status { position: absolute; bottom: 6px; right: 10px; font-size: 0.8rem; color: rgba(255,255,255,0.7); }

/* Composer */
.message-form {
  padding: 0.75rem 0.5rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  background: #0b0d12;
}
.message-form.hidden { display: none; }
.composer-bar { display: flex; align-items: center; gap: 0.4rem; color: var(--muted); }
.ghost.icon { width: 38px; height: 38px; border-radius: 0.8rem; border: 1px solid var(--border); background: rgba(255,255,255,0.05); color: var(--text); }
.recording-pill { color: var(--danger); font-size: 0.9rem; }
.preview-pill { font-size: 0.85rem; color: var(--muted); }

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  background: #0f131c;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  align-items: center;
}
.input-row input {
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0.9rem 1rem;
  font-size: 0.95rem;
}
.input-row input:focus { outline: none; }
.input-row button {
  border: none;
  background: transparent;
  color: var(--accent);
  padding: 0 1rem;
  font-size: 1.2rem;
  cursor: pointer;
}
.input-row button:disabled { opacity: 0.5; }

/* Toasts */
.toast-root { position: absolute; top: 1rem; right: 1rem; display: flex; flex-direction: column; gap: 0.4rem; }
.toast { background: #0f131a; border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 0.8rem; padding: 0.6rem 0.8rem; color: var(--text); opacity: 0; transform: translateX(120%); transition: all 0.2s ease; }
.toast.visible { opacity: 1; transform: translateX(0); }

.msg-menu {
  position: fixed;
  background: #111622;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  padding: 0.25rem;
  box-shadow: 0 12px 30px rgba(0,0,0,0.35);
  z-index: 50;
}
.msg-menu button {
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0.55rem 0.75rem;
  border-radius: 0.5rem;
  cursor: pointer;
  white-space: nowrap;
}
.msg-menu button:hover { background: rgba(255,255,255,0.06); }

.settings-panel {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  pointer-events: none;
  z-index: 40;
}
.settings-panel[hidden] { visibility: hidden; opacity: 0; }
.settings-panel:not([hidden]) { pointer-events: auto; }
.settings-card {
  width: 320px;
  max-width: 92vw;
  background: #0f131c;
  border-right: 1px solid var(--border);
  box-shadow: 12px 0 40px rgba(0,0,0,0.35);
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transform: translateX(-110%);
  transition: transform 0.2s ease, opacity 0.2s ease;
  pointer-events: auto;
}
.settings-panel:not([hidden]) .settings-card {
  transform: translateX(0);
}
.settings-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.settings-card h3 { margin: 0; }
.settings-card h4 { margin: 0; }
.settings-card p { margin: 0; color: var(--muted); }
.settings-card .icon-button {
  border-radius: 50%;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.05);
}
.color-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.35rem;
  margin-top: 0.5rem;
}
.color-chip {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--chip-color, rgba(255,255,255,0.1));
  cursor: pointer;
}
.color-chip[data-bubble-color="default"] {
  grid-column: span 2;
  border-radius: 0.7rem;
  width: 100%;
  height: 36px;
  border: 1px dashed var(--muted);
  color: var(--text);
  background: transparent;
}
.color-chip.active,
.color-chip:hover {
  border-color: var(--accent);
}

/* Auth screens */
body[data-page="login"], body[data-page="register"] {
  background: radial-gradient(circle at top, #1b2030, #0c0f16);
  display: grid;
  place-items: center;
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
}

.auth-card {
  width: min(420px, 92vw);
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.75rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.auth-card h1 { margin: 0 0 0.4rem; }
.auth-card p { color: var(--muted); line-height: 1.5; }
.auth-card form { display: flex; flex-direction: column; gap: 0.9rem; margin: 1rem 0; }
.auth-card label { display: flex; flex-direction: column; gap: 0.35rem; color: var(--muted); }
.auth-card input {
  padding: 0.75rem 0.9rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: #0f131c;
  color: var(--text);
}
.auth-card button {
  padding: 0.85rem 1rem;
  border-radius: 0.85rem;
  border: none;
  background: var(--accent);
  color: #06101f;
  font-weight: 700;
  cursor: pointer;
}
.auth-card .status { min-height: 1.2rem; color: var(--muted); }
.auth-card a { color: var(--accent); text-decoration: none; }
.auth-card a:hover { text-decoration: underline; }

.mobile-blocker {
  min-height: 100vh;
  background: radial-gradient(circle at top, #1b2030, #0c0f16);
  display: grid;
  place-items: center;
  color: var(--text);
  padding: 1rem;
}
.mobile-card {
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.4rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}
.mobile-card a.primary {
  display: inline-block;
  margin: 0.8rem 0;
  padding: 0.8rem 1.2rem;
  border-radius: 0.9rem;
  background: var(--accent);
  color: #06101f;
  font-weight: 700;
  text-decoration: none;
}
.mobile-card .small { font-size: 0.9rem; color: var(--muted); }

.muted { color: var(--muted); }
.list-empty { color: var(--muted); }

@media (max-width: 1040px) {
  .tg-root { grid-template-columns: 1fr; }
  .tg-sidebar { display: none; }
}
