/* CLB admin UI — minimal vanilla CSS */

:root {
  --bg: #0f1419;
  --bg-panel: #1a2028;
  --bg-input: #0d1117;
  --border: #2d3748;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #4f9eff;
  --accent-hover: #6cb0ff;
  --success: #48bb78;
  --warning: #ecc94b;
  --danger: #f56565;
  --pending: #718096;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.logo {
  font-weight: 700;
  font-size: 18px;
  color: var(--accent);
  letter-spacing: 0.5px;
}
.subtitle { color: var(--text-dim); font-size: 12px; }
.status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--pending);
  color: #fff;
}
.status.ok { background: var(--success); }
.status.err { background: var(--danger); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 53px);
}
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-panel);
}
.panel-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

/* ---------- domain list ---------- */
.domain-list, .dns-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.domain-list li, .dns-list li {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.domain-list li:hover, .dns-list li:hover {
  background: rgba(79, 158, 255, 0.08);
}
.domain-list li.active, .dns-list li.active {
  background: rgba(79, 158, 255, 0.15);
  border-left: 3px solid var(--accent);
  padding-left: 13px;
}
.domain-list li.empty, .dns-list li.empty {
  cursor: default;
  color: var(--text-dim);
  font-style: italic;
}
.domain-list li.empty:hover { background: transparent; }
.domain-name {
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.domain-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.domain-meta-text {
  flex: 1;
}
.domain-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ---------- cert badges ---------- */
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 600;
}
.badge-valid { background: var(--success); color: #fff; }
.badge-expiring { background: var(--warning); color: #000; }
.badge-expired { background: var(--danger); color: #fff; }
.badge-pending { background: var(--pending); color: #fff; }
.badge-error { background: var(--danger); color: #fff; }
/* M9 — Custom-cert domains render with a neutral "local certificate" badge
   so the SPA can distinguish operator-supplied PEMs from ACME certs at a
   glance. Greyed-out, no urgency colour. */
.badge-custom { background: var(--pending); color: #fff; }
/* M9b — DNS provider registry key tag (alidns / cloudflare / etc.) is
   informational, not a status indicator, so use a neutral muted colour.
   "legacy" badge marks records persisted before the Type field was
   added; operators can edit the record to set a proper Type. */
.badge-info { background: var(--accent, #4a5568); color: #fff; }
.badge-warn { background: var(--warning); color: #000; }

/* ---------- health status indicators ---------- */
.health-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.health-healthy { background: #22c55e; box-shadow: 0 0 4px #22c55e; }  /* green */
.health-degraded { background: #eab308; box-shadow: 0 0 6px #eab308; }  /* yellow */
.health-unhealthy { background: #ef4444; box-shadow: 0 0 8px #ef4444; } /* red */
.health-unchecked { background: #6b7280; }  /* gray - no data yet */

/* breathing animation for non-healthy status */
@keyframes health-breathe {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 0 6px currentColor;
  }
  50% {
    opacity: 0.5;
    transform: scale(0.85);
    box-shadow: 0 0 2px currentColor;
  }
}
.health-breathe {
  animation: health-breathe 2s ease-in-out infinite;
}

/* ---------- editor ---------- */
.editor-empty {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
}
.editor-empty h2 { font-weight: 400; font-size: 16px; }
.editor {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.editor-header h2 { margin: 0; }
.editor-actions { display: flex; gap: 8px; }

.cert-strip {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 13px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.cert-strip:empty { display: none; }
.cert-strip .cert-info { color: var(--text-dim); }

.form-section {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.form-section legend {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 6px;
}
.danger-zone { border-color: var(--danger); }
.danger-zone legend { color: var(--danger); }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }

input[type="text"],
input[type="number"],
select {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 3px;
  font-size: 13px;
  font-family: inherit;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------- buttons ---------- */
.btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 3px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.1s, border-color 0.1s;
}
.btn:hover { border-color: var(--accent); }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-icon { padding: 2px 6px; font-size: 14px; line-height: 1; cursor: pointer; text-decoration: none; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: transparent; }
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { filter: brightness(1.1); }

/* ---------- locations ---------- */
.location-item {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}
.location-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.location-header label { flex: 1; }
.upstream-item {
  display: grid;
  grid-template-columns: 1fr 80px 80px 80px 32px;
  gap: 8px;
  align-items: end;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.upstream-item:first-child { border-top: none; }

/* ---------- DNS modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 24px;
  min-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-content h3 { margin: 0; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.cred-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}
.cred-field input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 3px;
  font-size: 13px;
  font-family: inherit;
}

/* ---------- toasts ---------- */
.toast-container {
  position: fixed;
  top: 70px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  padding: 10px 14px;
  border-radius: 3px;
  min-width: 240px;
  font-size: 13px;
  animation: slide-in 0.2s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes slide-in {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ---------- utility ---------- */
.hidden { display: none !important; }

/* ---------- user bar (M5) ---------- */
.user-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 13px;
}
.user-bar #current-user { color: var(--text); }

/* ---------- login screen (M5) ---------- */
.login-screen {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 25, 0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}
.login-screen.visible { display: flex; }
.login-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px 32px;
  width: 360px;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.login-card h2 { margin: 0 0 6px; font-size: 18px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; color: var(--text-dim); font-size: 12px; }
.login-card input {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button { margin-top: 6px; }
.login-error {
  color: var(--danger);
  font-size: 12px;
  min-height: 16px;
}

/* ---------- nginx import modal ---------- */
.panel-header-actions {
  display: flex;
  gap: 6px;
}

.modal-content-wide {
  /* Wider than the default modal to give the textarea room to breathe. */
  max-width: 760px;
  width: 90vw;
}

.modal-hint {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 12px 0;
  line-height: 1.5;
}
.modal-hint code {
  background: var(--bg-input);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}

#import-config {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  width: 100%;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  resize: vertical;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 8px;
}
.checkbox-row input[type="checkbox"] { margin: 0; }

/* CORS allowed-methods: lay the 7 standard HTTP methods out horizontally.
   The <legend> stays in normal block flow above; only the .cors-methods-row
   wrapper inside the fieldset is flexed, so the legend isn't pulled into
   the same row as the checkboxes. Wraps to a second row on narrow viewports.
   Overrides .checkbox-row's vertical margin. */
.cors-methods-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  align-items: center;
}
.cors-methods-row .checkbox-row {
  margin-top: 0;
}

.import-preview {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.preview-summary {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 13px;
}
.preview-summary strong { color: var(--accent); }

.import-issues {
  margin-bottom: 10px;
  max-height: 240px;
  overflow-y: auto;
}
.import-issues.hidden { display: none; }

.issue {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  padding: 4px 8px;
  border-left: 3px solid;
  border-radius: 2px;
  margin-bottom: 4px;
  background: var(--bg-input);
}
.issue-warning { border-color: var(--warning); }
.issue-error   { border-color: var(--danger);  }
.issue-line    { color: var(--text-dim); min-width: 60px; }
.issue-ctx     { color: var(--text-dim); min-width: 100px; }
.issue-name    { color: var(--danger);  min-width: 100px; }
.issue-msg     { flex: 1; }

.preview-domain {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  margin-bottom: 6px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}
.preview-domain:hover { border-color: var(--accent); }
.preview-domain-check { margin-top: 4px; }
.preview-domain-body { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.preview-domain-name { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.preview-domain-meta { color: var(--text-dim); font-size: 12px; }
.preview-hint { color: var(--text-dim); font-size: 12px; margin-top: 6px; }
.badge-warn { background: var(--warning); color: #000; padding: 1px 6px; border-radius: 3px; font-size: 11px; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 220px 1fr; }
  .panel-right { display: none; }
}

/* ---------- M8: deny / HSTS / CORS / static ---------- */
.legend-hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-dim);
  margin-left: 6px;
  font-size: 11px;
}
.field-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}
.field-stack input[type="text"] { width: 100%; }

/* chip list (CORS origins / methods) */
.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 26px;
  padding: 4px;
  border: 1px dashed var(--border);
  border-radius: 3px;
  background: var(--bg-panel);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  padding: 2px 4px 2px 8px;
  border-radius: 12px;
}
.chip-remove {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.85);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.chip-remove:hover { color: #fff; }
.chip-list:empty::before {
  content: "(尚未添加)";
  color: var(--text-dim);
  font-size: 12px;
  font-style: italic;
}

/* deny path row */
.deny-row {
  display: grid;
  grid-template-columns: 1fr 90px 32px;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
}
.deny-row input[type="text"] { width: 100%; }

/* location mode toggle (pool vs static) */
.loc-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-dim);
}
.loc-mode-toggle label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-direction: row;
  cursor: pointer;
}
.static-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 3px;
}

/* ---------- IP Stats (非国内高频访问) ---------- */
.ip-stats-container {
  margin-top: 16px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.ip-stats-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ip-stats-empty {
  color: var(--text-dim);
  font-size: 12px;
  font-style: italic;
  text-align: center;
  padding: 8px;
}
.ip-stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.ip-stats-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 500;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
}
.ip-stats-table td {
  padding: 5px 6px;
  color: var(--text);
  border-bottom: 1px solid var(--border-subtle);
}
.ip-stats-table tr:last-child td {
  border-bottom: none;
}
.ip-stats-ip {
  font-family: monospace;
  color: var(--danger);
  font-weight: 500;
}
.ip-stats-count {
  font-weight: 600;
  color: var(--accent);
}
.ip-stats-time {
  color: var(--text-dim);
  font-size: 10px;
}

/* ---------- IP Blacklist ---------- */
.ip-blacklist-section {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.ip-blacklist-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--danger);
  margin-bottom: 8px;
}
.ip-blacklist-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ip-blacklist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  background: var(--bg-input);
  border-radius: 3px;
  font-size: 11px;
}
.ip-blacklist-ip {
  font-family: monospace;
  color: var(--danger);
  font-weight: 500;
}
.ip-blacklist-reason {
  flex: 1;
  color: var(--text-dim);
}

/* ---------- Button XS ---------- */
.btn-xs {
  padding: 2px 6px;
  font-size: 10px;
  border-radius: 3px;
}