:root {
  --ink: #0c1a1f;
  --bg: #eef3f1;
  --panel: #ffffff;
  --line: #d5e0dc;
  --text: #142428;
  --muted: #5f7370;
  --accent: #0d8f7a;
  --accent-2: #0a6e5e;
  --accent-soft: #d8f3ec;
  --ok: #1f9d63;
  --warn: #c9841a;
  --bad: #c23b45;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(12, 26, 31, 0.06);
  --font: "DM Sans", "PingFang SC", "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; min-height: 100%;
  background:
    radial-gradient(900px 420px at 100% -10%, #c9ebe3 0%, transparent 55%),
    radial-gradient(700px 380px at -5% 20%, #d7e4f2 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font: inherit; color: var(--text); background: #fff;
  border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 0.8rem;
}
select {
  height: 42px; line-height: 1.2; padding-top: 0; padding-bottom: 0;
  max-width: 100%;
}
select.field-sm, .field-sm {
  height: 40px; padding-left: 0.75rem; padding-right: 0.75rem;
}
button {
  cursor: pointer; background: var(--accent); border-color: transparent;
  color: #fff; font-weight: 600; transition: background .15s, transform .1s;
}
button:hover { background: var(--accent-2); }
button:active { transform: translateY(1px); }
button.secondary { background: #fff; color: var(--text); border-color: var(--line); }
button.secondary:hover { background: #f4f8f6; }
button.danger { background: var(--bad); }
button.ghost { background: transparent; color: var(--muted); border: 0; padding: 0.35rem 0.5rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
label { display: grid; gap: 0.35rem; font-size: 0.86rem; color: var(--muted); font-weight: 500; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.9rem; }
@media (max-width: 860px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.shell { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1.25rem 3rem; }
.top {
  display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem;
  padding: 0.85rem 1rem; background: rgba(255,255,255,0.72);
  border: 1px solid var(--line); border-radius: 16px; backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}
.brand {
  display: flex; align-items: baseline; gap: 0.45rem; min-width: 120px;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(145deg, #14b89a, #0a6e5e);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25);
}
.brand-name { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.03em; color: var(--ink); }
.nav { display: flex; gap: 0.25rem; flex-wrap: wrap; flex: 1; }
.nav button {
  background: transparent; color: var(--muted); border: 0; font-weight: 500;
  padding: 0.45rem 0.75rem; border-radius: 999px;
}
.nav button.active { color: var(--accent-2); background: var(--accent-soft); }
.user-menu { position: relative; margin-left: auto; }
.user-btn {
  display: flex; align-items: center; gap: 0.5rem;
  background: #fff; color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: 0.35rem 0.7rem 0.35rem 0.4rem; font-weight: 500;
}
.avatar {
  width: 28px; height: 28px; border-radius: 999px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-2); font-size: 0.75rem; font-weight: 700;
}
.user-drop {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 160px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 0.4rem; z-index: 20; display: none;
}
.user-drop.open { display: block; }
.user-drop button {
  width: 100%; text-align: left; background: transparent; color: var(--text);
  border: 0; font-weight: 500; padding: 0.55rem 0.7rem; border-radius: 8px;
}
.user-drop button:hover { background: #f3f7f5; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.15rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 0.85rem; font-size: 1.08rem; letter-spacing: -0.02em; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  margin-bottom: 0.9rem; flex-wrap: wrap;
}
.card-head h2 { margin: 0; }
.muted { color: var(--muted); font-size: 0.85rem; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td {
  text-align: left; padding: 0.7rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: middle;
}
.table th { color: var(--muted); font-weight: 500; font-size: 0.8rem; text-transform: none; }
.table td.addr-cell {
  max-width: 240px; vertical-align: middle;
}
.addr-with-copy {
  display: flex; align-items: flex-start; gap: 0.35rem; max-width: 100%;
}
.addr-with-copy .addr-text {
  flex: 1; min-width: 0;
  color: var(--accent-2); font-family: var(--mono); font-size: 0.8rem; font-weight: 500;
  white-space: normal; word-break: break-all; line-height: 1.45;
}
.copy-icon-btn {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0; margin-top: 0;
  background: #fff; color: var(--muted); border: 1px solid var(--line); border-radius: 8px;
}
.copy-icon-btn:hover { background: #f4f8f6; color: var(--accent-2); }
.copy-icon-btn:active { transform: none; }
.table td:last-child {
  width: 1%; white-space: nowrap; vertical-align: middle;
}
.table .row.acts {
  flex-wrap: nowrap; gap: 0.4rem; align-items: center;
}
.table .row.acts button {
  white-space: nowrap; flex-shrink: 0;
  padding: 0.35rem 0.7rem; line-height: 1.2; font-size: 0.82rem;
  height: auto; min-height: 0;
}
.badge {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.18rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
  background: #eef2f1; color: var(--muted);
}
.badge.ok { background: #e5f7ee; color: var(--ok); }
.badge.fail { background: #fdebec; color: var(--bad); }
.badge.draft { background: #fff4e5; color: var(--warn); }
.badge.paused { background: #eef1f5; color: #526070; }
.badge.deprecated { background: #fff4e5; color: var(--warn); }

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1rem;
}
.login-card { width: min(420px, 100%); }
.login-card h1 { margin: 0 0 0.2rem; font-size: 1.75rem; letter-spacing: -0.03em; }
.form { display: grid; gap: 0.85rem; }
[hidden] { display: none !important; }
.err { color: var(--bad); font-size: 0.9rem; }
.okmsg { color: var(--ok); font-size: 0.9rem; }
.mono { font-family: var(--mono); font-size: 0.82rem; }
.checkboxes { display: flex; flex-wrap: wrap; gap: 0.45rem 1rem; }
.checkboxes label { display: flex; align-items: center; gap: 0.35rem; color: var(--text); font-weight: 400; }
textarea { min-height: 88px; width: 100%; resize: vertical; }
.hint { font-size: 0.8rem; color: var(--muted); line-height: 1.45; }
.section {
  border: 1px solid var(--line); border-radius: 12px; padding: 1rem; background: #fbfdfc;
}
.section + .section { margin-top: 0.9rem; }
.section-title {
  display: flex; align-items: center; gap: 0.45rem;
  font-size: 0.95rem; font-weight: 650; color: var(--ink); margin-bottom: 0.75rem;
}
.help-btn {
  width: 18px; height: 18px; border-radius: 999px; padding: 0;
  display: inline-grid; place-items: center; font-size: 0.7rem; font-weight: 700;
  background: #e7f0ed; color: var(--accent-2); border: 0; vertical-align: middle;
  flex-shrink: 0;
}
.help-pop {
  display: none; margin: 0.35rem 0 0.75rem; padding: 0.7rem 0.85rem;
  background: #f2f8f6; border-radius: 10px; color: var(--muted); font-size: 0.82rem; line-height: 1.5;
}
.help-pop.open { display: block; }

.opt-group { display: grid; gap: 0.55rem; }
.opt-group + .opt-group {
  margin-top: 0.35rem; padding-top: 0.85rem;
  border-top: 1px dashed #cfe0db;
}
.opt-group-label {
  font-size: 0.78rem; font-weight: 650; color: var(--muted);
  letter-spacing: 0.02em; text-transform: none;
}
.opt-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.65rem;
}
.opt-stack { display: grid; gap: 0.55rem; }
.opt-cell {
  display: grid; gap: 0.45rem; align-content: start;
  padding: 0.75rem 0.85rem; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; margin: 0; color: var(--text); font-weight: 400; font-size: 0.86rem;
}
.opt-cell.opt-inline {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
}
.opt-cell.opt-span { grid-column: 1 / -1; }
.opt-title {
  display: inline-flex; align-items: center; gap: 0.35rem;
  color: var(--text); font-weight: 550; font-size: 0.86rem; line-height: 1.3;
}
.opt-cell input[type="checkbox"] {
  width: 1.05rem; height: 1.05rem; accent-color: var(--accent); flex-shrink: 0;
}
.opt-num { width: 5.5rem; margin: 0; }
.section.is-readonly-adv {
  position: relative;
}
.section.is-readonly-adv .opt-cell.is-readonly,
.section.is-readonly-adv .opt-cell.is-readonly input,
.section.is-readonly-adv .opt-cell.is-readonly select {
  cursor: not-allowed;
}
.section.is-readonly-adv input:disabled,
.section.is-readonly-adv select:disabled {
  background: #f3f7f5; color: var(--muted); opacity: 1;
}
@media (max-width: 860px) {
  .opt-grid { grid-template-columns: 1fr; }
}

.pager { display: flex; gap: 0.5rem; align-items: center; justify-content: flex-end; margin-top: 0.85rem; }
.pager .muted { margin-right: auto; }

.chart-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; }
@media (max-width: 900px) { .chart-row { grid-template-columns: 1fr; } }
.chart-box { min-height: 220px; }
.chart-svg { width: 100%; height: 220px; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; margin-top: 0.5rem; font-size: 0.8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 0.3rem; }

.tag-input {
  display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0.5rem 0.55rem; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; min-height: 44px; align-items: center;
  transition: border-color .15s, box-shadow .15s;
}
.tag-input:focus-within {
  border-color: #9bcfc4;
  box-shadow: 0 0 0 3px rgba(13, 143, 122, 0.12);
}
.tag {
  display: inline-flex; align-items: center; gap: 0.3rem;
  background: var(--accent-soft); color: var(--accent-2);
  border-radius: 8px; padding: 0.28rem 0.55rem; font-size: 0.8rem; font-weight: 600;
  max-width: 100%; word-break: break-all; line-height: 1.35;
}
.tag button { background: transparent; border: 0; color: var(--accent-2); padding: 0; font-size: 0.95rem; line-height: 1; flex-shrink: 0; }
.tag-input input { border: 0; outline: none; flex: 1; min-width: 140px; padding: 0.3rem; background: transparent; }

.field { display: grid; gap: 0.4rem; }
.field-label { font-size: 0.86rem; color: var(--muted); font-weight: 500; }
.field-hint { margin: 0; font-size: 0.75rem; color: var(--muted); line-height: 1.4; }
.mono-area { font-family: var(--mono); font-size: 0.82rem; }

.lock-field { display: grid; gap: 0.35rem; }
.lock-field-head {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.86rem; color: var(--muted); font-weight: 500;
}
.edit-lock-btn {
  width: 28px; height: 28px; padding: 0; border-radius: 8px;
  display: inline-grid; place-items: center;
  background: #eef4f2; color: var(--accent-2); border: 1px solid transparent;
}
.edit-lock-btn:hover { background: var(--accent-soft); }
.edit-lock-btn:disabled { opacity: 0.4; cursor: default; }
input.is-locked {
  background: #f3f7f5; color: var(--muted); cursor: default;
}

.settings-card .card-head { margin-bottom: 0.35rem; }
.settings-lead { margin: 0.35rem 0 0; }
.settings-tabs {
  display: flex; gap: 0; margin: 1rem 0 1.1rem;
  border-bottom: 1px solid var(--line); background: transparent;
}
.settings-tabs button {
  position: relative; background: transparent; color: var(--muted); border: 0;
  border-radius: 0; font-weight: 550; padding: 0.75rem 1rem; margin-bottom: -1px;
}
.settings-tabs button:hover { background: #f4f8f6; color: var(--text); }
.settings-tabs button.active {
  color: var(--accent-2); background: transparent;
  box-shadow: inset 0 -2px 0 var(--accent);
}
.settings-pane { display: grid; gap: 0.9rem; }
.settings-block {
  border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.05rem;
  background: #fbfdfc; display: grid; gap: 0.85rem;
}
.settings-block-head h3 {
  margin: 0; font-size: 0.95rem; font-weight: 650; color: var(--ink); letter-spacing: -0.01em;
}
.settings-block-head p {
  margin: 0.25rem 0 0; font-size: 0.8rem; color: var(--muted); line-height: 1.45;
}
.settings-checks { gap: 0.55rem 1.25rem; }
.settings-checks label { color: var(--text); }
.settings-actions {
  display: flex; justify-content: flex-end; margin-top: 1.1rem; padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}

.country-list { display: grid; gap: 0.55rem; }
.country-card {
  border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden;
}
.country-card > summary {
  display: flex; align-items: center; gap: 0.55rem; cursor: pointer;
  padding: 0.75rem 0.9rem; font-weight: 600; list-style: none;
}
.country-card > summary::-webkit-details-marker { display: none; }
.country-card > summary::after {
  content: ""; margin-left: auto; width: 0.45rem; height: 0.45rem;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform .15s;
}
.country-card[open] > summary::after { transform: rotate(-135deg); margin-top: 0.2rem; }
.country-name { color: var(--ink); }
.country-code {
  font-size: 0.75rem; color: var(--muted); background: #eef3f1;
  padding: 0.12rem 0.45rem; border-radius: 6px; font-weight: 500;
}
.country-body {
  display: grid; gap: 0.75rem; padding: 0 0.9rem 0.95rem;
  border-top: 1px solid var(--line);
  padding-top: 0.85rem;
}

.name-rule-panel {
  border: 1px solid var(--line); border-radius: 12px; background: #fff; overflow: hidden;
}
.name-rule-tabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--line); background: #f7faf9; flex-wrap: wrap;
}
.name-rule-tabs button {
  flex: 1; min-width: 88px; border: 0; border-radius: 0; background: transparent;
  color: var(--muted); font-weight: 500; padding: 0.7rem 0.5rem;
}
.name-rule-tabs button.active {
  color: var(--accent-2); background: #fff;
  box-shadow: inset 0 -2px 0 var(--accent);
}
.name-rule-body { padding: 0.9rem; display: grid; gap: 0.75rem; }
.name-rule-add {
  display: grid; grid-template-columns: 140px 1fr auto; gap: 0.5rem; align-items: center;
}
@media (max-width: 700px) {
  .name-rule-add { grid-template-columns: 1fr; }
}
.name-rule-chips { display: flex; flex-wrap: wrap; gap: 0.45rem; min-height: 28px; }
.name-rule-chips .chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: var(--accent-soft); color: var(--accent-2);
  border-radius: 999px; padding: 0.28rem 0.6rem; font-size: 0.8rem; font-weight: 600;
}
.name-rule-chips .chip button {
  background: transparent; border: 0; color: var(--accent-2); padding: 0; line-height: 1;
}
.name-rule-chips .empty { color: var(--muted); font-size: 0.82rem; }

.empty-state {
  display: grid; place-items: center; text-align: center;
  padding: 2.5rem 1.25rem 2rem; gap: 0.75rem;
}
.empty-state svg { width: min(220px, 70vw); height: auto; }
.empty-state h3 { margin: 0.4rem 0 0; font-size: 1.15rem; letter-spacing: -0.02em; }
.empty-state p { margin: 0; color: var(--muted); max-width: 360px; line-height: 1.5; }

.combo-field { display: grid; gap: 0.45rem; }
.combo-field .custom-url { display: none; }
.combo-field.custom .custom-url { display: block; }

.tabs { display: flex; gap: 0.35rem; margin-bottom: 0.85rem; flex-wrap: wrap; }
.tabs button {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  border-radius: 999px; font-weight: 500;
}
.tabs button.active { background: var(--accent-soft); color: var(--accent-2); border-color: transparent; }
.tabs button:hover { background: #f4f8f6; }

.flash {
  margin-bottom: 0.85rem; padding: 0.75rem 1rem; border-radius: 12px; font-size: 0.9rem;
}
.flash.ok { background: #e5f7ee; color: var(--ok); }
.flash.err { background: #fdebec; color: var(--bad); }

.preview-box {
  margin-top: 0.35rem; padding: 0.75rem 0.9rem;
  background: #f2f8f6; border: 1px dashed #b7d5cd; border-radius: 10px;
  font-size: 0.88rem; color: var(--muted);
}
.preview-box strong { color: var(--ink); font-weight: 600; }
.preview-box .mono { color: var(--accent-2); word-break: break-all; }
.preview-box .line { margin-top: 0.35rem; }

.result-card .addr-row {
  display: grid; gap: 0.35rem; margin: 0.85rem 0; padding: 0.85rem 1rem;
  background: #f7faf9; border: 1px solid var(--line); border-radius: 12px;
}
.result-card .addr-label { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.result-card .addr-value {
  font-family: var(--mono); font-size: 0.92rem; color: var(--accent-2); word-break: break-all;
}
.result-card .addr-value a { color: inherit; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(12, 26, 31, 0.45);
  display: grid; place-items: center; z-index: 50; padding: 1rem;
}
.modal {
  width: min(720px, 100%); max-height: min(85vh, 900px); overflow: auto;
  background: #fff; border-radius: 16px; border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(12, 26, 31, 0.18); padding: 1.1rem 1.2rem;
}
.modal h3 { margin: 0 0 0.75rem; font-size: 1.05rem; }

.deploy-modal { width: min(480px, 100%); }
.deploy-dialog-body { text-align: center; padding: 0.5rem 0.25rem 0.25rem; }
.deploy-dialog-body h3 { margin: 0.65rem 0 0.35rem; }
.deploy-dialog-body .muted { margin: 0 0 0.85rem; }
.deploy-dialog-body .addr-row { text-align: left; }
.deploy-dialog-body .row { text-align: left; }
.deploy-spinner {
  width: 40px; height: 40px; margin: 0.4rem auto 0;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  border-radius: 50%; animation: deploy-spin 0.75s linear infinite;
}
@keyframes deploy-spin { to { transform: rotate(360deg); } }
.deploy-icon {
  width: 44px; height: 44px; margin: 0.25rem auto 0;
  border-radius: 999px; display: grid; place-items: center;
  font-size: 1.25rem; font-weight: 700;
}
.deploy-icon.ok { background: #e5f7ee; color: var(--ok); }
.deploy-icon.err { background: #fdebec; color: var(--bad); }
.deploy-err-msg {
  margin: 0.5rem 0 0; padding: 0.75rem 0.9rem; text-align: left;
  background: #fdebec; color: var(--bad); border-radius: 10px;
  font-size: 0.88rem; line-height: 1.45; word-break: break-word;
}
.detail-grid {
  display: grid; grid-template-columns: 120px 1fr; gap: 0.45rem 0.75rem; font-size: 0.88rem;
}
.detail-grid .k { color: var(--muted); }
.detail-grid .v { word-break: break-all; font-family: var(--mono); font-size: 0.82rem; }
.detail-pre {
  margin: 0.75rem 0 0; padding: 0.75rem; background: #0c1a1f; color: #d8f3ec;
  border-radius: 10px; font-family: var(--mono); font-size: 0.75rem;
  white-space: pre-wrap; word-break: break-all; max-height: 280px; overflow: auto;
}
.stats-hint {
  padding: 2rem 1rem; text-align: center; color: var(--muted);
}
