:root {
  --brand: #123c69;
  --brand-ink: #0b1f33;
  --brand-soft: #eaf2fb;
  --accent: #f2b705;
  --accent-soft: #fff4ca;
  --surface: #ffffff;
  --page: #f4f7fb;
  --line: #d9e2ec;
  --muted: #607086;
  --text: #17212f;
  --danger-soft: #fff3dc;
  --safe: #13795b;
  --safe-soft: #dff6ec;
  --near: #a16207;
  --near-soft: #fff4ca;
  --over: #b42318;
  --over-soft: #fee4e2;
  --shadow: 0 16px 38px rgba(15, 38, 66, 0.09);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  color: var(--text);
  background: var(--page);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(18, 60, 105, 0.06), transparent 420px),
    var(--page);
  font-family: "Segoe UI", Arial, sans-serif;
  overflow-x: hidden;
}

.app-header {
  color: #fff;
  background:
    linear-gradient(135deg, rgba(18, 60, 105, 0.96), rgba(11, 31, 51, 0.98)),
    var(--brand);
  border-bottom: 5px solid var(--accent);
  padding: 28px 0 34px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.brand-logo {
  width: 46px;
  height: 46px;
  object-fit: contain;
  background: #fff;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  padding: 4px;
}

.brand-name {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-back-link {
  margin-left: auto;
  padding: 0.55rem 0.8rem;
  color: #fff;
  font-size: 0.88rem;
  font-weight: 800;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 8px;
}

.brand-back-link:hover,
.brand-back-link:focus {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

.header-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 24px;
  align-items: end;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

.app-header h1 {
  max-width: 820px;
  margin-bottom: 10px;
  font-size: clamp(2rem, 4vw, 3.55rem);
  font-weight: 800;
  line-height: 1.02;
}

.header-copy {
  max-width: 780px;
  margin-bottom: 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 1.03rem;
}

.header-panel {
  padding: 18px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
}

.header-panel .panel-label,
.header-panel small {
  display: block;
  color: rgba(255, 255, 255, 0.74);
}

.header-panel strong {
  display: block;
  margin: 4px 0;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
}

.app-shell {
  padding-top: 24px;
  padding-bottom: 48px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-card,
.toolbar,
.project-intro,
.report-panel,
.utility-panel,
.work-card,
.paper-summary {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 116px;
  padding: 18px;
  min-width: 0;
}

.metric-card span,
.metric-card small {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  color: var(--brand-ink);
  font-size: clamp(1.55rem, 3vw, 2.15rem);
  line-height: 1.05;
}

.project-intro {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  margin-bottom: 18px;
  padding: 18px;
}

.project-intro h2 {
  margin-bottom: 6px;
  color: var(--brand-ink);
  font-size: 1.35rem;
  font-weight: 800;
}

.project-intro p {
  max-width: 840px;
  margin-bottom: 0;
  color: var(--muted);
}

.eyebrow-dark {
  margin-bottom: 5px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-card.safe {
  border-color: rgba(19, 121, 91, 0.35);
  background: linear-gradient(180deg, #fff, var(--safe-soft));
}

.status-card.near {
  border-color: rgba(161, 98, 7, 0.35);
  background: linear-gradient(180deg, #fff, var(--near-soft));
}

.status-card.over {
  border-color: rgba(180, 35, 24, 0.35);
  background: linear-gradient(180deg, #fff, var(--over-soft));
}

.report-panel {
  margin-bottom: 18px;
  padding: 18px;
}

.report-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--brand-ink);
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

.report-panel summary::-webkit-details-marker {
  display: none;
}

.report-panel summary::after {
  content: "+";
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  color: var(--brand-ink);
  background: var(--accent-soft);
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
}

.report-panel[open] summary {
  margin-bottom: 14px;
}

.report-panel[open] summary::after {
  content: "-";
}

.report-panel summary small {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
}

.report-notes {
  grid-column: span 2;
}

.toolbar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
  margin-bottom: 18px;
  padding: 18px;
  overflow: visible;
}

.control-field-wide {
  grid-column: span 2;
}

.control-field,
.toolbar-actions,
.saved-tools,
.import-tools,
.work-card,
.materials-card,
.side-stack {
  min-width: 0;
}

.control-field label {
  display: block;
  margin-bottom: 6px;
  color: var(--brand-ink);
  font-size: 0.9rem;
  font-weight: 700;
}

.form-control,
.form-select {
  min-height: 44px;
  color: var(--brand-ink);
  background-color: #fff;
  border: 1px solid #b9c7d8;
  border-radius: 6px;
  box-shadow: none;
}

.form-select {
  padding-right: 2.4rem;
  text-overflow: ellipsis;
}

.form-select {
  position: relative;
  z-index: 10;
  cursor: pointer;
}

.form-control:focus,
.form-select:focus {
  color: var(--brand-ink);
  background-color: #fff;
  border-color: var(--brand);
  box-shadow: 0 0 0 0.18rem rgba(18, 60, 105, 0.14);
}

.toolbar-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  grid-column: span 2;
}

.utility-panel {
  display: grid;
  grid-template-columns: minmax(190px, 0.7fr) minmax(0, 1.5fr) auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 18px;
  padding: 14px 18px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--brand-ink);
  font-weight: 700;
}

.saved-tools {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) repeat(3, auto);
  gap: 8px;
}

.import-tools {
  display: flex;
  justify-content: flex-end;
}

.btn {
  min-height: 42px;
  border-radius: 6px;
  font-weight: 700;
}

.btn i {
  margin-right: 6px;
}

.btn-brand {
  color: var(--brand-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.btn-brand:hover,
.btn-brand:focus {
  color: var(--brand-ink);
  background: #ffd14a;
  border-color: #ffd14a;
}

.paper-summary {
  display: none;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
  padding: 18px;
}

.paper-summary h2 {
  margin-bottom: 4px;
  font-size: 1.2rem;
}

.paper-summary p {
  margin-bottom: 0;
  color: var(--muted);
}

.paper-summary dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(170px, 1fr));
  gap: 12px;
  margin: 0;
}

.report-print-details {
  margin-top: 14px !important;
}

.print-notes {
  grid-column: 1 / -1;
}

.paper-summary dt {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

.paper-summary dd {
  margin: 2px 0 0;
  color: var(--brand-ink);
  font-weight: 800;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.work-card {
  padding: 18px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 14px;
}

.section-heading h2 {
  margin-bottom: 4px;
  color: var(--brand-ink);
  font-size: 1.2rem;
  font-weight: 800;
}

.section-heading p,
.helper-text {
  color: var(--muted);
  font-size: 0.92rem;
}

.section-heading.compact {
  margin-bottom: 10px;
}

.section-heading.compact h2 {
  margin-bottom: 0;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.table-scroll-hint {
  display: none;
  align-items: center;
  gap: 7px;
  margin: 4px 0 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.table {
  margin-bottom: 0;
  min-width: 860px;
}

.table thead th {
  color: #fff;
  background: var(--brand);
  border-color: rgba(255, 255, 255, 0.14);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}

.table tbody td {
  color: var(--text);
  border-color: #e8eef5;
  font-size: 0.94rem;
}

.table tbody tr:hover {
  background: #f8fbff;
}

.qty-input {
  width: 90px;
  min-width: 90px;
  text-align: right;
}

.group-pill,
.source-pill {
  display: inline-block;
  max-width: 170px;
  padding: 0.2rem 0.5rem;
  overflow: hidden;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

.group-pill {
  color: var(--brand-ink);
  background: var(--brand-soft);
}

.source-pill {
  color: #6d4a00;
  background: var(--accent-soft);
}

.flagged-row {
  background: var(--danger-soft);
}

.side-stack {
  display: grid;
  gap: 18px;
}

.side-stack .table {
  min-width: 0;
}

.load-warning {
  padding: 12px;
  border-radius: 6px;
  font-weight: 700;
}

.load-warning.safe {
  color: var(--safe);
  background: var(--safe-soft);
}

.load-warning.near {
  color: var(--near);
  background: var(--near-soft);
}

.load-warning.over {
  color: var(--over);
  background: var(--over-soft);
}

.status-pill {
  display: inline-block;
  padding: 0.18rem 0.45rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.safe {
  color: var(--safe);
  background: var(--safe-soft);
}

.status-pill.near {
  color: var(--near);
  background: var(--near-soft);
}

.status-pill.over {
  color: var(--over);
  background: var(--over-soft);
}

.missing-weight-list ul {
  max-height: 180px;
  margin: 0 0 8px;
  padding-left: 18px;
  overflow: auto;
  color: var(--text);
  font-size: 0.88rem;
}

.missing-weight-list small {
  color: var(--muted);
}

.reference-list {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.reference-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.reference-list span {
  display: grid;
  gap: 2px;
  color: var(--muted);
  min-width: 0;
}

.reference-list small {
  color: var(--brand-ink);
  font-weight: 700;
}

.reference-list strong {
  flex: 0 0 auto;
  color: var(--brand-ink);
  white-space: nowrap;
}

.text-muted {
  color: var(--muted) !important;
}

.mobile-sticky-summary {
  position: fixed;
  right: 12px;
  bottom: 12px;
  left: 12px;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: rgba(11, 31, 51, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25);
}

.mobile-sticky-summary span,
.mobile-sticky-summary small {
  display: block;
  color: #fff;
}

.mobile-sticky-summary span {
  font-weight: 800;
}

.mobile-sticky-summary small {
  color: rgba(255, 255, 255, 0.72);
}

.project-footer {
  padding: 26px 0;
  background: var(--brand-ink);
  color: #fff;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  gap: 22px;
  align-items: center;
}

.project-footer img {
  width: 54px;
  height: 54px;
  object-fit: contain;
  margin-bottom: 10px;
  padding: 5px;
  background: #fff;
  border-radius: 8px;
}

.project-footer p {
  max-width: 720px;
  margin-bottom: 0;
  color: rgba(255, 255, 255, 0.72);
}

@media (max-width: 1199.98px) {
  .app-header h1 {
    max-width: 720px;
  }

  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .control-field-wide {
    grid-column: span 2;
  }

  .toolbar-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-column: span 3;
  }

  .report-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .utility-panel {
    grid-template-columns: 1fr;
  }

  .saved-tools {
    grid-template-columns: minmax(170px, 1fr) repeat(3, minmax(86px, auto));
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .side-stack {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.9fr);
  }
}

@media (min-width: 1200px) {
  .container {
    max-width: 1320px;
  }

  .materials-card {
    min-height: 620px;
  }
}

@media (min-width: 768px) and (max-width: 991.98px) {
  .app-header {
    padding: 24px 0 30px;
  }

  .header-grid {
    grid-template-columns: minmax(0, 1fr) 220px;
    gap: 18px;
  }

  .app-header h1 {
    font-size: 2.45rem;
  }

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

  .control-field-wide {
    grid-column: 1 / -1;
  }

  .toolbar-actions {
    grid-column: span 2;
  }

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

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

  .report-notes {
    grid-column: 1 / -1;
  }

  .side-stack {
    grid-template-columns: 1fr;
  }

  .reference-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 22px;
  }
}

@media (max-width: 767.98px) {
  .app-header {
    padding: 18px 0 24px;
  }

  .brand-row {
    flex-wrap: wrap;
    margin-bottom: 16px;
  }

  .brand-back-link {
    margin-left: 0;
  }

  .brand-logo {
    width: 34px;
    height: 34px;
  }

  .app-header h1 {
    font-size: 2rem;
    line-height: 1.08;
  }

  .header-copy {
    font-size: 0.96rem;
  }

  .header-grid,
  .summary-grid,
  .toolbar,
  .report-grid {
    grid-template-columns: 1fr;
  }

  .control-field-wide {
    grid-column: auto;
  }

  .header-panel {
    padding: 14px;
  }

  .app-shell {
    padding-top: 16px;
    padding-bottom: 92px;
  }

  .summary-grid {
    gap: 10px;
    margin-bottom: 14px;
  }

  .metric-card,
  .toolbar,
  .project-intro,
  .report-panel,
  .utility-panel,
  .work-card {
    box-shadow: 0 8px 22px rgba(15, 38, 66, 0.07);
  }

  .metric-card {
    padding: 14px;
  }

  .metric-card strong {
    font-size: 1.55rem;
  }

  .toolbar {
    gap: 12px;
    padding: 14px;
  }

  .project-intro,
  .footer-inner {
    display: grid;
  }

  .project-intro {
    padding: 14px;
  }

  .report-panel,
  .utility-panel {
    padding: 14px;
  }

  .report-notes {
    grid-column: auto;
  }

  .toolbar-actions {
    grid-template-columns: 1fr 1fr;
    grid-column: auto;
  }

  .toolbar-actions .btn {
    padding-inline: 8px;
  }

  .saved-tools {
    grid-template-columns: 1fr;
  }

  .import-tools {
    justify-content: stretch;
  }

  .import-tools .btn {
    width: 100%;
  }

  .form-control,
  .form-select {
    min-height: 46px;
    font-size: 1rem;
  }

  .work-card {
    padding: 14px;
  }

  .metric-card {
    min-height: auto;
  }

  .section-heading {
    display: block;
  }

  .section-heading h2 {
    font-size: 1.1rem;
  }

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

  .action-row .btn {
    flex: 1 1 150px;
  }

  .table-scroll-hint {
    display: flex;
  }

  .table {
    min-width: 780px;
  }

  .table thead th,
  .table tbody td {
    font-size: 0.86rem;
  }

  .qty-input {
    width: 76px;
    min-width: 76px;
  }

  .group-pill,
  .source-pill {
    max-width: 130px;
  }

  .side-stack {
    gap: 14px;
  }

  .reference-list div {
    align-items: flex-start;
  }

  .mobile-sticky-summary {
    display: flex;
  }

  .project-footer {
    padding-bottom: 90px;
  }
}

@media (max-width: 420px) {
  .app-header h1 {
    font-size: 1.72rem;
  }

  .toolbar-actions {
    grid-template-columns: 1fr;
  }

  .utility-panel {
    gap: 10px;
  }

  .reference-list div {
    display: grid;
    gap: 4px;
  }

  .reference-list strong {
    justify-self: start;
  }
}

@page {
  size: letter;
  margin: 0.45in;
}

@media print {
  html,
  body {
    color: #000;
    background: #fff !important;
    font-size: 10pt;
  }

  .no-print,
  .toolbar,
  .utility-panel,
  .project-intro,
  .project-footer,
  .mobile-sticky-summary,
  .action-row,
  #loadError,
  #testResults {
    display: none !important;
  }

  .container {
    width: 100% !important;
    max-width: none !important;
    padding: 0 !important;
  }

  .app-header {
    color: #000;
    background: #fff !important;
    border-bottom: 2px solid #000;
    padding: 0 0 12px;
  }

  .brand-row {
    margin-bottom: 12px;
  }

  .brand-logo {
    background: #fff;
    border: 1px solid #000;
  }

  .eyebrow,
  .header-copy,
  .brand-name,
  .header-panel .panel-label,
  .header-panel small {
    color: #000;
  }

  .app-header h1 {
    margin-bottom: 6px;
    font-size: 22pt;
  }

  .header-grid {
    display: block;
  }

  .header-panel {
    margin-top: 10px;
    padding: 0;
    color: #000;
    background: #fff;
    border: 0;
  }

  .header-panel strong {
    color: #000;
    font-size: 14pt;
  }

  .app-shell {
    padding-top: 12px;
    padding-bottom: 0;
  }

  .summary-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 10px;
  }

  .metric-card,
  .work-card,
  .paper-summary {
    box-shadow: none;
    border: 1px solid #999;
    break-inside: avoid;
  }

  .metric-card {
    min-height: 0;
    padding: 9px;
  }

  .metric-card span,
  .metric-card small {
    color: #333;
    font-size: 8pt;
  }

  .metric-card strong {
    color: #000;
    font-size: 14pt;
  }

  .paper-summary {
    display: block;
    padding: 10px;
  }

  .paper-summary dl {
    grid-template-columns: repeat(2, 1fr);
    margin-top: 8px;
  }

  .content-grid {
    display: block;
  }

  .work-card {
    padding: 10px;
    margin-bottom: 10px;
  }

  .side-stack {
    display: block;
  }

  .side-stack .work-card.no-print {
    display: none;
  }

  .section-heading {
    margin-bottom: 8px;
  }

  .section-heading h2 {
    color: #000;
    font-size: 13pt;
  }

  .section-heading p {
    color: #222;
  }

  .table-responsive {
    overflow: visible !important;
    border: 0;
  }

  .table {
    min-width: 0;
    width: 100%;
    border-collapse: collapse;
  }

  .table thead {
    display: table-header-group;
  }

  .table thead th {
    color: #000 !important;
    background: #e9e9e9 !important;
    border: 1px solid #777;
    font-size: 7.8pt;
  }

  .table tbody td {
    border: 1px solid #bbb;
    font-size: 8pt;
    padding: 4px;
  }

  .table tbody tr {
    break-inside: avoid;
  }

  #materialsTable tbody tr.empty-row {
    display: none;
  }

  .qty-input {
    width: 48px;
    min-width: 48px;
    padding: 0;
    border: 0;
    font-size: 8pt;
    text-align: center;
  }

  .group-pill,
  .source-pill {
    max-width: none;
    padding: 0;
    color: #000;
    background: transparent;
    font-size: 7.5pt;
    font-weight: 600;
  }
}
