:root {
  color: #17211b;
  background: #f4f6f3;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --ink: #17211b;
  --muted: #6b756e;
  --line: #d9ded9;
  --surface: #ffffff;
  --accent: #176b46;
  --accent-hover: #105638;
  --danger: #b63a32;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.hidden { display: none !important; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: 0; }
.muted { color: var(--muted); line-height: 1.6; }

.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(260px, 42%) 1fr; background: #edf1ed; }
.login-mark { display: grid; place-items: center; background: #14271d; color: #cbe9d7; font-family: Georgia, serif; font-size: clamp(96px, 18vw, 250px); }
.login-panel { align-self: center; width: min(420px, calc(100% - 48px)); margin: 0 auto; }
.login-panel h1 { margin: 0; font-size: 42px; font-weight: 700; }
.login-panel label, #nodeForm label { display: grid; gap: 8px; margin-top: 28px; color: #39443d; font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #cfd5d0; border-radius: 6px; background: #fff; color: var(--ink); outline: none; padding: 12px 13px; transition: border-color 140ms ease, box-shadow 140ms ease; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23, 107, 70, .12); }
textarea { resize: vertical; }

.primary, .secondary, .copy-line button, .terminal-line button { min-height: 40px; border: 0; border-radius: 6px; padding: 0 16px; font-weight: 750; }
.primary { background: var(--accent); color: #fff; transition: background 140ms ease, transform 140ms ease; }
.primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.secondary { border: 1px solid var(--line); background: #fff; color: var(--ink); }
.wide { width: 100%; margin-top: 8px; }
.form-error { min-height: 21px; color: var(--danger); font-size: 13px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 228px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 28px 18px; background: #14271d; color: #d8e1db; }
.brand { display: flex; align-items: center; gap: 12px; margin: 0 10px 42px; color: #fff; }
.brand span { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid #789183; color: #cbe9d7; font-family: Georgia, serif; font-weight: 700; }
.brand strong { font-size: 18px; }
.sidebar nav { display: grid; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 11px; width: 100%; min-height: 44px; padding: 0 12px; border: 0; border-radius: 5px; background: transparent; color: #aebbb3; text-align: left; font-weight: 650; }
.nav-item:hover, .nav-item.active { background: #21382c; color: #fff; }
.nav-icon { display: grid; place-items: center; width: 22px; height: 22px; border: 1px solid currentColor; font-size: 10px; }
.sidebar-foot { margin-top: auto; padding: 16px 10px 0; border-top: 1px solid #2e4337; color: #aebbb3; font-size: 12px; }
.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #65cc91; box-shadow: 0 0 0 4px rgba(101,204,145,.12); }
.text-button { display: block; margin-top: 16px; padding: 0; border: 0; background: none; color: #aebbb3; }

main { min-width: 0; }
.topbar { min-height: 116px; display: flex; align-items: center; justify-content: space-between; padding: 24px clamp(24px, 4vw, 64px); border-bottom: 1px solid var(--line); background: rgba(255,255,255,.76); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar h1 { margin: 0; font-size: 28px; }
.workspace { padding: 36px clamp(24px, 4vw, 64px) 64px; animation: enter 220ms ease both; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.summary-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.summary-row div { display: grid; gap: 7px; padding: 22px 24px; border-right: 1px solid var(--line); }
.summary-row div:last-child { border-right: 0; }
.summary-row span { color: var(--muted); font-size: 12px; }
.summary-row strong { font-size: 22px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin: 38px 0 16px; }
.section-heading.spaced { margin-top: 56px; }
.section-heading h2 { margin: 0 0 5px; font-size: 18px; }
.section-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.search-wrap { width: min(320px, 100%); }
.search-wrap input { padding: 10px 12px; }

.table-wrap { overflow-x: auto; border-top: 1px solid #bcc5be; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: 15px 14px; border-bottom: 1px solid #e4e8e4; text-align: left; font-size: 13px; vertical-align: middle; }
th { color: var(--muted); background: #fafbfa; font-size: 11px; text-transform: uppercase; }
.align-right { text-align: right; }
.node-name { display: grid; gap: 4px; }
.node-name strong { font-size: 14px; }
.node-name span, .server-cell span { color: var(--muted); font-size: 11px; }
.rule-value { display: block; max-width: 760px; overflow-wrap: anywhere; color: #244b36; font-size: 13px; white-space: pre-wrap; }
.server-cell { display: grid; gap: 4px; max-width: 310px; }
.server-cell strong, .server-cell span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.protocol { display: inline-block; min-width: 58px; padding: 4px 7px; border: 1px solid #bfcac2; color: #385444; font-size: 10px; font-weight: 800; text-align: center; }
.state { display: inline-flex; align-items: center; gap: 7px; }
.state::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #87918a; }
.state.enabled::before { background: #23915f; }
.row-actions { display: flex; justify-content: flex-end; gap: 5px; }
.row-actions button { min-width: 34px; height: 32px; border: 1px solid transparent; border-radius: 4px; background: transparent; color: #536058; }
.row-actions button:hover { border-color: var(--line); background: #f4f6f4; color: var(--ink); }
.row-actions .delete:hover { color: var(--danger); }
.empty { display: grid; justify-items: center; gap: 7px; padding: 62px 20px; color: var(--muted); background: #fff; }

.copy-line, .terminal-line { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; border: 1px solid var(--line); background: #fff; }
.copy-line code, .terminal-line code { padding: 18px 20px; overflow-wrap: anywhere; line-height: 1.6; }
.copy-line button, .terminal-line button { margin: 7px; background: #e9efeb; color: #254735; }
.terminal-line { background: #16231c; border-color: #16231c; color: #d5e8dc; }
.terminal-line button { background: #2e493a; color: #eef8f1; }
.shadowrocket-qr { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: 16px; padding: 24px; border: 1px solid var(--line); background: #fff; color: var(--muted); font-size: 13px; text-align: center; }
.shadowrocket-qr img { display: block; width: min(280px, 100%); height: auto; aspect-ratio: 1; image-rendering: pixelated; }
.notice { display: grid; gap: 7px; margin-top: 40px; padding: 18px 20px; border-left: 3px solid #c1963d; background: #fbf7ec; color: #6b572e; }
.notice span { font-size: 13px; }

dialog { width: min(680px, calc(100% - 28px)); max-height: calc(100vh - 40px); padding: 0; border: 0; border-radius: 7px; box-shadow: 0 24px 70px rgba(12, 27, 18, .24); }
#ruleDialog { width: min(860px, calc(100% - 28px)); }
#ruleForm { padding: 32px 36px 28px; }
#ruleForm .dialog-head { margin-bottom: 24px; }
#ruleForm label { display: grid; gap: 10px; margin-top: 24px; color: #39443d; font-size: 15px; font-weight: 700; }
#ruleForm textarea { min-height: 220px; padding: 16px; line-height: 1.6; }
#ruleForm .rule-help { margin: 12px 0 0; line-height: 1.6; }
dialog::backdrop { background: rgba(15, 25, 19, .5); backdrop-filter: blur(2px); }
#nodeForm { padding: 26px; }
.dialog-head { display: flex; justify-content: space-between; align-items: start; }
.dialog-head h2 { margin: 0; }
.icon-button { width: 36px; height: 36px; border: 0; background: transparent; color: #617067; font-size: 26px; }
.mode-tabs { display: flex; gap: 4px; margin-top: 24px; border-bottom: 1px solid var(--line); }
.mode-tabs button { padding: 10px 14px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); }
.mode-tabs button.active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 700; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .check-row { display: flex !important; align-items: center; gap: 9px !important; }
.check-row input { width: 17px; height: 17px; accent-color: var(--accent); }
.import-hint { margin: 22px 0 -10px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.rule-help { margin: 8px 0 0; font-size: 12px; }
#ruleForm > .check-row { display: flex; align-items: center; gap: 9px; margin-top: 22px; font-size: 15px; }
#ruleForm > .check-row input { width: 17px; height: 17px; accent-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 10; padding: 12px 16px; border-radius: 5px; background: #183124; color: #fff; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity 160ms ease, transform 160ms ease; }
.toast.show { opacity: 1; transform: none; }

@media (max-width: 760px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-mark { display: none; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; width: 100%; height: auto; padding: 16px; }
  .brand { margin: 0 0 14px; }
  .sidebar nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sidebar-foot { display: none; }
  .topbar { min-height: 92px; padding: 18px; }
  .topbar h1 { font-size: 22px; }
  .topbar-actions { gap: 6px; }
  .workspace { padding: 22px 16px 44px; }
  .summary-row { grid-template-columns: 1fr 1fr; }
  .summary-row div { padding: 16px; }
  .summary-row div:nth-child(2) { border-right: 0; }
  .summary-row div:last-child { grid-column: span 2; border-top: 1px solid var(--line); }
  .section-heading { align-items: stretch; flex-direction: column; }
  .search-wrap { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .copy-line, .terminal-line { grid-template-columns: 1fr; }
}

button:disabled { cursor: default; opacity: .55; }
.primary:disabled:hover { background: var(--accent); transform: none; }

.node-picker { display: flex; flex-wrap: wrap; gap: 10px; }
.node-picker label { display: inline-flex; align-items: center; gap: 9px; padding: 10px 14px; border: 1px solid var(--line); background: #fff; font-size: 13px; cursor: pointer; }
.node-picker input { width: 16px; height: 16px; margin: 0; padding: 0; accent-color: var(--accent); }
.tag { padding: 2px 6px; border: 1px solid #bfcac2; color: #385444; font-size: 10px; font-weight: 800; }
.tag.warn { border-color: #d9b264; background: #fbf7ec; color: #7a5b16; }

.copy-line + .terminal-line, .terminal-line + .terminal-line { margin-top: 8px; }
.terminal-line code { font-size: 13px; }
