:root {
  --bg: #f6f7f9; --panel: #ffffff; --border: #dfe3e8; --text: #1d2430; --muted: #6b7280;
  --accent: #2563eb; --accent-2: #1d4ed8; --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
  --radius: 8px; --sidebar: 340px; --topbar: 44px;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0; }
kbd { border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; font-size: 11px; background: #fff; }

#topbar { position: fixed; inset: 0 0 auto 0; height: var(--topbar); display: flex; align-items: center; gap: 16px;
  padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--border); z-index: 1000; }
.brand { font-weight: 600; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand .muted { font-weight: 400; }
.logo { width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle, var(--accent) 30%, transparent 32%, transparent 48%, rgba(37,99,235,.5) 50%, transparent 58%, transparent 74%, rgba(37,99,235,.3) 76%, transparent 84%); }
#version { margin-left: auto; font-size: 12px; }
#mode-banner { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; border-radius: 999px; padding: 3px 12px; font-size: 13px; }

#sidebar { position: fixed; top: var(--topbar); bottom: 0; left: 0; width: var(--sidebar); background: var(--panel);
  border-right: 1px solid var(--border); overflow-y: auto; z-index: 900; }
#tabs { display: flex; position: sticky; top: 0; background: var(--panel); border-bottom: 1px solid var(--border); z-index: 2; }
#tabs button { flex: 1; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 10px 4px; color: var(--muted); font-weight: 500; }
#tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab { padding: 12px 14px 24px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 20px 0 8px; }

label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 3px; }
input, select { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: #fff; color: var(--text); }
input[type=checkbox], input[type=radio] { width: auto; flex: none; margin: 0; }
input[type=color] { padding: 2px; height: 31px; }
input:focus, select:focus { outline: 2px solid rgba(37,99,235,.25); border-color: var(--accent); }
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: var(--text); font: inherit; cursor: pointer; white-space: nowrap; }
button:hover, .button:hover { background: #f1f4f8; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
button.primary:hover { background: var(--accent-2); }
button.danger { color: var(--danger); }
button.small, .small button, .small .button { padding: 3px 8px; font-size: 12px; }
button.wide { width: 100%; margin-top: 14px; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { flex: 1; border: 0; border-radius: 0; }
.seg button.active { background: #e8efff; color: var(--accent); font-weight: 500; }
details { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 8px; }
summary { cursor: pointer; color: var(--accent); font-size: 13px; }

.cards { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.cards li { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; background: #fff; }
.cards li.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
.cards li.empty { color: var(--muted); border-style: dashed; text-align: center; }
.card-head { display: flex; align-items: center; gap: 8px; }
.card-head strong { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 13px; }
.card-head input.name { border: 0; padding: 2px 0; font-weight: 600; flex: 1; min-width: 0; }
.card-head input.name:focus { outline: none; border-bottom: 1px solid var(--accent); border-radius: 0; }
.swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.card-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 6px; }
.card-fields label { margin-top: 6px; }
.card-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

.legend { height: 10px; border-radius: 3px; margin: 8px 0 2px; }
.legend-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.layer-ctrl { display: grid; grid-template-columns: auto 1fr; gap: 4px 8px; align-items: center; font-size: 12px; margin-top: 6px; }
.layer-ctrl input[type=range] { padding: 0; }
.layer-ctrl .pair { display: flex; gap: 6px; }

.result { margin-top: 14px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.result .big { padding: 10px 12px; background: #f8fafc; border-bottom: 1px solid var(--border); }
.result .big .v { font-size: 22px; font-weight: 600; }
.result table { width: 100%; border-collapse: collapse; font-size: 13px; }
.result td { padding: 5px 12px; border-bottom: 1px solid #eef1f4; }
.result td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.result tr:last-child td { border-bottom: 0; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: #eef2ff; color: var(--accent); }
.badge.ok { background: #dcfce7; color: #166534; } .badge.warn { background: #fef3c7; color: #92400e; } .badge.bad { background: #fee2e2; color: #991b1b; }
.warnings { padding: 8px 12px; font-size: 12px; color: #92400e; background: #fffbeb; }

#mapwrap { position: fixed; top: var(--topbar); left: var(--sidebar); right: 0; bottom: 0; }
#map { position: absolute; inset: 0; }
#mapwrap.with-profile #map { bottom: 240px; }
#statusbar { position: absolute; left: 10px; bottom: 22px; z-index: 800; background: rgba(255,255,255,.92); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 8px; display: flex; gap: 12px; pointer-events: none; }
#mapwrap.with-profile #statusbar { bottom: 262px; }
#profile-panel { position: absolute; left: 0; right: 0; bottom: 0; height: 240px; background: var(--panel); border-top: 1px solid var(--border); z-index: 850; display: flex; flex-direction: column; }
#profile-panel .ph { display: flex; align-items: center; gap: 12px; padding: 6px 12px; font-size: 13px; }
#profile-panel .ph button { margin-left: auto; padding: 2px 8px; }
#profile { flex: 1; width: 100%; min-height: 0; cursor: crosshair; }

#toasts { position: absolute; left: 50%; transform: translateX(-50%); top: 12px; z-index: 1100; display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.toast { background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 6px; padding: 8px 12px; box-shadow: 0 4px 16px rgba(0,0,0,.12); font-size: 13px; }
.toast.error { border-left-color: var(--danger); } .toast.ok { border-left-color: var(--ok); }
.spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.5); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.site-icon { width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.site-icon.sel { outline: 3px solid rgba(37,99,235,.5); }
.rx-icon { width: 12px; height: 12px; background: #fff; border: 3px solid var(--danger); border-radius: 2px; transform: rotate(45deg); }
.leaflet-container.picking { cursor: crosshair; }
.site-label { background: rgba(255,255,255,.85); border: 0; box-shadow: none; font-weight: 600; padding: 0 4px; }
.site-label::before { display: none; }

@media (max-width: 760px) {
  :root { --sidebar: 100%; }
  #sidebar { bottom: auto; height: 46vh; width: 100%; border-right: 0; border-bottom: 1px solid var(--border); }
  #mapwrap { left: 0; top: calc(var(--topbar) + 46vh); }
  .brand .muted { display: none; }
  #profile-panel { height: 180px; } #mapwrap.with-profile #map { bottom: 180px; } #mapwrap.with-profile #statusbar { bottom: 202px; }
}
