/* ── RESET & TOKENS ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0e0e0e;
  --bg2:          #151515;
  --bg3:          #1c1c1c;
  --border:       rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.18);
  --text:         #e8e6e1;
  --muted:        #666;
  --muted2:       #444;
  --accent:       #b8f0a0;
  --accent2:      #7dd860;
  --up:           #4ade80;
  --wip:          #f59e0b;
  --mono:         'JetBrains Mono', monospace;
}

[data-theme="light"] {
  --bg:           #f0ede8;
  --bg2:          #e8e4de;
  --bg3:          #ddd8d0;
  --border:       rgba(0,0,0,0.10);
  --border-hover: rgba(0,0,0,0.22);
  --text:         #1a1a1a;
  --muted:        #6b6560;
  --muted2:       #9a948e;
  --accent:       #3a8c20;
  --accent2:      #2e7018;
  --up:           #1e8c3a;
  --wip:          #b87000;
}

html {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  transition: background 0.2s, color 0.2s;
}

body::before {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.03) 2px, rgba(0,0,0,0.03) 4px);
  pointer-events: none; z-index: 999;
}

body {
  min-height: 100vh;
  max-width: 760px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
  visibility: hidden;
}
body.ready { visibility: visible; }

/* ── HEADER ──────────────────────────────────────── */
.header { margin-bottom: 3rem; }

.header-top {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 0.6rem;
}

.header-eyebrow {
  font-size: 10px; letter-spacing: 0.15em;
  color: var(--muted); text-transform: uppercase;
}

.back-link {
  color: var(--muted); text-decoration: none; transition: color 0.15s;
}
.back-link:hover { color: var(--accent); }

.theme-toggle {
  background: none; border: none; padding: 0;
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--muted); cursor: pointer; transition: color 0.15s;
  -webkit-user-select: none; user-select: none;
}
.theme-toggle:hover { color: var(--accent); }

.logo {
  font-size: 42px; font-weight: 500;
  letter-spacing: -0.04em; line-height: 1; color: var(--text);
}
.logo .tld { color: var(--muted); font-weight: 400; }

.tagline { font-size: 12px; color: var(--muted); margin-top: 0.75rem; line-height: 1.6; }

/* ── MODULE LAYOUT ───────────────────────────────── */
.m-wrap { display: flex; flex-direction: column; gap: 1.5rem; }

.m-label {
  font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 0.5rem;
}

/* ── INPUTS ──────────────────────────────────────── */
input, textarea {
  width: 100%;
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  -moz-appearance: textfield;
  appearance: textfield;
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button { -webkit-appearance: none; }
input::placeholder { color: var(--muted2); }
input:focus { border-color: var(--border-hover); }

/* ── FORM GRID ───────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}
@media (max-width: 600px) { .form-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 400px) { .form-grid { grid-template-columns: 1fr; } }

.form-group { display: flex; flex-direction: column; gap: 0.4rem; }

.range-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 0.5rem; align-items: end; }
.range-sep { font-size: 14px; color: var(--muted2); text-align: center; padding-bottom: 9px; line-height: 1; }

.hint { font-size: 10px; color: var(--muted2); line-height: 1.5; }
.opt  { font-size: 10px; color: var(--muted2); }

/* ── DIVIDER ─────────────────────────────────────── */
.divider { height: 0.5px; background: var(--border); margin: 1.25rem 0; }

/* ── BUTTONS ─────────────────────────────────────── */
.m-btn {
  background: none;
  border: 0.5px solid var(--accent);
  border-radius: 6px;
  padding: 0.45rem 1.4rem;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.m-btn:hover { background: var(--accent); color: var(--bg); }
.m-btn:disabled { opacity: 0.4; pointer-events: none; }

.m-btn-secondary {
  background: none;
  border: 0.5px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 1.2rem;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.m-btn-secondary:hover { border-color: var(--border-hover); color: var(--text); }
.m-btn-secondary:disabled { opacity: 0.4; pointer-events: none; }

.m-btn-danger {
  border-color: #f87171;
  color: #f87171;
}
.m-btn-danger:hover { background: #f87171; color: var(--bg); border-color: #f87171; }

.btn-row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }

/* ── PILLS ───────────────────────────────────────── */
.m-pills { display: flex; gap: 4px; flex-wrap: wrap; }

.m-pill {
  background: none;
  border: 0.5px solid transparent;
  border-radius: 3px;
  padding: 3px 10px 3px 8px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted2);
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.m-pill:hover { color: var(--text); border-color: var(--border); }
.m-pill.active { color: var(--bg); background: var(--accent); border-color: var(--accent); }
.m-pill.active:hover { opacity: 0.88; }

/* ── STATUS / STATS ──────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}
.stat {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  text-align: center;
}
.stat:first-child { border-color: var(--accent); }
.stat-val {
  font-size: 22px; font-weight: 500;
  color: var(--text); margin-bottom: 0.3rem;
  font-variant-numeric: tabular-nums; line-height: 1;
}
.stat-lbl { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; }

.status-bar {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 1rem;
  display: flex; align-items: center; gap: 0.6rem;
  font-size: 12px; color: var(--muted);
}
.sdot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; transition: background 0.3s; }
.sdot.idle    { background: var(--muted2); }
.sdot.running { background: var(--accent); animation: pulse 2s infinite; }
.sdot.done    { background: var(--up); }
@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:.3 } }

/* ── OUTPUT / PANEL ──────────────────────────────── */
.m-output {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  font-size: 13px; color: var(--text);
  line-height: 1.65; white-space: pre-wrap; word-break: break-word;
}

/* ── RESULT LIST ─────────────────────────────────── */
.result-scroll {
  max-height: 300px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--muted2) var(--bg3);
}
.result-scroll::-webkit-scrollbar { width: 6px; }
.result-scroll::-webkit-scrollbar-track { background: var(--bg3); border-radius: 3px; }
.result-scroll::-webkit-scrollbar-thumb { background: var(--muted2); border-radius: 3px; }
.result-scroll::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.result-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.result-row {
  display: grid;
  grid-template-columns: 2.6em 1fr auto;
  align-items: center;
  gap: 0.6rem;
  padding: 5px 0.9rem;
  border-bottom: 0.5px solid var(--border);
  font-size: 11px;
  transition: background 0.1s;
  min-width: 0;
}
.result-row:last-child { border-bottom: none; }
.result-row:hover { background: var(--bg3); }

.r-num {
  font-size: 10px;
  color: var(--muted2);
  text-align: right;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.r-name {
  font-size: 12px;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  letter-spacing: 0.02em;
}
.r-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}
.r-len {
  font-size: 10px;
  color: var(--muted2);
  white-space: nowrap;
}

.tag-free {
  font-size: 9px; padding: 1px 6px; border-radius: 3px;
  border: 0.5px solid var(--up); color: var(--up);
  white-space: nowrap; text-transform: uppercase; letter-spacing: 0.08em;
  line-height: 1.7; flex-shrink: 0;
}
.tag-unconfirmed {
  font-size: 9px; padding: 1px 6px; border-radius: 3px;
  border: 0.5px solid var(--wip); color: var(--wip);
  white-space: nowrap; letter-spacing: 0.08em;
  line-height: 1.7; flex-shrink: 0;
}
.tag-mode {
  font-size: 9px; padding: 1px 6px; border-radius: 3px;
  white-space: nowrap; text-transform: uppercase; letter-spacing: 0.06em;
  line-height: 1.7; flex-shrink: 0;
}
.tag-mode.bot  { border: 0.5px solid var(--accent); color: var(--accent); }
.tag-mode.user { border: 0.5px solid var(--muted);  color: var(--muted); }
.tag-mode.both { border: 0.5px solid var(--muted2); color: var(--muted2); }

.r-empty {
  text-align: center;
  padding: 1.75rem 0;
  color: var(--muted2);
  font-size: 11px;
  letter-spacing: 0.08em;
}

/* ── PAGINATION ──────────────────────────────────── */
.pag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.9rem;
  border-top: 0.5px solid var(--border);
}
.pbtn {
  width: 24px; height: 24px;
  background: none; border: 0.5px solid var(--border);
  color: var(--muted); border-radius: 3px; cursor: pointer;
  font-size: 11px; display: flex; align-items: center; justify-content: center;
  transition: border-color 0.15s, color 0.15s;
  -webkit-user-select: none; user-select: none;
  flex-shrink: 0;
}
.pbtn:hover:not(.disabled) { border-color: var(--border-hover); color: var(--text); }
.pbtn.disabled { opacity: 0.25; cursor: default; pointer-events: none; }
.pinfo {
  font-size: 10px; color: var(--muted); text-align: center;
  letter-spacing: 0.08em;
}

/* ── LOG PANEL ───────────────────────────────────── */
.log-panel {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 40vh; min-height: 180px;
  background: var(--bg);
  border-top: 0.5px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 200;
  transform: translateY(0);
  transition: transform 0.25s ease;
}
.log-panel.hidden { transform: translateY(100%); }

.log-hdr {
  background: var(--bg2);
  border-bottom: 0.5px solid var(--border);
  padding: 0.4rem 1rem;
  display: flex; align-items: center; gap: 0.6rem;
  flex-shrink: 0; height: 34px;
}
.log-hdr-title { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.log-hdr-file { font-size: 11px; color: var(--muted2); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-hdr-right { display: flex; align-items: center; gap: 0.6rem; margin-left: auto; flex-shrink: 0; }
.log-scroll-label {
  display: flex; align-items: center; gap: 4px;
  font-size: 10px; color: var(--muted2); cursor: pointer;
  -webkit-user-select: none; user-select: none; white-space: nowrap;
}
.log-scroll-label input { width: auto; padding: 0; border: none; background: none; appearance: auto; cursor: pointer; }
.log-close {
  background: none; border: none; color: var(--muted2); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0 2px; transition: color 0.15s;
}
.log-close:hover { color: var(--text); }

.log-body {
  flex: 1; overflow-y: auto;
  padding: 0.6rem 1rem 1rem;
  font-size: 11px; line-height: 1.7;
}
.log-body::-webkit-scrollbar { width: 6px; }
.log-body::-webkit-scrollbar-track { background: var(--bg3); }
.log-body::-webkit-scrollbar-thumb { background: var(--muted2); border-radius: 3px; }
.log-body::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.ll-sep  { color: var(--accent); font-weight: 500; display: block; }
.ll-info { color: var(--up); display: block; }
.ll-warn { color: var(--wip); display: block; }
.ll-err  { color: #f87171; display: block; }
.ll-dbg  { color: var(--muted2); display: block; }

/* ── BADGE ───────────────────────────────────────── */
.topbadge {
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 3px 10px; border-radius: 3px;
  border: 0.5px solid var(--border); color: var(--muted2);
  white-space: nowrap;
}
.topbadge.running { border-color: var(--accent); color: var(--accent); }
.topbadge.done    { border-color: var(--up); color: var(--up); }

/* ── NAV LINK (текстовая кнопка/ссылка в шапке) ─── */
.nav-link {
  font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); background: none; border: none;
  cursor: pointer; text-decoration: none;
  transition: color 0.15s; padding: 0;
  font-family: var(--mono);
}
.nav-link:hover { color: var(--accent); }
.nav-link.active { color: var(--accent); }

/* ── FOOTER ──────────────────────────────────────── */
.footer {
  margin-top: 3.5rem; padding-top: 1.5rem;
  border-top: 0.5px solid var(--border);
  display: flex; align-items: flex-start;
  justify-content: space-between; flex-wrap: wrap; gap: 1rem;
}
.footer-meta { font-size: 10px; color: var(--muted2); line-height: 1.9; }
.footer-meta span { color: var(--muted); }
.footer-links { display: flex; gap: 1.25rem; }
.footer-links a {
  font-size: 10px; color: var(--muted); text-decoration: none;
  letter-spacing: 0.1em; text-transform: uppercase; transition: color 0.15s;
}
.footer-links a:hover { color: var(--accent); }

/* ── UTILITIES ───────────────────────────────────── */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ── ARCHIVE TABLE ───────────────────────────────── */
.archive-table { width: 100%; border-collapse: collapse; }
.archive-table th {
  text-align: left; font-size: 9px; color: var(--muted2);
  text-transform: uppercase; letter-spacing: 0.14em;
  padding: 0.35rem 0.55rem; border-bottom: 0.5px solid var(--border);
}
.archive-table td {
  padding: 0.45rem 0.55rem; border-bottom: 0.5px solid var(--border);
  font-size: 12px; vertical-align: middle; color: var(--text); line-height: 1;
}
.archive-table tbody tr.main-row:last-of-type td { border-bottom: none; }
.archive-table tbody tr.main-row:hover td { background: var(--bg3); }

.td-date  { font-size: 11px; color: var(--muted2); white-space: nowrap; }
.td-zone  { font-size: 13px; color: var(--text); }
.td-len   { font-size: 11px; color: var(--muted); white-space: nowrap; }
.td-count { font-size: 13px; color: var(--text); font-variant-numeric: tabular-nums; }
.td-dash  { font-size: 11px; color: var(--muted2); }

.tag-method { font-size: 9px; padding: 2px 8px; border-radius: 3px; white-space: nowrap; letter-spacing: 0.08em; text-transform: uppercase; }
.tag-timeweb { border: 0.5px solid var(--accent); color: var(--accent); }
.tag-whois   { border: 0.5px solid var(--muted); color: var(--muted); }

.actions-cell { display: flex; gap: 4px; align-items: center; }
.expand-btn, .dl-btn, .del-btn {
  background: none; border: 0.5px solid var(--border); color: var(--muted2);
  padding: 0; height: 18px; line-height: 18px;
  border-radius: 3px; cursor: pointer; font-size: 10px;
  font-family: var(--mono); letter-spacing: 0.06em;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  white-space: nowrap; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 66px; flex-shrink: 0;
}
.expand-btn:hover, .dl-btn:hover { border-color: var(--border-hover); color: var(--text); }
.expand-btn:disabled { opacity: 0.3; cursor: default; pointer-events: none; }
.del-btn { border-color: rgba(248,113,113,0.2); color: #f87171; }
.del-btn:hover { background: rgba(248,113,113,0.08); border-color: #f87171; }

.expand-row td { padding: 0; border-bottom: 0.5px solid var(--border); }

.expand-list-wrap {
  background: var(--bg);
  border-top: 0.5px solid var(--border);
  max-height: 200px;
  overflow-y: auto;
  padding: 0.6rem 0.9rem;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-content: flex-start;
  scrollbar-width: thin;
  scrollbar-color: var(--muted2) transparent;
}
.expand-list-wrap::-webkit-scrollbar { width: 4px; }
.expand-list-wrap::-webkit-scrollbar-track { background: transparent; }
.expand-list-wrap::-webkit-scrollbar-thumb { background: var(--muted2); border-radius: 2px; }
.expand-list-wrap::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.expand-chip {
  font-size: 11px;
  color: var(--accent);
  border: 0.5px solid rgba(184,240,160,0.2);
  border-radius: 3px;
  padding: 2px 7px;
  white-space: nowrap;
  letter-spacing: 0.02em;
  line-height: 1.6;
}
[data-theme="light"] .expand-chip {
  border-color: rgba(58,140,32,0.25);
}

.expand-loading { font-size: 11px; color: var(--muted2); padding: 0.15rem 0; }

.card-empty { text-align: center; padding: 3rem 0; color: var(--muted2); font-size: 12px; }
.page-subtitle { font-size: 12px; color: var(--muted2); margin-top: 0.4rem; }

/* ── ARCHIVE: results table panel ───────────────── */
.archive-panel {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

/* ── INDEX: header-right, results panel ─────────── */
.header-right { display: flex; align-items: center; gap: 1rem; }
.results-panel {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

/* ── LOGIN ───────────────────────────────────────── */
.m-input {
  width: 100%; background: var(--bg2);
  border: 0.5px solid var(--border); border-radius: 8px;
  padding: 0.6rem 0.9rem; font-family: var(--mono); font-size: 13px;
  color: var(--text); outline: none; transition: border-color 0.15s;
}
.m-input:focus { border-color: var(--border-hover); }
.m-input::placeholder { color: var(--muted2); }

.login-actions { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }

.m-status { font-size: 11px; color: var(--muted); letter-spacing: 0.06em; min-height: 1.4em; }
.m-status.err { color: #f87171; }

/* ── PILLS ─────────────────────────────────────────── */
.m-pills { display: flex; gap: 4px; flex-wrap: wrap; }
.m-pill {
  background: none; border: 0.5px solid transparent;
  border-radius: 3px; padding: 3px 10px 3px 8px;
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.08em; color: var(--muted2);
  cursor: pointer; transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.m-pill:hover { color: var(--text); border-color: var(--border); }
.m-pill.active { color: var(--bg); background: var(--accent); border-color: var(--accent); }
.m-pill.active:hover { opacity: 0.88; }

/* ── AUTH PAGE ───────────────────────────────────── */
.auth-logout-btn { margin-left: auto; }
.auth-btn-row { margin-top: 1rem; }
.auth-password-wrap { margin-top: 0.75rem; }
.auth-ready-msg { color: var(--up); font-size: 12px; }

/* ── MTPROTO TOGGLE ──────────────────────────────── */
.mtproto-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer;
  -webkit-user-select: none; user-select: none;
}
.mtproto-track {
  position: relative; width: 32px; height: 18px;
  background: var(--bg3); border: 0.5px solid var(--border);
  border-radius: 9px; transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.mtproto-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted2); transition: transform 0.2s, background 0.2s;
}
.mtproto-toggle:has(#mtprotoEnabled:checked) .mtproto-track {
  background: rgba(184,240,160,0.12); border-color: var(--accent);
}
.mtproto-toggle:has(#mtprotoEnabled:checked) .mtproto-thumb {
  transform: translateX(14px); background: var(--accent);
}
.mtproto-label { font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.mtproto-toggle:has(#mtprotoEnabled:checked) .mtproto-label { color: var(--accent); }

/* ── RESULT TAGS ─────────────────────────────────── */
.tag-pending {
  font-size: 9px; padding: 1px 6px; border-radius: 3px;
  border: 0.5px solid var(--muted2); color: var(--muted2);
  white-space: nowrap; letter-spacing: 0.06em;
  line-height: 1.7; flex-shrink: 0;
}

/* ── ANIMATION ───────────────────────────────────── */
@keyframes fadein {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ready .header    { animation: fadein 0.4s ease both; }
.ready .m-wrap    { animation: fadein 0.4s ease 0.05s both; }
.ready .footer    { animation: fadein 0.4s ease 0.1s both; }
