/* Best 4G Proxy NG — dark theme, vanilla CSS, no external deps */

:root {
  --bg: #0e1116;
  --bg-elevated: #161b22;
  --bg-card: #1b2129;
  --bg-input: #0e1116;
  --border: #2a313c;
  --border-strong: #3a424f;
  --text: #e6edf3;
  --text-muted: #9aa6b2;
  --text-dim: #6e7a87;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --green: #2ea043;
  --green-soft: rgba(46, 160, 67, 0.16);
  --red: #f85149;
  --red-soft: rgba(248, 81, 73, 0.16);
  --amber: #d29922;
  --amber-soft: rgba(210, 153, 34, 0.16);
  --purple: #a371f7;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { 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;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.app-main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.page-title { font-size: 1.5rem; font-weight: 650; margin: 0; }
.page-sub { color: var(--text-muted); font-size: 0.9rem; margin: 4px 0 0; }

/* ---------- Navbar ---------- */
.navbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  height: 56px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--text);
  font-size: 1.02rem;
  white-space: nowrap;
}
.nav-brand svg { color: var(--accent); }
.nav-links { display: flex; gap: 4px; }
.nav-link {
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.nav-link:hover { color: var(--text); background: var(--bg-card); text-decoration: none; }
.nav-link.active { color: var(--text); background: var(--accent-soft); }
.nav-spacer { flex: 1; }
.nav-meta { display: flex; align-items: center; gap: 14px; }
.nav-user { color: var(--text-muted); font-size: 0.88rem; white-space: nowrap; }
.nav-user strong { color: var(--text); font-weight: 600; }
.nav-version { color: var(--text-dim); font-size: 0.74rem; font-family: var(--mono); }

/* dropdown */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 180px;
  padding: 6px;
  z-index: 60;
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
}
.dropdown-item:hover { background: var(--bg-elevated); }
.dropdown-item.danger { color: var(--red); }
.dropdown-item.active { color: var(--text); background: var(--accent-soft); }
.dropdown-menu-left { right: auto; left: 0; min-width: 150px; }
/* an API trigger that reads as a nav link, with the chevron inline */
.nav-dropdown-btn { display: inline-flex; align-items: center; gap: 5px; background: none; border: none; cursor: pointer; font: inherit; }

/* mobile nav toggle — .btn below also sets display, so raise specificity to keep
   it hidden on desktop; the media query flips it back on for narrow screens. */
.navbar .nav-toggle { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 550;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-elevated); border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { flex-shrink: 0; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--red); border-color: rgba(248,81,73,0.4); }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-card); }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-green { color: var(--green); background: var(--green-soft); }
.badge-red { color: var(--red); background: var(--red-soft); }
.badge-amber { color: var(--amber); background: var(--amber-soft); }
.badge-gray { color: var(--text-muted); background: rgba(255,255,255,0.06); }
.badge-purple { color: var(--purple); background: rgba(163,113,247,0.16); }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

/* key/value rows */
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 0.88rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; word-break: break-all; }
.kv dd.mono { font-family: var(--mono); font-size: 0.84rem; }

/* system info bar */
.sysinfo {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  padding: 16px 18px;
  margin-bottom: 22px;
}
.sysinfo .item { display: flex; flex-direction: column; gap: 2px; }
.sysinfo .item span.label { color: var(--text-dim); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.sysinfo .item span.val { font-weight: 600; }
.sysinfo .item span.val.mono { font-family: var(--mono); font-size: 0.86rem; }

/* live indicator */
.live-indicator { display: inline-flex; align-items: center; gap: 7px; color: var(--text-muted); font-size: 0.84rem; }
.live-indicator .pulse {
  width: 9px; height: 9px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 0 rgba(46,160,67,0.6);
  animation: pulse 1.8s infinite;
}
.live-indicator.paused .pulse { background: var(--amber); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(46,160,67,0.5); }
  70% { box-shadow: 0 0 0 7px rgba(46,160,67,0); }
  100% { box-shadow: 0 0 0 0 rgba(46,160,67,0); }
}

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.85rem; font-weight: 550; color: var(--text); }
.field .hint { font-size: 0.78rem; color: var(--text-dim); }
.input, .select, textarea.input {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}
.input:focus, .select:focus, textarea.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea.input { resize: vertical; min-height: 70px; font-family: var(--mono); font-size: 0.82rem; }
.select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa6b2' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; padding-right: 32px;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

/* checkbox / toggle */
.checkbox { display: flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.checkbox span { font-size: 0.88rem; }

/* fieldset section */
.section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin: 0;
}
.section > legend, .section-title {
  font-weight: 650;
  font-size: 0.98rem;
  padding: 0 6px;
  color: var(--text);
}
.section-body { display: flex; flex-direction: column; gap: 16px; margin-top: 6px; }

/* repeatable rows (proxy users) */
.repeat-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; }

/* form actions sticky */
.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  position: sticky;
  bottom: 0;
  padding: 14px 0;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

/* error list */
.error-list {
  border: 1px solid var(--red);
  background: var(--red-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 0 0 18px;
}
.error-list h4 { margin: 0 0 8px; color: var(--red); font-size: 0.92rem; }
.error-list ul { margin: 0; padding-left: 18px; }
.error-list li { margin: 3px 0; font-size: 0.88rem; }
.error-list code { color: var(--amber); font-family: var(--mono); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card { width: 100%; max-width: 380px; padding: 32px; }
.login-card .brand {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  margin-bottom: 6px; font-size: 1.25rem; font-weight: 700;
}
.login-card .brand svg { color: var(--accent); }
.login-card .tagline { text-align: center; color: var(--text-muted); margin: 0 0 26px; font-size: 0.88rem; }

/* ---------- Tables (modems list) ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.tbl th, table.tbl td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
table.tbl th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; background: var(--bg-elevated); }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr:hover td { background: rgba(255,255,255,0.02); }

/* token display */
.token-box {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
  background: var(--bg-input); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px 10px;
}
.token-box code { flex: 1; font-family: var(--mono); font-size: 0.74rem; word-break: break-all; color: var(--green); }
.key-cell { display: flex; align-items: center; gap: 8px; }
.key-cell .key-code { font-family: var(--mono); font-size: 0.76rem; word-break: break-all; color: var(--green); }

/* API Docs page */
.doc-h2 { font-size: 1rem; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.doc-h3 { font-size: 0.9rem; margin: 22px 0 6px; color: var(--text); }
.doc-note { font-size: 0.82rem; color: var(--text-muted); margin: 8px 0 0; }
.docs p code, .doc-note code { font-family: var(--mono); font-size: 0.82em; color: var(--green); }
.doc-block { border: 1px solid var(--border); border-radius: var(--radius-sm); margin: 8px 0; overflow: hidden; }
.doc-block-head { display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px; background: var(--bg-elevated, #151a21); border-bottom: 1px solid var(--border); }
.doc-block-title { font-size: 0.74rem; color: var(--text-muted); font-family: var(--mono); }
.doc-block pre { margin: 0; padding: 10px 12px; overflow-x: auto; font-family: var(--mono);
  font-size: 0.78rem; line-height: 1.5; color: var(--text); white-space: pre; }
.rotate-url { font-family: var(--mono); font-size: 0.76rem; color: var(--text-muted); margin-top: 6px; word-break: break-all; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 100; backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 560px; max-height: 86vh; display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; border-radius: var(--radius-sm); display: flex; }
.modal-close:hover { background: var(--bg-elevated); color: var(--text); }

/* ---------- Toast ---------- */
.toast-root {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 40px));
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-left-width: 4px; border-radius: var(--radius-sm);
  padding: 12px 14px; box-shadow: var(--shadow);
  animation: toastIn 0.2s ease; font-size: 0.9rem;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.info { border-left-color: var(--accent); }
.toast .icon { flex-shrink: 0; margin-top: 1px; }
.toast.success .icon { color: var(--green); }
.toast.error .icon { color: var(--red); }
.toast.info .icon { color: var(--accent); }
.toast .msg { flex: 1; word-break: break-word; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }

/* ---------- States ---------- */
.empty-state, .loading-state, .error-state {
  text-align: center; padding: 64px 20px; color: var(--text-muted);
}
.empty-state svg, .error-state svg { color: var(--text-dim); margin-bottom: 14px; }
.empty-state h3 { color: var(--text); margin: 0 0 6px; font-weight: 600; }
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border-strong);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.muted { color: var(--text-muted); }
.mono { font-family: var(--mono); }
.text-sm { font-size: 0.85rem; }

/* status messages list inside cards */
/* ---- collapsible, scrollable per-modem status log ---- */
.status-log { margin: 10px 0 0; border: 1px solid var(--border, #2a323d); border-radius: 8px; background: var(--surface-2, #1b212b); }
.status-log > summary {
  cursor: pointer; list-style: none; padding: 7px 10px; font-size: 0.78rem;
  color: var(--text-muted, #9aa4b2); display: flex; align-items: center; gap: 6px; user-select: none;
}
.status-log > summary::-webkit-details-marker { display: none; }
.status-log > summary::after { content: "▸"; margin-left: auto; transition: transform .15s ease; }
.status-log[open] > summary::after { transform: rotate(90deg); }
.status-log > summary:hover { color: var(--text, #e6e9ef); }
.status-count { background: var(--border, #2a323d); border-radius: 10px; padding: 0 7px; font-size: 0.72rem; }
.status-msgs {
  margin: 0; padding: 6px 10px 10px; list-style: none; display: flex; flex-direction: column; gap: 4px;
  max-height: 160px; overflow-y: auto;            /* scrollable */
  border-top: 1px solid var(--border, #2a323d);
}
.status-msgs li { font-size: 0.8rem; color: var(--text-muted); padding-left: 14px; position: relative; word-break: break-word; }
.status-msgs li::before { content: "›"; position: absolute; left: 0; color: var(--text-dim); }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .nav-links { display: none; position: absolute; top: 56px; left: 0; right: 0; background: var(--bg-elevated); flex-direction: column; padding: 8px; border-bottom: 1px solid var(--border); }
  .nav-links.open { display: flex; }
  .nav-link { padding: 11px 12px; }
  .navbar .nav-toggle { display: inline-flex; }
  .nav-spacer { flex: 1; }
  .nav-user { display: none; }
  .field-row, .field-row-3 { grid-template-columns: 1fr; }
  .repeat-row { grid-template-columns: 1fr; }
  .app-main { padding: 18px 14px 56px; }
}

/* ---- status page refresh toolbar ---- */
.status-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.status-toolbar .auto-refresh {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted, #9aa4b2);
}
.select-sm {
  background: var(--surface-2, #1b212b);
  color: var(--text, #e6e9ef);
  border: 1px solid var(--border, #2a323d);
  border-radius: 7px; padding: 4px 8px; font-size: 13px; cursor: pointer;
}
.select-sm:focus { outline: none; border-color: var(--accent, #4f8cff); }
.live-indicator.paused .pulse { background: var(--muted, #9aa4b2); animation: none; }

/* ---- proxy access box on status cards ---- */
.proxy-box { margin: 10px 0 0; padding: 9px 11px; border: 1px solid var(--border, #2a323d); border-radius: 8px; background: rgba(79,140,255,0.06); }
.proxy-box.proxy-none { color: var(--text-muted, #9aa4b2); font-size: 0.8rem; background: none; }
.proxy-title { font-size: 0.78rem; color: var(--text-muted, #9aa4b2); display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.proxy-cred { display: flex; align-items: center; gap: 6px; }
.proxy-url { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8rem; background: var(--surface-2,#1b212b); padding: 4px 7px; border-radius: 6px; }
.proxy-fields { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; font-size: 0.74rem; color: var(--text-muted,#9aa4b2); }
.proxy-fields code { color: var(--text,#e6e9ef); cursor: pointer; }
.proxy-fields code:hover { text-decoration: underline; }
.btn-xs { padding: 3px 6px; font-size: 0.72rem; line-height: 1; }

/* ---- status page filter bar + modem table ---- */
.filter-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 14px; }
.filter-bar .input { width: 260px; max-width: 100%; padding: 5px 9px; font-size: 13px; }
.filter-count { font-size: 12px; color: var(--text-muted, #9aa4b2); margin-left: auto; }

table.tbl-status td { vertical-align: middle; padding: 9px 12px; }
table.tbl-status .col-num { width: 1%; white-space: nowrap; }
table.tbl-status .col-phone { width: 1%; white-space: nowrap; }
table.tbl-status .col-state { white-space: nowrap; }
table.tbl-status .col-actions { width: 1%; white-space: nowrap; text-align: right; }
table.tbl-status .col-actions .btn { margin-left: 4px; }
.num-tag {
  display: inline-block; min-width: 26px; text-align: center;
  font-family: var(--mono); font-size: 0.74rem; font-weight: 600;
  color: var(--text-muted, #9aa4b2); background: rgba(255,255,255,0.06);
  border-radius: 6px; padding: 2px 5px;
}
.status-row.is-open td { background: rgba(79,140,255,0.05); }
.status-detail > td { background: rgba(255,255,255,0.02); padding: 10px 14px 14px; }
.status-detail .proxy-box { margin-top: 0; }
