/* ===================== Базовые токены / тема ===================== */
:root {
  --bg:        #0c0f17;
  --bg-elev:   #141926;
  --bg-elev-2: #1b2233;
  --bg-input:  #0f141f;
  --border:    #232b3d;
  --border-2:  #2f3a52;
  --text:      #e6eaf2;
  --text-dim:  #9aa6be;
  --text-mute: #6b7790;
  --accent:    #4f8cff;
  --accent-2:  #3a73e6;
  --green:     #34d399;
  --green-dim: #0f3d2e;
  --red:       #f87171;
  --red-dim:   #3d1717;
  --amber:     #fbbf24;
  --up:        #f0883e;
  --down:      #4f8cff;
  --radius:    14px;
  --radius-sm: 9px;
  --shadow:    0 8px 30px rgba(0,0,0,.4);
  --mono:      ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --font:      system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1100px 600px at 80% -10%, rgba(79,140,255,.10), transparent 60%),
    radial-gradient(900px 500px at -10% 0%, rgba(52,211,153,.06), transparent 55%),
    var(--bg);
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

button { font-family: inherit; cursor: pointer; }
input, select, button { font-size: 15px; }

.hidden { display: none !important; }
.muted  { color: var(--text-dim); }
.center { text-align: center; }

/* ===================== Кнопки ===================== */
.btn {
  border: 1px solid var(--border-2);
  background: var(--bg-elev-2);
  color: var(--text);
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  font-weight: 550;
  transition: background .15s, border-color .15s, transform .05s, opacity .15s;
  white-space: nowrap;
  line-height: 1.2;
}
.btn:hover    { background: #232c40; border-color: #3a4761; }
.btn:active   { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: var(--accent-2);
  color: #fff;
}
.btn-primary:hover { background: linear-gradient(180deg, #5d97ff, #4079ef); }

.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-elev-2); }

.btn-danger { background: var(--red-dim); border-color: #5a2626; color: #ffb4b4; }
.btn-danger:hover { background: #4d1d1d; border-color: #7a3030; }

.btn-block { width: 100%; padding: 11px; }

.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 7px; }

/* ===================== Экран логина ===================== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 34px 30px 30px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-logo { font-size: 40px; text-align: center; line-height: 1; }
.login-card h1 { text-align: center; font-size: 22px; }
.login-sub { text-align: center; color: var(--text-dim); margin: -8px 0 8px; font-size: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--text-dim); font-weight: 550; }

input[type=text], input[type=password], input[type=number], select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,140,255,.18);
}
input::placeholder { color: var(--text-mute); }

.form-error {
  background: var(--red-dim);
  border: 1px solid #5a2626;
  color: #ffc2c2;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* ===================== Топбар ===================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(12,15,23,.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -.01em; display: inline-flex; align-items: center; gap: 8px; }
.brand-icon { font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.me-user { color: var(--text-dim); font-size: 14px; }

/* ===================== Контейнер ===================== */
.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ===================== Карточки ===================== */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 14px;
}
.stat { padding: 15px 16px; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-mute); font-weight: 600; }
.stat-value { font-size: 24px; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--text-dim); min-height: 14px; }

.stat-traffic { font-size: 17px; display: flex; gap: 14px; flex-wrap: wrap; }
.stat-traffic .up   { color: var(--up); }
.stat-traffic .down { color: var(--down); }
.stat-traffic span span { font-variant-numeric: tabular-nums; }

.status-line { display: inline-flex; align-items: center; gap: 9px; font-size: 19px; }
.dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--text-mute);
  box-shadow: 0 0 0 0 rgba(0,0,0,0);
  flex: none;
}
.dot.on  { background: var(--green); box-shadow: 0 0 10px 1px rgba(52,211,153,.55); }
.dot.off { background: var(--red);   box-shadow: 0 0 10px 1px rgba(248,113,113,.45); }

/* Прогресс-бар (CPU/RAM/квота) */
.bar {
  width: 100%;
  height: 6px;
  background: var(--bg-elev-2);
  border-radius: 99px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #6ea3ff);
  border-radius: 99px;
  transition: width .4s ease, background .3s;
}
.bar-fill.warn { background: linear-gradient(90deg, #d99a2b, var(--amber)); }
.bar-fill.crit { background: linear-gradient(90deg, #c4453f, var(--red)); }

/* ===================== Панели (график / таблица) ===================== */
.panel { padding: 18px 20px 20px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.panel-head h2 { font-size: 17px; }
.count { color: var(--text-mute); font-weight: 500; font-size: 14px; }

.range-switch {
  display: inline-flex;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.range-switch button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 5px 12px;
  border-radius: 6px;
  font-weight: 550;
  font-size: 13px;
  transition: background .15s, color .15s;
}
.range-switch button:hover { color: var(--text); }
.range-switch button.active { background: var(--accent); color: #fff; }

.chart-wrap { position: relative; height: 300px; width: 100%; }

/* ===================== Таблица ===================== */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 720px;
}
.users-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-mute);
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.users-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.users-table tbody tr:hover { background: rgba(255,255,255,.018); }
.users-table tbody tr:last-child td { border-bottom: none; }

.u-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.u-online {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-mute); flex: none;
}
.u-online.on { background: var(--green); box-shadow: 0 0 7px 1px rgba(52,211,153,.5); }
.u-uuid { font-family: var(--mono); font-size: 11px; color: var(--text-mute); }
.u-note { font-size: 12px; color: var(--text-dim); margin: 1px 0 2px; max-width: 260px; word-break: break-word; line-height: 1.3; }

.col-actions { text-align: right; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.traffic-cell { font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.4; display: flex; flex-direction: column; gap: 3px; }
.traffic-cell .up   { color: var(--up); }
.traffic-cell .down { color: var(--down); }
.tc-proto { display: flex; align-items: baseline; gap: 8px; }
.tc-proto .up, .tc-proto .down { font-size: 13px; }
.tc-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .03em;
  color: var(--text-mute);
  min-width: 44px;
  display: inline-block;
}
.tc-proto.dim { opacity: .45; }

/* Бейджи */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 99px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-on   { background: var(--green-dim); color: #6ee7b7; border-color: #1d5c45; }
.badge-off  { background: #2a2f3c;          color: var(--text-dim); border-color: var(--border-2); }
.badge-warn { background: #3a2f10;          color: var(--amber); border-color: #5c4a18; }
.badge-stack { display: inline-flex; flex-direction: column; gap: 4px; align-items: flex-start; }

/* Прогресс квоты в таблице */
.quota-cell { min-width: 150px; }
.quota-text { font-size: 12px; color: var(--text-dim); margin-bottom: 5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.quota-text b { color: var(--text); font-weight: 600; }
.quota-unlim { color: var(--text-mute); font-size: 13px; }

.expire-ok   { color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.expire-soon { color: var(--amber); }
.expire-bad  { color: var(--red); font-weight: 600; }
.expire-never{ color: var(--text-mute); }

/* ===================== Модалки ===================== */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4,6,11,.66);
  backdrop-filter: blur(3px);
  animation: fade .15s ease;
}
.modal {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: pop .16s cubic-bezier(.2,.9,.3,1.2);
}
.modal-wide { max-width: 720px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  z-index: 1;
}
.modal-head h3 { font-size: 17px; }
.modal-close {
  border: none; background: transparent; color: var(--text-dim);
  font-size: 26px; line-height: 1; width: 32px; height: 32px;
  border-radius: 8px; transition: background .15s, color .15s;
}
.modal-close:hover { background: var(--bg-elev-2); color: var(--text); }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
  flex-wrap: wrap;
}
.modal-actions .spacer { flex: 1; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop  { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* Поля формы в модалке */
.hint { font-size: 12px; color: var(--text-mute); margin-top: -2px; }
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
  font-size: 14px;
}
.checkbox-row input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }

/* Подписка / QR */
.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.qr-box img {
  width: 220px; height: 220px;
  background: #fff;
  border-radius: 12px;
  padding: 10px;
  image-rendering: pixelated;
}
.copy-field { display: flex; flex-direction: column; gap: 6px; }
.copy-field > label { font-size: 13px; color: var(--text-dim); font-weight: 550; }
.copy-row { display: flex; gap: 8px; }
.copy-row input {
  flex: 1;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-input);
  color: var(--text-dim);
}
.copy-row .btn { flex: none; }

/* Двухколоночная раскладка модалки «Подписка»: слева VLESS, справа AmneziaWG */
.sub-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 720px) {
  .sub-cols { grid-template-columns: 1fr; }
}
.sub-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0; /* чтобы длинные ссылки/textarea не распирали колонку грида */
}
.sub-col-head {
  font-size: 15px;
  font-weight: 650;
  color: var(--text);
  padding-bottom: 6px;
  margin-bottom: 2px;
  border-bottom: 1px solid var(--border);
}
.sub-col .copy-row input { min-width: 0; }

.modal-chart-wrap { position: relative; height: 280px; width: 100%; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--text-mute); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* ===================== Тосты ===================== */
.toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 40px));
}
.toast {
  background: var(--bg-elev-2);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: toastIn .2s ease;
}
.toast.ok   { border-left-color: var(--green); }
.toast.err  { border-left-color: var(--red); }
.toast.fade-out { animation: toastOut .25s ease forwards; }
@keyframes toastIn  { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

/* Спиннер */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.25);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  animation: spin .7s linear infinite;
  vertical-align: -3px;
}
.loading-block { text-align: center; padding: 30px; color: var(--text-dim); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== Адаптив (телефон) ===================== */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .container { padding: 16px 12px 50px; gap: 16px; }
  .topbar { padding: 10px 14px; }
  .brand { font-size: 15px; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 12px 13px; }
  .stat-value { font-size: 20px; }
  .panel { padding: 14px 14px 16px; }
  .chart-wrap { height: 230px; }
  .panel-head h2 { font-size: 15px; }
  .qr-box img { width: 180px; height: 180px; }
  .modal-body { padding: 16px; }
}
@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
}

.variants-title { margin: 16px 0 8px; font-weight: 600; font-size: 13px; opacity: .85; }
