:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #eef2f4;
  --border: #d7dee3;
  --text: #17232d;
  --muted: #667580;
  --brand: #11675d;
  --brand-strong: #0b5149;
  --blue: #245c9b;
  --blue-soft: #e8f1fb;
  --green-soft: #e5f3ef;
  --amber: #95610d;
  --amber-soft: #fff3d7;
  --red: #a43f47;
  --red-soft: #fdecee;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #10161b;
    --surface: #182128;
    --surface-soft: #202c33;
    --border: #34434d;
    --text: #edf3f5;
    --muted: #a5b1b8;
    --brand: #55b9aa;
    --brand-strong: #7bcbbf;
    --blue: #77aee9;
    --blue-soft: #1c334a;
    --green-soft: #193831;
    --amber: #f2bb5c;
    --amber-soft: #3b301b;
    --red: #ff9da5;
    --red-soft: #45262c;
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); -webkit-text-size-adjust: 100%; }
body { min-height: 100%; margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
code, .mono { font-family: var(--mono); letter-spacing: 0; }
.hidden { display: none !important; }
.muted, .help { color: var(--muted); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 62px;
  padding: 10px max(16px, calc((100% - 1120px) / 2));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}
.brand, .top-actions, .connection-state { display: flex; align-items: center; }
.brand { gap: 10px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 6px; color: #fff; background: var(--brand); font-weight: 800; }
.brand strong, .brand small { display: block; letter-spacing: 0; }
.brand strong { line-height: 1.1; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.top-actions { gap: 10px; }
.connection-state { gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.connection-state i { width: 8px; height: 8px; border-radius: 50%; background: #8b969d; }
.connection-state.online i { background: var(--brand); }
.connection-state.offline i { background: var(--red); }

.page { width: min(1120px, 100%); margin: 0 auto; padding: 28px 16px max(54px, env(safe-area-inset-bottom)); }
.access-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 480px); gap: 44px; align-items: center; min-height: calc(100vh - 150px); }
.access-layout h1 { max-width: 620px; font-size: 38px; }
.lead { max-width: 610px; margin: 12px 0 0; color: var(--muted); font-size: 17px; }

h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: 28px; line-height: 1.2; letter-spacing: 0; }
h2 { margin: 0; font-size: 18px; line-height: 1.3; letter-spacing: 0; }
.eyebrow { margin: 0 0 5px; color: var(--brand); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.help { margin: 0; font-size: 12px; }

.panel, .section-band, .map-workspace, .history-panel, .stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel { padding: 22px; }
.stack { display: grid; gap: 14px; }
.recovery-box { padding-top: 13px; border-top: 1px solid var(--border); }
.recovery-box summary { cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 700; }
.recovery-form { margin-top: 14px; }
.field { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  letter-spacing: 0;
}
input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.button, .compact-button, .id-button {
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
  text-decoration: none;
  text-align: center;
  font-weight: 750;
  letter-spacing: 0;
}
.button { min-height: 42px; padding: 9px 14px; }
.button.primary { color: #fff; border-color: var(--brand); background: var(--brand); }
.button.primary:hover { border-color: var(--brand-strong); background: var(--brand-strong); }
.button.secondary { background: var(--surface-soft); }
.button:disabled { cursor: not-allowed; opacity: .5; }
.compact-button { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.id-button { max-width: min(520px, 80vw); margin: 6px 0 0; padding: 0; overflow: hidden; border: 0; color: var(--muted); background: transparent; text-overflow: ellipsis; white-space: nowrap; }

.heading-row, .section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.heading-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.heading-row { margin-bottom: 18px; }
.section-heading { margin-bottom: 15px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { min-height: 112px; padding: 14px; }
.stat span, .stat small { display: block; color: var(--muted); font-size: 12px; }
.stat strong { display: block; margin: 7px 0 4px; font-size: 18px; line-height: 1.25; }
.notice { margin: -2px 0 18px; padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--amber) 35%, var(--border)); border-radius: var(--radius); color: var(--amber); background: var(--amber-soft); }
.notice.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, var(--border)); background: var(--red-soft); }

.section-band { padding: 20px; margin-bottom: 18px; }
.node-band { border-left: 4px solid var(--blue); }
.node-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; margin-bottom: 9px; }
.node-row code { min-height: 42px; padding: 11px 12px; overflow: hidden; border: 1px solid var(--border); border-radius: 6px; color: var(--muted); background: var(--surface-soft); text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 9px; border-radius: 999px; color: var(--brand); background: var(--green-soft); font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge.paused, .badge.quota { color: var(--amber); background: var(--amber-soft); }
.badge.revoked { color: var(--red); background: var(--red-soft); }

.location-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(270px, .75fr); gap: 18px; margin-bottom: 18px; }
.map-workspace, .history-panel { padding: 20px; min-width: 0; }
.map-search { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; margin-bottom: 10px; }
.map-canvas { position: relative; width: 100%; aspect-ratio: 16 / 9; min-height: 260px; max-height: 430px; overflow: hidden; border: 1px solid var(--border); border-radius: 6px; background: #dfe7e9; }
.map-placeholder { position: absolute; inset: 0; display: grid; place-content: center; gap: 4px; padding: 20px; color: #52646d; background: #e4ebed; text-align: center; }
.map-placeholder strong, .map-placeholder span { display: block; }
.map-placeholder span { font-size: 12px; }
.search-results { max-height: 220px; margin: 0 0 10px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.search-result { display: block; width: 100%; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--border); color: var(--text); background: var(--surface); text-align: left; }
.search-result:last-child { border-bottom: 0; }
.search-result strong, .search-result small { display: block; }
.search-result small { margin-top: 2px; color: var(--muted); }
.location-form { display: grid; gap: 13px; margin-top: 16px; }
.current-location { display: flex; justify-content: space-between; gap: 14px; padding-bottom: 13px; border-bottom: 1px solid var(--border); }
.current-location span, .current-location strong { display: block; }
.current-location span { color: var(--muted); font-size: 11px; }
.current-location code { align-self: flex-end; color: var(--muted); font-size: 12px; text-align: right; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field-wide { grid-column: 1 / -1; }
.action-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }
.history-list { display: grid; gap: 0; }
.history-item { display: grid; gap: 3px; padding: 12px 0; border-top: 1px solid var(--border); }
.history-item:first-child { padding-top: 0; border-top: 0; }
.history-item code, .history-item small { color: var(--muted); font-size: 11px; }
.history-item strong { font-size: 13px; }

.ca-band { border-left: 4px solid var(--brand); }
.fingerprint { display: block; margin: -5px 0 14px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.ca-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.download-block, .guide-step { min-height: 86px; padding: 13px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); background: var(--surface-soft); text-decoration: none; }
.download-block { color: #fff; border-color: var(--brand); background: var(--brand); }
.download-block strong, .download-block span, .guide-step strong, .guide-step span { display: block; }
.download-block span, .guide-step span { margin-top: 6px; font-size: 12px; }
.download-block span { color: rgba(255,255,255,.82); }
.guide-step span { color: var(--muted); }
.ca-band > .help { margin-top: 12px; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 32px); padding: 10px 14px; transform: translateX(-50%); border-radius: 6px; color: #fff; background: #153a34; box-shadow: 0 10px 28px rgba(0,0,0,.25); }
.toast.error { background: #8f3038; }

@media (max-width: 820px) {
  .access-layout { grid-template-columns: 1fr; gap: 24px; align-content: center; }
  .access-layout h1 { font-size: 30px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .location-layout { grid-template-columns: 1fr; }
  .history-panel { max-height: 440px; overflow: auto; }
  .ca-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .topbar { min-height: 58px; }
  .connection-state > span { display: none; }
  .page { padding-top: 18px; }
  .access-layout { min-height: calc(100vh - 112px); }
  .panel, .section-band, .map-workspace, .history-panel { padding: 16px; }
  .stats { gap: 8px; }
  .stat { min-height: 104px; padding: 12px; }
  .stat strong { font-size: 16px; }
  .node-row { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .current-location { display: grid; }
  .current-location code { text-align: left; }
  .heading-actions { max-width: 154px; }
  .action-row .button { flex: 1 1 150px; }
  .map-canvas { aspect-ratio: 4 / 3; min-height: 245px; }
}
