/*
 * TON Adoption admin — explicit CSS.
 *
 * We use Tailwind via CDN for layout utilities, but anything that needs
 * to look just-so (cards, pills, typography) is defined here so it
 * doesn't depend on JIT class generation timing.
 */

:root {
  --ink-950: #040810;
  --ink-900: #070b13;
  --ink-850: #0a1018;
  --ink-800: #0e1622;
  --ink-700: #131e2d;
  --ink-600: #1a2536;
  --fog-50:  #f3f6fa;
  --fog-100: #dfe6ee;
  --fog-200: #c2cdda;
  --fog-300: #9aa9bd;
  --fog-400: #6c7a91;
  --fog-500: #4a5667;
  --fog-600: #374052;
  --ton-300: #7cc9f5;
  --ton-400: #4fb7f0;
  --ton-500: #1aa3eb;
  --ton-700: #0a5a8a;
  --mint:    #4fd5a3;
  --amber:   #f1b656;
  --rose:    #f17a8a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink-950);
  color: var(--fog-100);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--ton-300); text-decoration: none; }
a:hover { color: var(--ton-400); }

code, pre, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* ───── Topbar ────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(7, 11, 19, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--ink-600);
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar-logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
}
.topbar-logo .mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--ton-500), var(--ton-700));
  color: var(--ink-950);
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, monospace;
  font-size: 13px;
}
.topbar-status {
  flex: 1;
  display: flex;
  gap: 14px;
  align-items: center;
  font-size: 12.5px;
  color: var(--fog-300);
  flex-wrap: wrap;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ───── Main container ───────────────────────────────────────────── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 20px 60px;
}

.section-label {
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fog-400);
  margin: 18px 0 10px;
  padding-left: 2px;
}
.section-label:first-child { margin-top: 4px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}
.grid-wide { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
.grid-tight { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.col-span-2 { grid-column: span 2; }
@media (max-width: 700px) { .col-span-2 { grid-column: span 1; } }

/* ───── Card ─────────────────────────────────────────────────────── */
.card {
  background: var(--ink-850);
  border: 1px solid var(--ink-600);
  border-radius: 10px;
  padding: 14px 16px 12px;
  display: flex;
  flex-direction: column;
  min-height: 110px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.card-title {
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fog-300);
  margin: 0;
}
.card-meta {
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  color: var(--fog-500);
}
.card-actions { display: flex; gap: 4px; align-items: center; }
.card-content { flex: 1; }
.card-footer {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--ink-700);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--fog-500);
  font-family: ui-monospace, monospace;
}
.card.error { border-color: rgba(241, 122, 138, 0.4); }
.card.warn  { border-color: rgba(241, 182, 86, 0.35); }
.card.ok    { /* default */ }

/* ───── Pills ────────────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.pill-ok    { color: var(--mint);  background: rgba(79, 213, 163, 0.10); border-color: rgba(79, 213, 163, 0.35); }
.pill-warn  { color: var(--amber); background: rgba(241, 182, 86, 0.10); border-color: rgba(241, 182, 86, 0.35); }
.pill-err   { color: var(--rose);  background: rgba(241, 122, 138, 0.10); border-color: rgba(241, 122, 138, 0.35); }
.pill-neutral { color: var(--fog-300); background: rgba(154, 169, 189, 0.06); border-color: rgba(154, 169, 189, 0.2); }
.pill-neutral::before { display: none; }

/* ───── Buttons ──────────────────────────────────────────────────── */
.btn {
  background: var(--ink-800);
  color: var(--fog-100);
  border: 1px solid var(--ink-600);
  border-radius: 7px;
  padding: 5px 12px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 120ms, color 120ms;
}
.btn:hover { border-color: var(--ton-500); color: var(--fog-50); }
.btn-icon {
  padding: 3px 7px;
  font-size: 13px;
  line-height: 1;
}
.btn-primary {
  background: var(--ton-500);
  color: var(--ink-950);
  border-color: var(--ton-500);
  font-weight: 600;
}
.btn-primary:hover { background: var(--ton-400); color: var(--ink-950); }
.btn-ghost { background: transparent; border: none; color: var(--fog-400); padding: 4px 6px; }
.btn-ghost:hover { color: var(--ton-300); }

/* ───── Metric (big number) ──────────────────────────────────────── */
.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 14px;
  margin-top: 4px;
}
.metric {
  display: flex;
  flex-direction: column;
}
.metric-value {
  font-size: 26px;
  font-weight: 600;
  font-family: ui-monospace, monospace;
  line-height: 1.1;
  color: var(--fog-50);
  letter-spacing: -0.02em;
}
.metric-value.dim { color: var(--fog-400); }
.metric-label {
  font-family: ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fog-400);
  margin-top: 4px;
}
.metric-sub {
  font-size: 11px;
  color: var(--fog-400);
  margin-top: 2px;
}

/* ───── Key/value list ───────────────────────────────────────────── */
.kv {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  gap: 10px;
}
.kv-row > .k {
  font-family: ui-monospace, monospace;
  font-size: 11.5px;
  color: var(--fog-400);
  letter-spacing: 0.02em;
}
.kv-row > .v {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--fog-100);
  text-align: right;
  word-break: break-all;
}

/* ───── List of items (likes, posts) ─────────────────────────────── */
.feed { display: flex; flex-direction: column; gap: 8px; }
.feed-item {
  border-bottom: 1px solid var(--ink-700);
  padding-bottom: 8px;
}
.feed-item:last-child { border-bottom: none; padding-bottom: 0; }
.feed-handle {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--ton-300);
}
.feed-when {
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  color: var(--fog-500);
  float: right;
}
.feed-preview {
  font-size: 12.5px;
  color: var(--fog-200);
  margin-top: 3px;
  line-height: 1.45;
}

/* ───── Skeleton + loading ───────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--ink-800) 25%, var(--ink-700) 50%, var(--ink-800) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: 4px;
  height: 12px;
  width: 100%;
}
.skeleton + .skeleton { margin-top: 6px; }
.skeleton.h-lg { height: 32px; }
.skeleton.h-xs { height: 8px; width: 60%; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.spinner {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 1.5px solid var(--fog-500);
  border-top-color: var(--ton-400);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───── Error display ────────────────────────────────────────────── */
.error-box {
  background: rgba(241, 122, 138, 0.05);
  border: 1px solid rgba(241, 122, 138, 0.25);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--rose);
  font-family: ui-monospace, monospace;
  line-height: 1.4;
}
.error-box pre {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--rose);
  white-space: pre-wrap;
  word-break: break-all;
  opacity: 0.8;
}

details summary {
  cursor: pointer;
  user-select: none;
  color: var(--fog-400);
  font-size: 11px;
  font-family: ui-monospace, monospace;
}
details summary:hover { color: var(--ton-300); }
details summary::-webkit-details-marker { display: none; }
details summary::marker { display: none; }
details summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 120ms;
}
details[open] summary::before { content: "▾ "; }

details pre {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--ink-900);
  border: 1px solid var(--ink-700);
  border-radius: 5px;
  font-size: 11px;
  color: var(--fog-300);
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ───── Footnote / log lines ─────────────────────────────────────── */
.log-list {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--fog-400);
  max-height: 200px;
  overflow-y: auto;
  background: var(--ink-900);
  border: 1px solid var(--ink-700);
  border-radius: 5px;
  padding: 6px 8px;
}
.log-list div { white-space: pre; }

/* ───── Login page ───────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--ink-850);
  border: 1px solid var(--ink-600);
  border-radius: 12px;
  padding: 26px 22px;
}
.login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
}
.login-card .sub {
  color: var(--fog-400);
  font-size: 13px;
  margin-bottom: 22px;
}
.login-error {
  background: rgba(241, 122, 138, 0.08);
  border: 1px solid rgba(241, 122, 138, 0.3);
  border-radius: 6px;
  padding: 9px 11px;
  font-size: 12.5px;
  color: var(--rose);
  margin-bottom: 14px;
}
.field { margin-bottom: 14px; }
.field-label {
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fog-400);
  display: block;
  margin-bottom: 5px;
}
.field-input {
  width: 100%;
  background: var(--ink-900);
  border: 1px solid var(--ink-600);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--fog-50);
  font-size: 13.5px;
  font-family: inherit;
}
.field-input:focus {
  outline: none;
  border-color: var(--ton-500);
}

/* ───── Utility ──────────────────────────────────────────────────── */
.muted { color: var(--fog-400); }
.dim   { color: var(--fog-500); }
.tnum  { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.empty-state { color: var(--fog-500); font-size: 12.5px; padding: 14px 0; text-align: center; }
.divider { height: 1px; background: var(--ink-700); margin: 10px 0; }

/* ───── Subsection inside card ──────────────────────────────────── */
.subsection {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--ink-700);
}
.subsection-title {
  font-family: ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fog-400);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.subsection-title .count {
  color: var(--fog-500);
  font-size: 9.5px;
  letter-spacing: 0.08em;
}

/* ───── Mini-table (rank · main · stats) ─────────────────────────────
 * Switched from `display: table-cell` to CSS grid: `display: table-cell`
 * does NOT honour `max-width`, so long queries like `"@cryptobot" (fraud
 * or scam or lawsuit ...)` were overflowing the card. Grid with
 * `1fr` middle column + `min-width: 0` forces the main cell to shrink
 * and ellipsise.
 */
.tbl { display: flex; flex-direction: column; font-size: 12px; }
.tbl-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 8px;
  padding: 4px 0;
  align-items: start;
}
.tbl-row + .tbl-row { border-top: 1px solid var(--ink-700); }
.tbl-rank { color: var(--fog-500); font-family: ui-monospace, monospace; font-size: 10.5px; text-align: right; padding-top: 1px; }
.tbl-main {
  color: var(--fog-100);
  font-family: ui-monospace, monospace;
  font-size: 11.5px;
  min-width: 0;        /* enables ellipsis inside grid */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tbl-main.wrap { white-space: normal; word-break: break-word; }
.tbl-stat {
  color: var(--fog-300);
  font-family: ui-monospace, monospace;
  font-size: 11px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding-top: 1px;
}
.tbl-stat .dim { color: var(--fog-500); }

/* Truncated text gets a tooltip-like hover badge */
.tbl-main[title] { cursor: help; }
.tbl-main .bar { white-space: normal; }

/* Locale split (RU / EN side-by-side) */
.locale-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr 1fr 1fr;
  gap: 8px;
  font-family: ui-monospace, monospace;
  font-size: 11.5px;
  padding: 4px 0;
  border-top: 1px solid var(--ink-700);
}
.locale-row:first-of-type { border-top: none; padding-top: 0; }
.locale-row .lang { color: var(--ton-300); font-weight: 600; }
.locale-row .stat { text-align: right; }
.locale-row .stat .lbl { color: var(--fog-500); font-size: 9.5px; letter-spacing: 0.05em; }

/* Subtle horizontal bar for relative magnitudes inside tables */
.bar {
  height: 3px;
  background: rgba(79, 183, 240, 0.18);
  border-radius: 2px;
  margin-top: 3px;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--ton-500);
  border-radius: 2px;
}

/* ───── Bot log tail (journal) ──────────────────────────────────── */
.bot-log {
  margin-top: 10px;
  background: var(--ink-900);
  border: 1px solid var(--ink-700);
  border-radius: 5px;
  max-height: 260px;
  overflow: auto;
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  line-height: 1.55;
  padding: 6px 8px;
  color: var(--fog-300);
  white-space: pre;
}
.bot-log .ln { display: block; }
.bot-log .ln.warn { color: var(--amber); }
.bot-log .ln.err  { color: var(--rose); }
.bot-log .ln.ok   { color: var(--mint); }

/* "Run now" inline button */
.btn-run {
  background: rgba(79, 183, 240, 0.10);
  border-color: rgba(79, 183, 240, 0.4);
  color: var(--ton-300);
  font-size: 11px;
  padding: 3px 8px;
  font-family: ui-monospace, monospace;
}
.btn-run:hover { background: var(--ton-500); color: var(--ink-950); border-color: var(--ton-500); }
.btn-run:disabled { opacity: 0.5; cursor: not-allowed; }

/* Daily-counter chip (autolike) */
.day-chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--fog-300);
  border: 1px solid var(--ink-600);
  border-radius: 5px;
  padding: 2px 8px;
  background: var(--ink-900);
}
.day-chip .num { color: var(--ton-300); font-weight: 600; }
.day-chip .dim { color: var(--fog-500); }
.day-chip + .day-chip { margin-left: 6px; }

/* ───── Backlinks card ─────────────────────────────────────────── */
.bl-row {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-top: 1px solid var(--ink-700);
  font-size: 12px;
}
.bl-row:first-child { border-top: none; padding-top: 0; }
.bl-name {
  font-family: ui-monospace, monospace;
  color: var(--fog-100);
  font-size: 11.5px;
}
.bl-meta {
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  color: var(--fog-400);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bl-meta a { color: var(--ton-300); }
.bl-stat {
  font-family: ui-monospace, monospace;
  font-size: 11.5px;
  color: var(--fog-100);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.bl-stat .sub { color: var(--fog-400); font-size: 10px; }

/* Sparkline (used in WM history) */
.sparkline {
  display: inline-flex;
  align-items: end;
  gap: 1px;
  height: 26px;
  margin-top: 4px;
}
.sparkline span {
  width: 3px;
  background: var(--ton-500);
  min-height: 1px;
  opacity: 0.85;
  border-radius: 1px;
}
.sparkline span:last-child { background: var(--ton-300); opacity: 1; }
