:root {
  --bg: #f4f6f2;
  --surface: #ffffff;
  --surface-soft: #f8faf7;
  --ink: #17201c;
  --muted: #66716b;
  --line: #dce2dd;
  --line-strong: #c8d0ca;
  --green: #167a52;
  --green-dark: #0f5f3e;
  --green-soft: #e7f5ed;
  --coral: #d65745;
  --coral-soft: #fff0ed;
  --blue: #21729a;
  --shadow: 0 12px 32px rgba(23, 32, 28, 0.08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { color: inherit; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.app-header {
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 246, 242, 0.96);
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; color: white; background: var(--ink); }
.brand-mark svg { width: 20px; height: 20px; }
.brand div { display: flex; align-items: baseline; gap: 9px; }
.brand strong { font-size: 15px; }
.brand span { color: var(--muted); font-size: 12px; }

.server-state { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.server-state > span { width: 7px; height: 7px; border-radius: 50%; background: #d89a2c; }
.server-state.online > span { background: var(--green); }
.server-state.offline > span { background: var(--coral); }

.workspace { min-height: calc(100vh - 64px); display: grid; grid-template-columns: minmax(420px, 0.9fr) minmax(520px, 1.1fr); }
.input-pane, .output-pane { min-width: 0; }
.input-pane { padding: 34px 36px 32px; border-right: 1px solid var(--line); }
.output-pane { background: var(--surface); }
.section-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 18px; }
.eyebrow { margin: 0 0 5px; color: var(--green); font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
h1 { margin: 0; font-size: 24px; line-height: 1.2; }
.line-count { color: var(--muted); font: 12px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }

.protocol-strip { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.protocol-strip span { padding: 4px 7px; border: 1px solid var(--line-strong); border-radius: 4px; color: #49534e; background: var(--surface-soft); font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.field-label, .field span { display: block; margin-bottom: 7px; color: #4f5b54; font-size: 12px; font-weight: 650; }

textarea, input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: none;
  color: var(--ink);
  background: var(--surface);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
textarea:focus, input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 122, 82, 0.12); }
textarea { min-height: 292px; max-height: 48vh; resize: vertical; padding: 14px; font: 12px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; }
input { height: 38px; padding: 0 11px; font-size: 13px; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px 12px; margin-top: 18px; }
.key-field { grid-column: 1 / -1; }
.toggles { grid-column: 1 / -1; display: flex; align-items: center; gap: 18px; min-height: 28px; }
.toggles label { display: flex; align-items: center; gap: 8px; color: #445049; font-size: 12px; cursor: pointer; }
.toggles input { appearance: none; width: 34px; height: 20px; padding: 0; border: 0; border-radius: 10px; background: #c6cdc8; position: relative; cursor: pointer; box-shadow: none; }
.toggles input::after { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform 140ms ease; }
.toggles input:checked { background: var(--green); }
.toggles input:checked::after { transform: translateX(14px); }

.action-row { display: flex; gap: 10px; margin-top: 22px; }
.button { min-height: 40px; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 6px; border: 1px solid transparent; font-size: 13px; font-weight: 700; cursor: pointer; }
.button:disabled { opacity: .55; cursor: wait; }
.button.primary { flex: 1; color: white; background: var(--green); }
.button.primary:hover:not(:disabled) { background: var(--green-dark); }
.button.secondary { background: var(--surface); border-color: var(--line-strong); }
.button.secondary:hover:not(:disabled) { background: var(--surface-soft); }

.tabs { height: 54px; display: flex; align-items: stretch; padding: 0 24px; border-bottom: 1px solid var(--line); background: var(--surface); }
.tab { padding: 0 14px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: 13px; font-weight: 650; cursor: pointer; }
.tab.active { color: var(--ink); border-bottom-color: var(--green); }
.tab span { min-width: 18px; height: 18px; margin-left: 4px; padding: 0 5px; display: inline-grid; place-items: center; border-radius: 9px; background: #edf0ed; font-size: 10px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.result-summary { min-height: 78px; padding: 18px 28px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); color: var(--muted); }
.result-summary strong { color: var(--ink); font-size: 13px; }
.result-summary.ready { justify-content: space-between; }
.summary-stat { display: flex; gap: 22px; }
.summary-stat div { display: grid; gap: 3px; }
.summary-stat b { font-size: 18px; }
.summary-stat span { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.empty-icon { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); color: var(--muted); }

.node-table-wrap { max-height: 184px; overflow: auto; border-bottom: 1px solid var(--line); }
.node-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 11px; }
.node-table th, .node-table td { padding: 10px 12px; border-bottom: 1px solid #edf0ed; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-table th { position: sticky; top: 0; background: var(--surface-soft); color: var(--muted); font-weight: 650; }
.node-table th:nth-child(1) { width: 30%; }
.node-table th:nth-child(2) { width: 16%; }
.node-table th:nth-child(4) { width: 12%; }
.protocol-pill { display: inline-block; padding: 3px 6px; border-radius: 3px; color: var(--blue); background: #eaf5f9; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.code-toolbar { height: 42px; padding: 0 14px 0 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #25302b; color: #aeb9b3; background: #19221e; font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.code-toolbar > div { display: flex; gap: 4px; }
.icon-button { width: 32px; height: 32px; display: inline-grid; place-items: center; border: 0; border-radius: 5px; color: inherit; background: transparent; cursor: pointer; }
.icon-button:hover:not(:disabled) { background: rgba(255,255,255,.1); color: white; }
.icon-button:disabled { opacity: .35; cursor: default; }
.icon-button svg { width: 16px; height: 16px; }
.code-output { margin: 0; height: calc(100vh - 64px - 54px - 78px - 42px); min-height: 340px; padding: 20px; overflow: auto; color: #d9e4de; background: #111815; font: 11px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; }

.issues-list, .subscriptions-list { min-height: calc(100vh - 118px); padding: 22px 24px; }
.empty-state { min-height: 240px; display: grid; place-items: center; align-content: center; gap: 12px; color: var(--muted); }
.empty-state svg { width: 28px; height: 28px; color: var(--green); }
.empty-state strong { color: var(--ink); font-size: 13px; }
.issue-item { display: grid; grid-template-columns: 44px 1fr; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.issue-line { color: var(--coral); font: 700 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.issue-item strong { display: block; margin-bottom: 4px; font-size: 12px; text-transform: uppercase; }
.issue-item p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }

.subscription-card { padding: 16px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); box-shadow: 0 4px 14px rgba(23,32,28,.04); }
.subscription-head { display: flex; justify-content: space-between; gap: 12px; }
.subscription-head strong { display: block; margin-bottom: 4px; font-size: 13px; }
.subscription-meta { color: var(--muted); font-size: 11px; }
.subscription-actions { display: flex; gap: 3px; }
.subscription-actions .icon-button { color: var(--muted); }
.subscription-url { margin-top: 13px; padding-top: 12px; border-top: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--blue); font: 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }

.toast { position: fixed; left: 50%; bottom: 22px; z-index: 20; max-width: min(460px, calc(100vw - 32px)); padding: 11px 14px; border-radius: 6px; color: white; background: #17201c; box-shadow: var(--shadow); font-size: 12px; opacity: 0; transform: translate(-50%, 12px); pointer-events: none; transition: opacity 160ms ease, transform 160ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #842f25; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .input-pane { border-right: 0; border-bottom: 1px solid var(--line); }
  .code-output { height: 480px; min-height: 360px; }
  .issues-list, .subscriptions-list { min-height: 420px; }
}

@media (max-width: 560px) {
  .app-header { height: 58px; padding: 0 16px; }
  .brand div { display: grid; gap: 1px; }
  .brand span { font-size: 10px; }
  .workspace { min-height: calc(100vh - 58px); }
  .input-pane { padding: 24px 16px; }
  h1 { font-size: 21px; }
  textarea { min-height: 250px; }
  .settings-grid { grid-template-columns: 1fr; }
  .key-field, .toggles { grid-column: 1; }
  .action-row { display: grid; grid-template-columns: 1fr 1fr; }
  .tabs { padding: 0 8px; }
  .tab { flex: 1; padding: 0 6px; }
  .result-summary { padding: 16px; }
  .node-table th, .node-table td { padding: 9px 8px; }
  .node-table th:nth-child(3), .node-table td:nth-child(3) { display: none; }
  .node-table th:nth-child(1) { width: 48%; }
  .node-table th:nth-child(2) { width: 28%; }
  .node-table th:nth-child(4) { width: 24%; }
  .code-output { min-height: 380px; height: 58vh; padding: 16px; }
}
