/* ============================================
   Varifanto Admin — design tokens
   Palette: warm near-black + coral accent
============================================ */
:root {
  --bg:        #0d0e11;
  --surface:   #16181d;
  --surface-2: #1c1e24;
  --border:    #262931;
  --border-2:  #333742;
  --text:      #ecedf0;
  --muted:     #7d818c;
  --dim:       #4b4f59;
  --accent:    #ff6b47;
  --accent-2:  #ff8a6b;
  --ok:        #4ade80;
  --warn:      #fbbf24;
  --err:       #f87171;
  --tg-bubble: #2b3542;
  --tg-bg:     #16222d;

  --font-ui:   -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, "Menlo", monospace;

  --radius:    6px;
  --radius-lg: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }

/* ============================================
   Login
============================================ */
.login-body {
  display: grid; place-items: center; min-height: 100vh;
  background: radial-gradient(ellipse at top, #17181d 0%, var(--bg) 60%);
}
.login-wrap {
  width: 100%; max-width: 340px;
  padding: 40px 32px;
}
.login-brand { text-align: center; margin-bottom: 36px; }
.login-form { display: flex; flex-direction: column; gap: 18px; }

.brand-mark {
  width: 44px; height: 44px;
  display: inline-grid; place-items: center;
  background: var(--accent); color: #0d0e11;
  font-family: var(--font-mono); font-weight: 700; font-size: 22px;
  border-radius: var(--radius);
  margin: 0 auto 10px;
}
.brand-name { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.brand-sub  { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

/* ============================================
   Layout
============================================ */
.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  height: 100vh;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 20px 16px;
}
.brand-row {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 4px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.brand-row .brand-mark { margin: 0; width: 36px; height: 36px; font-size: 18px; }
.brand-row .brand-name { font-size: 15px; }
.brand-row .brand-sub  { font-size: 10px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--radius);
  font-size: 14px;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); }
.nav-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--dim);
  width: 18px;
}
.nav-item.active .nav-num { color: var(--accent); }

.sidebar-foot {
  display: flex; flex-direction: column; gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.main {
  overflow-y: auto;
  padding: 32px 40px 60px;
}

/* ============================================
   Headers & panels
============================================ */
.view-header {
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.view-header h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.view-sub {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}
.panel-head { margin-bottom: 16px; }
.panel-head h2 {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 600;
}
.panel-sub { font-size: 12px; color: var(--muted); }

/* ============================================
   Stats grid
============================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute; top: 0; left: 0;
  width: 3px; height: 100%;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.2s;
}
.stat-card.highlight::before { opacity: 1; }
.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text);
}
.stat-delta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* ============================================
   Countries
============================================ */
.country-list { display: flex; flex-direction: column; gap: 6px; }
.country-row {
  display: grid;
  grid-template-columns: 60px 1fr 60px;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.country-code {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
}
.country-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.country-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.country-count {
  font-family: var(--font-mono);
  font-size: 13px;
  text-align: right;
  color: var(--muted);
}

/* ============================================
   Filters
============================================ */
.filters {
  display: flex; gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.filter {
  display: flex; flex-direction: column; gap: 4px;
  min-width: 180px;
}
.filter span {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ============================================
   Tables
============================================ */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  text-align: left;
  padding: 12px 14px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-2); }
.table td.mono, .table td.num { font-family: var(--font-mono); font-size: 12px; }
.table .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}
.badge-ok   { background: rgba(74, 222, 128, 0.15); color: var(--ok); }
.badge-wait { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.badge-blk  { background: rgba(248, 113, 113, 0.15); color: var(--err); }

/* ============================================
   Forms
============================================ */
.field {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 16px;
}
.field-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex; justify-content: space-between;
}
input[type="text"], input[type="password"], input[type="url"],
input[type="email"], select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.12s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}
textarea {
  resize: vertical;
  font-family: var(--font-ui);
  min-height: 90px;
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='%237d818c'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%237d818c' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.06s, background 0.12s, border-color 0.12s;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent);
  color: #0d0e11;
}
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border-2);
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.form-error {
  color: var(--err);
  font-size: 13px;
  min-height: 18px;
}
.form-status {
  color: var(--muted);
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}

/* ============================================
   Broadcast composer
============================================ */
.broadcast-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
}
@media (max-width: 1100px) {
  .broadcast-grid { grid-template-columns: 1fr; }
}
.broadcast-actions {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.est { color: var(--muted); font-size: 13px; }

/* Inline buttons editor */
.btn-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  gap: 6px;
  margin-bottom: 6px;
}
.btn-row input { padding: 8px 10px; font-size: 13px; }
.btn-row .btn-del {
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--muted);
  border-radius: var(--radius);
  padding: 0 10px;
  cursor: pointer;
}
.btn-row .btn-del:hover { color: var(--err); border-color: var(--err); }

/* Telegram preview */
.preview-panel { position: sticky; top: 20px; align-self: start; }
.tg-frame {
  background: var(--tg-bg);
  border-radius: var(--radius-lg);
  padding: 20px 16px;
  min-height: 200px;
  border: 1px solid var(--border);
}
.tg-bubble {
  background: var(--tg-bubble);
  border-radius: 12px 12px 12px 4px;
  padding: 8px 10px 6px;
  max-width: 100%;
  color: #fff;
  font-size: 14px;
  line-height: 1.4;
  position: relative;
}
.tg-photo {
  border-radius: 8px;
  height: 160px;
  background-size: cover;
  background-position: center;
  background-color: rgba(0,0,0,0.2);
  margin-bottom: 6px;
}
.tg-text { white-space: pre-wrap; word-wrap: break-word; }
.tg-text a { color: #6ab7ff; }
.tg-buttons {
  display: flex; flex-direction: column; gap: 4px;
  margin-top: 8px;
}
.tg-btn {
  background: rgba(255,255,255,0.06);
  border-radius: 6px;
  padding: 8px;
  text-align: center;
  font-size: 13px;
  color: #6ab7ff;
}
.tg-meta {
  text-align: right;
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  margin-top: 2px;
}

/* ============================================
   Toast
============================================ */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.err { border-color: var(--err); color: var(--err); }
.toast.ok  { border-color: var(--ok); color: var(--ok); }

/* ============================================
   Mobile
============================================ */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0;
    flex-direction: row; align-items: center;
    padding: 12px 16px;
    z-index: 10;
  }
  .brand-row { border: none; padding: 0; margin: 0 auto 0 0; }
  .nav { flex-direction: row; gap: 4px; }
  .nav-num { display: none; }
  .nav-item { padding: 6px 10px; font-size: 12px; }
  .sidebar-foot { flex-direction: row; padding: 0; border: none; margin-left: 8px; }
  .main { padding: 20px 16px 40px; }
}
