:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --border-strong: #c3c9d2;
  --text: #1a1e24;
  --muted: #5b6471;
  --accent: #2456d3;
  --accent-hover: #1c47b3;
  --accent-text: #ffffff;
  --focus: #2456d3;

  --neutral-bg: #eceff3;
  --neutral-fg: #3c4450;
  --info-bg: #e2f1f8;
  --info-fg: #0a5f80;
  --progress-bg: #ede7fa;
  --progress-fg: #5a34ad;
  --success-bg: #e2f3e8;
  --success-fg: #17693b;
  --attention-bg: #fff1d6;
  --attention-fg: #8a5100;
  --danger-bg: #fdeaea;
  --danger-fg: #b3242a;
  --danger-solid: #c62a30;
  --danger-border: #f0b3b5;

  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 10px 30px rgb(15 23 42 / 0.18);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #181c22;
    --surface-2: #20252d;
    --border: #2c323b;
    --border-strong: #3b434e;
    --text: #e6e9ee;
    --muted: #98a2b0;
    --accent: #6f9bff;
    --accent-hover: #8aaeff;
    --accent-text: #0b1530;
    --focus: #8aaeff;

    --neutral-bg: #262c35;
    --neutral-fg: #c5ccd6;
    --info-bg: #10323f;
    --info-fg: #7fcbea;
    --progress-bg: #2b2244;
    --progress-fg: #c4b0f5;
    --success-bg: #12301f;
    --success-fg: #7fd6a1;
    --attention-bg: #3a2a0c;
    --attention-fg: #f2c46d;
    --danger-bg: #3a1618;
    --danger-fg: #ff9a9d;
    --danger-solid: #e0484e;
    --danger-border: #6b2a2e;

    --shadow: 0 10px 30px rgb(0 0 0 / 0.5);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

p {
  margin: 0;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.mono {
  font-family: var(--mono);
  font-size: 0.95em;
}

.num {
  font-variant-numeric: tabular-nums;
}

.prewrap {
  white-space: pre-wrap;
}

.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.error-text,
.status-error {
  color: var(--danger-fg);
}

.status-ok {
  color: var(--success-fg);
}

.status-warn {
  color: var(--attention-fg);
}

.status-muted {
  color: var(--muted);
}

.hint-attention {
  color: var(--attention-fg);
}

/* ── controls ─────────────────────────────────────────────────────────── */

input,
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  width: 100%;
  min-width: 0;
}

textarea {
  resize: vertical;
}

input:disabled {
  opacity: 0.6;
}

label {
  font-weight: 500;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-short {
  max-width: 90px;
  text-transform: uppercase;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 400;
  cursor: pointer;
}

.check input {
  width: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 500;
  line-height: 1.2;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

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

.btn-sm {
  padding: 5px 10px;
  font-size: 13px;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  font-size: 22px;
  line-height: 1;
  padding: 4px 10px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn-danger {
  background: var(--surface);
  color: var(--danger-fg);
  border-color: var(--danger-border);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-bg);
}

.btn-danger-solid {
  background: var(--danger-solid);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
}

.link {
  font: inherit;
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
}

.link:hover {
  text-decoration: underline;
}

/* ── badges, chips, callouts ──────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  vertical-align: middle;
}

.badge-sm {
  font-size: 11px;
  padding: 1px 7px;
}

.badge-strong.tone-danger {
  background: var(--danger-solid);
  color: #fff;
}

.tone-neutral {
  background: var(--neutral-bg);
  color: var(--neutral-fg);
}

.tone-info {
  background: var(--info-bg);
  color: var(--info-fg);
}

.tone-progress {
  background: var(--progress-bg);
  color: var(--progress-fg);
}

.tone-success {
  background: var(--success-bg);
  color: var(--success-fg);
}

.tone-attention {
  background: var(--attention-bg);
  color: var(--attention-fg);
}

.tone-danger {
  background: var(--danger-bg);
  color: var(--danger-fg);
}

.callout {
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.callout.tone-danger {
  border: 1px solid var(--danger-border);
}

.notice {
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
}

.notice-warn {
  background: var(--attention-bg);
  color: var(--attention-fg);
}

.notice-error {
  background: var(--danger-bg);
  color: var(--danger-fg);
}

.form-error {
  color: var(--danger-fg);
  min-height: 0;
}

.form-error:empty {
  display: none;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.dot-ok {
  background: var(--success-fg);
}

.dot-fail {
  background: var(--danger-solid);
}

.dot-unknown {
  background: var(--border-strong);
}

/* ── boot & login ─────────────────────────────────────────────────────── */

.boot {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── app shell ────────────────────────────────────────────────────────── */

.mock-badge {
  display: none;
}

html[data-mock] .mock-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--attention-bg);
  color: var(--attention-fg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.content {
  padding: 16px 24px 48px;
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.banner {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--danger-bg);
  color: var(--danger-fg);
  border: 1px solid var(--danger-border);
}

.banner .btn {
  margin-left: auto;
}

.toolbar {
  display: flex;
  gap: 10px 14px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar input[type='search'] {
  width: 260px;
  max-width: 100%;
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  font: inherit;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.chip[aria-pressed='true'] {
  background: var(--text);
  color: var(--surface);
  border-color: var(--text);
}

.chip-danger {
  border-color: var(--danger-border);
  color: var(--danger-fg);
}

.chip-danger[aria-pressed='true'] {
  background: var(--danger-solid);
  border-color: var(--danger-solid);
  color: #fff;
}

.chip-count {
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
}

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

/* ── accounts table ───────────────────────────────────────────────────── */

.accounts {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.accounts th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.accounts td {
  padding: 12px;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.accounts tbody tr:last-child td {
  border-bottom: 0;
}

.accounts td > * + * {
  margin-top: 4px;
}

.accounts .name {
  font-weight: 600;
  font-size: 15px;
}

.row-paused td {
  background: var(--danger-bg);
}

.row-paused td:first-child {
  box-shadow: inset 4px 0 0 var(--danger-solid);
}

.pause-reason {
  font-weight: 600;
  color: var(--danger-fg);
}

.flags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.proxy-ip {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.country {
  font-size: 12px;
  font-weight: 600;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
}

.job-line {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.c-actions {
  min-width: 220px;
}

.actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.confirm {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  max-width: 440px;
}

.confirm-danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.confirm-text {
  font-size: 13px;
}

.confirm-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ── dialogs ──────────────────────────────────────────────────────────── */

dialog {
  color: var(--text);
  background: var(--surface);
  border: 0;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgb(10 14 20 / 0.45);
}

.drawer {
  margin: 0 0 0 auto;
  width: min(680px, 100vw);
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  border-left: 1px solid var(--border);
}

.drawer-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.drawer-head,
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.drawer-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.drawer-title h2 {
  overflow-wrap: anywhere;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.hint {
  color: var(--muted);
}

.section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.section-head .check {
  margin-left: auto;
}

.info {
  margin: 0;
  display: grid;
  gap: 6px;
}

.info > div {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 12px;
}

.info dt {
  color: var(--muted);
}

.info dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.copyable {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.flag-list,
.history,
.jobs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history li,
.jobs li {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.history li:last-child,
.jobs li:last-child {
  border-bottom: 0;
}

.history-line {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.arrow {
  color: var(--muted);
}

.mini {
  border-collapse: collapse;
  min-width: 260px;
}

.mini td {
  padding: 4px 12px 4px 0;
  border-bottom: 1px solid var(--border);
}

.mini td.num {
  text-align: right;
  font-weight: 600;
}

/* live log */

.log {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  display: grid;
  grid-template-columns: auto auto auto minmax(0, 1fr);
  align-content: start;
  max-height: 360px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
}

.log:empty {
  display: none;
}

.log.hide-debug .lvl-debug {
  display: none;
}

.ev {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  column-gap: 8px;
  padding: 3px 10px;
  align-items: baseline;
}

.ev time {
  color: var(--muted);
  white-space: nowrap;
}

.ev-level {
  font-weight: 600;
  min-width: 5.5em;
}

.ev-kind {
  color: var(--muted);
}

.ev-msg {
  overflow-wrap: anywhere;
}

.lvl-debug .ev-level {
  color: var(--muted);
}

.lvl-info .ev-level {
  color: var(--info-fg);
}

.lvl-warn {
  background: var(--attention-bg);
}

.lvl-warn .ev-level {
  color: var(--attention-fg);
}

.lvl-error {
  background: var(--danger-bg);
}

.lvl-error .ev-level,
.lvl-error .ev-msg {
  color: var(--danger-fg);
}

details.ev-msg summary {
  cursor: pointer;
}

details.ev-msg summary::marker {
  color: var(--muted);
}

.ev-msg pre {
  margin: 4px 0;
  padding: 6px 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface);
  border-radius: var(--radius-sm);
}

.replace summary {
  cursor: pointer;
  list-style: none;
}

.replace summary::-webkit-details-marker {
  display: none;
}

.replace summary h3 {
  display: inline;
}

.replace summary h3::after {
  content: ' ▸';
}

.replace[open] summary h3::after {
  content: ' ▾';
}

.replace-controls {
  display: flex;
}

/* create sheet */

.sheet {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  border-radius: 12px;
}

.sheet-inner {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 32px);
}

.sheet-body {
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sheet-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.paste {
  font-family: var(--mono);
  font-size: 13px;
}

.parse-status {
  font-size: 13px;
}

.proxy-input {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.proxy-grid {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.proxy-fields {
  flex: 1;
  display: grid;
  grid-template-columns: 2fr 0.8fr 2fr 1.4fr;
  gap: 10px;
}

.proxy-fields input {
  font-family: var(--mono);
  font-size: 13px;
}

.f-type {
  width: 110px;
  flex: none;
}

.is-bulk .proxy-grid {
  justify-content: flex-start;
}

.di-hints {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.di-hints dt {
  color: var(--muted);
  font-size: 12px;
}

.di-hints dd {
  margin: 0;
  font-family: var(--mono);
}

.bulk {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-x: auto;
}

.bulk-table {
  width: 100%;
  border-collapse: collapse;
}

.bulk-table th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  padding: 4px 6px;
}

.bulk-table td {
  padding: 6px;
  vertical-align: top;
  border-top: 1px solid var(--border);
}

.bulk-table td.num {
  color: var(--muted);
}

.bulk-table td.mono {
  max-width: 220px;
  overflow-wrap: anywhere;
}

.row-invalid td {
  background: var(--danger-bg);
}

/* toasts */

.toasts {
  position: fixed;
  inset: auto 16px 16px auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition:
    opacity 0.3s,
    transform 0.3s;
}

.toast.leaving {
  opacity: 0;
  transform: translateY(6px);
}

/* ── narrow screens ───────────────────────────────────────────────────── */

@media (max-width: 860px) {
  .topbar {
    padding: 10px 16px;
  }

  .content {
    padding: 12px 16px 40px;
  }

  .conn {
    display: none;
  }

  .toolbar input[type='search'] {
    width: 100%;
  }

  .accounts,
  .accounts tbody,
  .accounts tr,
  .accounts td {
    display: block;
    width: 100%;
  }

  .accounts {
    background: transparent;
    border: 0;
    border-radius: 0;
    overflow: visible;
  }

  .accounts thead {
    display: none;
  }

  .accounts tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    overflow: hidden;
  }

  .accounts td {
    display: grid;
    grid-template-columns: 116px 1fr;
    gap: 2px 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
  }

  .accounts td > * + * {
    margin-top: 0;
  }

  .accounts td > * {
    grid-column: 2;
    min-width: 0;
  }

  .accounts td > .badge {
    justify-self: start;
  }

  .ellipsis {
    max-width: none;
  }

  .accounts td::before {
    content: attr(data-label);
    grid-column: 1;
    grid-row: 1 / span 4;
    color: var(--muted);
    font-size: 12px;
    padding-top: 2px;
  }

  .accounts td.c-name {
    display: block;
    padding-top: 12px;
  }

  .accounts td.c-name::before,
  .accounts td.c-actions::before {
    content: none;
  }

  .accounts td.c-actions {
    display: block;
    min-width: 0;
    border-bottom: 0;
    background: var(--surface-2);
  }

  .row-paused td.c-actions {
    background: var(--danger-bg);
  }

  .row-paused td:first-child {
    box-shadow: inset 0 4px 0 var(--danger-solid);
  }

  .confirm {
    max-width: none;
  }

  .drawer-head,
  .sheet-head {
    padding: 12px 16px;
  }

  .drawer-body {
    padding: 14px 16px 28px;
  }

  .info > div {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .log {
    display: block;
  }

  .ev {
    display: grid;
    grid-template-columns: auto auto 1fr;
  }

  .ev-msg {
    grid-column: 1 / -1;
  }

  .sheet {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }

  .sheet-inner {
    height: 100%;
    max-height: 100dvh;
  }

  .sheet-body {
    flex: 1;
    padding: 14px 16px;
  }

  .sheet-foot {
    padding: 10px 16px;
  }

  .proxy-grid {
    flex-direction: column;
    align-items: stretch;
  }

  .proxy-fields {
    grid-template-columns: 1fr 100px;
  }

  .f-login,
  .f-password {
    grid-column: 1 / -1;
  }

  .f-type {
    width: 100%;
  }
}
