:root {
  --bg: #0e1117;
  --surface: #151a22;
  --surface-2: #1a202b;
  --surface-3: #202733;
  --border: #2b3442;
  --border-soft: #222a36;
  --text: #edf2f7;
  --muted: #8a96a7;
  --muted-2: #677386;
  --blue: #4c9aff;
  --blue-soft: #122b4a;
  --cyan: #48c6b8;
  --red: #ef6d78;
  --yellow: #e7bb63;
  --radius: 7px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 14px; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.auth-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 20px; background: #0d1117; }
.auth-mark { position: absolute; top: 28px; left: 34px; display: flex; align-items: center; gap: 11px; color: #cad3df; font-size: 15px; letter-spacing: .01em; }
.mark-box { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; background: var(--blue); color: #08121f; font-size: 16px; font-weight: 800; border-radius: 6px; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 38px 38px 34px; box-shadow: 0 20px 70px rgba(0,0,0,.3); }
.eyebrow, .section-kicker, .top-kicker { color: var(--blue); font-size: 10px; letter-spacing: .15em; font-weight: 700; }
.auth-card h1 { margin: 13px 0 8px; font-size: 30px; font-weight: 650; letter-spacing: -.02em; }
.auth-card p { margin: 0 0 28px; color: var(--muted); line-height: 1.65; }
.auth-card label, .modal-card label { display: block; color: #aeb8c5; font-size: 12px; margin: 17px 0 0; }
.auth-card input, .modal-card input, .modal-card textarea { display: block; width: 100%; margin-top: 8px; background: #0f141b; border: 1px solid var(--border); border-radius: 5px; color: var(--text); padding: 12px 13px; outline: 0; transition: border-color .15s, box-shadow .15s; }
.auth-card input:focus, .modal-card input:focus, .modal-card textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(76,154,255,.13); }
.auth-hint { min-height: 20px; margin-top: 16px; color: var(--red); font-size: 12px; line-height: 1.5; }
.auth-footer { position: absolute; bottom: 24px; color: var(--muted-2); font-size: 11px; }

.app-shell { min-height: 100vh; display: flex; }
.sidebar { width: 238px; flex: 0 0 238px; min-height: 100vh; display: flex; flex-direction: column; padding: 27px 16px 18px; background: #11161e; border-right: 1px solid var(--border-soft); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 11px 31px; color: #eef3f9; }
.brand strong { display: block; font-size: 16px; line-height: 1.05; font-weight: 700; }
.brand small { display: block; margin-top: 4px; color: var(--muted-2); font-size: 9px; letter-spacing: .18em; }
.sidebar-label { padding: 0 12px 10px; color: var(--muted-2); font-size: 10px; letter-spacing: .14em; }
nav { display: grid; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; border-radius: 6px; background: transparent; color: var(--muted); padding: 12px; text-align: left; transition: .15s; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--blue-soft); color: #e6f1ff; }
.nav-icon { width: 19px; text-align: center; font-size: 19px; line-height: 1; color: currentColor; }
.sidebar-bottom { margin-top: auto; padding: 15px 11px 0; border-top: 1px solid var(--border-soft); }
.server-status { display: flex; align-items: center; gap: 9px; padding: 8px 0 17px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 0 4px rgba(72,198,184,.1); }
.server-status strong { display: block; color: #d9e2ec; font-size: 12px; font-weight: 600; }
.server-status small { display: block; color: var(--muted-2); font-size: 9px; letter-spacing: .12em; margin-top: 3px; }
.logout { border: 0; padding: 5px 0; color: var(--muted); background: transparent; font-size: 12px; }
.logout:hover { color: var(--red); }

.main-area { min-width: 0; flex: 1; }
.topbar { min-height: 89px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px 42px; border-bottom: 1px solid var(--border-soft); background: #10151d; }
.top-kicker { color: var(--muted-2); font-size: 9px; }
.topbar h2 { margin: 5px 0 0; font-size: 23px; font-weight: 650; letter-spacing: -.02em; }
.top-actions, .editor-actions, .panel-tools, .publish-actions, .url-row { display: flex; align-items: center; gap: 9px; }
.account-name { color: var(--muted); font-size: 12px; margin-right: 9px; }
.view { padding: 35px 42px 58px; max-width: 1450px; }
.overview-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 42px; }
.metric { min-height: 120px; padding: 20px 21px; border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--surface); }
.metric-label { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 15px; color: var(--text); font-size: 28px; font-weight: 650; letter-spacing: -.03em; }
.metric small { display: block; margin-top: 4px; color: var(--muted-2); font-size: 11px; }
.accent-metric strong { color: var(--cyan); font-size: 22px; margin-top: 19px; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 17px; }
.section-heading h3, .panel-heading h3 { margin: 7px 0 0; font-size: 18px; font-weight: 620; letter-spacing: -.015em; }
.muted { color: var(--muted); margin: 9px 0 0; font-size: 12px; }
.quiet-button, .secondary, .primary, .danger-button, .back-button { border: 1px solid transparent; border-radius: 5px; padding: 9px 14px; transition: background .15s, border-color .15s, color .15s; }
.secondary:disabled, .primary:disabled { cursor: wait; opacity: .6; }
.quiet-button { background: transparent; color: var(--muted); border-color: var(--border); }
.quiet-button:hover { color: var(--text); border-color: #48566a; background: var(--surface); }
.secondary { color: #d9e5f3; border-color: #3b4a5e; background: var(--surface-2); }
.secondary:hover { border-color: var(--blue); color: #fff; }
.primary { color: #06111e; background: var(--blue); border-color: var(--blue); font-weight: 650; }
.primary:hover { background: #77b4ff; border-color: #77b4ff; }
.danger-button { color: #ff9ba1; border-color: rgba(239,109,120,.4); background: rgba(239,109,120,.07); }
.danger-button:hover { background: rgba(239,109,120,.15); border-color: var(--red); }
.wide { width: 100%; margin-top: 24px; padding: 12px; }
.small { padding: 8px 11px; font-size: 12px; }

.config-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 13px; }
.config-card { min-height: 167px; display: flex; flex-direction: column; padding: 19px; border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--surface); transition: border-color .15s, transform .15s; }
.config-card:hover { border-color: #3c516a; transform: translateY(-1px); }
.config-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.config-card h4 { margin: 0; color: #eff4fa; font-size: 16px; font-weight: 620; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state-pill { display: inline-flex; align-items: center; border-radius: 20px; padding: 4px 8px; font-size: 10px; color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.state-pill.live { color: var(--cyan); border-color: rgba(72,198,184,.36); background: rgba(72,198,184,.08); }
.config-card-meta { display: flex; gap: 15px; margin-top: 21px; color: var(--muted); font-size: 11px; }
.config-card-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; padding-top: 17px; border-top: 1px solid var(--border-soft); }
.config-card-time { color: var(--muted-2); font-size: 10px; }
.card-actions { display: flex; gap: 6px; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 29px; height: 29px; border: 1px solid var(--border); border-radius: 5px; color: var(--muted); background: transparent; }
.icon-button:hover { color: var(--text); border-color: #53657c; background: var(--surface-2); }
.icon-button.delete:hover { color: var(--red); border-color: rgba(239,109,120,.5); }
.empty-state { padding: 70px 20px; text-align: center; border: 1px dashed #334052; border-radius: var(--radius); background: rgba(21,26,34,.45); }
.empty-icon { display: inline-flex; align-items: center; justify-content: center; width: 43px; height: 43px; border: 1px solid #405169; border-radius: 8px; color: var(--blue); font-size: 25px; }
.empty-state h3 { margin: 15px 0 6px; font-size: 17px; }
.empty-state p { margin: 0 0 18px; color: var(--muted); font-size: 12px; }
.empty-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }

.editor-view { padding-top: 23px; }
.editor-toolbar { display: flex; align-items: center; gap: 22px; margin-bottom: 21px; }
.back-button { padding: 7px 0; color: var(--muted); background: transparent; }
.back-button:hover { color: var(--text); }
.editor-title { min-width: 0; flex: 1; display: flex; align-items: center; gap: 9px; }
.editor-title input { min-width: 0; width: 330px; padding: 4px 0; border: 0; border-bottom: 1px solid transparent; outline: 0; background: transparent; color: var(--text); font-size: 19px; font-weight: 620; }
.editor-title input:focus { border-bottom-color: var(--blue); }
.dirty-indicator { color: var(--yellow); font-size: 11px; }
.editor-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab { border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 11px 15px; color: var(--muted); background: transparent; }
.tab:hover { color: var(--text); }
.tab.active { color: #e7f1ff; border-bottom-color: var(--blue); }
.tab-count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 17px; margin-left: 4px; border-radius: 9px; color: var(--muted); background: var(--surface-3); font-size: 10px; }
.tab-panel { padding-top: 27px; }
.panel-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 15px; margin-bottom: 16px; }
.code-wrap { position: relative; display: flex; min-height: 590px; overflow: hidden; border: 1px solid var(--border); border-radius: 6px; background: #0c1015; }
.line-numbers { flex: 0 0 48px; padding: 17px 10px 17px 0; overflow: hidden; color: #495667; border-right: 1px solid #19212b; text-align: right; font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; user-select: none; white-space: pre; }
#yaml-editor { min-width: 0; flex: 1; resize: none; border: 0; outline: 0; padding: 17px 18px; color: #d8e4f1; background: transparent; font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 2; white-space: pre; }
.editor-foot { display: flex; justify-content: space-between; padding: 8px 3px; color: var(--muted-2); font-size: 10px; letter-spacing: .08em; }
.stack-list { display: grid; gap: 9px; }
.node-row, .rule-row { display: flex; align-items: center; gap: 13px; min-height: 71px; padding: 13px 15px; border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--surface); }
.node-index { flex: 0 0 25px; color: var(--muted-2); font: 11px ui-monospace, monospace; }
.node-main, .rule-main { min-width: 0; flex: 1; }
.node-name, .rule-content { display: block; overflow: hidden; color: #e7edf5; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.node-sub { display: block; margin-top: 5px; color: var(--muted); font: 11px ui-monospace, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.type-tag, .policy-tag { display: inline-flex; align-items: center; border: 1px solid rgba(76,154,255,.55); border-radius: 4px; padding: 3px 6px; color: var(--blue); font-size: 10px; letter-spacing: .04em; white-space: nowrap; }
.policy-tag { min-width: 74px; justify-content: center; color: var(--cyan); border-color: rgba(72,198,184,.35); }
.rule-content { font-weight: 500; }
.rule-arrow { color: var(--muted-2); }
.inline-empty { padding: 50px 20px; border: 1px dashed #334052; color: var(--muted); text-align: center; font-size: 12px; }

.publish-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 17px; align-items: start; }
.publish-card, .qr-card { padding: 21px; border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--surface); }
.publish-card-label { color: var(--muted-2); font-size: 10px; letter-spacing: .12em; font-weight: 700; }
.url-row { margin-top: 13px; }
.url-row input { min-width: 0; flex: 1; padding: 11px 12px; border: 1px solid var(--border); border-radius: 5px; color: #c9d6e5; background: #0f141b; outline: 0; font: 12px ui-monospace, monospace; }
.publish-note { margin-top: 13px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.publish-actions { margin-top: 13px; flex-wrap: wrap; }
.qr-card { display: flex; flex-direction: column; align-items: center; min-height: 354px; }
.qr-card .publish-card-label { align-self: stretch; }
.qr-image { width: 248px; height: 248px; margin-top: 22px; padding: 7px; border-radius: 4px; background: #fff; }
.qr-placeholder { display: flex; align-items: center; justify-content: center; width: 248px; height: 248px; margin-top: 22px; border: 1px dashed #3b4759; color: var(--muted-2); text-align: center; font-size: 11px; }
.published-list { display: grid; gap: 10px; }
.published-row { display: flex; align-items: center; gap: 17px; padding: 17px 19px; border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--surface); }
.published-row-main { min-width: 0; flex: 1; }
.published-row h4 { margin: 0 0 7px; font-size: 14px; }
.published-row code { display: block; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.modal-root { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(4,7,11,.76); }
.modal-card { width: min(640px, 100%); max-height: calc(100vh - 40px); overflow: auto; padding: 25px; border: 1px solid #3c4758; border-radius: 8px; background: #181f29; box-shadow: 0 24px 80px rgba(0,0,0,.45); }
.modal-card h3 { margin: 0 0 7px; font-size: 19px; }
.modal-card > p { margin: 0 0 19px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.modal-card textarea { min-height: 175px; resize: vertical; font: 12px/1.6 ui-monospace, monospace; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.rule-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.rule-form-grid label:last-child { grid-column: 1 / -1; }
.modal-card select { display: block; width: 100%; margin-top: 8px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 5px; color: var(--text); background: #0f141b; outline: 0; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: min(360px, calc(100vw - 30px)); padding: 11px 14px; border: 1px solid #3b4b60; border-radius: 5px; color: #e9f2fc; background: #202a38; box-shadow: 0 10px 30px rgba(0,0,0,.3); font-size: 12px; animation: toast-in .18s ease-out; }
.toast.success { border-color: rgba(72,198,184,.5); background: #172e30; }
.toast.error { border-color: rgba(239,109,120,.55); background: #342126; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 860px) {
  .sidebar { width: 70px; flex-basis: 70px; padding: 20px 10px; }
  .brand { justify-content: center; padding: 0 0 26px; }
  .brand > div, .sidebar-label, .nav-item span:last-child, .sidebar-bottom > *:not(.status-dot) { display: none; }
  .nav-item { justify-content: center; padding: 12px 0; }
  .sidebar-bottom { padding: 14px 0 0; text-align: center; }
  .server-status { justify-content: center; }
  .topbar, .view { padding-left: 24px; padding-right: 24px; }
  .publish-layout { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .auth-mark { left: 20px; top: 20px; }
  .auth-card { padding: 29px 23px 25px; }
  .topbar { align-items: flex-start; padding-top: 18px; padding-bottom: 18px; }
  .top-actions { gap: 5px; }
  .account-name { display: none; }
  .top-actions .primary { padding: 8px 10px; font-size: 12px; }
  .view { padding: 24px 15px 45px; }
  .overview-grid { gap: 8px; margin-bottom: 28px; }
  .metric { min-height: 100px; padding: 14px 12px; }
  .metric strong { margin-top: 11px; font-size: 22px; }
  .metric small { font-size: 10px; }
  .editor-toolbar { flex-wrap: wrap; gap: 10px; }
  .editor-title { order: 3; flex-basis: 100%; }
  .editor-title input { width: 100%; }
  .editor-actions { margin-left: auto; }
  .panel-heading { align-items: flex-start; }
  .code-wrap { min-height: 480px; }
  .publish-actions button { flex: 1; }
  .node-row, .rule-row { gap: 8px; padding: 11px; }
  .node-index { display: none; }
  .rule-arrow { display: none; }
  .rule-form-grid { grid-template-columns: 1fr; }
  .rule-form-grid label:last-child { grid-column: auto; }
}
