:root {
  --bg: #f4f2ee; --panel: #fffdf9; --ink: #1c1b19; --muted: #6a665f; --line: #ddd8cf;
  --accent: #b4730a; --accent-ink: #fff; --accent-soft: #f7e7c8;
  --ok: #1f7a4d; --warn: #9a5b00; --err: #b3261e;
  --code-bg: #15171a; --code-ink: #d9dde3; --code-dim: #6f7885; --code-key: #e8a317; --code-sec: #7cc4a4;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121315; --panel: #1b1d20; --ink: #ecebe8; --muted: #9a978f; --line: #2d2f33;
    --accent: #e8a317; --accent-ink: #14130f; --accent-soft: #3a2d10;
    --ok: #5fcf97; --warn: #f0b24a; --err: #ff8a80;
    --code-bg: #0c0d0f;
  }
}
* { box-sizing: border-box; }
html { color-scheme: light dark; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--sans); }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }

.top { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; gap: 10px; align-items: center; margin-right: auto; }
.logo { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font: 800 18px var(--mono); }
.brand h1 { font-size: 17px; letter-spacing: -.01em; }
.brand p { font-size: 12px; color: var(--muted); }
.ver { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.ver label { cursor: pointer; }
.ver input { position: absolute; opacity: 0; pointer-events: none; }
.ver span { display: block; padding: 7px 14px; font-weight: 600; font-size: 13px; }
.ver input:checked + span { background: var(--accent); color: var(--accent-ink); }
.ver input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: -2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

button { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button:disabled { opacity: .45; cursor: not-allowed; }
select, input:not([type=checkbox]):not([type=radio]) { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; }
.actions select { width: auto; max-width: 100%; min-width: 0; }
.top > * { min-width: 0; }
.actions { max-width: 100%; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input.invalid, select.invalid { border-color: var(--err); box-shadow: 0 0 0 2px color-mix(in srgb, var(--err) 25%, transparent); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; padding: 16px; max-width: 1600px; margin: 0 auto; align-items: start; }
.form { min-width: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.tabs button { border-radius: 999px; padding: 6px 13px; font-size: 13px; }
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
section[hidden] { display: none; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin-bottom: 10px; }
h2 small, h3 small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.sub { font-size: 14px; margin: 18px 0 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 12px; margin-top: 8px; }
.grid label, .card > label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.grid .wide { grid-column: 1 / -1; }
.grid label.check, label.check { display: flex; gap: 8px; align-items: flex-start; color: var(--ink); font-size: 13.5px; }
label.check input { margin-top: 3px; }
label.big { font-size: 15px; font-weight: 600; }
.note { color: var(--accent); }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.hint:empty { display: none; }
.add { width: 100%; border-style: dashed; color: var(--muted); padding: 9px; margin-bottom: 8px; }

.seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; font-size: 12.5px; color: var(--muted); height: 100%; }
.seg b { display: block; color: var(--ink); font-size: 14px; }
.seg input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.item { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.item-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-weight: 600; font-size: 14px; }
.item-head button { padding: 3px 9px; font-size: 12px; color: var(--err); }
.item .grid { margin-top: 4px; }
.item[data-type="dhcp"] .only-static, .item[data-type="dhcp"] .only-pppoe,
.item[data-type="static"] .only-pppoe, .item[data-type="pppoe"] .only-static { display: none; }
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; margin: 12px 0 4px; }
.presets label { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 13px; cursor: pointer; }
.presets em { font-style: normal; font-size: 10.5px; border-radius: 999px; padding: 1px 7px; margin-left: auto; border: 1px solid var(--line); color: var(--muted); }
.presets em.official { color: var(--ok); border-color: var(--ok); }
.presets a { color: inherit; opacity: .6; font-size: 11px; }

.out { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 92px); min-width: 0; }
.out-head { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { font: 600 11.5px var(--mono); border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 9px; color: var(--muted); }
.out-actions { display: flex; gap: 8px; }
.problems { display: grid; gap: 6px; max-height: 30vh; overflow: auto; flex: none; }
.problems:empty { display: none; }
.problems div { font-size: 12.5px; border-radius: 8px; padding: 7px 10px; border: 1px solid; }
.problems .err { color: var(--err); border-color: var(--err); background: color-mix(in srgb, var(--err) 9%, transparent); }
.problems .warn { color: var(--warn); border-color: var(--warn); background: color-mix(in srgb, var(--warn) 9%, transparent); }
.script { margin: 0; flex: 1; min-height: 260px; overflow: auto; background: var(--code-bg); color: var(--code-ink); border-radius: var(--radius); padding: 12px 0; font: 12px/1.55 var(--mono); tab-size: 2; counter-reset: ln; }
.script .l { display: block; padding: 0 14px 0 52px; position: relative; white-space: pre; }
.script .l::before { counter-increment: ln; content: counter(ln); position: absolute; left: 0; width: 38px; text-align: right; color: var(--code-dim); opacity: .6; user-select: none; }
.script .c { color: var(--code-dim); }
.script .s { color: var(--code-sec); font-weight: 600; }
.script .m { color: var(--code-key); }
.script.stale { opacity: .35; }
.code { background: var(--code-bg); color: var(--code-ink); border-radius: 8px; padding: 10px 12px; overflow: auto; font: 12px/1.5 var(--mono); margin: 8px 0 12px; }
.apply { font-size: 13px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.apply summary { cursor: pointer; color: var(--ink); font-weight: 600; }
.apply ol, .prose ol { padding-left: 20px; margin: 8px 0 0; }
code { font: 12px var(--mono); background: color-mix(in srgb, var(--ink) 8%, transparent); padding: 1px 5px; border-radius: 4px; }
.prose p { margin: 6px 0; }
.prose h2 { margin-top: 10px; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: 13px; z-index: 20; }

@media (max-width: 980px) {
  .actions { flex: 1 1 100%; }
  .actions select { flex: 1 1 100%; }
  .layout { grid-template-columns: 1fr; padding: 12px 16px; }
  .out { position: static; max-height: none; }
  .script { max-height: 70vh; }
  .top { position: static; }
}
@media (prefers-reduced-motion: no-preference) { button, .seg span { transition: background .15s, border-color .15s; } }
