*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #17212b;
  --nav-bg:     #0a1119;
  --sidebar:    #0e1621;
  --bubble-out: #2b5278;
  --bubble-in:  #182533;
  --text:       #d1d5db;
  --muted:      #6b7d8d;
  --accent:     #5288c1;
  --unread:     #4ea8de;
  --border:     #1f2f3f;
  --input-bg:   #232e3c;
  --danger:     #e06c75;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

/* ── Auth screen ── */
#auth-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 200;
}
#auth-box {
  background: var(--sidebar); padding: 2rem 2rem 1.5rem;
  border-radius: 14px; width: 340px;
  display: flex; flex-direction: column; gap: .85rem;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
.auth-logo { font-size: 2.5rem; text-align: center; }
#auth-box h2 { color: var(--accent); text-align: center; font-size: 1.2rem; margin-bottom: .25rem; }
#auth-tabs { display: flex; gap: 2px; background: var(--input-bg); border-radius: 8px; padding: 3px; }
.tab-btn {
  flex: 1; padding: .45rem; border: none; border-radius: 6px;
  background: none; color: var(--muted); font-size: 13px; cursor: pointer;
}
.tab-btn.active { background: var(--accent); color: #fff; }
#auth-box input {
  width: 100%; padding: .6rem .85rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--input-bg);
  color: var(--text); font-size: 14px;
}
#auth-box input:focus { outline: none; border-color: var(--accent); }
#auth-box button {
  width: 100%; padding: .65rem; border-radius: 8px; border: none;
  background: var(--accent); color: #fff; font-size: 14px; cursor: pointer;
}
#auth-box button:hover:not(:disabled) { filter: brightness(1.1); }
#auth-box button:disabled { opacity: .55; cursor: default; }
.error { color: var(--danger); font-size: 13px; text-align: center; }

/* ── Add TG account overlay ── */
#add-tg-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10,17,25,.85); z-index: 150; backdrop-filter: blur(4px);
}
#add-tg-box {
  background: var(--sidebar); padding: 2rem; border-radius: 14px;
  width: 360px; display: flex; flex-direction: column; gap: .85rem;
  box-shadow: 0 8px 40px rgba(0,0,0,.7);
}
#add-tg-box h2 { color: var(--accent); text-align: center; font-size: 1.1rem; }
#add-tg-box input {
  width: 100%; padding: .6rem .85rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--input-bg);
  color: var(--text); font-size: 14px;
}
#add-tg-box input:focus { outline: none; border-color: var(--accent); }
#add-tg-box button {
  width: 100%; padding: .65rem; border-radius: 8px; border: none;
  background: var(--accent); color: #fff; font-size: 14px; cursor: pointer;
}
#add-tg-box button:hover:not(:disabled) { filter: brightness(1.1); }
#add-tg-box button:disabled { opacity: .55; cursor: default; }
.btn-secondary { background: var(--input-bg) !important; color: var(--muted) !important; border: 1px solid var(--border) !important; }
.btn-secondary:hover:not(:disabled) { filter: none !important; background: var(--border) !important; color: var(--text) !important; }
.step-hint { color: var(--muted); font-size: 12px; text-align: center; }
.step-hint a { color: var(--accent); }

/* ── App layout ── */
#app { display: flex; height: 100vh; }

/* ── Nav bar (60px) ── */
#nav-bar {
  width: 60px; min-width: 60px;
  background: var(--nav-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 0; gap: 4px;
}
.nav-btn {
  width: 44px; height: 44px; border-radius: 12px; border: none;
  background: none; color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn:hover { background: var(--input-bg); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; }
.nav-btn.nav-logout:hover { background: rgba(224,108,117,.15); color: var(--danger); }
.nav-spacer { flex: 1; }

/* ── Section panel (340px) ── */
#section-panel {
  width: 340px; min-width: 340px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.panel-section { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.panel-header {
  padding: .7rem .85rem; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: .5rem; flex-shrink: 0;
}
.panel-title { font-weight: 600; font-size: 15px; color: var(--text); }
.tg-name { font-weight: 600; color: var(--accent); font-size: 15px; }
#search-input {
  padding: .4rem .75rem; border-radius: 20px;
  border: 1px solid var(--border); background: var(--input-bg);
  color: var(--text); font-size: 13px; width: 100%;
}
#search-input:focus { outline: none; border-color: var(--accent); }
.panel-action-btn {
  margin: .75rem; padding: .65rem; border-radius: 8px; border: none;
  background: var(--accent); color: #fff; font-size: 14px; cursor: pointer;
  flex-shrink: 0;
}
.panel-action-btn:hover { filter: brightness(1.1); }
.panel-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; color: var(--muted); padding: 2rem; text-align: center; }
.empty-icon { font-size: 3rem; }

/* ── Chat list ── */
#chat-list { overflow-y: auto; flex: 1; }
.chat-item { display: flex; align-items: center; gap: .75rem; padding: .65rem .85rem; cursor: pointer; border-bottom: 1px solid var(--border); transition: background .1s; }
.chat-item:hover, .chat-item.active { background: var(--bg); }
.avatar { border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar-fallback { border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; color: #fff; }
.chat-meta { flex: 1; overflow: hidden; }
.chat-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-last { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.unread-badge { background: var(--unread); color: #fff; border-radius: 50%; min-width: 18px; height: 18px; font-size: 11px; display: flex; align-items: center; justify-content: center; padding: 0 4px; flex-shrink: 0; }

/* ── Accounts section ── */
.account-item { display: flex; align-items: center; gap: .75rem; padding: .7rem .85rem; cursor: pointer; border-bottom: 1px solid var(--border); transition: background .1s; }
.account-item:hover { background: var(--bg); }
.account-item.active { background: var(--bg); cursor: default; }
.account-info { flex: 1; overflow: hidden; }
.account-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-phone { color: var(--muted); font-size: 12px; margin-top: 1px; }
.account-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.account-check { color: var(--accent); font-size: 16px; }
.account-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 3px 6px; border-radius: 4px; }
.account-del:hover { color: var(--danger); background: rgba(224,108,117,.12); }

/* ── Main chat area ── */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; position: relative; }
#chat-header { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border); background: var(--sidebar); flex-shrink: 0; cursor: pointer; }
#chat-header:hover { background: var(--bg); }
#chat-info { flex: 1; min-width: 0; }
#chat-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-status { color: var(--muted); font-size: 12px; min-height: 16px; }

/* ── Messages ── */
#messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .4rem; }
.bubble-wrap { display: flex; }
.bubble-wrap.out { justify-content: flex-end; }
.bubble-wrap.in  { justify-content: flex-start; }
.bubble { max-width: 68%; padding: .5rem .75rem; border-radius: 12px; font-size: 14px; line-height: 1.45; word-break: break-word; }
.bubble.out { background: var(--bubble-out); border-bottom-right-radius: 3px; }
.bubble.in  { background: var(--bubble-in);  border-bottom-left-radius: 3px; }
.bubble .sender { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.bubble .text { white-space: pre-wrap; }
.bubble .meta { display: flex; justify-content: flex-end; align-items: center; gap: 4px; margin-top: 4px; font-size: 11px; color: var(--muted); }
.bubble .ticks { color: var(--muted); }
.bubble .ticks.read { color: var(--accent); }
/* media */
.bubble img.media { max-width: 100%; max-height: 320px; border-radius: 8px; margin-top: 6px; display: block; cursor: pointer; }
.bubble video.media { max-width: 100%; max-height: 320px; border-radius: 8px; margin-top: 6px; display: block; }
.bubble audio.media { margin-top: 6px; width: 100%; }
.bubble img.sticker { width: 150px; height: 150px; object-fit: contain; }
.sticker-lottie { width: 150px; height: 150px; }
.video-note video { border-radius: 50%; width: 180px; height: 180px; object-fit: cover; }
.doc-link { display: flex; align-items: center; gap: .5rem; color: var(--accent); text-decoration: none; margin-top: 6px; padding: .4rem .6rem; background: rgba(82,136,193,.12); border-radius: 8px; font-size: 13px; }
.doc-link:hover { text-decoration: underline; }
.media-placeholder { color: var(--muted); font-style: italic; font-size: 12px; margin-top: 4px; }

/* ── Input area ── */
#input-area { display: flex; align-items: flex-end; gap: .4rem; padding: .6rem .75rem; border-top: 1px solid var(--border); background: var(--sidebar); flex-shrink: 0; }
#attach-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; flex-shrink: 0; display: flex; align-items: center; }
#attach-btn:hover { color: var(--accent); }
#file-preview { display: flex; align-items: center; gap: .4rem; background: var(--input-bg); border-radius: 8px; padding: .3rem .6rem; font-size: 12px; color: var(--text); flex-shrink: 0; max-width: 140px; }
#file-preview-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#file-preview-clear { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; flex-shrink: 0; }
#msg-input { flex: 1; background: var(--input-bg); color: var(--text); border: 1px solid var(--border); border-radius: 20px; padding: .5rem .9rem; font-size: 14px; resize: none; max-height: 150px; overflow-y: auto; line-height: 1.4; }
#msg-input:focus { outline: none; border-color: var(--accent); }
#send-btn { background: var(--accent); border: none; border-radius: 50%; width: 38px; height: 38px; color: #fff; font-size: 18px; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
#send-btn:hover { filter: brightness(1.15); }

/* ── Automations area ── */
#automations-area {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg);
}
.auto-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1.25rem; border-bottom: 1px solid var(--border);
  background: var(--sidebar); flex-shrink: 0;
}
.auto-topbar h3 { font-size: 16px; color: var(--text); }
.auto-actions { display: flex; gap: .5rem; }
.auto-actions button {
  padding: .5rem 1rem; border-radius: 8px; border: none;
  font-size: 13px; cursor: pointer;
}
#auto-save-btn { background: var(--input-bg); color: var(--text); border: 1px solid var(--border); }
#auto-save-btn:hover { background: var(--border); }
#auto-run-btn { background: var(--accent); color: #fff; }
#auto-run-btn:hover { filter: brightness(1.1); }
.auto-columns { display: flex; flex: 1; overflow: hidden; }
.auto-col {
  flex: 1; display: flex; flex-direction: column; border-right: 1px solid var(--border);
  overflow: hidden;
}
.auto-col:last-child { border-right: none; }
.auto-col-title {
  padding: .7rem 1rem; font-weight: 600; font-size: 13px;
  border-bottom: 1px solid var(--border); background: var(--sidebar);
  color: var(--text); flex-shrink: 0;
}
.auto-col textarea {
  flex: 1; background: var(--bg); color: var(--text);
  border: none; resize: none; padding: 1rem;
  font-size: 13px; line-height: 1.6; font-family: inherit;
}
.auto-col textarea:focus { outline: none; }
#auto-media-drop {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: .75rem;
  padding: 1.5rem; text-align: center;
}
#auto-media-drop.drag-over { background: rgba(82,136,193,.1); }
#auto-media-placeholder { display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.drop-icon { font-size: 2.5rem; }
#auto-media-placeholder p { color: var(--muted); font-size: 13px; }
#auto-media-btn {
  padding: .5rem 1.2rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--input-bg); color: var(--text); font-size: 13px; cursor: pointer;
}
#auto-media-btn:hover { border-color: var(--accent); color: var(--accent); }
#auto-media-preview img, #auto-media-preview video {
  max-width: 100%; max-height: 160px; border-radius: 8px; display: block; margin: 0 auto .4rem;
}

/* multi-media list */
#auto-media-list { overflow-y: auto; max-height: 45%; padding: .4rem .6rem 0; flex-shrink: 0; }
.media-item {
  display: flex; align-items: center; gap: .6rem; padding: .4rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; margin-bottom: .4rem;
}
.media-item.media-error { border-color: rgba(224,108,117,.5); }
.media-item.media-stale { border-color: rgba(210,153,34,.6); background: rgba(210,153,34,.08); }
.media-item.media-stale .media-item-name { color: var(--muted); text-decoration: line-through; }
.media-item-stale { font-size: 11px; color: #d29922; }
.media-item-thumb {
  width: 40px; height: 40px; border-radius: 6px; flex-shrink: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center; font-size: 20px; background: var(--input-bg);
}
.media-item-thumb img, .media-item-thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-item-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .3rem; }
.media-item-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-item-kind {
  padding: .25rem .4rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--input-bg); color: var(--text); font-size: 12px; cursor: pointer; max-width: 130px;
}
.media-item-kind:focus { outline: none; border-color: var(--accent); }
.media-item-del {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 14px; padding: 4px 6px; border-radius: 4px; flex-shrink: 0;
}
.media-item-del:hover { color: var(--danger); background: rgba(224,108,117,.12); }
#auto-result {
  margin: .5rem 1rem; padding: .5rem .75rem; border-radius: 8px;
  font-size: 12px; background: var(--input-bg); color: var(--text);
}

/* stacked text + media column */
.auto-subcol { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.auto-subcol:first-child { border-bottom: 1px solid var(--border); }
.auto-subcol #auto-media-drop { flex: 1; }

/* accounts column */
.auto-accounts { flex: 1; overflow-y: auto; padding: .5rem; }
.auto-account-row {
  display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem;
  border-radius: 8px; cursor: pointer;
}
.auto-account-row:hover { background: var(--sidebar); }
.auto-account-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.auto-account-meta { flex: 1; overflow: hidden; }
.auto-account-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.auto-account-phone { font-size: 11px; color: var(--muted); }
.auto-account-warn { font-size: 11px; color: var(--danger); }
.auto-accounts-empty { color: var(--muted); font-size: 12px; padding: 1rem; text-align: center; }

.auto-settings { border-top: 1px solid var(--border); padding: .75rem; flex-shrink: 0; }
.auto-settings-title { font-size: 12px; color: var(--muted); margin-bottom: .5rem; }
.auto-delay-row { display: flex; gap: .75rem; }
.auto-delay-row label { font-size: 12px; color: var(--text); display: flex; align-items: center; gap: .35rem; }
.auto-delay-row input {
  width: 56px; padding: .3rem .4rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 13px;
}
.auto-delay-row input:focus { outline: none; border-color: var(--accent); }
#auto-open-log {
  margin-top: .75rem; width: 100%; padding: .55rem; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 13px; cursor: pointer;
}
#auto-open-log:hover { filter: brightness(1.1); }

/* ── Reply quote inside bubble ── */
.reply-quote {
  border-left: 3px solid var(--accent); padding: 2px 8px; margin-bottom: 4px;
  background: rgba(82,136,193,.12); border-radius: 4px; cursor: pointer;
  font-size: 12px; max-width: 100%; overflow: hidden;
}
.reply-quote .rq-name { color: var(--accent); font-weight: 600; }
.reply-quote .rq-text { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bubble .sender { cursor: pointer; }
.bubble .sender:hover { text-decoration: underline; }

/* comment button under channel posts */
.comments-btn {
  margin-top: 6px; display: inline-flex; align-items: center; gap: 5px;
  background: rgba(82,136,193,.15); color: var(--accent); border: none;
  border-radius: 8px; padding: .35rem .7rem; font-size: 12px; cursor: pointer;
}
.comments-btn:hover { background: rgba(82,136,193,.28); }

/* ── Reply bar above composer ── */
#reply-bar { padding: .4rem .75rem 0; background: var(--sidebar); flex-shrink: 0; }
.reply-bar-line { display: flex; align-items: center; gap: .5rem; background: var(--input-bg); border-left: 3px solid var(--accent); border-radius: 6px; padding: .35rem .6rem; }
.reply-bar-info { flex: 1; overflow: hidden; }
.reply-bar-title { color: var(--accent); font-size: 12px; font-weight: 600; }
.reply-bar-text { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#reply-bar-clear { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; flex-shrink: 0; }
#reply-bar-clear:hover { color: var(--danger); }

/* ── Thread / comments overlay ── */
#thread-panel {
  position: absolute; inset: 0; z-index: 20;
  background: var(--bg); display: flex; flex-direction: column;
}
#thread-header { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border); background: var(--sidebar); flex-shrink: 0; }
#thread-back { background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; padding: 0 4px; }
#thread-back:hover { color: var(--accent); }
#thread-title { font-weight: 600; font-size: 15px; }
#thread-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .4rem; }
#thread-input-area { display: flex; align-items: flex-end; gap: .4rem; padding: .6rem .75rem; border-top: 1px solid var(--border); background: var(--sidebar); flex-shrink: 0; }
#thread-input { flex: 1; background: var(--input-bg); color: var(--text); border: 1px solid var(--border); border-radius: 20px; padding: .5rem .9rem; font-size: 14px; resize: none; max-height: 120px; line-height: 1.4; }
#thread-input:focus { outline: none; border-color: var(--accent); }
#thread-send { background: var(--accent); border: none; border-radius: 50%; width: 38px; height: 38px; color: #fff; font-size: 18px; cursor: pointer; flex-shrink: 0; }
#thread-send:hover { filter: brightness(1.15); }

/* ── Profile / info overlay ── */
#profile-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 340px; max-width: 90%;
  z-index: 30; background: var(--sidebar); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; box-shadow: -4px 0 24px rgba(0,0,0,.4);
}
#profile-header { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
#profile-close { background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; }
#profile-close:hover { color: var(--danger); }
#profile-title { font-weight: 600; font-size: 15px; }
#profile-body { flex: 1; overflow-y: auto; padding: 1.5rem 1rem; display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.profile-avatar { margin-bottom: .5rem; }
.profile-name { font-size: 18px; font-weight: 600; text-align: center; }
.profile-username { color: var(--accent); font-size: 13px; }
.profile-verified { color: var(--accent); }
.profile-fields { width: 100%; margin-top: 1rem; display: flex; flex-direction: column; gap: .85rem; }
.profile-field { display: flex; flex-direction: column; gap: 2px; padding: .6rem .75rem; background: var(--bg); border-radius: 8px; }
.profile-field-label { color: var(--muted); font-size: 11px; }
.profile-field-value { font-size: 14px; word-break: break-word; white-space: pre-wrap; }
.profile-open-btn { margin-top: 1rem; width: 100%; padding: .6rem; border: none; border-radius: 8px; background: var(--accent); color: #fff; font-size: 14px; cursor: pointer; }
.profile-open-btn:hover { filter: brightness(1.1); }
.profile-loading { color: var(--muted); }

/* ── Context menu ── */
#context-menu {
  position: fixed; z-index: 300; background: var(--input-bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 4px;
  box-shadow: 0 6px 24px rgba(0,0,0,.5); min-width: 170px;
}
.ctx-item { padding: .5rem .7rem; border-radius: 6px; font-size: 13px; cursor: pointer; color: var(--text); }
.ctx-item:hover { background: var(--accent); color: #fff; }

/* ── Search results ── */
.search-section-title { padding: .5rem .85rem .25rem; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.search-type { color: var(--muted); font-size: 11px; }

/* ── Statistics dashboard ── */
#stats-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
#stats-area .auto-topbar #stats-refresh {
  padding: .5rem 1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--input-bg); color: var(--text); font-size: 13px; cursor: pointer;
}
#stats-area .auto-topbar #stats-refresh:hover { border-color: var(--accent); color: var(--accent); }

.stats-summary {
  display: flex; flex-wrap: wrap; gap: .6rem; padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.stat-tile {
  background: var(--sidebar); border: 1px solid var(--border); border-radius: 10px;
  padding: .6rem 1rem; min-width: 110px; flex: 1;
}
.stat-tile-val { font-size: 22px; font-weight: 700; color: var(--text); }
.stat-tile-label { font-size: 11px; color: var(--muted); margin-top: 2px; }

.stats-cards { flex: 1; overflow-y: auto; padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: .85rem; }

.stat-card { background: var(--sidebar); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.stat-card.disabled { opacity: .6; }
.stat-card-head { display: flex; align-items: center; gap: .75rem; padding: .85rem 1rem; }
.stat-head-info { flex: 1; min-width: 0; }
.stat-acc-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: .5rem; }
.stat-acc-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.stat-active-chip { font-size: 10px; background: rgba(82,136,193,.2); color: var(--accent); padding: 1px 7px; border-radius: 10px; font-weight: 500; }

.risk-chip { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 12px; flex-shrink: 0; }
.risk-ok         { background: rgba(63,185,80,.15);  color: #4caf50; }
.risk-warning    { background: rgba(210,153,34,.18); color: #d29922; }
.risk-danger     { background: rgba(248,81,73,.16);  color: #f85149; }
.risk-restricted { background: rgba(248,81,73,.28);  color: #ff7b72; }

.stat-expand { background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 0 4px; flex-shrink: 0; }
.stat-expand:hover { color: var(--accent); }

.stat-metrics {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 1px; background: var(--border); border-top: 1px solid var(--border);
}
.stat-cell { background: var(--sidebar); padding: .6rem .4rem; text-align: center; }
.stat-cell-val { font-size: 18px; font-weight: 700; }
.stat-cell-val.warn { color: #d29922; }
.stat-cell-val.err  { color: #f85149; }
.stat-cell-label { font-size: 11px; color: var(--muted); margin-top: 2px; }

.stat-details { padding: 1rem; border-top: 1px solid var(--border); background: var(--bg); }
.stat-reco-title, .stat-events-title { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: .5rem; }
.stat-reco { list-style: none; display: flex; flex-direction: column; gap: .4rem; margin-bottom: .85rem; }
.stat-reco li { font-size: 13px; line-height: 1.45; padding-left: .25rem; }
.stat-last { font-size: 12px; color: var(--muted); margin-bottom: .85rem; }
.stat-actions { margin-bottom: 1rem; }
.stat-toggle { padding: .5rem 1rem; border-radius: 8px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 13px; cursor: pointer; }
.stat-toggle:hover:not(:disabled) { border-color: var(--accent); }
.stat-toggle.danger { color: var(--danger); border-color: rgba(224,108,117,.4); }
.stat-toggle:disabled { opacity: .5; }

.stat-events {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px;
  max-height: 240px; overflow-y: auto; background: #0d1117; border-radius: 8px; padding: .6rem;
}
.stat-ev { display: flex; gap: .6rem; padding: 1px 0; line-height: 1.5; }
.stat-ev-ts { color: var(--muted); flex-shrink: 0; }
.stat-ev-msg { flex: 1; word-break: break-word; }
.stat-ev.lvl-ok    .stat-ev-msg { color: #3fb950; }
.stat-ev.lvl-warn  .stat-ev-msg { color: #d29922; }
.stat-ev.lvl-error .stat-ev-msg { color: #f85149; }
.stat-ev.lvl-system .stat-ev-msg { color: #bc8cff; font-weight: 600; }
.stat-ev-empty { color: var(--muted); }

/* ── Shared utilities ── */
.hidden { display: none !important; }

/* scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
