:root {
  --bg: var(--tg-theme-bg-color, #0e1116);
  --bg-soft: var(--tg-theme-secondary-bg-color, #171b23);
  --card: var(--tg-theme-section-bg-color, #1b2029);
  --text: var(--tg-theme-text-color, #eef2f7);
  --muted: var(--tg-theme-hint-color, #8d98a8);
  --accent: var(--tg-theme-button-color, #4f8cff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #e05d5d;
  --ok: #3fbf7f;
  --line: rgba(255, 255, 255, 0.08);
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: var(--tg-theme-bg-color, #f4f6fa);
    --bg-soft: var(--tg-theme-secondary-bg-color, #e9edf4);
    --card: var(--tg-theme-section-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #161a20);
    --muted: var(--tg-theme-hint-color, #66707d);
    --line: rgba(0, 0, 0, 0.08);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; font-size: 15px; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.boot {
  display: grid; place-items: center; min-height: 70vh;
  color: var(--muted); font-size: 16px;
}

.app { max-width: 1180px; margin: 0 auto; padding: 12px 14px 40px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 8px 4px 14px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 26px; }
.brand-title { font-size: 18px; font-weight: 700; letter-spacing: 0.2px; }
.brand-sub { color: var(--muted); font-size: 13px; }
.chat-picker select {
  min-width: 220px; max-width: 100%; padding: 9px 12px;
  color: var(--text); background: var(--bg-soft);
  border: 1px solid var(--line); border-radius: 10px; font-size: 14px;
}

.nav {
  display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 12px;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav-btn {
  flex: 0 0 auto; padding: 8px 13px; border-radius: 999px;
  background: var(--bg-soft); color: var(--muted); border: 1px solid transparent;
  font-size: 14px; cursor: pointer;
}
.nav-btn.active { background: var(--accent); color: var(--accent-text); }
.nav-btn:hover { color: var(--text); }

.content { display: grid; gap: 14px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.two-col { display: grid; gap: 14px; grid-template-columns: 1.4fr 1fr; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.card h2, .card h3 { margin: 0 0 10px; font-size: 17px; }
.card h3 { font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.card .big { font-size: 28px; font-weight: 750; line-height: 1.1; }
.card .small { color: var(--muted); font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 10px; }
.spacer { flex: 1; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 12px;
  background: var(--bg-soft); color: var(--muted);
}
.badge.ok { background: rgba(63, 191, 127, .15); color: var(--ok); }
.badge.warn { background: rgba(224, 93, 93, .15); color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--text); font-size: 14px;
  cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { background: rgba(224, 93, 93, .16); color: var(--danger); border-color: rgba(224, 93, 93, .3); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }

label.field { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
input[type="text"], input[type="number"], input[type="url"], select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-soft);
  color: var(--text); font-size: 14px; font-family: inherit;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.check { display: flex; align-items: center; gap: 9px; color: var(--text); font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.list { display: grid; gap: 8px; }
.list-item {
  display: flex; align-items: flex-start; gap: 10px;
  border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px;
  background: var(--bg-soft);
}
.list-item .body { flex: 1; min-width: 0; }
.list-item .title-line { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.list-item .name { font-weight: 650; }
.list-item .meta { color: var(--muted); font-size: 12px; }
.list-item .text { margin-top: 5px; white-space: pre-wrap; word-break: break-word; }
.empty { color: var(--muted); padding: 14px 0; text-align: center; }

.quote-text { font-size: 16px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.quote-text::before { content: "«"; color: var(--muted); }
.quote-text::after { content: "»"; color: var(--muted); }

pre.preview {
  margin: 0; padding: 13px; border-radius: 11px; background: var(--bg-soft);
  border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word;
  font-family: inherit; font-size: 14px; line-height: 1.45;
}
pre.logs {
  margin: 0; padding: 12px; border-radius: 11px; background: #0b0d12; color: #cfd7e3;
  max-height: 420px; overflow: auto; font-size: 12px; white-space: pre-wrap;
}

.chart { display: flex; align-items: flex-end; gap: 4px; height: 130px; padding-top: 8px; }
.chart .bar-wrap { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 4px; }
.chart .bar { background: var(--accent); border-radius: 4px 4px 2px 2px; min-height: 2px; opacity: .85; }
.chart .bar-label { color: var(--muted); font-size: 9px; text-align: center; margin-top: 4px; white-space: nowrap; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table-wrap { overflow-x: auto; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table tr:last-child td { border-bottom: none; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: min(92vw, 560px); padding: 11px 16px; border-radius: 12px;
  background: #1f2633; color: #fff; box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
  z-index: 50; font-size: 14px;
}
.toast.error { background: #7d2b2b; }

.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .55);
  display: grid; place-items: center; padding: 18px; z-index: 60;
}
.modal-card {
  width: min(92vw, 440px); background: var(--card); border-radius: 16px;
  border: 1px solid var(--line); padding: 18px;
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.modal-body { color: var(--muted); font-size: 14px; white-space: pre-wrap; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.error-box {
  border: 1px solid rgba(224, 93, 93, .35); background: rgba(224, 93, 93, .1);
  color: var(--danger); padding: 12px 14px; border-radius: 11px; font-size: 14px;
}
.loading { color: var(--muted); padding: 30px 0; text-align: center; }

@media (max-width: 640px) {
  .app { padding: 10px 10px 30px; }
  .chat-picker, .chat-picker select { width: 100%; }
  .card { padding: 13px; }
  .big { font-size: 24px; }
}
