/* ==========================================================================
   Network Architect – Zaphire SD-planlegger
   ========================================================================== */

:root {
  --font: "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --surface-3: #eef0f4;
  --border: #e3e6ec;
  --border-strong: #cfd4dc;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-text: #4338ca;

  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --err: #dc2626;
  --err-soft: #fee2e2;
  --info: #2563eb;
  --info-soft: #dbeafe;

  --type-plc: #2563eb;
  --type-ventilation: #059669;
  --type-other: #475569;
  --iot: #7c3aed;

  --canvas-bg: #e9ecf1;
  --canvas-dot: #d3d8e0;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-pop: 0 12px 40px rgba(15, 23, 42, 0.18);

  --panel-w: 560px;
  --topbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17;
    --surface: #121826;
    --surface-2: #161d2c;
    --surface-3: #1c2537;
    --border: #232d40;
    --border-strong: #33405a;
    --text: #e6eaf2;
    --muted: #94a3b8;
    --faint: #64748b;

    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: rgba(129, 140, 248, 0.14);
    --accent-text: #c7d2fe;

    --ok-soft: rgba(22, 163, 74, 0.16);
    --warn-soft: rgba(217, 119, 6, 0.16);
    --err-soft: rgba(220, 38, 38, 0.16);
    --info-soft: rgba(37, 99, 235, 0.18);

    --type-plc: #60a5fa;
    --type-ventilation: #34d399;
    --type-other: #94a3b8;
    --iot: #a78bfa;

    --canvas-bg: #0e131d;
    --canvas-dot: #1d2636;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { flex-shrink: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.num { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   Buttons & inputs
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0b0f17; } }

.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; color: var(--text); }

.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }

.btn-dashed {
  width: 100%;
  justify-content: center;
  border-style: dashed;
  background: transparent;
  color: var(--muted);
}
.btn-dashed:hover { color: var(--accent-text); border-color: var(--accent); background: var(--accent-soft); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  transition: background 0.12s, color 0.12s;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.danger:hover { background: var(--err-soft); color: var(--err); }

.field {
  width: 100%;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 0.12s, box-shadow 0.12s;
  min-width: 0;
}
.field:hover { border-color: var(--border-strong); }
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.field { height: auto; padding: 7px 9px; resize: vertical; }
select.field { padding-right: 4px; }
input[type="number"].field { text-align: right; font-variant-numeric: tabular-nums; }

.label {
  display: block;
  margin-bottom: 4px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--text);
  color: var(--surface);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 14px; }
.brand-text span { font-size: 11.5px; color: var(--muted); }

.project-switcher { position: relative; margin-left: 12px; }
.switcher-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  max-width: 340px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-weight: 600;
}
.switcher-btn:hover { border-color: var(--border-strong); }
.switcher-btn svg { width: 16px; height: 16px; color: var(--muted); }
.switcher-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; gap: 4px; }

.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.sync-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
}
.sync-status[data-state="busy"]::before { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.sync-status[data-state="error"] { color: var(--err); }
.sync-status[data-state="error"]::before { background: var(--err); }
@keyframes pulse { 50% { opacity: 0.25; } }

/* Dropdown menu */
.menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 300px;
  max-width: 380px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
}
.menu-section-title {
  padding: 8px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--faint);
}
.menu-list { max-height: 280px; overflow-y: auto; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
}
.menu-item:hover { background: var(--surface-3); }
.menu-item svg { width: 16px; height: 16px; color: var(--muted); }
.menu-item .menu-item-main { flex: 1; min-width: 0; }
.menu-item .menu-item-title { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item .menu-item-meta { display: block; font-size: 11.5px; color: var(--muted); }
.menu-item.is-current { background: var(--accent-soft); }
.menu-item.is-current .menu-item-title { color: var(--accent-text); }
.menu-item.danger { color: var(--err); }
.menu-item.danger svg { color: var(--err); }
.menu-divider { height: 1px; margin: 6px 4px; background: var(--border); }

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */
.layout {
  height: calc(100% - var(--topbar-h));
  display: grid;
  grid-template-columns: var(--panel-w) 6px minmax(0, 1fr);
  /* Keep both columns window-high so their content scrolls instead of stretching the row */
  grid-template-rows: minmax(0, 1fr);
}

.editor {
  overflow-y: auto;
  padding: 18px 18px 40px;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  scrollbar-gutter: stable;
}

.resizer {
  cursor: col-resize;
  background: transparent;
  position: relative;
}
.resizer::after {
  content: "";
  position: absolute;
  inset: 0 2px;
  border-radius: 2px;
  transition: background 0.12s;
}
.resizer:hover::after, .resizer.is-dragging::after { background: var(--accent); }
body.is-resizing { cursor: col-resize; user-select: none; }

.workspace {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* --------------------------------------------------------------------------
   Editor: project header & summary
   -------------------------------------------------------------------------- */
.project-head { margin-bottom: 16px; }
.project-name {
  width: 100%;
  padding: 4px 6px;
  margin-left: -6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.project-name:hover { border-color: var(--border); }
.project-name:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.project-desc {
  width: 100%;
  margin: 2px 0 0 -6px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  resize: none;
  field-sizing: content;
  min-height: 28px;
}
.project-desc:hover { border-color: var(--border); }
.project-desc:focus { outline: none; border-color: var(--accent); background: var(--surface); color: var(--text); }

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.stat {
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat-value { display: block; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat-label { display: block; font-size: 11.5px; color: var(--muted); }

.licenses {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--muted);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.status-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  text-align: left;
  font-weight: 500;
}
.status-banner svg { width: 18px; height: 18px; }
.status-banner .grow { flex: 1; }
.status-banner .link { font-size: 12px; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.status-banner[data-level="error"] { background: var(--err-soft); color: var(--err); border-color: color-mix(in srgb, var(--err) 30%, transparent); }
.status-banner[data-level="warning"] { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.status-banner[data-level="ok"] { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); cursor: default; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 0 10px;
}
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }

/* --------------------------------------------------------------------------
   Site cards
   -------------------------------------------------------------------------- */
.site {
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.site[data-status="error"] { border-color: color-mix(in srgb, var(--err) 55%, var(--border)); }
.site[data-status="warning"] { border-color: color-mix(in srgb, var(--warn) 55%, var(--border)); }
.site.is-flash { box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-sm); border-color: var(--accent); }

.site-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px 4px 6px;
}
.site-head .collapse svg { transition: transform 0.15s; }
.site.is-collapsed .site-head .collapse svg { transform: rotate(-90deg); }
.site-name {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 14.5px;
  font-weight: 700;
}
.site-name:hover { border-color: var(--border); }
.site-name:focus { outline: none; border-color: var(--accent); }

.tier {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .tier { color: #0b0f17; } }
.tier[data-state="error"] { background: var(--err); color: #fff; }
.tier[data-state="none"] { background: var(--surface-3); color: var(--faint); }
.tier[data-state="override"]::after { content: "•"; margin-left: 4px; opacity: 0.8; }

.site-meter { padding: 2px 14px 10px 44px; }
.meter {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
/* Where the spare capacity starts */
.meter-limit {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  opacity: 0.55;
}
.meter > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--ok);
  transition: width 0.25s ease, background 0.25s;
}
.meter[data-level="warning"] > i { background: var(--warn); }
.meter[data-level="error"] > i { background: var(--err); }
.site-stats {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.site-stats b { color: var(--text); font-weight: 600; }
.site-stats .push { margin-left: auto; }

.site-body { padding: 0 12px 12px; border-top: 1px solid var(--border); }
.site.is-collapsed .site-body { display: none; }

.comp-grid {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 112px 80px 80px;
  gap: 6px;
  align-items: center;
}
.comp-head {
  padding: 10px 0 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.comp-head .r { text-align: right; }

.comp {
  padding: 4px 0;
  border-radius: var(--radius-sm);
}
.type-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--type-plc) 12%, transparent);
  color: var(--type-plc);
}
.type-btn svg { width: 17px; height: 17px; }
.type-btn:hover { background: color-mix(in srgb, var(--type-plc) 22%, transparent); }
.comp[data-type="ventilation"] .type-btn { background: color-mix(in srgb, var(--type-ventilation) 12%, transparent); color: var(--type-ventilation); }
.comp[data-type="ventilation"] .type-btn:hover { background: color-mix(in srgb, var(--type-ventilation) 22%, transparent); }
.comp[data-type="other"] .type-btn { background: color-mix(in srgb, var(--type-other) 12%, transparent); color: var(--type-other); }
.comp[data-type="other"] .type-btn:hover { background: color-mix(in srgb, var(--type-other) 22%, transparent); }
.comp.has-error .field[data-field="tags"] { border-color: var(--err); background: var(--err-soft); }
.comp .field { height: 30px; font-size: 13px; }
.iot-select { color: var(--muted); }
.iot-select.is-pinned {
  color: var(--iot);
  font-weight: 600;
  border-color: color-mix(in srgb, var(--iot) 45%, var(--border));
  background: color-mix(in srgb, var(--iot) 7%, var(--surface));
}
.comp-actions { display: flex; justify-content: flex-end; }
.comp-actions .icon-btn { width: 26px; height: 26px; }
.comp-actions .icon-btn svg { width: 15px; height: 15px; }
.comp-extra {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  margin: 4px 0 2px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
}
.comp-extra label { display: grid; gap: 3px; min-width: 0; }
.comp-extra .field { height: 28px; font-weight: 400; }
.comp-extra-actions { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.comp-extra-actions .hint { margin: 0; font-weight: 400; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; font-size: 12px; }

.comp-empty {
  margin: 12px 0 4px;
  padding: 14px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}

.add-row { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.add-row .btn { flex: 1; justify-content: center; }
.add-row .dot { width: 8px; height: 8px; border-radius: 50%; }

.site-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
  color: var(--muted);
}
.site-foot select { width: auto; height: 28px; font-size: 12.5px; }

.site-issues { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.site-issues:empty { display: none; }

.issue {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  line-height: 1.4;
}
.issue svg { width: 15px; height: 15px; margin-top: 1px; }
.issue[data-level="error"] { background: var(--err-soft); color: var(--err); }
.issue[data-level="warning"] { background: var(--warn-soft); color: var(--warn); }
.issue[data-level="info"] { background: var(--info-soft); color: var(--info); }
@media (prefers-color-scheme: dark) {
  .issue[data-level="info"] { color: #93c5fd; }
}

/* Settings */
.settings { margin-top: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.settings summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  list-style: none;
  cursor: pointer;
  font-weight: 600;
}
.settings summary::-webkit-details-marker { display: none; }
.settings summary svg { width: 16px; height: 16px; color: var(--muted); }
.settings summary .chev { margin-left: auto; transition: transform 0.15s; }
.settings[open] summary .chev { transform: rotate(180deg); }
.settings-body { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 4px 14px 14px; }
.settings-body .full { grid-column: 1 / -1; }
.hint { margin-top: 4px; font-size: 11.5px; color: var(--faint); }
.input-suffix { position: relative; }
.input-suffix .field { padding-right: 38px; }
.input-suffix span { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--faint); pointer-events: none; }

/* --------------------------------------------------------------------------
   Workspace tabs & views
   -------------------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 2px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 42px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); }
.tab.is-active::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.count[data-level="error"] { background: var(--err); color: #fff; }
.count[data-level="warning"] { background: var(--warn); color: #fff; }

.view { display: none; flex: 1; min-height: 0; }
.view.is-active { display: flex; }

/* Topology canvas */
.view-topology { position: relative; }

.topology-switch {
  position: absolute;
  top: 14px;
  left: 16px;
  z-index: 2;
  display: flex;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.topology-switch button {
  height: 28px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}
.topology-switch button:hover { color: var(--text); }
.topology-switch button[aria-checked="true"] { background: var(--accent-soft); color: var(--accent-text); }
.canvas {
  position: relative;
  flex: 1;
  overflow: hidden;
  cursor: grab;
  background-color: var(--canvas-bg);
  background-image: radial-gradient(var(--canvas-dot) 1px, transparent 1px);
  background-size: 18px 18px;
  touch-action: none;
}
.canvas.is-panning { cursor: grabbing; }
.canvas-stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.canvas-stage svg {
  display: block;
  border-radius: 12px;
  box-shadow: var(--shadow);
  user-select: none;
}
.canvas-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
}
.canvas-placeholder[hidden] { display: none; }

.canvas-tools {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.zoom-readout {
  min-width: 56px;
  height: 30px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.zoom-readout:hover { background: var(--surface-3); color: var(--text); }
.tools-divider { width: 1px; height: 18px; margin: 0 2px; background: var(--border); }

/* Report & issues views */
.view-report, .view-issues { overflow-y: auto; }
.view-inner { width: 100%; max-width: 1080px; margin: 0 auto; padding: 24px 24px 48px; }
.view-title { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; }
.view-title h2 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.view-title .grow { flex: 1; }

.panel {
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-head h3 { margin: 0; font-size: 14px; }
.panel-head .muted { color: var(--muted); font-size: 12.5px; }
.panel-head .grow { flex: 1; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  padding: 9px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
table.data td { padding: 9px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data .r { text-align: right; font-variant-numeric: tabular-nums; }
table.data tfoot td { font-weight: 700; background: var(--surface-2); }
table.data .sub td { padding-top: 6px; padding-bottom: 6px; color: var(--muted); font-size: 12.5px; }
table.data .sub td:first-child { padding-left: 36px; }
table.data .iot-row td { background: color-mix(in srgb, var(--iot) 6%, transparent); font-weight: 600; }

.mini-meter { display: inline-flex; align-items: center; gap: 8px; }
.mini-meter .meter { width: 80px; }

.type-dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; vertical-align: 1px; background: var(--type-plc); }
.type-dot[data-type="ventilation"] { background: var(--type-ventilation); }
.type-dot[data-type="other"] { background: var(--type-other); }

.status-pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.status-pill[data-status="ok"] { background: var(--ok-soft); color: var(--ok); }
.status-pill[data-status="warning"] { background: var(--warn-soft); color: var(--warn); }
.status-pill[data-status="error"] { background: var(--err-soft); color: var(--err); }
.status-pill[data-status="empty"] { background: var(--surface-3); color: var(--muted); }

.issue-group { margin-bottom: 20px; }
.issue-group h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 13px; }
.issue-list { display: grid; gap: 6px; }
.issue-list .issue { font-size: 13px; padding: 10px 12px; border: 0; text-align: left; width: 100%; }
.issue-list button.issue:hover { filter: brightness(0.97); }
.issue .issue-site { margin-left: auto; padding-left: 12px; font-size: 11.5px; font-weight: 600; opacity: 0.8; white-space: nowrap; }

.empty-state {
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 64px 24px;
  text-align: center;
  color: var(--muted);
}
.empty-state svg { width: 40px; height: 40px; color: var(--ok); }
.empty-state h3 { margin: 0; color: var(--text); font-size: 15px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow-pop);
  font-weight: 500;
  z-index: 50;
}
.toast[data-level="error"] { background: var(--err); color: #fff; }

/* --------------------------------------------------------------------------
   Small screens: stack editor above the drawing
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  .layout { display: flex; flex-direction: column; height: auto; }
  .editor { border-right: 0; border-bottom: 1px solid var(--border); overflow: visible; }
  .resizer { display: none; }
  .workspace { height: 80vh; }
  .brand-text span, .sync-status { display: none; }
  .topbar { gap: 8px; padding: 0 10px; }
  .project-switcher { margin-left: 0; min-width: 0; }
  .switcher-btn { max-width: 44vw; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .comp-grid { grid-template-columns: 28px minmax(0, 1fr) 96px 70px 80px; }
  .comp-extra { grid-template-columns: minmax(0, 1fr); }
}

/* --------------------------------------------------------------------------
   Collaboration: login, presence, user menu
   -------------------------------------------------------------------------- */
.avatar {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--avatar, var(--faint));
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 0 0 2px var(--surface);
  flex-shrink: 0;
}

.presence { display: flex; align-items: center; }
.presence .avatar + .avatar { margin-left: -6px; }

.peers { display: inline-flex; align-items: center; }
.peers:empty { display: none; }
.peers .avatar { width: 22px; height: 22px; font-size: 9.5px; }
.peers .avatar + .avatar { margin-left: -5px; }

.user-switcher { position: relative; }
.user-btn {
  display: grid;
  place-items: center;
  padding: 2px;
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.user-btn .avatar { width: 30px; height: 30px; font-size: 11.5px; box-shadow: none; }
.user-btn:hover .avatar { filter: brightness(1.1); }
.menu-right { left: auto; right: 0; min-width: 240px; }
.menu-note { padding: 10px 12px 6px; font-size: 12.5px; color: var(--muted); }
.menu-note strong { display: block; color: var(--text); font-size: 13.5px; }

.menu-section-title { display: flex; align-items: center; gap: 6px; }
.menu-section-title svg { width: 14px; height: 14px; }
.menu-row { display: flex; align-items: center; gap: 2px; }
.menu-row .menu-item { flex: 1; min-width: 0; }
.menu-row .icon-btn { flex-shrink: 0; }
.menu-empty { padding: 6px 10px 10px; font-size: 12.5px; color: var(--faint); }

.editor-message {
  display: grid;
  place-items: center;
  min-height: 200px;
  color: var(--muted);
}

@keyframes remote-change {
  from { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
  to { box-shadow: 0 0 0 3px transparent; }
}
.field.is-remote, .site-name.is-remote, .project-name.is-remote, .project-desc.is-remote {
  animation: remote-change 1.4s ease-out;
}

.login {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.login-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: min(380px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.login-card .brand-mark { width: 40px; height: 40px; border-radius: 11px; margin-bottom: 10px; }
.login-card .brand-mark svg { width: 22px; height: 22px; }
.login-card h1 { margin: 0; font-size: 19px; letter-spacing: -0.01em; }
.login-card > p { margin: 0 0 14px; color: var(--muted); }
.login-card .label { margin-top: 8px; }
.login-card .btn { justify-content: center; margin-top: 16px; height: 38px; }
.login-error {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--err-soft);
  color: var(--err);
  font-size: 12.5px;
}

@media (max-width: 900px) {
  .presence { display: none; }
}

/* --------------------------------------------------------------------------
   PLC builder
   -------------------------------------------------------------------------- */
.builder-btn.is-active { color: var(--accent-text); background: var(--accent-soft); }
.field.is-built {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  color: var(--accent-text);
  font-weight: 600;
  cursor: default;
}

.dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  box-shadow: var(--shadow-pop);
}
.dialog::backdrop { background: rgba(15, 23, 42, 0.45); }
.dialog-card {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.dialog-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 16px 12px 20px;
  border-bottom: 1px solid var(--border);
}
.dialog-head .grow { flex: 1; min-width: 0; }
.dialog-head h2 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
.dialog-head p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.dialog-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent-text);
}
.dialog-icon svg { width: 18px; height: 18px; }
.dialog-body { overflow-y: auto; }
.dialog-foot { padding: 12px 20px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }
.dialog-actions { display: flex; align-items: center; gap: 8px; }
.dialog-actions .grow { flex: 1; }

.builder-table td, .builder-table th { padding: 7px 20px; }
.builder-table td:first-child { font-weight: 500; }
.builder-table .field { width: 84px; height: 30px; margin-left: auto; }
.builder-table .builder-base td { color: var(--muted); background: var(--surface-2); }
.builder-note {
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.builder-table tr.is-over td { background: var(--err-soft); }
.builder-table tr.is-over .field { border-color: var(--err); }
.builder-table tr.is-over .builder-note { background: var(--err); color: #fff; }
.builder-total { display: flex; align-items: baseline; gap: 6px; margin-right: 8px; color: var(--muted); font-size: 12.5px; }
.builder-total strong { color: var(--text); font-size: 20px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.builder-issues { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
.builder-issues:empty { display: none; }
