/* =====================================================================
   Telegram Manager — "Nightwatch" console theme
   Layered steel-blue surfaces · mono data voice · amber attention lamps
   Signals: azure = interactive/selected, amber = unread, green = online
   ===================================================================== */

:root {
  /* surfaces */
  --bg:        #090D15;
  --bg-rail:   #070A11;
  --surface-1: #0E141F;
  --surface-2: #141C2B;
  --surface-3: #1A2436;
  --field:     #0A101B;

  /* lines */
  --border:        rgba(154, 176, 214, .12);
  --border-strong: rgba(154, 176, 214, .24);

  /* ink */
  --text:   #E8EDF6;
  --text-2: #93A0B8;
  --text-3: #5D6A82;

  /* signals */
  --accent:        #4E9CFF;
  --accent-strong: #77B4FF;
  --accent-soft:   rgba(78, 156, 255, .13);
  --amber:         #F2A33C;
  --amber-ink:     #201302;
  --green:         #35D68F;
  --danger:        #F16B6B;

  /* message bubbles */
  --bubble-in:         #131B2A;
  --bubble-out:        #17284A;
  --bubble-out-border: rgba(96, 150, 255, .30);

  /* type */
  --font-ui:      "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --font-mono:    "Cascadia Code", "Cascadia Mono", ui-monospace, "SF Mono", Consolas, "Roboto Mono", monospace;

  --radius: 12px;
  --shadow-1: 0 4px 16px rgba(0, 0, 0, .35);
  --shadow-2: 0 24px 64px rgba(0, 0, 0, .55);

  font-synthesis: none;
}

/* ================= BASE ================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }

::selection { background: rgba(78, 156, 255, .35); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(154, 176, 214, .16); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(154, 176, 214, .28); }
::-webkit-scrollbar-track { background: transparent; }

button { font-family: inherit; }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* mono micro-label — the console’s labeling voice */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-3);
}

/* ================= FORMS ================= */
input, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 11px 13px;
  width: 100%;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(78, 156, 255, .15);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  width: 100%;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .55; cursor: default; }

.btn-secondary {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  width: 100%;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-2);
  width: 34px;
  height: 34px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s, color .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

.form-error { color: var(--danger); font-size: 12.5px; min-height: 17px; margin-top: 10px; }
.hint { font-size: 12.5px; color: var(--text-3); line-height: 1.45; }
.hint span { color: var(--text); }

/* ================= SPINNER / EMPTY ================= */
.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid rgba(154, 176, 214, .18);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spin-anim { animation: spin .8s linear infinite; }

.panel-empty {
  padding: 36px 22px;
  text-align: center;
  color: var(--text-3);
  font-size: 13.5px;
  line-height: 1.5;
  margin: auto;
}

/* ================= LOGIN ================= */
.login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg);
  background-image:
    radial-gradient(rgba(154, 176, 214, .05) 1px, transparent 1.4px),
    radial-gradient(880px 460px at 50% -140px, rgba(78, 156, 255, .12), transparent 65%);
  background-size: 22px 22px, auto;
}
.login-card {
  width: 360px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 32px 26px;
  text-align: center;
  box-shadow: var(--shadow-2);
  animation: rise .45s cubic-bezier(.2, .7, .3, 1);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
.login-logo {
  width: 52px;
  height: 52px;
  margin: 0 auto 18px;
  border-radius: 15px;
  background: linear-gradient(145deg, #5FA8FF, #2E6FDB);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 28px rgba(78, 156, 255, .3);
}
.login-eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
}
.login-card h1 {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -.01em;
}
.login-sub { color: var(--text-2); font-size: 13.5px; margin: 8px 0 24px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-foot {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .06em;
  color: var(--text-3);
  margin-top: 18px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

/* ================= APP LAYOUT ================= */
.app { height: 100%; display: flex; }

/* --- Sidebar: the switchboard --- */
.sidebar {
  width: 264px;
  background: var(--bg-rail);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  transition: width .18s ease;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 10px 12px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: linear-gradient(145deg, #5FA8FF, #2E6FDB);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(78, 156, 255, .25);
}
.brand-name {
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -.01em;
}
.collapse-btn svg { transition: transform .18s ease; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 10px 10px;
}
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-strong); }
.nav-icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-badge {
  margin-left: auto;
  min-width: 19px;
  height: 17px;
  padding: 0 5px;
  border-radius: 6px;
  background: var(--amber);
  color: var(--amber-ink);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nav-item.logout:hover { background: rgba(241, 107, 107, .12); color: var(--danger); }

.sidebar-label { padding: 8px 20px 6px; border-top: 1px solid var(--border); }

.account-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.acct-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 11px;
  cursor: pointer;
  transition: background .15s;
}
.acct-item:hover { background: var(--surface-2); }
.acct-item.active {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(78, 156, 255, .35);
}
.acct-ava { position: relative; flex-shrink: 0; }
.acct-ava .avatar { width: 38px; height: 38px; font-size: 14px; border-radius: 12px; }
.acct-dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--bg-rail);
  background: var(--text-3);
  z-index: 2;
}
.acct-dot.on { background: var(--green); box-shadow: 0 0 6px rgba(53, 214, 143, .7); }
.acct-info { flex: 1; min-width: 0; }
.acct-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.acct-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .03em;
  color: var(--text-3);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.acct-item.active .acct-sub { color: var(--text-2); }
.acct-meta { display: flex; align-items: center; flex-shrink: 0; }
.acct-badge {
  min-width: 19px;
  height: 17px;
  padding: 0 5px;
  border-radius: 6px;
  background: var(--amber);
  color: var(--amber-ink);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.acct-gear {
  display: none;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.acct-gear:hover { background: var(--surface-3); color: var(--text); }
/* on hover the gear replaces the badge */
.acct-item:hover .acct-gear { display: flex; }
.acct-item:hover .acct-meta { display: none; }

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px;
  border-top: 1px solid var(--border);
}

/* --- collapsed sidebar: icon rail --- */
.sidebar.collapsed { width: 76px; }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .brand-name,
.sidebar.collapsed .sidebar-label .eyebrow,
.sidebar.collapsed .acct-info,
.sidebar.collapsed .acct-gear { display: none; }
.sidebar.collapsed .sidebar-head {
  flex-direction: column;
  gap: 6px;
  padding: 14px 0 8px;
}
.sidebar.collapsed .collapse-btn svg { transform: rotate(180deg); }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px 0; gap: 0; }
.sidebar.collapsed .nav-badge {
  position: absolute;
  top: 1px;
  right: 5px;
  margin: 0;
  border: 2px solid var(--bg-rail);
  box-sizing: content-box;
}
.sidebar.collapsed .sidebar-label { padding: 5px 18px; }
.sidebar.collapsed .acct-item { justify-content: center; padding: 6px 0; gap: 0; }
.sidebar.collapsed .acct-meta,
.sidebar.collapsed .acct-item:hover .acct-meta {
  display: flex;
  position: absolute;
  top: -1px;
  right: 8px;
  z-index: 3;
}
.sidebar.collapsed .acct-badge { border: 2px solid var(--bg-rail); box-sizing: content-box; }

/* --- Chat list panel --- */
.chatlist {
  width: 330px;
  background: var(--surface-1);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}
.chatlist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 10px 16px;
  min-height: 60px;
}
.chatlist-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.chatlist-actions .icon-btn.active {
  color: var(--accent-strong);
  background: var(--accent-soft);
}
.chatlist-title { display: flex; flex-direction: column; overflow: hidden; }
#active-account-name {
  font-family: var(--font-display);
  font-weight: 650;
  font-size: 15.5px;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-line {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-top: 3px;
}
.status-line.on { color: var(--green); }

.search-wrap { position: relative; padding: 0 12px 10px; }
.search-wrap .search-icon {
  position: absolute;
  left: 24px;
  top: 10px;
  color: var(--text-3);
  pointer-events: none;
}
.search-wrap input {
  background: var(--field);
  border-radius: 10px;
  padding: 8px 12px 8px 34px;
  font-size: 13.5px;
}

.dialog-list { flex: 1; overflow-y: auto; padding: 2px 0 12px; }

.dialog {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  margin: 1px 8px;
  border-radius: 11px;
  cursor: pointer;
  transition: background .12s;
  position: relative;
}
.dialog:hover { background: var(--surface-2); }
.dialog.active {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(78, 156, 255, .35);
}
.dialog .avatar { flex-shrink: 0; }
.dialog-main { flex: 1; min-width: 0; }
.dialog-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.dialog-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dialog-time {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-3);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.dialog-muted {
  display: inline-flex;
  align-items: center;
  color: var(--text-3);
  flex-shrink: 0;
  margin-left: 2px;
}
.dialog.active .dialog-muted { color: var(--text-2); }
.dialog.active .dialog-time { color: var(--text-2); }
.dialog-preview {
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.dialog.active .dialog-preview { color: var(--text-2); }
.dialog-badge {
  min-width: 19px;
  height: 17px;
  padding: 0 5px;
  border-radius: 6px;
  background: var(--amber);
  color: var(--amber-ink);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  flex-shrink: 0;
}
.dialog-acct { margin-top: 4px; }
.acct-chip {
  display: inline-block;
  max-width: 100%;
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .04em;
  color: #fff;
  padding: 1px 7px;
  border-radius: 5px;
  opacity: .85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dialog.active .acct-chip { opacity: 1; }

/* archived-chats entry + back nav */
#chatlist-back { flex-shrink: 0; }
.archived-icon {
  width: 40px;
  height: 40px;
  border-radius: 13px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-3);
  color: var(--text-2);
}
.archived-row:hover .archived-icon { color: var(--text); }
.dialog-badge.muted { background: var(--text-3); color: var(--bg); }

/* peek (press-and-hold preview) */
.peek {
  position: fixed;
  inset: 0;
  z-index: 130;
  background: rgba(4, 7, 13, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
  animation: peek-in .12s ease;
}
@keyframes peek-in { from { opacity: 0; } to { opacity: 1; } }
.peek-card {
  width: min(480px, 92vw);
  max-height: 68vh;
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.peek-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.peek-head .avatar { width: 38px; height: 38px; font-size: 14px; border-radius: 12px; }
.peek-title {
  font-family: var(--font-display);
  font-weight: 650;
  font-size: 14.5px;
  letter-spacing: -.01em;
}
.peek-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-top: 2px;
}
.peek-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(154, 176, 214, .045) 1px, transparent 1.4px);
  background-size: 22px 22px;
}

/* ================= AVATARS ================= */
.avatar {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
.avatar.sm { width: 40px; height: 40px; font-size: 14px; border-radius: 12px; }
.avatar > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* ================= CHAT AREA ================= */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(154, 176, 214, .045) 1px, transparent 1.4px);
  background-size: 22px 22px;
}
.chat-placeholder { flex: 1; display: flex; align-items: center; justify-content: center; }
.placeholder-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 340px;
  padding: 24px;
  text-align: center;
  color: var(--text-3);
}
.placeholder-card svg { margin-bottom: 8px; opacity: .7; }
.placeholder-title { font-size: 14.5px; font-weight: 600; color: var(--text-2); }
.placeholder-sub { font-size: 12.5px; line-height: 1.5; }

.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 18px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  min-height: 60px;
}
.chat-header .avatar { width: 40px; height: 40px; font-size: 15px; border-radius: 12px; }
.chat-header-info { flex: 1; min-width: 0; }
#chat-menu-btn { flex-shrink: 0; }
.chat-title {
  font-family: var(--font-display);
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-subtitle {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .05em;
  color: var(--text-3);
  margin-top: 2px;
}

/* --- Messages --- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px clamp(16px, 6%, 90px);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.msg {
  max-width: 66%;
  padding: 8px 12px 6px;
  border-radius: 12px;
  position: relative;
  font-size: 13.8px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg.in {
  align-self: flex-start;
  background: var(--bubble-in);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.out {
  align-self: flex-end;
  background: var(--bubble-out);
  border: 1px solid var(--bubble-out-border);
  border-bottom-right-radius: 4px;
}
.msg.consec-in  { border-top-left-radius: 6px; }
.msg.consec-out { border-top-right-radius: 6px; }
.msg.pending { opacity: .5; }
.msg-sender { font-size: 12.5px; font-weight: 600; color: var(--accent-strong); margin-bottom: 2px; }
.msg-meta {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .04em;
  color: rgba(232, 237, 246, .42);
  text-align: right;
  margin-top: 3px;
  user-select: none;
}
.msg-media-tag { color: var(--accent); font-style: italic; }
.msg-reply {
  border-left: 2px solid var(--accent);
  padding: 3px 8px;
  margin-bottom: 5px;
  font-size: 12px;
  color: var(--text-2);
  background: rgba(255, 255, 255, .045);
  border-radius: 4px;
}

/* hover action on every message bubble */
.msg-act {
  position: absolute;
  top: -11px;
  right: -8px;
  width: 25px;
  height: 25px;
  border-radius: 8px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  padding: 0;
}
.msg:hover .msg-act { display: flex; }
.msg-act:hover { color: var(--text); background: var(--surface-2); }

.date-sep {
  align-self: center;
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 12px;
  border-radius: 999px;
  margin: 12px 0 7px;
}
.load-older { text-align: center; padding: 12px; color: var(--text-3); }

/* --- Message media --- */
.msg-photo {
  display: block;
  max-width: min(320px, 60vw);
  max-height: 340px;
  border-radius: 9px;
  margin: 3px 0;
  cursor: pointer;
}
.msg-photo.sticker { max-width: 160px; max-height: 160px; border-radius: 6px; background: transparent; }
.msg-file { display: flex; align-items: center; gap: 10px; padding: 6px 2px; }
.msg-file-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(78, 156, 255, .3);
  color: var(--accent-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
}
.msg-file-meta { min-width: 0; }
.msg-file-name {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 230px;
}
.msg-file-name a { color: var(--text); text-decoration: none; }
.msg-file-name a:hover { color: var(--accent-strong); }
.msg-file-sub {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .03em;
  color: var(--text-2);
}
audio.msg-audio { display: block; height: 40px; max-width: 260px; margin: 2px 0; }

/* ================= COMPOSER ================= */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface-1);
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  background: var(--field);
  border-radius: 11px;
  padding: 9px 14px;
  resize: none;
  min-height: 40px;
  max-height: 148px;
  line-height: 1.45;
  overflow-y: auto;
}
.composer .composer-btn, .composer .send-btn { margin-bottom: 0; }
.send-btn.editing { background: var(--amber); color: var(--amber-ink); }
.send-btn.editing:hover { background: #F7B65C; }
.composer-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.composer-btn:hover { background: var(--surface-3); color: var(--accent-strong); }
.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: none;
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, transform .05s;
}
.send-btn:hover { background: var(--accent-strong); }
.send-btn:active { transform: scale(.94); }

.reply-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface-1);
  border-top: 1px solid var(--border);
}
.reply-bar { width: 3px; align-self: stretch; min-height: 30px; background: var(--accent); border-radius: 2px; }
.reply-bar.amber { background: var(--amber); }
.reply-banner-title.amber { color: var(--amber); }
.reply-banner-text { flex: 1; min-width: 0; }
.reply-banner-title {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent-strong);
}
.reply-banner-body {
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-pop {
  position: absolute;
  bottom: 74px;
  left: 14px;
  right: 14px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-2);
  z-index: 20;
}
.tpl-item { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.tpl-item:hover { background: var(--surface-3); }
.tpl-item-title { font-size: 13px; font-weight: 600; }
.tpl-item-body {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.tpl-manage {
  padding: 11px 14px;
  text-align: center;
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
}
.tpl-manage:hover { background: var(--surface-3); }

/* ================= MODALS ================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 13, .64);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(6px);
}
.modal {
  width: 400px;
  max-width: calc(100vw - 32px);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow-2);
  position: relative;
  animation: pop .18s cubic-bezier(.2, .7, .3, 1);
}
@keyframes pop {
  from { opacity: 0; transform: scale(.96) translateY(6px); }
  to   { opacity: 1; transform: none; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -.01em;
}
.modal-step { display: flex; flex-direction: column; gap: 12px; }
.modal-step label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-2);
}
#input-phone, #input-code { font-family: var(--font-mono); letter-spacing: .04em; }
#input-code { font-size: 17px; letter-spacing: .3em; }
.modal-loading {
  position: absolute;
  inset: 0;
  background: rgba(14, 20, 31, .72);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ================= CONTEXT MENU ================= */
.ctx-menu {
  position: fixed;
  z-index: 120;
  min-width: 176px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 5px;
  box-shadow: var(--shadow-2);
  animation: pop .12s cubic-bezier(.2, .7, .3, 1);
}
.ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}
.ctx-item:hover { background: var(--surface-3); }
.ctx-item svg { flex-shrink: 0; color: var(--text-2); }
.ctx-item.danger { color: var(--danger); }
.ctx-item.danger svg { color: var(--danger); }
.ctx-item.danger:hover { background: rgba(241, 107, 107, .12); }
.ctx-sep { height: 1px; background: var(--border); margin: 4px 6px; }
.ctx-item .ctx-chevron { margin-left: auto; color: var(--text-3); }
.ctx-item .ctx-note {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .04em;
  color: var(--text-3);
}
.ctx-header {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 10px 8px;
  margin-bottom: 3px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-3);
}
.ctx-back {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
}
.ctx-back:hover { color: var(--text); }

/* ================= CONFIRM MODAL ================= */
.modal-sm { width: 360px; }
.confirm-body {
  font-size: 13.5px;
  color: var(--text-2);
  line-height: 1.5;
  margin-bottom: 14px;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 16px;
  cursor: pointer;
  user-select: none;
}
.check-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.modal-actions { display: flex; gap: 10px; }
.modal-actions button { flex: 1; }
.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn-danger:hover { background: #F58585; }
.btn-danger:active { transform: translateY(1px); }
.btn-danger:disabled { opacity: .55; cursor: default; }

/* nested modals (confirm / crop) must sit above the account modal that opens them */
#confirm-modal, #crop-modal { z-index: 70; }

/* ================= PHOTO CROP MODAL ================= */
.crop-stage {
  position: relative;
  width: 100%;
  max-width: 280px;
  aspect-ratio: 1 / 1;
  margin: 4px auto 16px;
  border-radius: 12px;
  overflow: hidden;
  background: #05080e;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.crop-stage.dragging { cursor: grabbing; }
.crop-img {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none;
  pointer-events: none;
  -webkit-user-drag: none;
}
.crop-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 9999px rgba(5, 8, 14, .55);
  border: 2px solid rgba(255, 255, 255, .6);
  pointer-events: none;
}
.crop-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  color: var(--text-3);
}
.crop-controls input[type="range"] {
  flex: 1;
  width: auto;
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
  background: transparent;
  border: none;
}
.crop-controls input[type="range"]:focus { box-shadow: none; }

/* ================= ACCOUNT SETTINGS MODAL ================= */
.modal-wide {
  width: 448px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}
.profile-top {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}
.profile-ava-wrap { position: relative; flex-shrink: 0; }
.avatar.xl { width: 72px; height: 72px; border-radius: 20px; font-size: 25px; }
.ava-edit {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  border: 2px solid var(--surface-1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  z-index: 2;
}
.ava-edit:hover { background: var(--accent-strong); }
.profile-id { min-width: 0; }
.profile-name {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-phone {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: .05em;
  color: var(--text-2);
  margin-top: 3px;
}
.link-btn {
  background: none;
  border: none;
  padding: 0;
  margin-top: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--danger);
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-2);
}
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field textarea { resize: none; }
.field-hint {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .03em;
  color: var(--text-3);
  min-height: 14px;
}
.field-hint.ok { color: var(--green); }
.field-hint.bad { color: var(--danger); }
.username-wrap { position: relative; }
.at-sign {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-3);
  pointer-events: none;
}
#pf-username { padding-left: 30px; font-family: var(--font-mono); letter-spacing: .03em; }

.danger-zone {
  margin-top: 18px;
  border: 1px solid rgba(241, 107, 107, .28);
  border-radius: 12px;
  padding: 14px;
}
.danger-title { color: var(--danger); margin-bottom: 10px; }
.danger-row { display: flex; gap: 10px; margin-bottom: 10px; }
.btn-danger-outline {
  flex: 1;
  background: transparent;
  border: 1px solid rgba(241, 107, 107, .4);
  color: var(--danger);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-danger-outline:hover { background: rgba(241, 107, 107, .12); }

/* ================= TOASTS ================= */
.toast-container {
  position: fixed;
  bottom: 22px;
  right: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
}
.toast {
  background: var(--surface-2);
  color: var(--text);
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  box-shadow: var(--shadow-1);
  font-size: 13.5px;
  max-width: 320px;
  animation: toast-in .25s ease;
  transition: opacity .3s;
}
.toast.err { border-left-color: var(--danger); }
.toast-title { font-weight: 600; margin-bottom: 2px; }
.toast-body { color: var(--text-2); font-size: 12.5px; }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ================= DASHBOARD ================= */
.dashboard {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(154, 176, 214, .035) 1px, transparent 1.4px);
  background-size: 22px 22px;
  overflow-y: auto;
}
.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* keep the title aligned with the centered 1080px body below */
  padding: 20px max(32px, calc((100% - 1016px) / 2)) 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.dash-header h1 {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -.015em;
  margin-top: 3px;
}
.dash-body {
  padding: 24px 32px 36px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
}
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}
.stat-row .panel-empty { grid-column: 1 / -1; }
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px 16px;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 31px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.stat-value.accent { color: var(--amber); }
.stat-value.good { color: var(--green); }
.stat-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-top: 9px;
}
.dash-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
.dash-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
}
.dash-card-title {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 16px;
}

.chart { display: flex; flex-direction: column; gap: 12px; }
.chart-row {
  display: grid;
  grid-template-columns: minmax(80px, 140px) 1fr 44px;
  align-items: center;
  gap: 12px;
}
.chart-label {
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart-track { height: 8px; background: var(--field); border-radius: 4px; overflow: hidden; }
.chart-bar {
  height: 100%;
  background: linear-gradient(90deg, #C77E24, var(--amber));
  border-radius: 4px;
  min-width: 3px;
  transition: width .5s ease;
}
.chart-val {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.account-table { display: flex; flex-direction: column; }
.acct-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 14px;
  align-items: center;
  padding: 10px 8px;
  border-radius: 9px;
}
.acct-row:not(:last-child) { border-bottom: 1px solid var(--border); }
.acct-row:hover { background: var(--surface-2); cursor: pointer; }
.acct-row-name { font-size: 13.5px; font-weight: 500; }
.acct-status {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-3);
}
.acct-status .sdot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }
.acct-status .sdot.on { background: var(--green); box-shadow: 0 0 6px rgba(53, 214, 143, .6); }
.acct-unread {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-2);
  min-width: 68px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ================= TEMPLATE MODAL ================= */
.template-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 16px;
}
.template-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 9px;
}
.template-row-main { flex: 1; min-width: 0; }
.template-row-title { font-size: 13px; font-weight: 600; }
.template-row-body {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.template-form { display: flex; flex-direction: column; gap: 10px; }
.template-form textarea { resize: vertical; }

/* ================= RESPONSIVE ================= */
@media (max-width: 1180px) {
  .chatlist { width: 300px; }
  .messages { padding: 20px 4%; }
  .msg { max-width: 76%; }
}
@media (max-width: 960px) {
  .chatlist { width: 264px; }
  .dash-cols { grid-template-columns: 1fr; }
  .dash-header, .dash-body { padding-left: 20px; padding-right: 20px; }
}

/* ================= MOTION PREFERENCES ================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  /* keep functional loading indicators alive */
  .spinner, .spin-anim {
    animation-duration: .8s !important;
    animation-iteration-count: infinite !important;
  }
}
