:root {
  color: #dce8f0;
  background: #07101a;
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --panel: #0d1925;
  --panel-2: #111f2d;
  --border: #233849;
  --muted: #8fa7b8;
  --cyan: #4ed7ed;
  --orange: #ffad52;
  --magenta: #ee6dff;
  --danger: #ff8d8d;
  --topbar-height: 52px;
  --visual-viewport-height: 100dvh;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
button, input, select, textarea { font: inherit; }
button { min-height: 36px; color: #07121b; background: var(--cyan); border: 1px solid #78e7f6; border-radius: 6px; padding: 7px 11px; cursor: pointer; font-weight: 650; }
button:hover { filter: brightness(1.1); }
button:disabled { cursor: default; opacity: .35; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid #b7f4ff; outline-offset: 2px; }
button.secondary, button.compact, button.icon-button { color: #d4e2ec; background: #142534; border-color: #315064; }
button.compact { padding: 7px 9px; }
button.icon-button { padding: 1px 6px; min-width: 24px; }
button.danger { color: #ffe9e9; background: #6d2630; border-color: #bd5967; }
input, select, textarea { width: 100%; color: #eef7fb; background: #07131e; border: 1px solid #2b465a; border-radius: 6px; padding: 8px 9px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(78, 215, 237, .12); }
textarea { resize: vertical; }
label { display: block; margin: 9px 0 4px; color: var(--muted); font-size: 12px; }

#boot { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(circle at 50% 35%, #14293b, #07101a 55%); transition: opacity .25s ease; }
.app-ready #boot { opacity: 0; pointer-events: none; }
.boot-card { width: min(420px, calc(100% - 40px)); padding: 28px; text-align: center; background: rgba(9, 22, 33, .92); border: 1px solid #29485d; border-radius: 12px; box-shadow: 0 22px 90px #0009; }
.boot-mark { display: inline-grid; place-items: center; width: 58px; height: 58px; color: var(--cyan); border: 1px solid var(--cyan); border-radius: 50%; letter-spacing: .1em; }
.boot-card h1 { margin: 16px 0 8px; font-size: 20px; }
.boot-card p { color: var(--muted); }
.fatal-error { padding: 10px; color: var(--danger) !important; background: #3b1820; border-radius: 6px; white-space: pre-wrap; text-align: left; }
.hidden { display: none !important; }

#app-shell { display: grid; width: 100%; height: var(--visual-viewport-height); grid-template-columns: minmax(250px, 310px) 1fr minmax(230px, 290px); grid-template-rows: var(--topbar-height) 1fr; grid-template-areas: "top top top" "tools map info"; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 14px; padding: 0 14px; background: #0b1722; border-bottom: 1px solid var(--border); }
.topbar > :first-child { white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; margin-left: auto; }
.panel-toggle, .panel-heading, .tool-tabs { display: none; }
.web-badge { margin-left: 7px; padding: 2px 5px; color: var(--cyan); background: #12303a; border: 1px solid #2b7885; border-radius: 4px; font-size: 10px; letter-spacing: .12em; }
.pack-meta { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.network-status { flex: 0 0 auto; padding: 3px 7px; color: #bff5d9; border: 1px solid #34785f; border-radius: 999px; font-size: 11px; }
.network-status.offline { color: #ffd1a6; border-color: #9a683c; }
.tools-panel { grid-area: tools; border-right: 1px solid var(--border); }
.info-panel { grid-area: info; border-left: 1px solid var(--border); }
.scroll-panel { overflow-x: hidden; overflow-y: auto; padding: 12px; background: var(--panel); }
section, details { margin: 0 0 12px; padding: 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; }
section h2, section h3 { margin: 0 0 10px; }
section h2 { font-size: 15px; }
section h3 { font-size: 13px; }
details > summary { margin: -12px -12px 8px; padding: 11px 12px; color: #e7f4fa; cursor: pointer; font-weight: 700; }
.picker { position: relative; }
.picker-row { display: flex; align-items: flex-start; gap: 6px; }
.grow { flex: 1; min-width: 0; }
.search-results { position: absolute; z-index: 20; top: calc(100% + 3px); left: 0; right: 0; max-height: 220px; overflow: auto; padding: 4px; background: #0a1722; border: 1px solid #35546a; border-radius: 6px; box-shadow: 0 12px 35px #000b; }
.search-result { display: block; width: 100%; padding: 9px 8px; color: #dce8f0; background: transparent; border: 0; text-align: left; font-weight: 500; }
.search-result:hover { background: #173145; }
.toggle { display: flex; align-items: center; gap: 7px; color: #c8d8e3; }
.toggle input { width: auto; }
.button-row { display: flex; gap: 7px; margin-top: 10px; }
.button-row button { flex: 1; }
.summary, .summary-line { margin: 9px 0 0; color: #a9bfce; white-space: pre-wrap; word-break: break-word; font: 12px/1.5 Inter, system-ui, sans-serif; }
.item-list { margin-top: 8px; color: #bdced9; font-size: 12px; }
.item-list.empty { padding: 7px; color: #6f8798; border: 1px dashed #2d4352; border-radius: 5px; }
.list-row { display: flex; align-items: center; gap: 6px; min-height: 40px; padding: 4px 0; border-bottom: 1px solid #1d3342; }
.list-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-link { flex: 1; min-width: 0; overflow: hidden; padding: 3px 4px; color: #dce8f0; background: transparent; border: 0; text-align: left; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.shared-marker-row.selected { margin: 0 -4px; padding: 4px; background: #183246; border-radius: 4px; }
.marker-swatch { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; background: #42bff5; }
.marker-red { background: #ff5d73; } .marker-orange { background: #ff9f43; } .marker-yellow { background: #ffd166; }
.marker-green { background: #57e389; } .marker-blue { background: #42bff5; } .marker-purple { background: #a98bff; } .marker-white { background: #f1f5f8; }
.shared-status { margin-bottom: 6px; padding: 6px 8px; color: #9eb5c5; background: #0a1722; border: 1px solid #294253; border-radius: 5px; font-size: 12px; }
.shared-status.connected { color: #bff5d9; border-color: #34785f; }
.shared-status.connecting, .shared-status.reconnecting { color: #ffe0aa; border-color: #8a6731; }
.shared-status.offline { color: #ffd1a6; border-color: #9a683c; }
.shared-status.auth_failed, .shared-status.forbidden, .shared-status.failed { color: #ffb5b5; border-color: #914450; }
.credential-note { margin: 8px 0; color: var(--muted); font-size: 11px; }
.inline-error { margin: 8px 0; padding: 7px; color: #ffd0d0; background: #3b1820; border-radius: 5px; font-size: 11px; overflow-wrap: anywhere; }

.map-panel { grid-area: map; position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #08111b; }
#map-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.map-stats, .legend { position: absolute; color: #88a1b2; background: rgba(7, 16, 26, .82); border: 1px solid rgba(57, 83, 101, .7); border-radius: 6px; backdrop-filter: blur(5px); }
.map-stats { top: 10px; left: 10px; padding: 5px 8px; font-size: 11px; }
.legend { left: 10px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 7px 12px; max-width: calc(100% - 20px); padding: 7px 9px; font-size: 11px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-line { display: inline-block; width: 19px; border-top: 2px solid #6b8292; }
.legend-line.ansiblex { border-color: var(--orange); border-top-style: dashed; }
.legend-line.capital { border-color: var(--magenta); border-top-style: dotted; }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.legend-dot.selected { background: #ffe182; }
.legend-dot.coverage { background: #b16cff; box-shadow: 0 0 0 3px rgba(177, 108, 255, .2); }
.legend-ring { display: inline-block; width: 11px; height: 11px; border: 2px solid #42bff5; border-radius: 50%; }
.user-message { position: absolute; top: 44px; left: 50%; max-width: min(620px, calc(100% - 28px)); padding: 8px 12px; transform: translateX(-50%); border-radius: 6px; box-shadow: 0 8px 28px #0008; }
.user-message.error { color: #ffd6d6; background: rgba(102, 28, 38, .94); border: 1px solid #c65361; }
.user-message.success { color: #d8fff1; background: rgba(20, 72, 62, .94); border: 1px solid #3a9b84; }

.system-info h2 { margin: 0 0 12px; color: #f0f8fb; font-size: 20px; }
.system-info.empty { color: var(--muted); }
.info-row { display: grid; grid-template-columns: 42% 58%; gap: 8px; padding: 5px 0; border-bottom: 1px solid #1d3342; }
.info-key { color: var(--muted); }
.info-value { overflow-wrap: anywhere; text-align: right; }
.inline-warning { padding: 8px; color: #ffd59a; background: #3a2a17; border-radius: 5px; font-size: 12px; }
.help-card { color: var(--muted); font-size: 12px; }
.modal-backdrop { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); background: rgba(1, 6, 10, .72); }
.modal-card { width: min(460px, 100%); max-height: calc(var(--visual-viewport-height) - 24px); overflow: auto; overscroll-behavior: contain; padding: 18px; background: #101f2c; border: 1px solid #38566a; border-radius: 10px; box-shadow: 0 22px 80px #000c; }
.modal-card h2 { margin: 0; }
.modal-actions button { flex: 1; }
.panel-scrim { position: fixed; z-index: 24; inset: var(--topbar-height) 0 0; width: 100%; min-height: 0; padding: 0; background: rgba(1, 6, 10, .56); border: 0; border-radius: 0; }
.context-sheet { position: fixed; z-index: 45; display: grid; gap: 7px; width: 250px; padding: 10px; background: #101f2c; border: 1px solid #38566a; border-radius: 10px; box-shadow: 0 18px 60px #000c; }
.context-sheet-heading { display: flex; align-items: center; gap: 8px; color: #eef7fb; }
.context-sheet-heading strong { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.context-sheet > button:not(.secondary) { text-align: left; }
.app-update { position: fixed; z-index: 80; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 9px; max-width: calc(100% - 28px); padding: 10px; color: #e9f7fc; background: #142b3b; border: 1px solid #3e708a; border-radius: 9px; box-shadow: 0 16px 55px #000b; }

@media (max-width: 1280px), (pointer: coarse) {
  :root { --topbar-height: 56px; }
  #app-shell { grid-template-columns: 1fr; grid-template-areas: "top" "map"; }
  .topbar { gap: 9px; padding-right: max(10px, env(safe-area-inset-right)); padding-left: max(10px, env(safe-area-inset-left)); }
  .topbar .panel-toggle { display: inline-flex; align-items: center; }
  .topbar > :first-child { order: -1; }
  .topbar > #tools-toggle { order: -2; }
  .pack-meta { display: none; }
  .panel-heading { position: sticky; z-index: 2; top: -12px; display: flex; align-items: center; gap: 8px; margin: -12px -12px 10px; padding: 9px 12px; background: #0d1925; border-bottom: 1px solid var(--border); }
  .panel-heading strong { flex: 1; }
  .tool-tabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; margin-bottom: 10px; }
  .tool-tabs button { min-width: 0; padding-right: 5px; padding-left: 5px; font-size: 12px; }
  .tools-panel, .info-panel { position: fixed; z-index: 30; top: var(--topbar-height); bottom: 0; display: block; width: min(410px, calc(100vw - 28px)); max-height: calc(var(--visual-viewport-height) - var(--topbar-height)); border: 1px solid var(--border); box-shadow: 0 18px 55px #000c; transition: transform .18s ease-out; }
  .tools-panel { left: 0; border-left: 0; transform: translateX(-105%); }
  .info-panel { right: 0; border-right: 0; transform: translateX(105%); }
  .tools-open .tools-panel, .info-open .info-panel { transform: translateX(0); }
  .context-sheet.touch { top: auto !important; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); left: auto !important; width: min(360px, calc(100% - 24px)); }
  .tools-panel [data-tool-panel] { display: none; }
  .tools-panel [data-tool-panel].tool-section-active { display: block; }
  .scroll-panel { overscroll-behavior: contain; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
  button, input, select { min-height: 44px; }
  textarea { min-height: 96px; }
  button.compact, button.icon-button { min-width: 44px; min-height: 44px; padding: 7px; }
  .search-result, .list-link { min-height: 44px; }
  .map-stats { top: 8px; left: 8px; }
  .legend { bottom: max(8px, env(safe-area-inset-bottom)); left: 8px; max-width: calc(100% - 16px); }
}

@media (max-width: 760px), (orientation: portrait) and (pointer: coarse) {
  .topbar strong { display: inline-block; max-width: 31vw; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; white-space: nowrap; }
  .web-badge { display: none; }
  .network-status { display: none; }
  .tools-panel, .info-panel { top: auto; right: 0; bottom: 0; left: 0; width: 100%; max-height: min(74%, calc(var(--visual-viewport-height) - var(--topbar-height))); border-right: 0; border-bottom: 0; border-left: 0; border-radius: 14px 14px 0 0; transform: translateY(105%); }
  .tools-open .tools-panel, .info-open .info-panel { transform: translateY(0); }
  .context-sheet { right: 0 !important; bottom: 0 !important; left: 0 !important; width: 100%; padding: 14px max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); border-right: 0; border-bottom: 0; border-left: 0; border-radius: 14px 14px 0 0; }
  .legend { max-height: 58px; overflow: hidden; }
  .app-update { right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); left: 8px; flex-wrap: wrap; max-width: none; }
}

@media (pointer: coarse) {
  button:hover { filter: none; }
}
