:root {
  --bg: #f4f5f7; --panel: #ffffff; --line: #e3e5e9; --text: #1d2129; --sub: #6b7280;
  --accent: #2563eb; --ok: #16a34a; --warn: #d97706; --bad: #dc2626; --chip: #f1f3f6;
  --code: #f6f7f9; --user: #e8f0fe; --think: #8a8f98;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --panel: #1a1d23; --line: #2b2f37; --text: #e6e8eb; --sub: #9aa1ab;
    --accent: #4f8cff; --ok: #22c55e; --warn: #f59e0b; --bad: #f87171; --chip: #242830;
    --code: #15181d; --user: #1f2a44; --think: #7c838e;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 6px 14px; cursor: pointer; white-space: nowrap; flex: none; }
a.btn { display: inline-block; background: var(--accent); color: #fff; border-radius: 6px; padding: 6px 14px; text-decoration: none; white-space: nowrap; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.bad { background: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%; }
textarea { resize: vertical; }
.hidden { display: none !important; }
.err { color: var(--bad); min-height: 1.5em; }

.login { height: 100%; display: flex; align-items: center; justify-content: center; }
.login form { width: 280px; display: flex; flex-direction: column; gap: 10px; }
.login h1 { font-size: 22px; margin: 0 0 6px; text-align: center; }

.app { height: 100%; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 20px; padding: 0 16px; height: 48px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex: none; }
.brand { font-weight: 600; font-size: 16px; }
nav { display: flex; gap: 4px; }
nav button { background: transparent; color: var(--sub); padding: 6px 12px; }
nav button.on { color: var(--text); background: var(--chip); }
.meta { margin-left: auto; color: var(--sub); font-size: 12px; }

main { flex: 1; display: flex; min-height: 0; }
.left { flex: 1; overflow: auto; padding: 16px; min-width: 0; }
.right { width: 460px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); }

.mesh { color: var(--sub); font-size: 12px; margin-bottom: 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.card .hd { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.card .num { font-weight: 600; }
.card .name { color: var(--sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sub); flex: none; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }
.card .rate { display: flex; gap: 14px; font-variant-numeric: tabular-nums; margin-bottom: 6px; }
.card .rate b { font-size: 18px; font-weight: 600; }
.card .rate span { color: var(--sub); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip { background: var(--chip); border-radius: 4px; padding: 1px 6px; font-size: 12px; color: var(--sub); }
.chip.ok { color: var(--ok); } .chip.bad { color: var(--bad); } .chip.warn { color: var(--warn); }
.card .errline { color: var(--bad); font-size: 12px; word-break: break-all; }

.tbl { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { color: var(--sub); font-weight: 500; }
.tbl td.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; }
.tbl tr.click { cursor: pointer; }

h2 { font-size: 15px; margin: 18px 0 10px; }
h2:first-child { margin-top: 0; }
.form { display: grid; grid-template-columns: 76px minmax(0, 440px); gap: 10px 12px; align-items: center; margin: 14px 0 0; }
.form label { color: var(--sub); }
.row { display: flex; gap: 8px; }

.chatbar { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { flex: 1; }

.m-user { align-self: flex-end; background: var(--user); border-radius: 10px; padding: 8px 12px; max-width: 88%; white-space: pre-wrap; }
.m-text { line-height: 1.6; word-wrap: break-word; }
.m-text p { margin: 0 0 8px; } .m-text p:last-child { margin: 0; }
.m-text pre { background: var(--code); padding: 8px 10px; border-radius: 6px; overflow-x: auto; font-size: 12px; }
.m-text code { background: var(--code); padding: 1px 4px; border-radius: 4px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; }
.m-text pre code { padding: 0; background: none; }
.m-text table { border-collapse: collapse; margin: 6px 0; font-size: 13px; display: block; overflow-x: auto; }
.m-text th, .m-text td { border: 1px solid var(--line); padding: 3px 8px; }
.m-text ul, .m-text ol { margin: 4px 0 8px; padding-left: 20px; }
.m-text h3, .m-text h4 { font-size: 14px; margin: 10px 0 4px; }
.m-think { color: var(--think); font-size: 12px; border-left: 2px solid var(--line); padding-left: 8px; white-space: pre-wrap; max-height: 120px; overflow: hidden; cursor: pointer; }
.m-think.open { max-height: none; }
.m-tool { font-size: 12px; color: var(--sub); }
.m-tool .ln { cursor: pointer; display: flex; gap: 6px; align-items: baseline; }
.m-tool .st { width: 14px; text-align: center; flex: none; }
.m-tool .st.ok { color: var(--ok); } .m-tool .st.bad { color: var(--bad); }
.m-tool pre { background: var(--code); padding: 6px 8px; border-radius: 6px; max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 4px 0 0 20px; }
.m-approve { border: 1px solid var(--warn); border-radius: 10px; padding: 10px 12px; }
.m-approve .tt { font-weight: 600; margin-bottom: 4px; }
.m-approve .why { margin-bottom: 6px; }
.m-approve pre { background: var(--code); padding: 6px 8px; border-radius: 6px; max-height: 300px; overflow: auto; font-size: 12px; white-space: pre-wrap; word-break: break-all; }
.m-approve .row { margin-top: 8px; }
.m-approve.done { border-color: var(--line); opacity: .75; }
.m-err { color: var(--bad); font-size: 13px; }
.m-usage { color: var(--sub); font-size: 11px; text-align: right; }

@media (max-width: 900px) {
  main { flex-direction: column; }
  .right { width: auto; height: 60vh; border-left: 0; border-top: 1px solid var(--line); }
}

.newkey { display: flex; gap: 8px; align-items: center; background: var(--code); border: 1px solid var(--warn); border-radius: 8px; padding: 8px 10px; max-width: 520px; }
.newkey span { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; flex: 1; }
#extReqs { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; margin-bottom: 12px; }
#extReqs:empty { display: none; }

.settings { display: flex; gap: 20px; align-items: flex-start; }
.snav { width: 120px; flex: none; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; }
.snav button { background: transparent; color: var(--sub); text-align: left; padding: 8px 12px; }
.snav button.on { background: var(--panel); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.panes { flex: 1; min-width: 0; max-width: 760px; }
.pane { display: flex; flex-direction: column; gap: 14px; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; }
.box-hd { font-weight: 600; display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.box .tbl { border: 0; border-radius: 0; }
.box .tbl tr:last-child td { border-bottom: 0; }
button.sm { padding: 3px 10px; font-size: 12px; }
.seg { display: inline-flex; background: var(--chip); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { background: transparent; color: var(--sub); padding: 5px 16px; border-radius: 6px; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg .live { color: var(--ok); font-size: 11px; margin-left: 4px; }
.msg { font-size: 12px; color: var(--sub); min-height: 1em; }
.msg.ok { color: var(--ok); } .msg.bad { color: var(--bad); }
#provTag:empty { display: none; }
#provTag { align-self: center; white-space: nowrap; flex: none; }
@media (max-width: 900px) { .settings { flex-direction: column; } .snav { flex-direction: row; width: auto; position: static; } }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.toolbar .mesh { margin: 0; }
.colpick { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px; min-width: 150px; box-shadow: 0 6px 20px rgba(0,0,0,.12); }
.menu label { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 4px; cursor: pointer; white-space: nowrap; }
.menu label:hover { background: var(--chip); }
.menu input, .sitelist input[type=checkbox] { width: auto; margin: 0; }
.tblwrap { overflow-x: auto; }
.sitelist td, .sitelist th { white-space: nowrap; vertical-align: middle; }
.sitelist tbody tr:hover { background: var(--chip); }
.sitelist .site { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.sitelist .sub { color: var(--sub); font-size: 12px; }
.sitelist .lines div + div { margin-top: 2px; }
.sitelist .bad { color: var(--bad); } .sitelist .ok { color: var(--ok); } .sitelist .warn { color: var(--warn); }
.sitelist .errcell { color: var(--bad); font-size: 12px; white-space: normal; }
.sitelist td.num { font-variant-numeric: tabular-nums; }
.sitelist input:not([type=checkbox]) { padding: 3px 6px; min-width: 120px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.ovpn { margin-bottom: 12px; }
.ovpn-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 12px; }
.ovpn-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--sub); font-size: 12px; }
.ovpn-grid textarea { font-family: ui-monospace, Consolas, monospace; font-size: 11px; color: var(--text); }
.ovpn-grid input { color: var(--text); }
@media (max-width: 1100px) { .ovpn-grid { grid-template-columns: 1fr; } }
.ovpn-opts { display: flex; align-items: center; gap: 10px; align-self: end; }
.ovpn-opts .chk { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; white-space: nowrap; }
.ovpn-opts .chk input { width: auto; margin: 0; }
.ovpn-opts input[name=vname] { width: 130px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.sitelist .del { color: var(--bad); text-decoration: line-through; }
#restoreFile { width: auto; flex: 1; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; }
.modal-box { background: var(--panel); border-radius: 12px; width: min(980px, 100%); padding: 18px 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal-hd { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-size: 15px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 14px; margin-bottom: 16px; font-size: 13px; }
.kv > div:nth-child(odd) { color: var(--sub); }
.kv .tag { display: inline-block; background: var(--chip); border-radius: 4px; padding: 1px 7px; margin: 0 4px 4px 0; font-size: 12px; }
.sitelist .site.click { cursor: pointer; text-decoration: underline dotted; }
#maskBtn.on { background: var(--accent); color: #fff; border-color: var(--accent); }
#vmAct, #ipv6Wan, #ipv6Ra { width: auto; } #vmCmd { width: 260px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.sitelist td.ck { text-align: center; font-weight: 600; cursor: default; }
.sitelist td.ck.ok { color: var(--ok); } .sitelist td.ck.bad { color: var(--bad); } .sitelist td.ck.warn { color: var(--warn); } .sitelist td.ck.na { color: var(--sub); }
.form .chk { display: flex; align-items: center; color: var(--text); } .form .chk input { width: auto; margin: 0; }
#ikbakTbl td { vertical-align: middle; }
.menu .mi { display: block; width: 100%; text-align: left; background: transparent; color: var(--text); padding: 6px 10px; border-radius: 4px; }
.menu .mi:hover { background: var(--chip); }
.route-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px 12px; }
.route-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--sub); font-size: 12px; }
.route-grid input, .route-grid select { color: var(--text); }
#speedForm { grid-template-columns: repeat(3, 160px); }
.box-hd .row { align-items: center; }
.sitelist .bar { display: inline-block; height: 6px; border-radius: 3px; background: var(--accent); vertical-align: middle; margin-right: 6px; }
@media (max-width: 1100px) { .route-grid { grid-template-columns: 1fr 1fr; } }
