/* ===== noclipSPY — Apple / iOS design language ===== */
:root {
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --label: #1C1C1E;
  --sec: rgba(60,60,67,0.6);
  --ter: rgba(60,60,67,0.3);
  --sep: rgba(60,60,67,0.14);
  --blue: #007AFF;
  --red: #FF3B30;
  --green: #34C759;
  --amber: #FF9500;
  --in-bubble: #E9E9EB;
  --nav-bg: rgba(249,249,249,0.92);
  --chip-bg: rgba(120,120,128,0.12);
  --tint-red: rgba(255,59,48,0.10);
  --tint-amber: rgba(255,149,0,0.11);
  --shadow: 0 1px 3px rgba(0,0,0,0.05);
}
:root[data-theme="dark"] {
  --bg: #000000;
  --card: #1C1C1E;
  --label: #FFFFFF;
  --sec: rgba(235,235,245,0.6);
  --ter: rgba(235,235,245,0.3);
  --sep: rgba(84,84,88,0.5);
  --blue: #0A84FF;
  --red: #FF453A;
  --green: #30D158;
  --amber: #FF9F0A;
  --in-bubble: #262629;
  --nav-bg: rgba(20,20,22,0.86);
  --chip-bg: rgba(120,120,128,0.24);
  --tint-red: rgba(255,69,58,0.16);
  --tint-amber: rgba(255,159,10,0.16);
  --shadow: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--label);
  font-family: -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.view { display: flex; flex-direction: column; min-height: 100vh; }
.view[hidden] { display: none; }

.large-title {
  font-family: -apple-system, "SF Pro Display", system-ui, sans-serif;
  font-size: 34px; font-weight: 700; letter-spacing: -0.5px;
  margin: 0; padding: 4px 20px 8px;
}

/* ---------- chat-list header ---------- */
.app-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 10px 20px 2px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.app-title {
  font-family: -apple-system, "SF Pro Display", system-ui, sans-serif;
  font-size: 34px; font-weight: 700; letter-spacing: -0.5px; line-height: 1;
}
.header-action {
  width: 38px; height: 38px; border: none; border-radius: 50%;
  background: var(--chip-bg); color: var(--sec);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0; flex-shrink: 0;
}
.header-action svg { width: 21px; height: 21px; opacity: 0.85; }
.header-action:active { opacity: 0.6; }

.header-actions { display: flex; align-items: center; gap: 6px; }

/* search */
.search-wrap { padding: 6px 16px 6px; }
.search-box {
  display: flex; align-items: center; gap: 7px;
  background: var(--chip-bg); border-radius: 10px; padding: 8px 10px; color: var(--sec);
}
.search-box svg { width: 17px; height: 17px; flex-shrink: 0; }
.search-box input {
  flex: 1; min-width: 0; border: none; background: none; outline: none;
  font-size: 17px; color: var(--label); font-family: inherit; letter-spacing: -0.3px;
}
.search-box input::placeholder { color: var(--sec); }
.search-box input::-webkit-search-cancel-button { -webkit-appearance: none; }

.enc-status {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 20px 12px; color: var(--sec); font-size: 13px; letter-spacing: -0.1px;
}
.enc-status svg { width: 13px; height: 13px; color: var(--green); }

/* ---------- chat list (inset grouped card) ---------- */
.chat-list {
  margin: 0 16px 24px; background: var(--card);
  border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
}
.chat-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px 9px 14px; cursor: pointer;
}
.chat-item:active { background: rgba(120,120,128,0.10); }
.chat-item:not(:last-child)::after {
  content: ""; position: absolute; left: 78px; right: 0; bottom: 0;
  height: 1px; background: var(--sep);
}
.chat-body { flex: 1; min-width: 0; }
.chat-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chat-name { font-size: 17px; font-weight: 600; letter-spacing: -0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: 15px; color: var(--ter); flex-shrink: 0; letter-spacing: -0.2px; }
.chat-bottom { display: flex; align-items: center; gap: 6px; margin-top: 1px; }
.chat-preview { flex: 1; font-size: 15px; color: var(--sec); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-preview.deleted { color: var(--red); }
.pill {
  display: inline-flex; align-items: center; gap: 3px; flex-shrink: 0;
  font-size: 12px; font-weight: 600; line-height: 1.5;
  padding: 1px 8px 1px 6px; border-radius: 20px;
  background: var(--tint-red); color: var(--red);
}
.pill svg { width: 11px; height: 11px; }

/* ---------- avatars ---------- */
.avatar {
  flex-shrink: 0; width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 20px; letter-spacing: 0.2px;
  text-transform: uppercase; user-select: none;
}
.avatar-sm { width: 34px; height: 34px; font-size: 14px; }
.avatar-msg { display: none; }

/* refined Apple-ish gradient palette */
.tg-c0 { background: linear-gradient(145deg,#FF8FB1,#FF5C8A); }
.tg-c1 { background: linear-gradient(145deg,#FFB65C,#FF9330); }
.tg-c2 { background: linear-gradient(145deg,#A98BFF,#7A5CFF); }
.tg-c3 { background: linear-gradient(145deg,#64D2C4,#22B3A0); }
.tg-c4 { background: linear-gradient(145deg,#4F8CFF,#2E6BFF); }
.tg-c5 { background: linear-gradient(145deg,#6E7BFF,#4E5BE0); }
.tg-c6 { background: linear-gradient(145deg,#FF9EC4,#E85C9A); }

.empty { color: var(--sec); text-align: center; margin-top: 64px; padding: 0 32px; font-size: 15px; }

/* ---------- nav header (thread + settings) ---------- */
.thread-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px 8px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--nav-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--sep);
}
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--blue);
  cursor: pointer; padding: 4px; border-radius: 50%; flex-shrink: 0;
}
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:active { opacity: 0.5; }
.thread-title-wrap { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; flex: 1; }
.thread-title { font-size: 16px; font-weight: 600; letter-spacing: -0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-sub { font-size: 12px; color: var(--sec); }

/* ---------- filter chips ---------- */
.filter-bar {
  flex-shrink: 0;
  display: flex; gap: 8px; padding: 10px 16px;
  background: var(--bg); border-bottom: 1px solid var(--sep);
  overflow-x: auto; scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 14px; border: none; border-radius: 20px;
  background: var(--chip-bg); color: var(--sec);
  font-size: 14px; font-weight: 600; letter-spacing: -0.2px; cursor: pointer;
  font-family: inherit; transition: background .15s, color .15s;
}
.filter-chip svg { width: 13px; height: 13px; }
.filter-chip.active { background: var(--blue); color: #fff; }

/* ---------- thread / messages ---------- */
#thread-view { height: 100vh; }
.thread-header { flex-shrink: 0; }
.thread-messages {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 3px;
  padding: 14px 14px 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}
.msg-row { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; }
.msg-row.out { justify-content: flex-end; }

.bubble {
  max-width: 78%; padding: 8px 13px; border-radius: 20px;
  font-size: 16px; line-height: 1.32; letter-spacing: -0.2px;
  background: var(--in-bubble); color: var(--label);
  border-bottom-left-radius: 7px;
}
.msg-row.out .bubble {
  background: var(--blue); color: #fff;
  border-bottom-left-radius: 20px; border-bottom-right-radius: 7px;
}
.bubble.deleted {
  background: var(--tint-red);
  border: 1px solid rgba(255,59,48,0.22);
}
.msg-row.out .bubble.deleted { background: var(--tint-red); color: var(--label); }

.bubble .sender { font-size: 13px; font-weight: 600; color: var(--blue); margin-bottom: 1px; }
.bubble .body { white-space: pre-wrap; word-break: break-word; }
.bubble .footer {
  display: flex; align-items: center; gap: 5px; justify-content: flex-end;
  font-size: 11px; color: var(--ter); margin-top: 3px;
}
.msg-row.out .bubble .footer { color: rgba(255,255,255,0.7); }
.bubble .footer .ico { width: 11px; height: 11px; }
.footer .edited-mark { color: var(--amber); display: inline-flex; align-items: center; gap: 2px; }
.footer .deleted-mark { color: var(--red); display: inline-flex; align-items: center; gap: 2px; }

/* change boxes: было→стало and deleted marker */
.change-box {
  margin-top: 5px; padding: 8px 11px; border-radius: 13px;
  font-size: 13px; line-height: 1.4;
}
.change-box.edit { background: var(--tint-amber); border: 1px solid rgba(255,149,0,0.22); }
.change-box.del { background: transparent; padding: 0; margin-top: 0; }
.change-box .change-title {
  display: flex; align-items: center; gap: 5px; font-weight: 600; margin-bottom: 4px;
}
.change-box.edit .change-title { color: var(--amber); }
.change-box.del .change-title { color: var(--red); margin-bottom: 4px; }
.change-box .ico { width: 12px; height: 12px; }
.diff-line { margin-top: 2px; }
.diff-old { color: var(--red); text-decoration: line-through; opacity: 0.75; }
.diff-new { color: var(--green); }
.diff-arrow { color: var(--ter); margin: 0 5px; }

/* ---------- media ---------- */
.media-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px; margin-bottom: 3px; border-radius: 9px;
  background: rgba(120,120,128,0.14); font-size: 13px; color: var(--sec);
}
.media-link { display: block; }
.media-img { display: block; max-width: 100%; max-height: 340px; border-radius: 14px; margin-bottom: 3px; }
.media-round { display: block; width: 200px; height: 200px; max-width: 70vw; border-radius: 50%; object-fit: cover; margin-bottom: 3px; background: #000; }
.media-sticker { display: block; width: 140px; height: 140px; object-fit: contain; margin-bottom: 3px; }
.media-audio { display: block; width: 240px; max-width: 100%; height: 40px; margin: 2px 0 3px; }
.media-doc {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 13px; margin-bottom: 3px;
  border-radius: 12px; background: rgba(120,120,128,0.14); color: var(--blue);
  text-decoration: none; font-size: 14px; word-break: break-all;
}
.enc-media {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 140px; min-height: 96px; margin-bottom: 3px;
  border-radius: 14px; background: rgba(120,120,128,0.12);
  color: var(--sec); font-size: 13px;
}

/* ---------- settings ---------- */
.settings-list { padding: 4px 0 32px; }
.grp {
  margin: 0 16px; background: var(--card);
  border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
}
.grp-hdr {
  color: var(--sec); font-size: 13px; text-transform: uppercase;
  letter-spacing: 0.4px; padding: 24px 20px 6px;
}
.grp-foot { color: var(--sec); font-size: 13px; line-height: 1.35; padding: 7px 20px 0; letter-spacing: -0.1px; }
.setting-row {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; min-height: 48px; cursor: pointer;
}
.setting-row:not(:last-child)::after {
  content: ""; position: absolute; left: 57px; right: 0; bottom: 0;
  height: 1px; background: var(--sep);
}
.ico {
  width: 29px; height: 29px; border-radius: 7px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.ico svg { width: 17px; height: 17px; }
.ico-red { background: linear-gradient(145deg,#FF5C5C,#FF3B30); }
.ico-blue { background: linear-gradient(145deg,#4F8CFF,#007AFF); }
.ico-amber { background: linear-gradient(145deg,#FFB338,#FF9500); }
.ico-green { background: linear-gradient(145deg,#34C759,#28A745); }
.setting-name { flex: 1; font-size: 17px; letter-spacing: -0.3px; }
.setting-text { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.setting-desc { font-size: 13px; color: var(--sec); }
.val-on { display: inline-flex; align-items: center; gap: 5px; color: var(--green); font-size: 16px; font-weight: 500; letter-spacing: -0.2px; }
.val-on svg { width: 15px; height: 15px; }
.setting-group.disabled { opacity: 0.4; pointer-events: none; }
.settings-note { padding: 14px 20px 0; font-size: 13px; color: var(--sec); }
.settings-status { padding: 8px 20px 0; font-size: 13px; color: var(--green); min-height: 20px; }

/* ---------- admin panel ---------- */
.admin-body { flex: 1; overflow-y: auto; padding: 8px 0 40px; }
.stat-hero {
  margin: 12px 16px 0; background: var(--card); border-radius: 16px;
  padding: 22px 20px; box-shadow: var(--shadow); text-align: center;
}
.stat-hero .num {
  font-family: -apple-system, "SF Pro Display", system-ui, sans-serif;
  font-size: 46px; font-weight: 700; letter-spacing: -1.2px; line-height: 1; color: var(--blue);
}
.stat-hero .lbl { color: var(--sec); font-size: 14px; margin-top: 6px; letter-spacing: -0.2px; }
.stat-hero .sub { color: var(--green); font-size: 13px; margin-top: 8px; font-weight: 500; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 16px 0; }
.stat-card { background: var(--card); border-radius: 14px; padding: 15px 16px; box-shadow: var(--shadow); }
.stat-card .num {
  font-family: -apple-system, "SF Pro Display", system-ui, sans-serif;
  font-size: 27px; font-weight: 700; letter-spacing: -0.6px; line-height: 1;
}
.stat-card .num.red { color: var(--red); }
.stat-card .num.amber { color: var(--amber); }
.stat-card .num.green { color: var(--green); }
.stat-card .lbl { color: var(--sec); font-size: 13px; margin-top: 6px; letter-spacing: -0.1px; }

.admin-refresh {
  margin: 20px 16px 0; padding: 12px; width: calc(100% - 32px);
  border: none; border-radius: 12px; background: var(--chip-bg); color: var(--blue);
  font-size: 16px; font-weight: 500; font-family: inherit; cursor: pointer; letter-spacing: -0.2px;
}
.admin-refresh:active { opacity: 0.6; }

/* ---------- lock screen ---------- */
.lock-screen {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg); color: var(--label);
  display: flex; align-items: center; justify-content: center;
}
.lock-inner { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 24px; }
.lock-inner > svg { color: var(--blue); margin-bottom: 18px; }
.lock-title { font-family: -apple-system,"SF Pro Display",system-ui,sans-serif; font-size: 22px; font-weight: 700; letter-spacing: -0.4px; }
.lock-sub { color: var(--sec); font-size: 15px; margin-top: 6px; }
.lock-btn {
  margin-top: 24px; padding: 13px 28px; border: none; border-radius: 12px;
  background: var(--blue); color: #fff; font-size: 17px; font-weight: 600;
  font-family: inherit; cursor: pointer; letter-spacing: -0.2px;
}
.lock-btn:active { opacity: 0.7; }

/* iOS switch */
.switch { position: relative; display: inline-block; width: 51px; height: 31px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: rgba(120,120,128,0.24); border-radius: 16px; transition: background .2s; }
.slider::before {
  content: ""; position: absolute; height: 27px; width: 27px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.18); transition: transform .2s;
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(20px); }
