:root {
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #182339;
  background: #f4f6fa;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --ink: #182339;
  --muted: #738098;
  --line: #e4e9f1;
  --blue: #345bdb;
  --blue-dark: #2648bd;
  --teal: #128b77;
  --red: #c54855;
  --surface: #fff;
  --soft: #f7f8fc;
  --shadow: 0 14px 36px rgba(33, 50, 83, .07);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: #f4f6fa; }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.topbar {
  height: 72px; padding: 0 max(28px, calc((100vw - 1320px) / 2));
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(255,255,255,.94); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; gap: 11px; align-items: center; text-decoration: none; color: inherit; }
.brand-mark { display: grid; place-items: center; width: 37px; height: 37px; border-radius: 12px; color: white; font-size: 19px; font-weight: 800; background: linear-gradient(145deg,#5278ef,#2844bd); box-shadow: 0 6px 14px #345bdb33; }
.brand strong { display: block; font-size: 16px; letter-spacing: .02em; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.topbar-right { display: flex; align-items: center; gap: 18px; }
.connection-state { color: var(--muted); display: inline-flex; align-items: center; gap: 7px; font-size: 12px; }
.connection-state i { width: 7px; height: 7px; border-radius: 50%; background: #a7b0c0; }
.connection-state.is-online { color: #13866f; }
.connection-state.is-online i { background: #19a683; box-shadow: 0 0 0 4px #19a6831b; }

.page { width: min(1320px, calc(100% - 56px)); margin: 42px auto 72px; }
h1,h2,h3,p { margin-top: 0; }
h1 { margin-bottom: 8px; color: var(--ink); font-size: clamp(25px,3vw,32px); letter-spacing: -.035em; }
h2 { margin-bottom: 0; font-size: 17px; letter-spacing: -.02em; }
h3 { margin-bottom: 3px; font-size: 14px; }
.muted { margin-bottom: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.subtle { color: var(--muted); font-size: 12px; }
.eyebrow { margin-bottom: 8px; color: #5972c4; font-size: 10px; font-weight: 750; letter-spacing: .13em; }

.login-card { width: min(510px, 100%); margin: 9vh auto 0; padding: 38px 40px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 30px; }
.login-form { margin-top: 30px; }
.login-form > label,.field-label { display: block; margin-bottom: 8px; color: #46536c; font-size: 12px; font-weight: 650; }
.token-row { display: flex; gap: 9px; }
.token-row input { min-width: 0; flex: 1; }
.hint { margin: 8px 0 0; color: #8994a8; font-size: 11px; line-height: 1.65; }

input:not([type=checkbox]),select { width: 100%; min-height: 40px; padding: 9px 11px; color: var(--ink); background: #fff; border: 1px solid #dbe1eb; border-radius: 8px; outline: none; transition: border-color .15s,box-shadow .15s; }
input:not([type=checkbox]):focus,select:focus { border-color: #7891ed; box-shadow: 0 0 0 3px #345bdb17; }
input::placeholder { color: #a2acbc; }

.button { min-height: 38px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid transparent; border-radius: 8px; font-size: 12px; font-weight: 650; transition: .15s ease; white-space: nowrap; }
.button:disabled { opacity: .55; cursor: wait; }
.button-primary { color: #fff; background: var(--blue); box-shadow: 0 4px 10px #345bdb22; }
.button-primary:hover:not(:disabled) { background: var(--blue-dark); transform: translateY(-1px); }
.button-secondary { color: #43516b; background: #fff; border-color: #dce2ec; }
.button-secondary:hover:not(:disabled) { background: #f7f8fc; border-color: #c7d0df; }
.button-quiet { color: #67748a; background: transparent; border-color: transparent; }
.button-quiet:hover { background: #f0f2f7; }
.button-danger-quiet { color: #a94450; background: #fff; border-color: #efd7da; }
.button-danger-quiet:hover { background: #fff5f5; border-color: #e9bfc4; }
.button-compact { min-height: 39px; padding: 0 12px; }
.button-full { width: 100%; justify-content: flex-start; }

.page-heading,.resource-heading,.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.page-heading { margin-bottom: 25px; }
.toolbar { display: flex; align-items: center; gap: 12px; }
.refresh-toggle { display: inline-flex; align-items: center; gap: 7px; color: #68758b; font-size: 11px; white-space: nowrap; }
input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--blue); }
.notice { margin: 0 0 16px; padding: 12px 15px; border: 1px solid; border-radius: 9px; font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
.notice-error { color: #9f3440; background: #fff4f4; border-color: #f0d0d3; }
.notice-success { color: #14705f; background: #effaf6; border-color: #c8eadd; }

.metrics-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 13px; margin-bottom: 20px; }
.metric-card { min-height: 119px; padding: 17px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 3px 12px #23385f05; }
.metric-label { display: block; color: #768198; font-size: 11px; }
.metric-value { display: block; margin: 10px 0 5px; color: #202d46; font-size: 26px; font-weight: 720; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.metric-foot { color: #a0a9b8; font-size: 10px; }

.workspace { display: grid; grid-template-columns: 252px minmax(0,1fr); gap: 17px; align-items: start; }
.sidebar,.resource-area { background: var(--surface); border: 1px solid var(--line); border-radius: 13px; box-shadow: 0 3px 12px #23385f05; }
.sidebar { position: sticky; top: 18px; padding: 20px 17px; }
.section-heading { margin-bottom: 20px; }
.section-heading h2 { margin-bottom: 5px; }
.select-control { margin-bottom: 20px; }
.create-product-form { padding: 15px 0 2px; border-top: 1px solid var(--line); }
.inline-form { display: flex; gap: 7px; }
.inline-form input { min-width: 0; }
.divider { height: 1px; margin: 18px 0 15px; background: var(--line); }
.credential-actions .hint { margin-bottom: 12px; }
.button-stack { display: grid; gap: 7px; }

.resource-area { min-width: 0; padding: 20px; }
.resource-heading { margin-bottom: 17px; }
.resource-heading h2 { margin-bottom: 5px; }
.resource-content { display: grid; gap: 13px; }
.product-group { overflow: hidden; border: 1px solid var(--line); border-radius: 11px; }
.product-group-heading { min-height: 46px; padding: 11px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #fafbfe; border-bottom: 1px solid var(--line); }
.product-name { color: #34415b; font-size: 12px; font-weight: 700; }
.product-counts { color: var(--muted); font-size: 10px; }
.resource-columns { display: grid; grid-template-columns: minmax(0,1.3fr) minmax(225px,.9fr); }
.resource-column { min-width: 0; padding: 15px; }
.resource-column + .resource-column { border-left: 1px solid var(--line); }
.column-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 11px; }
.column-heading h3 { margin: 0; color: #56637a; font-size: 11px; }
.count-pill { min-width: 22px; padding: 3px 6px; color: #68768f; background: #eff2f8; border-radius: 20px; text-align: center; font-size: 10px; }
.route-list,.client-list { display: grid; gap: 8px; }
.route-card,.client-card { min-width: 0; padding: 11px 11px 10px; background: #fff; border: 1px solid #e9edf3; border-radius: 9px; }
.route-topline,.client-topline { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.route-title,.client-title { min-width: 0; color: #33415c; font-size: 12px; font-weight: 650; overflow-wrap: anywhere; }
.route-location { margin-top: 5px; color: #79869b; font-size: 10px; overflow-wrap: anywhere; }
.route-meta,.client-meta { margin-top: 6px; color: #9aa4b3; font-size: 10px; line-height: 1.55; overflow-wrap: anywhere; }
.route-actions { display: flex; gap: 4px; flex-shrink: 0; }
.text-button { padding: 4px 6px; color: #5369b4; background: transparent; border: 0; border-radius: 5px; font-size: 10px; }
.text-button:hover { background: #f1f3fb; }
.text-button-danger { color: #ae4b56; }
.switch { width: 32px; height: 18px; padding: 2px; position: relative; border: 0; border-radius: 99px; background: #c5ccda; transition: .15s; }
.switch::after { content: ""; display: block; width: 14px; height: 14px; border-radius: 50%; background: white; transition: .15s; }
.switch.is-on { background: #19a683; }
.switch.is-on::after { transform: translateX(14px); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 6px; color: #13846e; background: #eaf8f3; border-radius: 20px; font-size: 9px; white-space: nowrap; }
.badge-offline { color: #8b95a5; background: #f0f2f6; }
.badge-disabled { color: #ad5961; background: #fff0f1; }
.service-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.service-chip { padding: 4px 6px; color: #69758b; background: #f3f5f9; border-radius: 5px; font-size: 9px; }
.peer-box { margin-top: 8px; padding: 8px; background: #f6f8fc; border-radius: 7px; }
.peer-title { color: #69758c; font-size: 9px; font-weight: 650; }
.peer-candidate { margin-top: 4px; color: #53627a; font: 10px ui-monospace,Consolas,monospace; overflow-wrap: anywhere; }
.empty-state { padding: 30px 16px; color: #99a3b2; text-align: center; font-size: 11px; line-height: 1.7; }
.empty-inline { padding: 11px; color: #a0a8b6; text-align: center; font-size: 10px; border: 1px dashed #e2e7ef; border-radius: 8px; }
.loading { opacity: .55; pointer-events: none; }

.dialog { width: min(590px,calc(100% - 28px)); max-height: min(90vh,780px); padding: 23px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 28px 80px #101b3366; }
.dialog::backdrop { background: #18233b70; backdrop-filter: blur(2px); }
.dialog form { margin: 0; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.dialog-heading h2 { font-size: 20px; }
.icon-button { width: 30px; height: 30px; padding: 0; color: #778399; background: #f4f6fa; border: 0; border-radius: 8px; font-size: 20px; line-height: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.form-field { min-width: 0; display: grid; gap: 6px; color: #59667d; font-size: 11px; font-weight: 600; }
.form-field-check { display: flex; align-items: center; padding-top: 23px; }
.form-field-check input { margin: 0 2px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.secret-list { display: grid; gap: 11px; margin-top: 18px; }
.secret-item { padding: 11px; background: #f7f8fc; border: 1px solid #e6eaf2; border-radius: 9px; }
.secret-label { margin-bottom: 7px; color: #69758b; font-size: 10px; font-weight: 650; }
.secret-value-row { display: flex; align-items: center; gap: 8px; }
.secret-value { min-width: 0; flex: 1; color: #2d3d5e; font: 11px ui-monospace,Consolas,monospace; overflow-wrap: anywhere; user-select: all; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 220px minmax(0,1fr); }
  .resource-columns { grid-template-columns: 1fr; }
  .resource-column + .resource-column { border-top: 1px solid var(--line); border-left: 0; }
  .metrics-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 700px) {
  .topbar { height: 62px; padding: 0 17px; }
  .page { width: calc(100% - 30px); margin: 25px auto 46px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .toolbar { width: 100%; justify-content: space-between; }
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .resource-area { padding: 15px; }
  .resource-heading { align-items: flex-start; }
  .login-card { margin-top: 7vh; padding: 27px 22px; }
}
@media (max-width: 430px) {
  .metrics-grid { gap: 8px; }
  .metric-card { min-height: 105px; padding: 13px; }
  .metric-value { font-size: 22px; }
  .token-row { align-items: stretch; flex-direction: column; }
  .token-row .button { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-field-check { padding-top: 0; }
}
