/* Дашборд @ananauz_bot — чистый mobile-first UI. Тему задаёт app.js из Telegram.themeParams
   (переменные --tg-*); ниже — фолбэки для светлой и тёмной темы, если мини-апп открыт не из Telegram. */

:root {
  --bg: #f1f3f6;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --text: #0f1419;
  --muted: #7a8793;
  --accent: #2f8fed;
  --accent-contrast: #ffffff;
  --border: rgba(0, 0, 0, .08);
  --danger: #e0485b;
  --ins-bg: rgba(46, 160, 67, .22);
  --ins-fg: #1a7f37;
  --del-bg: rgba(224, 72, 91, .18);
  --del-fg: #c53b4d;
  --mark-bg: #ffe08a;
  --mark-fg: #5a4600;
  --bubble-in: #ffffff;
  --bubble-out: #d7ecff;
  --online: #35c759;
  --offline: #9aa6b2;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1621;
    --surface: #17212b;
    --surface-2: #1b2735;
    --text: #e9eef3;
    --muted: #8595a3;
    --accent: #5aa6f0;
    --border: rgba(255, 255, 255, .08);
    --bubble-in: #1b2735;
    --bubble-out: #2b5278;
    --ins-fg: #6fd48a;
    --del-fg: #ff8ea0;
    --mark-bg: #7a5c00;
    --mark-fg: #ffe9a8;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1621;
  --surface: #17212b;
  --surface-2: #1b2735;
  --text: #e9eef3;
  --muted: #8595a3;
  --accent: #5aa6f0;
  --border: rgba(255, 255, 255, .08);
  --bubble-in: #1b2735;
  --bubble-out: #2b5278;
  --ins-fg: #6fd48a;
  --del-fg: #ff8ea0;
  --mark-bg: #7a5c00;
  --mark-fg: #ffe9a8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
}

#view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}

.state {
  color: var(--muted);
  text-align: center;
  padding: 48px 24px;
  font-size: 15px;
}

.state.error { color: var(--danger); }

/* ── шапки ── */
.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.bar h1 { font-size: 17px; margin: 0; font-weight: 600; }
.bar .sub { color: var(--muted); font-size: 12px; }

.back {
  appearance: none;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px 0 0;
}

.bar .title { min-width: 0; }
.bar .title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── поиск ── */
.search {
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 4;
}
.search input {
  width: 100%;
  border: 0;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
}
.search input::placeholder { color: var(--muted); }

.found { color: var(--muted); font-size: 12px; padding: 8px 16px 0; }

/* ── список чатов ── */
.chats { list-style: none; margin: 0; padding: 0; }
.chats li { border-bottom: 1px solid var(--border); }

.chat {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.chat:active { background: var(--surface-2); }

.avatar {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 16px;
}
.avatar.c0 { background: #e17076; }
.avatar.c1 { background: #eda86c; }
.avatar.c2 { background: #a695e7; }
.avatar.c3 { background: #7bc862; }
.avatar.c4 { background: #6ec9cb; }
.avatar.c5 { background: #65aadd; }
.avatar.c6 { background: #ee7aae; }

.chat-body { flex: 1; min-width: 0; }
.chat-body .row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  justify-content: space-between;
}
.chat .name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat .nick { color: var(--muted); font-weight: 400; font-size: 13px; }
.chat time { color: var(--muted); font-size: 12px; flex: none; }
.chat .preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.badge {
  flex: none;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 11px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 12px;
  font-weight: 600;
  display: grid;
  place-items: center;
}

mark { background: var(--mark-bg); color: var(--mark-fg); border-radius: 3px; padding: 0 1px; }

/* ── лента сообщений ── */
.messages { padding: 12px 10px 16px; display: flex; flex-direction: column; gap: 6px; }

.day { text-align: center; margin: 10px 0 6px; }
.day span {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  padding: 3px 12px;
  border-radius: 12px;
}

.msg {
  max-width: 85%;
  padding: 8px 11px;
  border-radius: 14px;
  background: var(--bubble-in);
  box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.in { align-self: flex-start; border-bottom-left-radius: 5px; }
.msg.out { align-self: flex-end; background: var(--bubble-out); border-bottom-right-radius: 5px; }
.msg.deleted { opacity: .72; outline: 1px dashed var(--del-fg); }
.msg.unknown { font-style: italic; }
.msg.target { animation: flash 1.6s ease; }
@keyframes flash {
  0%, 40% { box-shadow: 0 0 0 2px var(--accent); }
  100% { box-shadow: 0 1px 1px rgba(0, 0, 0, .05); }
}

.msg .text { white-space: pre-wrap; }
.msg .media {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 13px;
  margin-bottom: 4px;
}
.msg .media::before { content: "📎"; }

.meta {
  margin-top: 4px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
}
.deleted-mark { color: var(--del-fg); font-weight: 600; }

/* версии / diff */
.ver { border-left: 2px solid var(--border); padding: 2px 0 2px 9px; margin: 4px 0; }
.ver + .ver { margin-top: 6px; }
.ver-head { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.ver.lost { font-size: 12px; color: var(--muted); font-style: italic; border-color: var(--del-fg); }
ins { background: var(--ins-bg); color: var(--ins-fg); text-decoration: none; border-radius: 3px; }
del { background: var(--del-bg); color: var(--del-fg); border-radius: 3px; }

details.history { margin-top: 5px; }
details.history summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--accent);
  list-style: none;
}
details.history summary::-webkit-details-marker { display: none; }
details.history[open] summary { margin-bottom: 4px; }

.more {
  align-self: center;
  margin: 8px auto;
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  border-radius: 14px;
  padding: 7px 16px;
  font-size: 13px;
  cursor: pointer;
}

/* ── онлайн ── */
.online-wrap { padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.ucard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
}
.ucard .uhead { display: flex; align-items: center; gap: 10px; }
.ucard .uname { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ucard .unick { color: var(--muted); font-size: 13px; font-weight: 400; }
.pill {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  border-radius: 10px;
  padding: 3px 9px;
}
.pill.online { background: rgba(53, 199, 89, .16); color: var(--online); }
.pill.offline { background: var(--surface-2); color: var(--muted); }
.pill.unknown { background: var(--surface-2); color: var(--muted); }

.lastseen {
  margin: 10px 0 2px;
  font-size: 14px;
  color: var(--muted);
}
.lastseen b { color: var(--text); font-weight: 600; }
.lastseen.online b { color: var(--online); }

.today-total { font-size: 13px; color: var(--muted); margin: 10px 0 6px; }
.today-total b { color: var(--text); }
.sessions { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--surface-2);
  border-radius: 9px;
  padding: 4px 9px;
  font-size: 12px;
  white-space: nowrap;
}
.chip .dot { color: var(--online); }

.week { margin-top: 10px; }
.week summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--accent);
  list-style: none;
}
.week summary::-webkit-details-marker { display: none; }
.wday {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}
.wday:last-child { border-bottom: 0; }
.wday .wlabel { color: var(--muted); }
.wday .wval { text-align: right; }
.wday .wval small { color: var(--muted); display: block; font-size: 11px; }
.week-total { margin-top: 8px; font-size: 13px; }
.week-total b { color: var(--accent); }

/* ── нижние табы ── */
.tabbar {
  flex: none;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  padding: 7px 0 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font: inherit;
}
.tab-ic { font-size: 20px; filter: grayscale(1) opacity(.7); }
.tab-tx { font-size: 11px; }
.tab.on { color: var(--accent); }
.tab.on .tab-ic { filter: none; }
