/* ═══════════════════════════════════════════════════════════
   PROXY GATEWAY — style.css  (consolidated)
   ═══════════════════════════════════════════════════════════ */

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

/* ── Tokens ────────────────────────────────────────────────── */
:root {
  --bg:           #07090e;
  --bg-card:      #0c1220;
  --bg-hover:     #101a2e;
  --bg-selected:  rgba(48, 120, 220, 0.07);
  --border:       #182030;
  --border-hi:    #243650;
  --text-dim:     #3d5570;
  --text:         #6b90b8;
  --text-hi:      #a8c4e0;
  --text-bright:  #d4e8ff;
  --accent:       #3b9eff;
  --accent-dim:   #152644;
  --accent-glow:  rgba(59, 158, 255, 0.15);
  --green:        #20d870;
  --green-dim:    rgba(32, 216, 112, 0.1);
  --red:          #f04040;
  --red-dim:      rgba(240, 64, 64, 0.1);
  --amber:        #f0a020;
  --amber-dim:    rgba(240, 160, 32, 0.1);
  --cyan:         #00cccc;
  --purple:       #a070f0;
  --orange:       #f07030;

  --font-mono:    'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-disp:    'Oxanium', 'Orbitron', sans-serif;
  --radius:       2px;
  --t:            140ms ease;
}

/* ── Base ──────────────────────────────────────────────────── */
html { font-size: 14px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Background grid ───────────────────────────────────────── */
.bg-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image:
    linear-gradient(rgba(24, 32, 48, 0.6) 1px, transparent 1px),
    linear-gradient(90deg, rgba(24, 32, 48, 0.6) 1px, transparent 1px);
  background-size: 44px 44px;
  pointer-events: none;
}

/* ── Layout ────────────────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 28px;
  position: relative;
  z-index: 1;
}

/* ── Header ────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 200;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 9, 14, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-hex {
  font-size: 30px;
  color: var(--accent);
  line-height: 1;
  filter: drop-shadow(0 0 10px rgba(59, 158, 255, 0.6));
  animation: hexPulse 4s ease-in-out infinite;
}

@keyframes hexPulse {
  0%, 100% { filter: drop-shadow(0 0 8px rgba(59, 158, 255, 0.5)); }
  50%       { filter: drop-shadow(0 0 16px rgba(59, 158, 255, 0.9)); }
}

.brand-title {
  font-family: var(--font-disp);
  font-size: 21px;
  font-weight: 800;
  color: var(--text-bright);
  letter-spacing: 0.14em;
  line-height: 1;
}

.brand-sub {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-dim);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-top: 4px;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 15px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--t);
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-outline {
  color: var(--text);
  border-color: var(--border-hi);
  background: transparent;
}
.btn-outline:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-glow);
}

.btn-primary {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: var(--accent-dim);
}
.btn-primary:not(:disabled):hover {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(59, 158, 255, 0.4);
}

.btn-ghost {
  color: var(--text-dim);
  border-color: transparent;
  background: transparent;
  padding: 4px 9px;
  font-size: 11px;
}
.btn-ghost:not(:disabled):hover {
  color: var(--text-hi);
  background: var(--bg-hover);
  border-color: var(--border-hi);
}

/* ── Main / Sections ───────────────────────────────────────── */
main { padding: 40px 0 20px; }

.section { margin-bottom: 52px; }

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 16px;
}

.section-title {
  font-family: var(--font-disp);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.25em;
  color: var(--text-dim);
  flex-shrink: 0;
}

.probe-summary {
  font-size: 12px;
  color: var(--text-dim);
}

/* ── Table ─────────────────────────────────────────────────── */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  overflow-x: auto;
}

.proxy-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.proxy-table thead {
  background: var(--bg-card);
}

.proxy-table th {
  padding: 9px 16px;
  text-align: left;
  font-family: var(--font-disp);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

.proxy-table td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  transition: background var(--t);
}

.proxy-table tbody tr:last-child td { border-bottom: none; }

.proxy-table tbody tr {
  cursor: pointer;
  transition: background var(--t);
}
.proxy-table tbody tr:hover { background: var(--bg-hover); }
.proxy-table tbody tr.row-selected {
  background: var(--bg-selected);
}
.proxy-table tbody tr.row-selected td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}

/* Table cell types */
.cell-name   { color: var(--text-hi); font-weight: 500; white-space: nowrap; }
.cell-host   { color: var(--text-hi); font-size: 12px; }
.cell-port   { color: var(--cyan); font-weight: 600; font-size: 13px; text-align: right; }
.cell-region { font-size: 11px; color: var(--text-hi); letter-spacing: 0.1em; white-space: nowrap; }

/* Notes cell — same brightness as Name column */
.cell-notes  { color: var(--text-hi); font-weight: 500; max-width: 420px; word-break: break-word; }

/* Protocol badges */
.type-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 2px;
  font-family: var(--font-disp);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  border: 1px solid;
}
.type-http        { color: #60aaff; border-color: #1a3866; background: rgba(48, 96, 200, 0.12); }
.type-https       { color: #40e0aa; border-color: #0d4030; background: rgba(16, 120, 80,  0.12); }
.type-socks5      { color: #c080ff; border-color: #3a1060; background: rgba(120, 40, 180, 0.12); }
.type-shadowsocks { color: #ff9050; border-color: #602010; background: rgba(180, 64, 16,  0.12); }
.type-mtproto     { color: #40ccff; border-color: #0d3050; background: rgba(16, 100, 160, 0.12); }

/* ── Latency cell ──────────────────────────────────────────── */
.latency-cell { min-width: 160px; }

.lat-idle { color: var(--text-dim); font-size: 12px; }

.lat-running {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--amber);
  font-size: 11px;
}

.lat-value { font-weight: 500; font-size: 13px; }
.lat-ok    { color: var(--green); }
.lat-slow  { color: var(--amber); }
.lat-bad   { color: var(--red);   }

.lat-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lat-bar {
  height: 3px;
  width: 64px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}

.lat-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}
.lat-bar-fill.ok   { background: var(--green); }
.lat-bar-fill.slow { background: var(--amber); }
.lat-bar-fill.bad  { background: var(--red);   }

/* ── Probe note ────────────────────────────────────────────── */
.probe-note {
  margin-top: 12px;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.8;
  max-width: 820px;
}

/* ── Formats panel ─────────────────────────────────────────── */
.formats-proxy-label {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}

.formats-empty {
  border: 1px dashed var(--border-hi);
  border-radius: var(--radius);
  padding: 44px 32px;
  text-align: center;
  color: var(--text-dim);
}

.formats-empty-icon {
  font-size: 30px;
  margin-bottom: 12px;
  color: var(--border-hi);
}

.formats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(420px, 1fr));
  gap: 12px;
  width: 100%;
  overflow-x: auto;
}

.format-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  overflow: hidden;
  transition: border-color var(--t);
  width: 100%;
  min-width: 420px;
  margin-bottom: 16px;
}
.format-card:hover { border-color: var(--border-hi); }

.format-card-wide { grid-column: 1 / -1; }

.format-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 13px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}

.format-label {
  font-family: var(--font-disp);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--text-dim);
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 2px;
  transition: all var(--t);
  line-height: 1;
}
.copy-btn:hover  { color: var(--text-hi); background: var(--bg-hover); }
.copy-btn.copied { color: var(--green); }

.format-code {
  display: block;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-hi);
  line-height: 1.75;
  overflow-x: auto;
  white-space: pre;
  word-break: normal;
  overflow: visible;
}

/* Syntax tokens */
.tk-scheme { color: var(--accent);      }
.tk-auth   { color: var(--amber);       }
.tk-host   { color: var(--text-bright); }
.tk-port   { color: var(--cyan);        }
.tk-key    { color: var(--text-dim);    }
.tk-val    { color: #88ccaa;            }
.tk-cmd    { color: var(--purple);      }
.tk-frag   { color: var(--purple);      }

/* ── Spinner ───────────────────────────────────────────────── */
.spinner {
  width: 11px;
  height: 11px;
  border: 2px solid rgba(59, 158, 255, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}
.hidden { display: none !important; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Footer ────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 22px 0;
  font-size: 11px;
  color: var(--text-dim);
  position: relative;
  z-index: 1;
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Proxy groups ───────────────────────────────────────────── */
.proxy-group { margin-bottom: 24px; }
.proxy-group:last-child { margin-bottom: 0; }

/* Group header: label left, clear button right */
.proxy-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-disp);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.28em;
  color: var(--text-dim);
  padding: 0 0 8px 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

/* ── Custom checkboxes ──────────────────────────────────────── */
.th-check, .td-check {
  width: 36px;
  padding: 0 0 0 14px !important;
  text-align: center;
  vertical-align: middle;
}

.chk-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
}

.chk-wrap input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.chk-box {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 1px solid var(--border-hi);
  border-radius: 2px;
  background: transparent;
  transition: all var(--t);
  position: relative;
  flex-shrink: 0;
}

.chk-wrap:hover .chk-box {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.chk-wrap input:checked + .chk-box {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.chk-wrap input:checked + .chk-box::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0px;
  width: 5px;
  height: 9px;
  border: 2px solid var(--accent);
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

/* Indeterminate state */
.chk-wrap input:indeterminate + .chk-box {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.chk-wrap input:indeterminate + .chk-box::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 5px;
  width: 8px;
  height: 2px;
  background: var(--accent);
  border: none;
  transform: none;
}

/* ── Selected section ───────────────────────────────────────── */
.selected-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}

/* ── Latency running / progress states ──────────────────────── */
.lat-running {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--amber);
  font-size: 11px;
}

.lat-attempts {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: 6px;
}

.lat-running-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 200px;
}

.lat-running-label {
  font-size: 11px;
  color: var(--amber);
  white-space: nowrap;
  min-width: 70px;
}

.lat-bar-run { width: 90px !important; flex-shrink: 0; }

.lat-err-hint {
  display: inline-block;
  margin-left: 8px;
  font-size: 10px;
  color: var(--red);
  opacity: 0.75;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

/* ── View toggle ─────────────────────────────────────────────── */
.view-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border-hi);
  border-radius: 3px;
  overflow: hidden;
}

.view-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 34px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background var(--t), color var(--t);
  white-space: nowrap;
}

.view-toggle-btn:hover {
  background: var(--bg-hover);
  color: var(--text-hi);
}

.view-toggle-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.view-toggle-btn + .view-toggle-btn {
  border-left: 1px solid var(--border-hi);
}

/* ── Server cards ────────────────────────────────────────────── */
#server-cards-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding-left: 44px;  /* room for floating clear buttons */
}
@media (max-width: 900px) {
  #server-cards-container { padding-left: 0; }
}

.server-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: visible;        /* allow clear btn to float outside */
  position: relative;
}

.server-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.server-card-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.server-card-icon {
  font-size: 18px;
  color: var(--accent);
  line-height: 1;
  opacity: 0.8;
}

.server-card-title {
  font-family: var(--font-disp);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-bright);
  margin: 0 0 3px 0;
  text-transform: uppercase;
}

.server-card-host {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

/* Header right side: badges + probe button */
.server-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* Probe server button — matches global btn-primary styling */
.probe-server-btn {
  font-size: 10px !important;
  padding: 5px 12px !important;
  letter-spacing: 0.08em;
}

/* Card body: floating clear btn sits to the LEFT of the card,
   the table fills the card normally with no layout tricks.
   This avoids any flex tricks that clip mobile columns.        */
.server-card-body {
  position: relative;
}

/* Clear button floats outside the card's left edge, vertically centred */
.server-card-clear-wrap {
  position: absolute;
  left: -44px;
  top: 0;
  bottom: 0;
  width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Group/card clear buttons ──────────────────────────────────
   .group-clear-btn — inline in protocol group header
   .card-clear-btn  — floats left of server card
   Both hidden until .visible is added.
────────────────────────────────────────────────────────────── */
.group-clear-btn,
.card-clear-btn {
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t);
  cursor: pointer;
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.06em;
  border-radius: 2px;
  white-space: nowrap;
  background: none;
  border: none;
}

.group-clear-btn.visible,
.card-clear-btn.visible {
  opacity: 1;
  pointer-events: auto;
}

/* Protocol-view group clear */
.group-clear-btn {
  font-size: 10px;
  padding: 2px 9px;
  height: 22px;
  color: var(--text-hi);
  background: var(--bg-hover);
  border: 1px solid var(--border-hi);
}
.group-clear-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-glow);
}

/* Server card clear: rotated vertical text, floats left of card */
.card-clear-btn {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  font-size: 9px;
  padding: 8px 3px;
  color: var(--text-hi);
  background: var(--bg-hover);
  border: 1px solid var(--border-hi);
  letter-spacing: 0.12em;
}
.card-clear-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-glow);
}

/* On narrow screens, hide floating clear btn (no room left of card) */
@media (max-width: 900px) {
  .server-card-clear-wrap { display: none; }
}

/* ── Server card inline connection strings ────────────────────── */
.server-inline-formats {
  border-top: 1px solid var(--border);
  padding: 20px 24px 24px;
  animation: fadeSlideIn 0.18s ease;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.server-formats-header { margin-bottom: 14px; }

.server-formats-label {
  font-family: var(--font-disp);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 800px) {
  .container { padding: 0 16px; }
  .brand-sub  { display: none; }
  .brand-title { font-size: 18px; }
  .formats-grid { grid-template-columns: 1fr; }
  .proxy-table th:nth-child(5),
  .proxy-table td:nth-child(5) { display: none; }
}

@media (max-width: 560px) {
  .header-actions .btn-outline span:last-child { display: none; }
  .proxy-table th:nth-child(2),
  .proxy-table td:nth-child(2) { display: none; }
}