/* Same palette and panel language as the Cable Tray Arranger. */
:root {
  color-scheme: light;
  --ink: #15202a;
  --muted: #61707d;
  --label: #52606b;
  --line: #d8e0e6;
  --line-strong: #a8b5bf;
  --paper: #f4f7f9;
  --surface: #ffffff;
  --field: #fbfcfd;
  --sidebar: #edf2f5;
  --accent: #ff7a2f;
  --accent-dark: #c94f10;
  --blue: #2d79ff;
  --green: #3d9b68;
  --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;
}

[hidden] { display: none !important; }

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

h1, h2, h3, 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; }
.muted { color: var(--muted); font-size: 0.875rem; }

/* Buttons */
.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.primary { color: #1b120c; background: var(--accent); }
.button.secondary { color: var(--ink); background: var(--surface); border-color: var(--line-strong); }
.button:hover { filter: brightness(1.08); }
.button.secondary:hover { filter: none; background: var(--sidebar); }
.button:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.button.secondary:disabled:hover { background: var(--surface); }

/* Layout: inputs on the left, results on the right, each scrolling on its own. */
.app-shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(330px, 390px) minmax(0, 1fr);
}

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

.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; }

.panel, .drawing-panel, .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 { margin-bottom: 4px; }
.unit-badge { padding: 4px 7px; background: #e8edf1; color: #53616c; font-size: 0.75rem; font-weight: 800; text-transform: uppercase; }
.divider { margin: 18px 0; border: 0; border-top: 1px solid var(--line); }

/* Fields */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid label, .field-label { display: grid; gap: 6px; color: var(--label); font-size: 0.875rem; font-weight: 700; }
.field-label { margin-bottom: 6px; }
.field-wide { grid-column: 1 / -1; }
.mode-fields { margin-top: 14px; }

input[type="text"], input[type="number"], select {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--field);
  color: var(--ink);
  padding: 8px 10px;
}
input::placeholder { color: #93a0aa; }
input:focus, select:focus, button:focus-visible { outline: 3px solid rgba(45,121,255,.26); outline-offset: 1px; border-color: var(--blue); }
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--blue); cursor: pointer; }

/* Installation method: two-way switch in the same square style as the fields. */
/* Keeps the hidden radios inside the control, so focusing one never scrolls the page. */
.segmented {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--field);
}
.segmented input { position: absolute; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.segmented label {
  padding: 8px 10px;
  border-radius: 2px;
  color: var(--label);
  font-size: 0.875rem;
  font-weight: 750;
  text-align: center;
  cursor: pointer;
}
.segmented label:hover { background: var(--sidebar); color: var(--ink); }
.segmented input:checked + label { background: var(--ink); color: #fff; }
.segmented input:focus-visible + label { outline: 3px solid rgba(45,121,255,.26); outline-offset: 1px; }

/* Tables */
.table-wrap { overflow: auto; }
.controls .table-wrap { max-height: 42vh; min-height: 120px; }
table { width: 100%; border-collapse: collapse; }
th { padding: 0 5px 7px; color: var(--muted); text-align: left; font-size: 0.75rem; letter-spacing: .07em; text-transform: uppercase; }
td { padding: 7px 5px; border-top: 1px solid #e8edf0; font-size: 0.875rem; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
.schedule-table { table-layout: fixed; }
.schedule-table th:nth-child(1) { width: 46%; }
.schedule-table th:nth-child(2) { width: 20%; }
.schedule-table th:nth-child(3) { width: 22%; }
.schedule-table th:nth-child(4) { width: 12%; }
.schedule-table td:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.schedule-table td:last-child { padding-block: 2px; text-align: right; }
.empty-state td { padding: 22px 5px; color: var(--muted); text-align: center; }
.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; }
.table-note strong { color: var(--ink); font-variant-numeric: tabular-nums; }
#db-meta { margin-top: 8px; }
.db-status { padding: 8px 10px; border-left: 3px solid var(--blue); background: #eef4ff; color: var(--ink); }
.db-status.is-error { border-left-color: var(--danger); background: #fbe6e6; }

/* Recommendations */
.rec-list { display: flex; flex-wrap: wrap; gap: 8px; }
.rec-item { min-width: 140px; padding: 9px 12px; border: 1px solid var(--line); border-left: 3px solid var(--accent); background: var(--paper); }
.rec-size { font-size: 1rem; font-weight: 800; }
.rec-meta { margin-top: 2px; color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }

/* Summary strip */
.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.idle .state-dot { background: var(--line-strong); box-shadow: 0 0 0 4px rgba(168,181,191,.2); }
.fit-state.idle { color: var(--muted); }
.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; }
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 */
.drawing-panel { padding: 18px 18px 12px; box-shadow: var(--shadow); }
.drawing-heading { margin-bottom: 10px; }
.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.cable { background: var(--blue); }
.legend-dot.overflow { background: var(--danger); }
.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;
}
#conduit-canvas { display: block; width: 100%; height: 100%; }

/* Fill results */
.result-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px; }
.result-pct { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.result-pct.is-pass { color: var(--green); }
.result-pct.is-fail { color: var(--danger); }
.result-sub { margin-top: 4px; color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 7px; font-size: 0.75rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.pill.is-pass { background: #e3f2e9; color: #237148; }
.pill.is-fail { background: #fbe6e6; color: #972525; }

.fill-bar { position: relative; height: 10px; margin: 12px 0 6px; background: #e8edf1; }
.fill-bar .bar { display: block; height: 100%; transition: width .25s ease; }
.fill-bar .bar.is-pass { background: var(--green); }
.fill-bar .bar.is-fail { background: var(--danger); }
.fill-bar .limit-marker { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); opacity: .6; }
.bar-legend { display: flex; justify-content: space-between; color: var(--muted); font-size: .75rem; font-variant-numeric: tabular-nums; }

.conduit-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.conduit-result { padding: 14px; border: 1px solid var(--line); background: var(--paper); }
.conduit-result h3 { margin-bottom: 6px; color: var(--muted); font-size: .75rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }

/* Cable database dialog */
.cable-dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 32px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(17, 24, 32, .28);
}
.cable-dialog[open] { display: flex; flex-direction: column; }
.cable-dialog::backdrop { background: rgba(17, 24, 32, .62); backdrop-filter: blur(3px); }
.dialog-heading { display: flex; justify-content: space-between; gap: 20px; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.dialog-heading .eyebrow { margin-bottom: 5px; }
.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: var(--sidebar); color: var(--ink); }
.dialog-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 24px; }
.dialog-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; border-top: 1px solid var(--line); background: var(--paper); }
.dialog-actions { display: flex; gap: 8px; }
#selection-count { color: var(--muted); font-size: .875rem; font-weight: 700; font-variant-numeric: tabular-nums; }

#modalCableTable { table-layout: fixed; }
/* The header stays put while the 130-odd rows scroll under it. */
#modalCableTable thead th { position: sticky; top: 0; z-index: 1; padding-top: 14px; vertical-align: top; background: var(--surface); box-shadow: inset 0 -1px 0 var(--line); }
#modalCableTable .col-check { width: 44px; text-align: center; }
#modalCableTable .col-od { width: 130px; text-align: right; }
#modalCableTable td { font-variant-numeric: tabular-nums; }
#modalCableTable tbody tr { cursor: pointer; }
#modalCableTable tbody tr:hover { background: #f1f6ff; }
#modalCableTable th.col-check input { margin-top: 2px; }
#modalCableTable .filter-input {
  display: block;
  min-height: 32px;
  margin-top: 6px;
  padding: 5px 8px;
  font-size: .8rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  text-align: left;
}

.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); }
  .controls .table-wrap { max-height: 350px; }
  .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); }
  .drawing-heading { align-items: flex-start; flex-direction: column; }
  .canvas-shell { min-height: 280px; height: 340px; }
  .dialog-heading { padding: 18px; }
  .dialog-body { padding: 0 18px; }
  .dialog-foot { padding: 12px 18px; }
}

@media (prefers-reduced-motion: no-preference) {
  .button, .delete-button, .dialog-close, .segmented label { transition: background-color .15s ease, color .15s ease, border-color .15s ease, filter .15s ease; }
}

/* Print the schedule and results on plain paper, without the inputs. */
@media print {
  html, body { height: auto; overflow: visible; background: #fff; }
  .app-shell { display: block; }
  .controls, .workspace { overflow: visible; background: none; border: 0; padding: 0; }
  .controls { margin-bottom: 16px; }
  #database-section, #add-cable-section, .panel-actions, .delete-button, .segmented, .cable-dialog { display: none !important; }
  .panel, .drawing-panel, .summary-strip { box-shadow: none; break-inside: avoid; }
  .controls .table-wrap { max-height: none; }
  .topbar, .fill-bar, .pill { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
