:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f7fafb;
  --surface-tint: #eef8f5;
  --line: #dbe4e8;
  --line-strong: #adbdc5;
  --text: #14212a;
  --muted: #667681;
  --muted-strong: #43525d;
  --accent: #0a8f78;
  --accent-strong: #06715f;
  --accent-soft: #dff5ee;
  --indigo: #36529a;
  --indigo-soft: #e9eeff;
  --amber: #996100;
  --amber-soft: #fff4dc;
  --danger: #b42318;
  --danger-soft: #fff0ed;
  --warning: #8a5a00;
  --warning-soft: #fff7df;
  --ok: #08745c;
  --ok-soft: #e7f7f1;
  --code-bg: #0d1620;
  --code-text: #dcefe8;
  --focus: rgba(10, 143, 120, 0.22);
  --shadow: 0 12px 30px rgba(20, 33, 42, 0.08);
  --shadow-soft: 0 5px 16px rgba(20, 33, 42, 0.06);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  background: var(--bg);
  color: var(--text);
}

body {
  margin: 0;
  min-height: 100svh;
  background:
    radial-gradient(circle at top left, rgba(223, 245, 238, 0.9), rgba(243, 246, 248, 0) 310px),
    linear-gradient(180deg, #f8fbfc 0, var(--bg) 270px);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: 12px 12px 92px;
}

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.icon-small {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  vertical-align: -2px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  color: var(--text);
  font-size: 24px;
  line-height: 1.05;
}

h2 {
  font-size: 21px;
  line-height: 1.12;
}

h3 {
  font-size: 16px;
  line-height: 1.2;
}

.view-tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(252, 253, 254, 0.94);
  box-shadow: 0 -14px 30px rgba(20, 33, 42, 0.13);
  backdrop-filter: blur(18px);
}

.view-tabs button,
.edit-nav button,
.ghost-button,
.primary-button,
.fab-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}

.view-tabs button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  background: var(--surface-soft);
  color: var(--muted-strong);
  font-size: 12px;
}

.view-tabs button.active {
  border-color: rgba(10, 143, 120, 0.26);
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(10, 143, 120, 0.22);
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

.screen-head {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: -12px -12px 14px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(243, 246, 248, 0.92);
  backdrop-filter: blur(16px);
}

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

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.compact-select {
  min-width: 0;
  min-height: 44px;
  font-size: 12px;
  font-weight: 800;
}

.ghost-button,
.primary-button,
.fab-button,
.ghost-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.ghost-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
  padding: 0 13px;
}

.ghost-link {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
  font-weight: 850;
  text-decoration: none;
  padding: 0 13px;
}

.ghost-link.disabled {
  pointer-events: none;
  opacity: 0.55;
}

.primary-button {
  width: 100%;
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 14px 26px rgba(10, 143, 120, 0.22);
  padding: 0 16px;
}

.ghost-button:not(:disabled):active,
.primary-button:not(:disabled):active,
.fab-button:not(:disabled):active {
  transform: translateY(1px);
}

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

.ghost-button:not(:disabled):hover {
  border-color: var(--line-strong);
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

[hidden] {
  display: none !important;
}

.field-stack,
.option-panel label,
.form-grid label,
.inline-form label,
.node-fields label,
.manual-node-fields label,
.group-row label,
.sheet-grid label {
  display: grid;
  gap: 6px;
}

.field-stack > span,
.option-panel span,
.form-grid span,
.node-fields span,
.manual-node-fields span,
.group-row span,
.sheet-grid span {
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 800;
}

input[type="text"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

input[type="text"],
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
}

input[type="text"]:focus,
select:focus,
textarea:focus {
  border-color: rgba(10, 143, 120, 0.65);
  background: #ffffff;
}

.input-area {
  min-height: 40svh;
  font: 13px/1.55 ui-monospace, "SFMono-Regular", Consolas, monospace;
}

.option-panel,
.edit-stage {
  display: grid;
  gap: 14px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.option-panel {
  grid-template-columns: 1fr;
}

.wide-field {
  grid-column: 1 / -1;
}

small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.token-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.token-chip {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--indigo);
  font-size: 12px;
  font-weight: 820;
  padding: 0 9px;
}

.token-chip:active {
  transform: translateY(1px);
}

.sticky-actions {
  position: sticky;
  bottom: 72px;
  z-index: 25;
  display: grid;
  gap: 8px;
  margin: 14px -4px 0;
  padding: 10px 4px;
  background: linear-gradient(180deg, rgba(243, 246, 248, 0), rgba(243, 246, 248, 0.96) 30%);
}

.action-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.action-grid .ghost-button {
  min-width: 0;
  padding: 0 8px;
  font-size: 12px;
}

.notice,
.validation-banner,
.validation-details,
.diff-panel,
.warnings {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-soft);
  padding: 12px;
  font-size: 13px;
  line-height: 1.45;
}

.notice.error,
.validation-banner.error {
  border-color: #ffd0c8;
  background: var(--danger-soft);
  color: var(--danger);
}

.validation-banner.warning {
  border-color: #ffe4a3;
  background: var(--warning-soft);
  color: var(--warning);
}

.validation-banner.ok {
  border-color: #bdebd8;
  background: var(--ok-soft);
  color: var(--ok);
}

.validation-details h3,
.diff-panel h3,
.warnings h3 {
  margin-bottom: 8px;
}

.validation-details ul,
.warnings ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

.validation-details li[data-severity="error"] {
  color: var(--danger);
}

.validation-details li[data-severity="warning"] {
  color: var(--warning);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.section-preview {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
  padding: 12px;
}

.section-preview-head {
  display: grid;
  gap: 10px;
}

.section-preview-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.section-preview-code {
  max-height: 220px;
  margin: 0;
  overflow: auto;
  border: 1px solid #1e2c38;
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-text);
  font: 12px/1.55 ui-monospace, "SFMono-Regular", Consolas, monospace;
  padding: 12px;
  white-space: pre;
}

.stats div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f8fafb);
  box-shadow: var(--shadow-soft);
  padding: 12px 10px;
}

.stats span,
.stats small {
  display: block;
}

.stats span {
  font-size: 24px;
  font-weight: 850;
  line-height: 1;
}

.stats small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 820;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.diff-panel {
  margin-top: 12px;
}

.diff-viewer {
  max-height: 48svh;
  margin: 0;
  overflow: auto;
  border: 1px solid rgba(220, 228, 232, 0.15);
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-text);
  font: 12px/1.55 ui-monospace, "SFMono-Regular", Consolas, monospace;
  padding: 12px;
  white-space: pre;
}

.diff-added {
  color: #8ff0bd;
}

.diff-removed {
  color: #ffb7ad;
}

.yaml-preview,
.compact-editor,
.mini-editor {
  border-color: #1e2c38;
  background: var(--code-bg);
  color: var(--code-text);
  font: 12px/1.55 ui-monospace, "SFMono-Regular", Consolas, monospace;
}

.yaml-preview {
  min-height: calc(100svh - 300px);
  white-space: pre;
  overflow: auto;
}

.subscription-panel {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.subscription-head {
  display: grid;
  gap: 12px;
}

.subscription-head h3 {
  margin: 0;
  font-size: 15px;
}

.subscription-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.subscription-head label {
  display: grid;
  gap: 6px;
}

.subscription-head span {
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 800;
}

.subscription-actions {
  display: grid;
  grid-template-columns: 1.1fr 1fr 0.75fr;
  gap: 8px;
}

.subscription-actions .primary-button,
.subscription-actions .ghost-button,
.subscription-actions .ghost-link {
  width: 100%;
  min-width: 0;
}

.compact-editor {
  min-height: calc(100svh - 260px);
}

.mini-editor {
  min-height: 88px;
}

.edit-nav {
  position: sticky;
  top: 68px;
  z-index: 15;
  display: flex;
  gap: 7px;
  margin: 0 -12px;
  padding: 9px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: rgba(243, 246, 248, 0.95);
  backdrop-filter: blur(14px);
  scrollbar-width: none;
}

.edit-nav::-webkit-scrollbar {
  display: none;
}

.edit-nav button {
  display: inline-flex;
  flex: 0 0 auto;
  min-width: 78px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.88);
  color: var(--muted-strong);
  box-shadow: none;
  padding: 0 12px;
}

.edit-nav button.active {
  border-color: rgba(54, 82, 154, 0.22);
  background: var(--indigo);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(54, 82, 154, 0.2);
}

.edit-panel {
  display: none;
}

.edit-panel.active {
  display: block;
}

.panel-title {
  display: grid;
  gap: 5px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.panel-title h3 {
  display: flex;
  align-items: center;
  gap: 7px;
}

.panel-title p,
.empty-state {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.item-list {
  display: grid;
  gap: 12px;
}

.node-row,
.group-row {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #fbfcfd);
  box-shadow: var(--shadow-soft);
  padding: 13px;
}

.node-row-head {
  display: grid;
  gap: 8px;
}

.node-row-head strong {
  width: fit-content;
  border: 1px solid #ffe2a8;
  border-radius: 8px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 5px 8px;
  text-transform: uppercase;
}

.node-fields,
.nested-node-fields,
.manual-node-fields,
.form-grid,
.group-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 11px;
}

.nested-node-fields {
  margin-top: 10px;
}

.tls-fields {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.tls-toggle {
  margin-bottom: 0;
}

.manual-node-fields {
  grid-column: 1 / -1;
  padding-top: 2px;
}

.check-row,
.checkbox-row {
  display: flex !important;
  min-height: 44px;
  align-items: center;
  gap: 8px !important;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--text);
  font-size: 13px;
  font-weight: 760;
  padding: 0 10px;
}

.check-row input,
.checkbox-row input {
  width: 18px;
  height: 18px;
}

.alpn-field {
  display: grid;
  gap: 8px;
}

.alpn-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.alpn-chip {
  display: inline-flex !important;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px !important;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--text);
  font-size: 13px;
  font-weight: 760;
  padding: 0 12px;
}

.alpn-chip:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.alpn-chip input {
  width: 16px;
  height: 16px;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.advanced-inline {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--surface-tint), #ffffff);
  box-shadow: var(--shadow-soft);
  padding: 12px;
}

.preset-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.tool-launcher {
  width: 100%;
  margin-bottom: 12px;
}

.field-divider {
  grid-column: 1 / -1;
  height: 1px;
  margin: 4px 0;
  background: var(--line);
}

details {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 780;
}

.file-button {
  text-align: center;
}

.fab-container {
  display: none;
}

.bottom-sheet[hidden] {
  display: none;
}

.bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 33, 42, 0.42);
}

.sheet-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  max-height: min(82svh, 620px);
  overflow: auto;
  border-radius: 8px 8px 0 0;
  background: var(--surface);
  padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -20px 50px rgba(20, 33, 42, 0.2);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.sheet-grid {
  display: grid;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 12px;
  bottom: 86px;
  left: 12px;
  z-index: 60;
  border-radius: 8px;
  background: #14212a;
  color: #ffffff;
  font-size: 13px;
  font-weight: 760;
  padding: 12px 14px;
  text-align: center;
  box-shadow: var(--shadow);
}

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

.toast.hidden {
  display: none;
}

@media (min-width: 720px) {
  .app-shell {
    padding: 24px 24px 36px;
  }

  .view-tabs {
    position: sticky;
    top: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 16px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
  }

  .screen-head {
    position: static;
    grid-template-columns: 1fr auto;
    align-items: center;
    margin: 0 0 16px;
    padding: 0;
    border: 0;
    background: transparent;
    backdrop-filter: none;
  }

  .quick-actions {
    display: flex;
  }

  .section-preview-head {
    grid-template-columns: 1fr minmax(180px, 240px);
    align-items: center;
  }

  .option-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 16px;
  }

  .input-area {
    min-height: 280px;
  }

  .sticky-actions {
    position: static;
    margin: 14px 0 0;
    padding: 0;
    background: transparent;
  }

  .yaml-preview {
    min-height: 56svh;
  }

  .action-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .edit-nav {
    top: 62px;
    margin: 0 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .edit-stage {
    min-height: 560px;
    padding: 16px;
  }

  .node-row-head {
    grid-template-columns: auto auto 1fr;
    align-items: center;
  }

  .row-actions {
    justify-content: end;
  }

  .node-fields,
  .manual-node-fields,
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inline-form {
    grid-template-columns: minmax(0, 1fr) minmax(160px, 220px) auto;
    align-items: center;
  }

  .advanced-inline {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .advanced-inline .ghost-button {
    grid-column: auto;
  }

  .edit-panel[data-edit-panel="providers"] .inline-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(120px, 160px) minmax(110px, 140px) minmax(100px, 120px) auto;
  }

  .preset-actions {
    grid-template-columns: repeat(2, max-content);
  }

  .sheet-panel {
    right: 24px;
    bottom: 24px;
    left: auto;
    width: min(560px, calc(100vw - 48px));
    border-radius: 8px;
    padding: 16px;
  }

  .sheet-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1040px) {
  .view-panel[data-view="convert"].active,
  .view-panel[data-view="yaml"].active {
    max-width: 860px;
    margin: 0 auto;
  }

  .view-panel[data-view="edit"].active {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    gap: 18px;
  }

  .view-panel[data-view="edit"] .screen-head {
    grid-column: 1 / -1;
  }

  .edit-nav {
    position: sticky;
    top: 76px;
    display: grid;
    align-self: start;
    gap: 8px;
    overflow: visible;
    padding: 10px;
  }

  .edit-nav button {
    width: 100%;
    justify-content: flex-start;
  }

  .edit-stage {
    margin-top: 0;
  }
}
