:root {
  color-scheme: light;
  --ink: #15202a;
  --muted: #61707d;
  --line: #d8e0e6;
  --line-strong: #a8b5bf;
  --paper: #f4f7f9;
  --surface: #ffffff;
  --chrome: #111820;
  --chrome-soft: #1a2530;
  --accent: #ff7a2f;
  --accent-dark: #c94f10;
  --blue: #2d79ff;
  --green: #3d9b68;
  --warning: #d75f16;
  --danger: #ba3030;
  --shadow: 0 12px 34px rgba(20, 32, 42, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
}

button, input, select { font: inherit; }
button, label[for] { -webkit-tap-highlight-color: transparent; }


h1, h2, p { margin: 0; }
h2 { font-size: 1.08rem; line-height: 1.2; letter-spacing: -0.01em; }
.eyebrow { color: var(--muted); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }

.panel-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: 0.875rem;
  font-weight: 750;
  cursor: pointer;
}
.button.ghost { color: var(--ink); background: var(--surface); border-color: var(--line-strong); }
.button.ghost:hover { filter: none; background: #edf2f5; }
.button.primary { color: #1b120c; background: var(--accent); }
.button:hover { filter: brightness(1.08); }

.app-shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(350px, 430px) minmax(0, 1fr);
}

.controls {
  min-height: 0;
  overflow-y: auto;
  border-right: 1px solid var(--line-strong);
  background: #edf2f5;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel, .drawing-panel, .diagnostics, .summary-strip {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255,255,255,.8);
}
.panel { padding: 18px; }
.section-heading, .drawing-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-heading .eyebrow, .drawing-heading .eyebrow, .diagnostics .eyebrow { margin-bottom: 4px; }
.unit-badge { padding: 4px 7px; background: #e8edf1; color: #53616c; font-size: 0.75rem; font-weight: 800; text-transform: uppercase; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid label { display: grid; gap: 6px; color: #52606b; font-size: 0.875rem; font-weight: 700; }
.field-wide { grid-column: 1 / -1; }
.divider { margin: 18px 0; border: 0; border-top: 1px solid var(--line); }
.add-status { color: var(--danger); }
.field-grid #separation-field { transition: opacity .15s ease, filter .15s ease; }
.field-grid #separation-field.disabled { opacity: .45; filter: grayscale(1); }
.toggle-field { grid-template-columns: auto auto 1fr; align-items: center; gap: 9px; cursor: pointer; }
.toggle-field input { position: absolute; width: 1px; height: 1px; min-height: 0; opacity: 0; }
.toggle-control { position: relative; width: 38px; height: 22px; border-radius: 999px; background: #a8b5bf; transition: background-color .15s ease; }
.toggle-control::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s ease; }
.toggle-field input:checked + .toggle-control { background: var(--blue); }
.toggle-field input:checked + .toggle-control::after { transform: translateX(16px); }
.toggle-field input:focus-visible + .toggle-control { outline: 3px solid rgba(45,121,255,.26); outline-offset: 2px; }
.toggle-field strong { display: block; }
input, select {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: #fbfcfd;
  color: var(--ink);
  padding: 8px 10px;
}
.combo { position: relative; }
.combo-list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow-y: auto;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  box-shadow: var(--shadow);
}
.combo-list[hidden] { display: none; }
.combo-list li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 10px; color: var(--ink); font-weight: 600; cursor: pointer; }
.combo-list li small { color: var(--muted); font-size: .8rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.combo-list li:hover { background: #f4f7f9; }
.combo-list li.active { background: #edf2f5; box-shadow: inset 3px 0 0 var(--blue); }
.combo-list li.combo-empty { color: var(--muted); font-weight: 500; cursor: default; background: none; box-shadow: none; }
input:focus, select:focus, button:focus-visible, label.button:focus-within { outline: 3px solid rgba(45,121,255,.26); outline-offset: 1px; border-color: var(--blue); }

/* The schedule sits in the scrolling workspace, so the table grows with it
   and only scrolls sideways when the screen is too narrow for it. */
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 560px; border-collapse: collapse; table-layout: fixed; }
th { padding: 0 5px 7px; color: var(--muted); text-align: left; font-size: 0.75rem; letter-spacing: .07em; text-transform: uppercase; }
th.col-index { width: 64px; } th.col-code { width: 32%; } th.col-od { width: 68px; } th.col-type { width: 64px; } th.col-actions { width: 42px; }
td { padding: 5px; border-top: 1px solid #e8edf0; }
#cable-rows td { font-size: .875rem; font-variant-numeric: tabular-nums; }
#cable-rows .cable-code { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 650; }
#cable-rows .cable-code.custom { color: var(--muted); font-weight: 500; }
/* The tag and OD read as plain text until hovered or edited. */
#cable-rows .cable-tag, #cable-rows .cable-diameter { min-height: 32px; padding: 4px 6px; border-color: transparent; background: transparent; font-size: .875rem; text-overflow: ellipsis; }
#cable-rows .cable-diameter { -moz-appearance: textfield; appearance: textfield; }
#cable-rows .cable-diameter::-webkit-inner-spin-button, #cable-rows .cable-diameter::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
#cable-rows .cable-tag:hover, #cable-rows .cable-diameter:hover { border-color: var(--line); background: #fbfcfd; }
#cable-rows .cable-tag:focus, #cable-rows .cable-diameter:focus { border-color: var(--blue); background: #fbfcfd; }
#cable-rows .cable-tag::placeholder { color: #a8b5bf; }
/* The type is a select drawn as the coloured type tag. */
#cable-rows .cable-type { width: 48px; min-height: 0; padding: 3px 0; border: 0; border-radius: 0; text-align: center; text-align-last: center; color: #fff; font-size: .72rem; font-weight: 800; cursor: pointer; appearance: none; -webkit-appearance: none; }
#cable-rows .cable-type option { background: var(--surface); color: var(--ink); }
#cable-rows .empty-row td { padding: 18px 5px; color: var(--muted); text-align: center; }
#cable-rows .cable-type.is { background: var(--blue); } #cable-rows .cable-type.lv { background: #252c32; box-shadow: inset 0 -2px 0 var(--accent); } #cable-rows .cable-type.hv { background: var(--accent); color: #1b120c; } #cable-rows .cable-type.pe { background: var(--green); }
.index-cell { display: flex; align-items: center; gap: 2px; }
.cable-index { display: inline-flex; min-height: 36px; align-items: center; padding: 6px 3px; color: var(--muted); font-size: .875rem; font-variant-numeric: tabular-nums; font-weight: 800; }
.drag-handle { width: 24px; min-height: 32px; padding: 0; border: 0; background: transparent; color: #83909a; cursor: grab; font-size: 1.05rem; line-height: 1; }
.drag-handle:active { cursor: grabbing; }
#cable-rows tr.dragging { opacity: .38; }
#cable-rows tr.drag-target td { border-top-color: var(--blue); box-shadow: inset 0 2px 0 var(--blue); }
.delete-button { width: 32px; height: 32px; border: 0; background: transparent; color: #7a8791; font-size: 1.25rem; cursor: pointer; }
.delete-button:hover { background: #fff0f0; color: var(--danger); }
.table-note { color: var(--muted); font-size: 0.8rem; line-height: 1.5; margin-top: 12px; }

.workspace { min-width: 0; min-height: 0; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
/* Panels keep their full height and the workspace scrolls; without this the
   summary strip, which has a min-height, gets squashed down to it. */
.workspace > * { flex-shrink: 0; }
.summary-strip { min-height: 74px; display: flex; align-items: stretch; }
.fit-state { min-width: 190px; display: flex; align-items: center; gap: 9px; padding: 18px; border-right: 1px solid var(--line); font-weight: 800; }
.state-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(61,155,104,.13); }
.fit-state.warning .state-dot { background: var(--warning); box-shadow: 0 0 0 4px rgba(215,95,22,.13); }
.fit-state.error .state-dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(186,48,48,.13); }
.summary-strip dl { flex: 1; margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.summary-strip dl div { padding: 13px 18px; display: grid; align-content: center; border-right: 1px solid var(--line); }
.summary-strip dl div:last-child { border-right: 0; }
.summary-actions { display: flex; align-items: center; padding: 0 18px; border-left: 1px solid var(--line); }
dt { color: var(--muted); font-size: 0.75rem; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
dd { margin: 3px 0 0; font-size: 1.08rem; font-variant-numeric: tabular-nums; font-weight: 800; }

.drawing-panel { min-height: 430px; padding: 18px 18px 12px; box-shadow: var(--shadow); }
.drawing-heading { margin-bottom: 10px; }
.drawing-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px 20px; }
.freeform-toggle { display: grid; color: #52606b; font-size: .875rem; font-weight: 700; }
#tray-svg.freeform .cable { cursor: grab; }
#tray-svg.freeform.dragging, #tray-svg.freeform.dragging .cable { cursor: grabbing; }
#tray-svg.freeform { touch-action: none; }
/* In free-form mode only the cables respond; the bands, separation zones and
   barrier strips are a drawn guide. */
#tray-svg.freeform { user-select: none; }
#tray-svg.freeform > :not(.cable) { pointer-events: none; }
.legend { display: flex; gap: 13px; flex-wrap: wrap; color: var(--muted); font-size: .8rem; font-weight: 750; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { width: 9px; height: 9px; display: inline-block; border-radius: 50%; }
.legend-dot.is { background: var(--blue); } .legend-dot.lv { background: #252c32; border: 2px solid var(--accent); } .legend-dot.hv { background: var(--accent); } .legend-dot.pe { background: var(--green); }

.canvas-shell {
  min-height: 330px;
  height: min(52vh, 560px);
  border: 1px solid var(--line-strong);
  background-color: #f9fbfc;
  background-image: linear-gradient(rgba(96,116,131,.07) 1px, transparent 1px), linear-gradient(90deg, rgba(96,116,131,.07) 1px, transparent 1px);
  background-size: 24px 24px;
  overflow: hidden;
}
#tray-svg { display: block; width: 100%; height: 100%; }
/* Marks are placed by app.js at the tray's drawn edges and centre, which the
   letterboxed drawing insets from the canvas edges. */
.scale-row { position: relative; height: 1.6rem; color: var(--muted); font-size: .75rem; font-variant-numeric: tabular-nums; }
.scale-row span { position: absolute; top: 0; padding-top: 7px; border-left: 1px solid var(--line-strong); padding-left: 4px; white-space: nowrap; }
.scale-row #scale-mid { transform: translateX(-50%); border-left: 0; padding-left: 0; }
.scale-row #scale-max { transform: translateX(-100%); border-left: 0; border-right: 1px solid var(--line-strong); padding-left: 0; padding-right: 4px; }

.diagnostics { display: grid; grid-template-columns: minmax(150px, .3fr) 1fr; gap: 20px; padding: 18px; }
.diagnostics ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.diagnostics li { position: relative; padding-left: 19px; color: #44525d; font-size: .875rem; line-height: 1.45; }
.diagnostics li::before { content: ""; position: absolute; left: 0; top: .48em; width: 7px; height: 7px; background: var(--blue); }
.diagnostics li.warning::before { background: var(--warning); }
.diagnostics li.error::before { background: var(--danger); }

.report-image { margin: 14px 0 0; }
.report-image[hidden] { display: none; }
.report-image img { display: block; max-width: 100%; max-height: 360px; border: 1px solid var(--line); }

.example-dialog {
  width: min(820px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 32px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(17, 24, 32, .28);
}
.example-dialog::backdrop { background: rgba(17, 24, 32, .62); backdrop-filter: blur(3px); }
.example-dialog-heading { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; gap: 20px; padding: 22px 24px; border-bottom: 1px solid var(--line); background: var(--surface); }
.example-dialog-heading .eyebrow { margin-bottom: 5px; }
.example-dialog-heading > div > p:last-child { margin-top: 7px; color: var(--muted); font-size: .875rem; }
.dialog-close { flex: 0 0 auto; width: 36px; height: 36px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; font-size: 1.4rem; line-height: 1; }
.dialog-close:hover { background: #edf2f5; color: var(--ink); }
.example-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; padding: 20px 24px 24px; }
.example-card { min-width: 0; display: flex; flex-direction: column; align-items: stretch; gap: 11px; padding: 17px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); color: var(--ink); text-align: left; cursor: pointer; }
.example-card:hover { border-color: var(--blue); box-shadow: 0 8px 22px rgba(20, 32, 42, .09); transform: translateY(-1px); }
.example-card-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.example-card-heading strong { font-size: 1rem; }
.example-card-heading b { flex: 0 0 auto; color: var(--blue); font-size: .75rem; }
.example-card > small { min-height: 2.8em; color: var(--muted); font-size: .8rem; line-height: 1.4; }
.example-types { display: flex; flex-wrap: wrap; gap: 5px; }
.example-types span { padding: 3px 6px; background: #edf2f5; color: #465562; font-size: .68rem; font-weight: 800; }
.example-tray { padding-top: 10px; border-top: 1px solid #edf1f3; color: var(--muted); font-size: .75rem; font-weight: 700; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  /* One column that scrolls as a whole. min-height goes back to auto so
     the grid cannot squeeze both panes into the screen height. */
  .app-shell { grid-template-columns: 1fr; overflow-y: auto; }
  .controls, .workspace { min-height: auto; overflow-y: visible; }
  .controls { border-right: 0; border-bottom: 1px solid var(--line-strong); }
  .workspace { padding: 14px; }
  .canvas-shell { height: 420px; }
}

@media (max-width: 580px) {
  .button { padding-inline: 10px; white-space: nowrap; }
  .controls { padding: 14px; }
  .summary-strip { display: block; }
  .fit-state { border-right: 0; border-bottom: 1px solid var(--line); }
  .summary-strip dl { grid-template-columns: 1fr 1fr; }
  .summary-strip dl div:nth-child(2) { border-right: 0; }
  .summary-strip dl div:last-child { border-top: 1px solid var(--line); grid-column: 1 / -1; }
  .summary-actions { padding: 12px 18px; border-left: 0; border-top: 1px solid var(--line); }
  .drawing-heading { align-items: flex-start; flex-direction: column; }
  .drawing-tools { justify-content: flex-start; }
  .canvas-shell { min-height: 280px; height: 340px; }
  .diagnostics { grid-template-columns: 1fr; }
  .example-dialog-heading { padding: 18px; }
  .example-grid { grid-template-columns: 1fr; padding: 14px 18px 18px; }
  .example-card > small { min-height: auto; }
}

@media (prefers-reduced-motion: no-preference) {
  .button, .delete-button, .drag-handle, .dialog-close, .example-card { transition: background-color .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease, filter .15s ease, transform .15s ease; }
}
