:root {
  --blue: #245eea;
  --ink: #111827;
  --muted: #667085;
  --line: #d7dde8;
  --surface: #f7f9fc;
  --white: #ffffff;
  --green: #18834f;
  --orange: #b95b00;
  --red: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: Segoe UI, Arial, sans-serif;
  font-size: 15px;
}

.topbar {
  align-items: center;
  background: var(--blue);
  color: var(--white);
  display: flex;
  justify-content: space-between;
  min-height: 58px;
  padding: 0 28px;
}

.brand {
  color: var(--white);
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}

.userbar {
  align-items: center;
  display: flex;
  gap: 12px;
}

.role {
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 999px;
  padding: 3px 10px;
}

button,
.button-link {
  background: var(--blue);
  border: 0;
  color: var(--white);
  cursor: pointer;
  font-weight: 700;
  padding: 9px 13px;
  text-decoration: none;
}

.secondary {
  background: #344054;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.userbar button {
  background: rgba(255, 255, 255, 0.18);
}

.page {
  margin: 0 auto;
  max-width: 1280px;
  padding: 28px;
}

.auth-panel {
  background: var(--white);
  border: 1px solid var(--line);
  margin: 80px auto 0;
  max-width: 420px;
  padding: 28px;
}

.form {
  display: grid;
  gap: 16px;
}

label {
  color: var(--muted);
  display: grid;
  gap: 6px;
  font-weight: 600;
}

input {
  border: 1px solid var(--line);
  color: var(--ink);
  font: inherit;
  padding: 10px;
  width: 100%;
}

select {
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--ink);
  font: inherit;
  padding: 10px;
  width: 100%;
}

.section-header {
  align-items: end;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 18px;
}

.section-header.compact {
  margin-top: 24px;
}

h1 {
  font-size: 26px;
  margin: 0;
}

p {
  color: var(--muted);
  margin: 6px 0 0;
}

.project-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.project-card,
.closure-list a {
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--ink);
  display: grid;
  gap: 6px;
  padding: 16px;
  text-decoration: none;
}

.admin-panel {
  background: var(--white);
  border: 1px solid var(--line);
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
  padding: 18px;
}

.admin-panel h2 {
  font-size: 20px;
  margin: 0;
}

.admin-panel code {
  background: #eef2f8;
  border: 1px solid var(--line);
  display: block;
  overflow-wrap: anywhere;
  padding: 10px;
}

.admin-note {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.sync-select-header {
  align-items: end;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.sync-select-header p {
  margin: 4px 0 0;
}

.sync-select-actions {
  display: flex;
  gap: 8px;
}

.sync-select-actions input {
  min-width: 220px;
}

.sync-closure-list {
  border: 1px solid var(--line);
  display: grid;
  max-height: 420px;
  overflow: auto;
}

.sync-closure-heading {
  background: #eef2f8;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  display: grid;
  font-weight: 800;
  gap: 12px;
  grid-template-columns: minmax(240px, 1fr) 180px 210px;
  padding: 10px;
  position: sticky;
  top: 0;
  z-index: 1;
}

.sync-closure-row {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(240px, 1fr) 180px 210px;
  padding: 10px;
}

.sync-closure-row:last-child {
  border-bottom: 0;
}

.sync-closure-row small {
  color: var(--muted);
  display: block;
  margin-top: 3px;
}

.sync-option {
  align-items: center;
  color: var(--ink);
  display: flex;
  gap: 8px;
}

.sync-job-summary {
  align-items: center;
  display: flex;
  gap: 10px;
}

.sync-progress-table {
  border-collapse: collapse;
  width: 100%;
}

.sync-progress-table th,
.sync-progress-table td {
  border: 1px solid var(--line);
  padding: 9px;
  text-align: left;
  vertical-align: top;
}

.status-pill {
  background: #eef2f8;
  color: var(--ink);
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  margin-right: 8px;
  min-width: 72px;
  padding: 4px 7px;
  text-align: center;
  text-transform: uppercase;
}

.status-pill.running {
  background: #dbeafe;
  color: #1d4ed8;
}

.status-pill.success {
  background: #dcfce7;
  color: #15803d;
}

.status-pill.failed,
.status-pill.skipped {
  background: #fee2e2;
  color: #b91c1c;
}

.status-message {
  color: var(--muted);
}

.project-create-form h2 {
  border-top: 1px solid var(--line);
  font-size: 18px;
  margin: 8px 0 0;
  padding-top: 14px;
}

.project-create-form h2:first-child {
  border-top: 0;
  margin-top: 0;
  padding-top: 0;
}

.form-note {
  margin-top: 0;
}

.optional-layer-row {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) 140px;
}

.arc-image-panel {
  background: var(--white);
  border: 1px solid var(--line);
  margin-bottom: 16px;
  padding: 12px;
}

.arc-image-panel h2 {
  font-size: 16px;
  margin: 0 0 10px;
}

.arc-image-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}

.arc-image-card {
  border: 1px solid var(--line);
  color: var(--ink);
  display: grid;
  gap: 6px;
  padding: 8px;
  text-decoration: none;
}

.arc-image-card img {
  aspect-ratio: 4 / 3;
  background: #eef2f8;
  display: block;
  object-fit: cover;
  width: 100%;
}

.arc-image-card span {
  font-size: 12px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.project-olt {
  color: var(--blue);
  font-weight: 800;
}

.search {
  display: flex;
  gap: 8px;
  min-width: 340px;
}

.closure-list {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.sld-panel {
  background: var(--white);
  border: 1px solid var(--line);
  margin-bottom: 20px;
}

.sld-toolbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px 14px;
}

.sld-toolbar span {
  color: var(--muted);
}

.sld-canvas {
  background: #f7f9fc;
  max-height: 720px;
  overflow: auto;
  padding: 16px;
  touch-action: none;
  user-select: none;
}

.sld-controls {
  display: flex;
  gap: 6px;
}

.sld-controls button {
  min-width: 38px;
  padding: 7px 10px;
}

#sld-svg {
  cursor: grab;
  display: block;
  min-width: 1100px;
  width: 100%;
}

#sld-svg.is-panning {
  cursor: grabbing;
}

.sld-graph {
  min-height: 520px;
}

.sld-edge {
  fill: none;
  stroke: #667085;
  stroke-width: 2;
}

.sld-edge-label {
  fill: #344054;
  font-size: 10px;
  font-weight: 700;
  paint-order: stroke;
  pointer-events: none;
  stroke: #f7f9fc;
  stroke-width: 4px;
}

.sld-node rect {
  fill: #ffffff;
  stroke: var(--blue);
  stroke-width: 2;
}

.sld-node text {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
}

.sld-node:hover rect {
  fill: #eaf0ff;
  stroke-width: 3;
}

.messages {
  margin-bottom: 16px;
}

.message {
  background: #fff4ed;
  border: 1px solid #ffb088;
  color: #7a2e0e;
  padding: 10px 12px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.stats span,
.asset-summary span,
.qc-summary span {
  align-items: center;
  background: var(--white);
  border: 1px solid var(--line);
  display: flex;
  gap: 10px;
  padding: 9px 12px;
}

.asset-summary,
.qc-summary,
.adjacent-joints {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.adjacent-joints > div {
  background: var(--white);
  border: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
}

.adjacent-joints a {
  background: #eef2f8;
  border: 1px solid var(--line);
  color: var(--blue);
  font-weight: 700;
  padding: 4px 7px;
  text-decoration: none;
}

.trace-list,
.qc-list {
  display: grid;
  gap: 12px;
}

.trace-card,
.qc-issue {
  background: var(--white);
  border: 1px solid var(--line);
}

.trace-card header,
.qc-issue {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px;
}

.trace-card header {
  border-bottom: 1px solid var(--line);
}

.trace-path {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.trace-step {
  align-items: center;
  border: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) 120px minmax(0, 1fr);
  padding: 8px;
}

.trace-step b {
  border-radius: 4px;
  color: var(--white);
  padding: 7px;
  text-align: center;
}

.trace-step small,
.trace-step em {
  color: var(--muted);
  display: block;
  font-style: normal;
}

.trace-step a {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.trace-step.type-uncut b {
  background: var(--green);
}

.trace-step.type-fused b {
  background: var(--blue);
}

.trace-step.type-open b,
.severity-high {
  border-left: 5px solid var(--red);
}

.trace-step.type-prespliced b {
  background: var(--orange);
}

.severity-medium {
  border-left: 5px solid var(--orange);
}

.severity-low {
  border-left: 5px solid var(--green);
}

.qc-issue p {
  margin: 4px 0;
}

.qc-issue code {
  color: #344054;
  overflow-wrap: anywhere;
}

.schematic-toolbar {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin: 8px 0 12px;
}

.schematic-toolbar > span {
  font-size: 18px;
  font-weight: 800;
}

.filters {
  align-items: end;
  background: var(--white);
  border: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 1fr) 220px auto;
  margin-bottom: 12px;
  padding: 12px;
}

.filter-actions {
  display: flex;
  gap: 8px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.legend b {
  border-radius: 4px;
  color: var(--white);
  font-size: 12px;
  padding: 5px 8px;
}

.legend-uncut {
  background: var(--green);
}

.legend-fused {
  background: var(--blue);
}

.legend-open {
  background: var(--red);
}

.legend-prespliced {
  background: var(--orange);
}

.schematic-board {
  background: #e9eef7;
  border: 1px solid var(--line);
  display: grid;
  gap: 8px;
  overflow-x: auto;
  padding: 12px;
}

.schematic-head,
.splice-row {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(300px, 1fr) 150px minmax(300px, 1fr);
  min-width: 850px;
}

.schematic-head {
  color: #344054;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.splice-row {
  align-items: stretch;
  position: relative;
}

.splice-row:has(.admin-edit) {
  grid-template-columns: minmax(300px, 1fr) 150px minmax(300px, 1fr) minmax(320px, 0.8fr);
  min-width: 1200px;
}

.splice-row::before,
.splice-row::after {
  background: #98a2b3;
  content: "";
  height: 2px;
  position: absolute;
  top: 50%;
  width: calc(50% - 95px);
  z-index: 0;
}

.splice-row::before {
  left: calc(33.333% - 10px);
}

.splice-row::after {
  right: calc(33.333% - 10px);
}

.endpoint-card,
.splice-core {
  background: var(--white);
  border: 1px solid var(--line);
  min-width: 0;
  position: relative;
  z-index: 1;
}

.endpoint-card {
  border-left: 5px solid #8a94a6;
  min-height: 74px;
  padding: 10px 12px;
}

.endpoint-card small {
  color: var(--muted);
  display: block;
  font-weight: 700;
  margin-bottom: 4px;
}

.endpoint-card strong {
  display: block;
  overflow-wrap: anywhere;
}

.endpoint-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.endpoint-meta span,
.destination {
  background: #eef2f8;
  border: 1px solid var(--line);
  color: #344054;
  display: inline-block;
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
  padding: 3px 6px;
}

.destination {
  margin-top: 8px;
}

.endpoint-cable_fibre {
  border-left-color: var(--blue);
}

.endpoint-splitter_port {
  border-left-color: var(--orange);
}

.endpoint-drop {
  border-left-color: var(--green);
}

.endpoint-open {
  border-left-color: var(--red);
}

.splice-core {
  align-content: center;
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 10px;
  text-align: center;
}

.splice-id {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.splice-type {
  border-radius: 4px;
  color: var(--white);
  font-weight: 800;
  min-width: 100px;
  padding: 8px;
}

.type-uncut .splice-type,
.type-uncut::before,
.type-uncut::after {
  background: var(--green);
}

.type-fused .splice-type,
.type-fused::before,
.type-fused::after {
  background: var(--blue);
}

.type-open .splice-type,
.type-open::before,
.type-open::after {
  background: var(--red);
}

.type-prespliced .splice-type,
.type-prespliced::before,
.type-prespliced::after {
  background: var(--orange);
}

.type-blank .splice-type,
.type-blank::before,
.type-blank::after {
  background: var(--muted);
}

.visual-schematic {
  background: #171b21;
  border: 1px solid #343b46;
  margin-bottom: 14px;
}

.visual-scroll {
  max-height: 720px;
  overflow: auto;
  touch-action: none;
  user-select: none;
}

.visual-schematic svg {
  cursor: grab;
  display: block;
  min-width: 980px;
}

.visual-schematic svg.is-panning {
  cursor: grabbing;
}

.visual-schematic svg.is-editing {
  cursor: crosshair;
}

.visual-edit-controls {
  align-items: center;
  display: flex;
  gap: 10px;
}

.visual-edit-controls label {
  align-items: center;
  display: flex;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.visual-edit-controls select {
  border: 1px solid var(--border);
  padding: 7px 8px;
}

#visual-edit-status {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

#visual-edit-status.is-error {
  color: var(--red);
}

.visual-title {
  fill: #f5f8ff;
  font-size: 18px;
  font-weight: 800;
}

.visual-label,
.visual-block-title,
.visual-fibre-label,
.visual-cable-meta {
  fill: #d7dde8;
  font-size: 11px;
  font-weight: 700;
}

.visual-cable-meta {
  fill: #f5f8ff;
  paint-order: stroke;
  stroke: #171b21;
  stroke-width: 5px;
}

.visual-block-title {
  fill: #ffffff;
  max-width: 200px;
}

.visual-fibre-label {
  fill: #e5e7eb;
  paint-order: stroke;
  stroke: #20242b;
  stroke-width: 4px;
}

.visual-block {
  stroke-width: 1.5;
}

.input-block {
  fill: #123f2a;
  stroke: #59d38c;
}

.output-block {
  fill: #3b0645;
  stroke: #c56cff;
}

.visual-splice-column {
  fill: #080e10;
  stroke: #48606a;
}

.visual-tail-column,
.visual-output-column {
  fill: rgba(255, 255, 255, 0.04);
  stroke: #f5f8ff;
  stroke-width: 2;
}

.visual-splitter-block {
  fill: #061215;
  stroke: #2f6f7a;
  stroke-width: 1.5;
}

.visual-line {
  fill: none;
  marker-end: url(#splice-arrow);
  opacity: 0.9;
  stroke-linecap: round;
  stroke-width: 2.2;
}

.visual-line-open {
  stroke-dasharray: 7 6;
}

.visual-line-prespliced {
  stroke-width: 3;
}

.visual-dot {
  stroke: #c7f9cc;
  stroke-width: 1.5;
}

.visual-join-dot {
  stroke: #f8fafc;
  stroke-width: 2.5;
}

.visual-input-dot,
.visual-output-target {
  cursor: crosshair;
}

.visual-input-dot:hover,
.visual-output-target:hover {
  stroke: #ffffff;
  stroke-width: 4;
}

.visual-target-dot {
  fill: transparent;
  pointer-events: all;
  stroke: transparent;
}

.visual-target-dot:hover {
  fill: rgba(255, 255, 255, 0.12);
  stroke: #ffffff;
}

.visual-edit-preview {
  fill: none;
  pointer-events: none;
  stroke: #ffffff;
  stroke-dasharray: 8 6;
  stroke-linecap: round;
  stroke-width: 3;
}

.admin-edit {
  background: #fffaf0;
  border: 1px solid #f6c66b;
  display: grid;
  gap: 8px;
  padding: 10px;
  position: relative;
  z-index: 1;
}

.admin-edit label {
  gap: 4px;
}

.admin-edit input,
.admin-edit select {
  padding: 7px;
}

@media (max-width: 760px) {
  .topbar,
  .section-header,
  .userbar,
  .header-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    padding: 14px;
  }

  .search,
  .filters {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .filter-actions {
    flex-direction: column;
  }

  .schematic-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .sld-toolbar {
    align-items: stretch;
    flex-direction: column;
  }
}
