:root {
  --bg: #0f1115;
  --bg2: #171a21;
  --bg3: #1e2330;
  --border: #2a3142;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #4f8cff;
  --ok: #3ecf8e;
  --warn: #f0b429;
  --danger: #f07178;
  --row-hover: #222836;
  --selected: #243552;
  --font: "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mono: "SF Mono", "Menlo", "Consolas", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }
.ok { color: var(--ok); }

#app { min-height: 100%; display: flex; flex-direction: column; }

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse at top, #1a2236 0%, var(--bg) 60%);
}
.gate-card {
  width: min(420px, 100%);
  padding: 28px;
}
.gate-card h1 { margin: 0 0 8px; font-size: 1.6rem; }
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0,0,0,.35);
}
label {
  display: block;
  margin: 12px 0;
  color: var(--muted);
  font-size: 12px;
}
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  font: inherit;
}
textarea { min-height: 100px; font-family: var(--mono); font-size: 12px; }
button {
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 11px;
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
}
button:hover { border-color: #3d4860; background: #262c3c; }
button.primary {
  background: var(--accent);
  border-color: #3a74e0;
  color: white;
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  font-weight: 600;
}
button.danger { color: var(--danger); }
button.ok { border-color: #2f8f62; color: var(--ok); }
button:disabled { opacity: .5; cursor: not-allowed; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.brand {
  font-weight: 700;
  letter-spacing: .02em;
  margin-right: 8px;
  color: #f0c14b;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
}

.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  height: calc(100vh - 88px);
  overflow: hidden;
}
.accounts-pane, .detail-pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  min-width: 240px;
}
.accounts-pane {
  flex: 0 0 auto;
  width: var(--accounts-pane-width, 42%);
  max-width: calc(100% - 260px);
}
.detail-pane {
  flex: 1 1 auto;
  min-width: 280px;
  overflow: hidden;
}
.pane-resizer {
  flex: 0 0 6px;
  width: 6px;
  cursor: col-resize;
  background: var(--border);
  position: relative;
  z-index: 5;
  touch-action: none;
}
.pane-resizer::after {
  content: "";
  position: absolute;
  inset: 0 -3px;
}
.pane-resizer:hover,
.pane-resizer.dragging {
  background: var(--accent);
}
body.pane-resizing,
body.col-resizing {
  cursor: col-resize !important;
  user-select: none !important;
}
body.pane-resizing *,
body.col-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}
.pane-header {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  font-weight: 600;
}
.table-wrap { overflow: auto; flex: 1; }
table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}
th, td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#accounts-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg3);
  z-index: 2;
  color: var(--muted);
  font-weight: 600;
  padding-right: 10px;
}
.th-label {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
  touch-action: none;
}
.col-resizer:hover,
.col-resizer.dragging {
  background: var(--accent);
}
tbody tr { cursor: pointer; user-select: none; }
tbody tr:hover { background: var(--row-hover); }
tbody tr.selected { background: var(--selected); }
tbody tr.selected td { box-shadow: inset 0 0 0 9999px rgba(79, 140, 255, 0.08); }
tbody tr input[data-check] { cursor: pointer; width: 16px; height: 16px; }
.status-CONNECTED { color: var(--ok); font-weight: 600; }
.status-CONNECTING, .status-AUTHENTICATING { color: var(--warn); }
.status-ERROR { color: var(--danger); }
.status-DISCONNECTED { color: var(--muted); }

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.tab {
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  padding: 10px 16px;
  color: var(--muted);
}
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.tab-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.console {
  margin: 0;
  flex: 1;
  overflow: auto;
  padding: 12px;
  background: #0b0d12;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.captcha-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.map-wrap {
  flex: 1;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #0b0d12;
}
#map-image {
  image-rendering: pixelated;
  max-width: 100%;
  background: #222;
  border: 1px solid var(--border);
}
.input-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  align-items: center;
}
.target-label {
  display: flex;
  gap: 6px;
  align-items: center;
  margin: 0;
  color: var(--muted);
  white-space: nowrap;
}
.target-label select { width: auto; margin: 0; }
#btn-send { width: auto; margin: 0; }

.status-bar {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  color: var(--muted);
  font-size: 12px;
}
.status-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.status-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 12px;
  min-width: 0;
}
#status-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-progress-label {
  flex: 0 1 auto;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--accent);
}
/* Full-width bar under the tiny status text */
.status-progress {
  width: 100%;
  padding: 0 12px 6px;
}
.status-progress .token-progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #0a0c10;
  border: 1px solid var(--border);
  overflow: hidden;
}
.token-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 160px;
  max-width: 100%;
  flex: 1;
}
.token-progress-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--bg3);
  border: 1px solid var(--border);
  overflow: hidden;
  min-width: 80px;
}
.token-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3a74e0, var(--accent));
  transition: width 0.25s ease-out;
  min-width: 0;
}
/* Animated stripe while total is unknown / starting */
.token-progress-bar.indeterminate,
.modal-progress-fill.indeterminate {
  width: 40% !important;
  min-width: 48px;
  transform: none !important;
  animation: token-progress-slide 1.1s ease-in-out infinite;
}
@keyframes token-progress-slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

/* Tokens-to-Renew modal progress (standalone — don't share footer flex layout) */
.modal-progress-wrap {
  margin: 10px 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg3);
}
.modal-progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
}
.modal-progress-meta #tr-progress-label {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.modal-progress-meta #tr-progress-pct {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.modal-progress-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: #0a0c10;
  border: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}
.modal-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #3a74e0, var(--accent), #7eb0ff);
  background-size: 200% 100%;
  transition: width 0.3s ease-out;
  will-change: width, transform;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.55);
}
.modal-card {
  position: relative;
  width: min(640px, 100%);
  max-height: min(90vh, 900px);
  overflow: auto;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}
.modal-header, .modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-footer {
  border-bottom: 0;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}
.modal-header h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 16px; }
.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}
.form-grid {
  display: grid;
  gap: 4px 12px;
}
.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 80;
  max-width: min(420px, calc(100vw - 32px));
  background: #1c2434;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  white-space: pre-wrap;
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }

.proxy-list, .server-list {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}
.help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin: 0 0 12px;
}
.help a { color: var(--accent); }

@media (max-width: 1100px) {
  .workspace {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 88px);
  }
  .accounts-pane {
    width: 100% !important;
    max-width: none;
    max-height: 40vh;
  }
  .pane-resizer {
    width: 100%;
    height: 6px;
    flex-basis: 6px;
    cursor: row-resize;
  }
  .detail-pane { min-height: 50vh; }
}
