:root {
  color-scheme: light;
  --ink: #1f2933;
  --muted: #62717f;
  --line: #c9d2d9;
  --paper: #f6f7f9;
  --panel: #ffffff;
  --green: #227a54;
  --red: #b42318;
  --blue: #2f5f98;
  --steel: #5d6670;
  --concrete: #dfe5ea;
  --yellow: #fff4cc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

button,
input,
select {
  font: inherit;
}

.app-header {
  min-height: 76px;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
}

.author {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

h2 {
  font-size: 15px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

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

button {
  border: 1px solid #9aa8b4;
  background: #f8fafc;
  color: var(--ink);
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

button:hover {
  background: #eef3f7;
  box-shadow: 0 2px 8px rgba(31, 41, 51, 0.10);
}

button:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: none;
}

.primary-action {
  border-color: #1f5a99;
  background: #1f5a99;
  color: #ffffff;
  font-weight: 700;
}

.primary-action:hover {
  background: #174a7f;
}

.primary-action.needs-generate {
  border-color: #b88720;
  background: #fff4cc;
  color: #4f3510;
}

.layout {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.input-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.input-action-bar {
  position: sticky;
  top: 10px;
  z-index: 11;
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  border: 1px solid #b7c4d0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 24px rgba(31, 41, 51, 0.10);
  padding: 8px;
}

.input-action-bar span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
}

.panel-section,
.drawing-box,
.recommend-box,
.calc-sheet {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel-section {
  padding: 14px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.demand-coeffs {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: #364653;
  font-size: 12px;
  font-weight: 700;
}

.full-row {
  margin-top: 12px;
}

input,
select,
textarea {
  min-width: 0;
  width: 100%;
  border: 1px solid #aeb9c3;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  padding: 7px 8px;
  font-weight: 400;
}

textarea {
  resize: vertical;
  line-height: 1.35;
}

input[readonly] {
  background: #eef3f7;
  color: #425466;
}

.import-actions {
  margin-top: 10px;
}

.import-summary {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfd;
  padding: 9px;
  color: #425466;
  font-size: 12px;
  line-height: 1.45;
}

.import-summary strong {
  color: var(--ink);
}

.import-table-wrap {
  max-height: 260px;
  border: 1px solid var(--line);
  border-radius: 7px;
  margin-top: 10px;
}

.import-table-wrap table {
  font-size: 11px;
}

.import-table-wrap button {
  padding: 4px 8px;
  font-size: 11px;
}

.import-warning {
  color: var(--red);
  font-weight: 700;
}

.check-row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.check-row input {
  width: auto;
}

.custom-dia {
  margin-top: 10px;
}

.formula-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
  line-height: 1.35;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 12px;
}

.segmented label {
  align-items: center;
  justify-content: center;
  flex-direction: row;
  border: 1px solid #aeb9c3;
  border-radius: 6px;
  padding: 8px;
  background: #f8fafc;
  cursor: pointer;
}

.segmented input {
  width: auto;
}

.region-table {
  display: grid;
  grid-template-columns: 1.5fr 0.7fr 0.7fr;
  gap: 6px;
  margin-top: 12px;
  align-items: end;
}

.layer-table {
  grid-template-columns: 1.35fr repeat(4, minmax(58px, 0.7fr));
}

.region-head {
  font-size: 12px;
  font-weight: 700;
  color: var(--blue);
}

.workspace {
  min-width: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stale-overlay {
  position: sticky;
  top: 8px;
  z-index: 12;
  pointer-events: none;
  margin-bottom: -58px;
  display: flex;
  justify-content: stretch;
}

.stale-overlay[hidden] {
  display: none;
}

.stale-overlay > div {
  width: 100%;
  border: 1px solid #d29a24;
  border-radius: 8px;
  background: rgba(255, 244, 204, 0.96);
  color: #4f3510;
  box-shadow: 0 10px 28px rgba(31, 41, 51, 0.18);
  padding: 10px 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  pointer-events: auto;
}

.stale-overlay strong {
  display: inline;
}

.workspace.results-stale .visual-band,
.workspace.results-stale .summary-strip,
.workspace.results-stale .recommend-box,
.workspace.results-stale .calc-sheet {
  outline: 2px solid rgba(210, 154, 36, 0.35);
  background-image: linear-gradient(rgba(255, 244, 204, 0.20), rgba(255, 244, 204, 0.20));
}

.visual-band {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(380px, 1.1fr);
  gap: 16px;
}

.visual-band .theory-box {
  grid-column: 1 / -1;
}

.print-region-sections {
  display: none;
}

.print-section-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.print-section-title {
  color: #203246;
  font-size: 12px;
  font-weight: 700;
  margin: 0 0 5px;
  text-align: center;
}

.drawing-box {
  min-height: 0;
  padding: 12px;
  overflow-x: auto;
}

.theory-box {
  padding-bottom: 8px;
}

.box-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 8px;
}

svg {
  width: 100%;
  height: auto;
  display: block;
}

#sectionSvg,
#spanSvg {
  max-height: 230px;
}

#theorySvg {
  max-height: 390px;
}

#sectionSvg {
  width: 620px;
  max-width: none;
  max-height: none;
}

#spanSvg {
  width: 820px;
  max-width: none;
  max-height: none;
}

#theorySvg {
  width: 100%;
  min-width: 1120px;
  max-width: none;
  max-height: none;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.metric {
  background: #ffffff;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  padding: 12px;
}

.metric.ok {
  border-left-color: var(--green);
}

.metric.bad {
  border-left-color: var(--red);
}

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

.metric .value {
  margin-top: 5px;
  font-size: 20px;
  font-weight: 700;
}

.calc-sheet {
  padding: 14px;
}

.recommend-box {
  padding: 14px;
}

.recommend-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.recommend-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 10px;
}

.recommend-title {
  color: #1f3f66;
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 8px;
}

.recommend-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid #e4eaf0;
  padding: 6px 0;
  color: #425466;
  font-size: 12px;
}

.recommend-line:first-of-type {
  border-top: 0;
}

.recommend-line strong {
  color: var(--ink);
  text-align: right;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 12px;
}

th,
td {
  border: 1px solid #b8c3cc;
  padding: 6px 8px;
  vertical-align: top;
  white-space: nowrap;
}

th {
  background: #dfeaf4;
  color: #203246;
  text-align: left;
}

td.formula {
  color: #425466;
  font-family: Consolas, "Courier New", monospace;
}

td.value {
  text-align: right;
  background: var(--yellow);
}

td.ok {
  color: var(--green);
  font-weight: 700;
}

td.bad {
  color: var(--red);
  font-weight: 700;
}

.section-row td {
  background: #edf2f6;
  color: #1f3f66;
  font-weight: 700;
}

.note-box {
  margin-top: 14px;
  color: #435260;
  line-height: 1.45;
  font-size: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.symbol-box {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.symbol-box summary {
  cursor: pointer;
  padding: 10px 12px;
  color: var(--blue);
  font-size: 14px;
  font-weight: 700;
  list-style: none;
}

.symbol-box summary::-webkit-details-marker {
  display: none;
}

.symbol-box summary::after {
  content: "+";
  float: right;
  color: #52616e;
  font-weight: 700;
}

.symbol-box[open] summary {
  border-bottom: 1px solid var(--line);
}

.symbol-box[open] summary::after {
  content: "-";
}

.symbol-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
}

.symbol-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfd;
  padding: 8px;
  min-height: 70px;
}

.symbol {
  color: #1f3f66;
  font-family: "Times New Roman", serif;
  font-size: 18px;
  font-weight: 700;
}

.symbol-desc {
  margin-top: 3px;
  color: #425466;
  font-size: 11px;
  line-height: 1.35;
  white-space: normal;
}

.help-btn {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-left: 6px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #9aa8b4;
  color: #1f3f66;
  background: #ffffff;
  font-size: 12px;
  font-weight: 700;
}

.ref-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(31, 41, 51, 0.28);
  display: grid;
  place-items: center;
  padding: 24px;
}

.ref-panel[hidden] {
  display: none;
}

.ref-card {
  width: min(780px, 100%);
  max-height: min(720px, 88vh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 18px;
  box-shadow: 0 18px 50px rgba(31, 41, 51, 0.2);
}

.ref-card #refClose {
  float: right;
}

.ref-card ul {
  padding-left: 20px;
  color: #425466;
  line-height: 1.5;
}

.ref-card table {
  margin-top: 12px;
  font-size: 12px;
}

.dim-text,
.svg-label {
  font: 13px Arial, Helvetica, sans-serif;
  fill: #293845;
}

#theorySvg .svg-small {
  font-size: 13px;
}

#theorySvg .svg-label {
  font-size: 15px;
}

.svg-small {
  font: 12px Arial, Helvetica, sans-serif;
  fill: #52616e;
}

.status-pill {
  font: 700 13px Arial, Helvetica, sans-serif;
}

.print-watermark {
  display: none;
}

.print-report-head {
  display: none;
}

@media (max-width: 1120px) {
  .layout,
  .visual-band {
    grid-template-columns: 1fr;
  }

  .input-panel {
    order: -1;
  }
}

@media (max-width: 700px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .layout {
    padding: 10px;
  }

  .grid-2,
  .grid-3,
  .recommend-grid,
  .symbol-grid,
  .summary-strip {
    grid-template-columns: 1fr;
  }
}

@media print {
  .app-header,
  .input-panel,
  .ref-panel,
  .stale-overlay,
  .symbol-box {
    display: none;
  }

  @page {
    size: A4 landscape;
    margin: 10mm 9mm 12mm;
  }

  html,
  body {
    background: #fff;
    color: #111827;
    font-size: 9pt;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: repeating-linear-gradient(
      -32deg,
      transparent 0,
      transparent 108mm,
      rgba(20, 37, 58, 0.055) 108mm,
      rgba(20, 37, 58, 0.055) 132mm,
      transparent 132mm,
      transparent 210mm
    );
    z-index: 9998;
  }

  .print-watermark {
    display: block;
    position: fixed;
    top: 46%;
    left: 50%;
    width: 260mm;
    transform: translate(-50%, -50%) rotate(-32deg);
    transform-origin: center;
    z-index: 9999;
    pointer-events: none;
    color: rgba(16, 36, 59, 0.09);
    font: 800 30pt Arial, Helvetica, sans-serif;
    letter-spacing: 0;
    text-align: center;
    text-transform: uppercase;
    white-space: nowrap;
  }

  h1,
  h2,
  h3 {
    break-after: avoid;
  }

  .layout {
    display: block;
    width: 100%;
    padding: 0;
  }

  .workspace {
    display: block;
    width: 100%;
  }

  .print-report-head {
    display: block;
    order: 0;
    border-bottom: 2px solid #1f5a99;
    padding-bottom: 8px;
    margin-bottom: 8px;
    break-inside: avoid;
  }

  .print-report-head h1 {
    margin: 0;
    color: #0f2338;
    font-size: 18pt;
    line-height: 1.15;
  }

  .print-report-head p {
    margin: 2px 0;
    color: #3b4b5a;
  }

  .report-meta {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    margin-top: 8px;
    font-size: 8pt;
  }

  .report-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
    margin-top: 8px;
  }

  .report-meta div,
  .report-summary-grid div {
    border: 1px solid #b9c7d5;
    background: #f8fbfd;
    padding: 5px;
    min-height: 28px;
  }

  .report-meta strong,
  .report-summary-grid strong {
    display: block;
    color: #1f5a99;
    font-size: 7.5pt;
    text-transform: uppercase;
  }

  .report-meta span,
  .report-summary-grid span {
    display: block;
    margin-top: 2px;
    overflow-wrap: anywhere;
  }

  .summary-strip {
    order: 1;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 5px;
    margin: 8px 0;
    break-inside: avoid;
  }

  .visual-band {
    display: grid;
    grid-template-columns: 0.9fr 1.1fr;
    gap: 6mm;
    width: 100%;
    margin-top: 6mm;
  }

  .visual-band .drawing-box:first-child {
    display: none;
  }

  .print-region-sections {
    display: block;
    grid-column: 1 / -1;
    break-inside: avoid;
  }

  .print-section-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4mm;
  }

  .print-section-title {
    font-size: 8.5pt;
    margin-bottom: 2mm;
  }

  .visual-band .drawing-box:nth-child(3) {
    grid-column: 1 / -1;
  }

  .visual-band .theory-box {
    grid-column: 1 / -1;
    break-before: page;
  }

  .calc-sheet {
    margin-top: 6mm;
    break-before: page;
  }

  .recommend-box {
    margin-top: 6mm;
    break-inside: avoid;
  }

  .drawing-box,
  .recommend-box,
  .calc-sheet,
  .metric {
    break-inside: avoid;
    margin-bottom: 8px;
    box-shadow: none;
  }

  .panel-section,
  .drawing-box,
  .recommend-box,
  .calc-sheet,
  .metric,
  .note-box,
  .symbol-item {
    border-color: #aebccd;
    border-radius: 4px;
  }

  .drawing-box,
  .recommend-box,
  .calc-sheet {
    padding: 8px;
  }

  .drawing-box {
    overflow: visible;
    min-height: 0;
  }

  .box-title,
  .calc-sheet h2,
  .recommend-box h2,
  .symbol-box h2 {
    font-size: 11pt;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #9fb0c1;
  }

  .table-wrap {
    overflow: visible;
    margin-top: 8px;
    width: 100%;
  }

  table {
    width: 100%;
    table-layout: auto;
    font-size: 7.1pt;
    line-height: 1.22;
    page-break-inside: auto;
  }

  tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  th,
  td {
    padding: 3px 4px;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: none;
  }

  td.value,
  th.value {
    text-align: right;
  }

  td.formula {
    font-size: 6.5pt;
    overflow-wrap: normal;
  }

  tr.formula-row {
    display: none;
  }

  .section-row td {
    font-size: 8pt;
    padding-top: 5px;
  }

  #flexureTable {
    font-size: 7.2pt;
  }

  #flexureTable th:nth-child(1),
  #flexureTable td:nth-child(1) { width: 13%; }
  #flexureTable th:nth-child(2),
  #flexureTable td:nth-child(2) { width: 11%; }
  #flexureTable th:nth-child(3),
  #flexureTable td:nth-child(3) { width: 14%; }
  #flexureTable th:nth-child(10),
  #flexureTable td:nth-child(10) { width: 15%; }

  #shearTable th:nth-child(1),
  #shearTable td:nth-child(1),
  #torsionTable th:nth-child(1),
  #torsionTable td:nth-child(1) {
    width: 12%;
  }

  #shearTable th:nth-child(7),
  #shearTable td:nth-child(7),
  #torsionTable th:nth-child(8),
  #torsionTable td:nth-child(8) {
    width: 13%;
  }

  #skinTable {
    font-size: 7pt;
  }

  .note-box {
    margin-top: 8px;
    padding: 8px;
    font-size: 8pt;
    line-height: 1.35;
  }

  .symbol-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .symbol-item {
    padding: 5px;
  }

  .symbol {
    font-size: 13pt;
  }

  .symbol-desc {
    font-size: 7pt;
  }

  svg {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: auto;
    overflow: visible;
  }

  #sectionSvg {
    max-height: 78mm;
  }

  .print-region-sections svg {
    max-height: 58mm;
  }

  #spanSvg {
    max-height: 72mm;
  }

  #theorySvg {
    max-height: 118mm;
  }
}
