/* PrimeStack IT — Diagram Studio
   Brand colours live in the first block: change --brand / --brand-2 to re-skin. */
/* PrimeStack IT — Diagram Studio
   Colors follow the PrimeStack IT quote (ITFlow): blue #0d6efd, ink #212529, muted #6c757d. */
:root {
  --brand: #0d6efd;
  --brand-2: #0a58ca;
  --brand-ink: #ffffff;

  --bg: #f1f3f5;
  --panel: #ffffff;
  --panel-2: #f8f9fa;
  --line: #dee2e6;
  --line-2: #ced4da;
  --text: #212529;
  --muted: #6c757d;
  --field: #ffffff;
  --hover: #f1f3f5;
  --danger: #dc3545;
  --warn: #d97706;
  --ok: #198754;
  --shadow: 0 10px 30px rgba(33, 37, 41, .15);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --brand: #3d8bfd;
  --brand-2: #6ea8fe;
  --brand-ink: #ffffff;
  --bg: #0b1120;
  --panel: #0f172a;
  --panel-2: #131d33;
  --line: #1f2a44;
  --line-2: #2a3756;
  --text: #e2e8f0;
  --muted: #8a9bb8;
  --field: #0b1324;
  --hover: #1a2540;
  --danger: #f43f5e;
  --warn: #f59e0b;
  --ok: #10b981;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.4 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }

button {
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 7px;
  padding: 5px 11px; cursor: pointer; white-space: nowrap;
}
button:hover { background: var(--hover); }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.icon { padding: 5px 9px; min-width: 32px; }
button.wide { width: 100%; }
button.on { border-color: var(--brand); color: var(--brand); }
button:disabled { opacity: .4; cursor: default; }

input, select, textarea {
  background: var(--field); border: 1px solid var(--line-2); border-radius: 6px; padding: 5px 8px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 50%, transparent); border-color: var(--brand); }
textarea { resize: vertical; min-height: 60px; }

/* ---------- top bar ---------- */
.topbar {
  border-top: 4px solid #0d6efd;
  height: 58px; flex: none; display: flex; align-items: center; gap: 18px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 30px; height: 30px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 14px; letter-spacing: .2px; }
.brand-text span { font-size: 11px; color: var(--muted); }
.project-title { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.project-title input { max-width: 360px; background: transparent; border-color: transparent; font-weight: 600; font-size: 14px; }
.project-title input:hover { border-color: var(--line-2); }
.save-state { color: var(--muted); font-size: 11px; white-space: nowrap; }
.actions { display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 220px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 9px; padding: 6px; box-shadow: var(--shadow);
  max-height: calc(100vh - 70px); overflow-y: auto;
}
.menu-list button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 10px; }
.menu-list button:hover { background: var(--hover); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 5px 0; }
#btnIssues .badge { margin-left: 6px; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; font-weight: 700; text-align: center; }
.badge.err { background: var(--danger); color: #fff; }
.badge.warn { background: var(--warn); color: #1f1300; }
.badge.ok { background: var(--ok); color: #03140d; }

/* ---------- layout ---------- */
.layout { --pal: 250px; --insp: 300px; flex: 1; display: grid; grid-template-columns: var(--pal) 1fr var(--insp); min-height: 0; transition: grid-template-columns .18s ease; }

/* palette */
.palette { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.palette-head { padding: 10px; border-bottom: 1px solid var(--line); }
.palette-list { flex: 1; overflow-y: auto; padding: 4px 6px 10px; }
.palette-foot { padding: 10px; border-top: 1px solid var(--line); }
.pal-cat { margin-top: 6px; }
.pal-cat > summary {
  list-style: none; cursor: pointer; padding: 8px 6px; font-size: 11px; font-weight: 700; letter-spacing: .6px;
  text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px;
}
.pal-cat > summary::-webkit-details-marker { display: none; }
.pal-cat > summary .dot { width: 8px; height: 8px; border-radius: 2px; }
.pal-cat > summary .count { margin-left: auto; font-weight: 500; }
.pal-item {
  display: flex; align-items: center; gap: 9px; padding: 6px 7px; border-radius: 7px; cursor: grab; user-select: none;
}
.pal-item:hover { background: var(--hover); }
.pal-item svg { width: 26px; height: 26px; flex: none; padding: 4px; border-radius: 6px; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.pal-item .t { min-width: 0; }
.pal-item .t b { display: block; font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-item .t small { display: block; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-item .edit { margin-left: auto; opacity: 0; padding: 2px 6px; font-size: 11px; }
.pal-item:hover .edit { opacity: 1; }

/* stage */
.stage { position: relative; overflow: hidden; background: var(--bg); }
#canvas { width: 100%; height: 100%; display: block; cursor: default; touch-action: none; }
#canvas.panning { cursor: grabbing; }
#canvas text { user-select: none; -webkit-user-select: none; }
.stage.drop-target::after { content: ""; position: absolute; inset: 0; border: 2px dashed var(--brand); pointer-events: none; }
.legend {
  position: absolute; left: 12px; bottom: 12px; display: flex; flex-wrap: wrap; gap: 4px 10px; max-width: 60%;
  background: color-mix(in srgb, var(--panel) 88%, transparent); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 11px; color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.hint { position: absolute; bottom: 58px; left: 50%; transform: translateX(-50%); font-size: 11.5px; color: var(--muted);
  background: color-mix(in srgb, var(--panel) 85%, transparent); border: 1px solid var(--line); padding: 5px 12px; border-radius: 20px; white-space: nowrap; pointer-events: none; }
.zoom { position: absolute; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px; }
.zoom span { min-width: 44px; text-align: center; font-size: 12px; color: var(--muted); }
.zoom button { border: 0; background: transparent; }

/* inspector */
.inspector { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 14px; }
.inspector h3 { margin: 0 0 2px; font-size: 15px; }
.inspector .sub { color: var(--muted); font-size: 12px; margin-bottom: 12px; display: flex; align-items: center; gap: 6px; }
.inspector .chip { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; border: 1px solid currentColor; }
.section { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.section > h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); display: flex; align-items: center; justify-content: space-between; }
.field { margin-bottom: 9px; }
.field label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.stat b { display: block; font-size: 18px; }
.stat span { color: var(--muted); font-size: 11px; }
.meter { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 5px; }
.meter i { display: block; height: 100%; border-radius: 3px; }
.kv { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; font-size: 12.5px; }
.kv span:first-child { color: var(--muted); }
.port-list { display: flex; flex-direction: column; gap: 2px; }
.port-row { display: grid; grid-template-columns: 10px 1fr auto auto; align-items: center; gap: 7px; padding: 3px 4px; border-radius: 5px; font-size: 12px; }
.port-row:hover { background: var(--hover); }
.port-row .pdot { width: 9px; height: 9px; border-radius: 50%; }
.port-row .to { color: var(--muted); font-size: 11px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.port-row button { padding: 0 5px; font-size: 11px; border: 0; background: transparent; color: var(--muted); }
.port-row button:hover { color: var(--text); }
.issues { display: flex; flex-direction: column; gap: 4px; }
.issue { display: grid; grid-template-columns: 8px 1fr; gap: 8px; align-items: start; padding: 6px 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; font-size: 12px; }
.issue:hover { border-color: var(--line-2); }
.issue i { width: 8px; height: 8px; border-radius: 50%; margin-top: 4px; }
.issue.error i { background: var(--danger); }
.issue.warn i { background: var(--warn); }
.issue.info i { background: var(--brand); }
.muted { color: var(--muted); }
.empty { color: var(--muted); font-size: 12px; padding: 6px 0; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 18, .6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 24px; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: var(--shadow); width: min(1100px, 100%); max-height: 100%; display: flex; flex-direction: column; }
.modal.narrow { width: min(760px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 18px; overflow: auto; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; padding: 8px 12px; color: var(--muted); }
.tabs button.active { color: var(--text); border-bottom-color: var(--brand); }
.table-wrap { overflow: auto; max-height: 60vh; border: 1px solid var(--line); border-radius: 8px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.grid th, table.grid td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.grid th { position: sticky; top: 0; background: var(--panel-2); font-weight: 600; color: var(--muted); font-size: 11.5px; }
table.grid tr:hover td { background: var(--hover); }
.tab-tools { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; }
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.proj-card { border: 1px solid var(--line-2); border-radius: 10px; padding: 12px; background: var(--panel-2); display: flex; flex-direction: column; gap: 6px; }
.proj-card.current { border-color: var(--brand); }
.proj-card b { font-size: 13.5px; }
.proj-card .btn-row button { padding: 3px 8px; font-size: 12px; }
.tpl-card { cursor: pointer; }
.tpl-card:hover { border-color: var(--brand); }
.ports-editor { width: 100%; border-collapse: collapse; }
.ports-editor td, .ports-editor th { padding: 3px 4px; text-align: left; font-size: 12px; }
.ports-editor th { color: var(--muted); font-weight: 600; }

/* toasts */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 60; pointer-events: none; }
.toast { background: var(--panel); border: 1px solid var(--line-2); border-left: 4px solid var(--brand); padding: 9px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 12.5px; animation: tin .15s ease-out; }
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
@keyframes tin { from { transform: translateY(6px); opacity: 0; } }

@media (max-width: 1100px) {
  .layout { --pal: 210px; --insp: 260px; }
  .hint { display: none; }
}
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .palette, .inspector { display: none; }
  .brand-text span, .project-title { display: none; }
}

/* ---------- v2 additions ---------- */
.menu-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: 6px 10px 2px; font-weight: 700; }
.menu-who { padding: 6px 10px; display: flex; flex-direction: column; }
.menu-who span { color: var(--muted); font-size: 11.5px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; padding: 0; font-weight: 700; font-size: 12px; background: var(--brand); color: #fff; border-color: var(--brand); }
.avatar:hover { background: var(--brand-2); }
.pal-tabs { display: flex; gap: 4px; margin-top: 8px; }
.pal-tabs button { flex: 1; padding: 4px 6px; font-size: 12px; }
.pal-tabs button.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.pal-heading { margin: 12px 6px 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: 11px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase; color: var(--text); display: flex; justify-content: space-between; }
.pal-heading span { color: var(--muted); font-weight: 500; }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; margin-bottom: 14px; border: 1px solid var(--brand); border-radius: 8px; background: color-mix(in srgb, var(--brand) 8%, transparent); }
code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
/* Export menu: "Cable schedule   [Excel] [CSV]" rows */
.menu-pair { display: flex; align-items: center; gap: 4px; padding: 2px 6px 2px 10px; }
.menu-pair span { flex: 1; white-space: nowrap; }
.menu-list .menu-pair button { display: inline-block; width: auto; padding: 4px 9px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }
.menu-list .menu-pair button:first-of-type { border-color: #198754; color: #198754; font-weight: 600; }
.menu-sub { color: var(--muted); font-size: 11.5px; margin-left: 4px; }
/* Sheet tabs (System / Access control) */
.sheet-tabs { position: absolute; left: 12px; top: 10px; right: 12px; width: max-content; max-width: calc(100% - 24px); flex-wrap: wrap; z-index: 4; display: flex; gap: 2px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 3px; box-shadow: var(--shadow); }
.sheet-tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; font-weight: 600; color: var(--muted); }
.sheet-tabs button:hover { background: var(--hover); color: var(--text); }
.sheet-tabs button.on { background: var(--brand); color: #fff; }
.sheet-tabs [data-sheet="access"].on { background: #e11d48; }
.sheet-tabs .count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; font-size: 11px; line-height: 17px; background: color-mix(in srgb, currentColor 18%, transparent); }
.sheet-tabs .count:empty { display: none; }
.sheet-tabs .arrange { margin-left: 6px; border: 1px solid var(--line) !important; color: var(--text) !important; font-weight: 500 !important; }
.stage.sheet-access .hint { display: none; }
.sheet-checks { display: flex; gap: 14px; flex-wrap: wrap; }
.sheet-checks label { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; cursor: pointer; }
/* Floor tabs */
.floor-tabs { display: flex; gap: 2px; align-items: center; max-width: 46vw; overflow-x: auto; scrollbar-width: thin; }
.floor-tabs button { position: relative; white-space: nowrap; }
.floor-tabs button.on { background: var(--text); color: var(--panel); }
.floor-tabs .n { margin-left: 6px; font-size: 10.5px; opacity: .6; font-weight: 500; }
.floor-tabs [data-floor-x] { font-style: normal; margin-left: 6px; padding: 0 3px; border-radius: 4px; opacity: .55; }
.floor-tabs [data-floor-x]:hover { opacity: 1; background: color-mix(in srgb, currentColor 22%, transparent); }
.floor-tabs .add { font-size: 15px; padding: 3px 9px !important; }
.floor-rename { width: 120px; padding: 5px 8px; border: 1px solid var(--brand); border-radius: 6px; font: inherit; font-weight: 600; background: var(--field); color: var(--text); }
.tab-sep { width: 1px; align-self: stretch; margin: 4px 6px; background: var(--line); }
/* Conductor view */
.sheet-tabs .cond-toggle.on { background: #1f2937 !important; color: #fff !important; border-color: #1f2937 !important; }
.sheet-tabs .cond-toggle.on::before { content: ""; display: inline-block; width: 14px; height: 6px; margin-right: 6px; vertical-align: middle; border-radius: 2px; background: linear-gradient(#dc2626 0 50%, #9ca3af 50% 100%); }
.cond-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.cond-table th { text-align: left; font-weight: 600; color: var(--muted); padding: 2px 4px; font-size: 11px; }
.cond-table td { padding: 2px 4px; white-space: nowrap; }
.cond-table select { width: 100%; font-size: 12px; padding: 3px 4px; }
.cdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; border: 1px solid color-mix(in srgb, var(--text) 45%, transparent); }
.swatches { display: flex; flex-wrap: wrap; gap: 5px; }
.swatches .sw { width: 22px; height: 22px; border-radius: 50%; border: 1px solid color-mix(in srgb, var(--text) 40%, transparent); padding: 0; }
.swatches .sw.on { outline: 2px solid var(--brand); outline-offset: 2px; }
/* Custom view tabs */
.view-tabs { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; }
.view-tabs .view-tab.on { background: #6f42c1; color: #fff; }
.view-tabs .add { font-weight: 500 !important; }
label.radio { display: flex; align-items: center; gap: 7px; font-size: 13px; margin: 4px 0; cursor: pointer; }
label.radio input[type=checkbox], label.radio input[type=radio] { width: auto; flex: none; margin: 0; }
/* Inline cable label editor */
.label-edit { position: absolute; z-index: 6; transform: translate(-50%, -50%); width: 180px; padding: 5px 9px; border: 2px solid var(--brand); border-radius: 9px; font: 600 12.5px Inter, "Segoe UI", system-ui, sans-serif; text-align: center; background: var(--field); color: var(--text); box-shadow: var(--shadow); }
/* Collapsible sidebars ([ and ] keys, or the edge tabs) */
.layout.no-pal { --pal: 0px; }
.layout.no-insp { --insp: 0px; }
.layout.no-pal .palette, .layout.no-insp .inspector { visibility: hidden; overflow: hidden; border: 0; padding: 0; }
.edge-toggle { position: absolute; top: 50%; z-index: 5; transform: translateY(-50%); width: 18px; height: 56px; padding: 0; border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 13px; line-height: 1; box-shadow: var(--shadow); opacity: .75; }
.edge-toggle:hover { opacity: 1; color: var(--text); }
.edge-toggle.left { left: 0; border-left: 0; border-radius: 0 8px 8px 0; }
.edge-toggle.right { right: 0; border-right: 0; border-radius: 8px 0 0 8px; }
.layout.no-pal .edge-toggle.left, .layout.no-insp .edge-toggle.right { opacity: 1; background: var(--brand); color: #fff; border-color: var(--brand); }
@media (max-width: 800px) { .edge-toggle { display: none; } }
