:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --ink: #202523;
  --muted: #66706b;
  --line: #d8dfda;
  --green: #226b58;
  --green-2: #174e41;
  --amber: #f0b33e;
  --red: #c84c3d;
  --blue: #356f9f;
  --shadow: 0 14px 32px rgba(28, 37, 32, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button,
.file-action {
  min-height: 38px;
  border: 1px solid var(--green);
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.file-action:hover {
  background: var(--green-2);
  border-color: var(--green-2);
}

button.ghost,
.file-action.ghost {
  background: #fff;
  color: var(--green-2);
  border-color: var(--line);
}

button.ghost:hover,
.file-action.ghost:hover {
  background: var(--surface-2);
}

button.danger {
  background: #fff;
  color: var(--red);
  border-color: #e6c1ba;
}

button.danger:hover {
  background: #fff0ed;
  border-color: var(--red);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 107, 88, 0.12);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

label input,
label textarea {
  color: var(--ink);
  font-size: 14px;
  font-weight: 400;
  text-transform: none;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 244, 0.94);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  letter-spacing: 0;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.top-actions,
.action-row,
.table-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.file-action {
  display: inline-flex;
  align-items: center;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

.file-action input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

main {
  display: grid;
  gap: 16px;
  width: min(1480px, calc(100% - 32px));
  margin: 18px auto 42px;
}

.project-strip {
  display: grid;
  grid-template-columns: minmax(210px, 1.3fr) minmax(180px, 1fr) minmax(170px, 0.8fr) minmax(150px, 0.6fr);
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.metric {
  min-height: 74px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 30px;
  line-height: 1;
}

.metric.attention strong {
  color: var(--red);
}

.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 12px 14px;
}

.tab:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.tab.active {
  border-bottom-color: var(--green);
  color: var(--green-2);
  font-weight: 800;
}

.tab-panel {
  display: none;
  gap: 16px;
}

.tab-panel.active {
  display: grid;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
}

.panel-heading h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

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

.search-wrap {
  width: min(380px, 100%);
}

.option-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.option-group,
.option-card,
.database-group,
.direct-group,
.plan-card,
.approved-card,
.warning-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.option-group {
  display: grid;
  align-content: start;
  padding: 14px;
}

.option-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.option-group-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.option-group-head span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.option-hint {
  margin: 8px 0 0;
  max-width: 820px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.step-label {
  display: inline-block !important;
  margin: 0 0 5px !important;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--green-2) !important;
  padding: 3px 8px;
  font-size: 11px !important;
}

.compact-action {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 13px;
}

.choice-list {
  display: grid;
  gap: 0;
}

.option-card {
  display: grid;
  gap: 10px;
  padding: 11px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
}

.option-card:last-child {
  border-bottom: 0;
}

.option-card.active-option {
  border-bottom-color: rgba(34, 107, 88, 0.28);
}

.option-head {
  display: grid;
  grid-template-columns: 1fr 132px;
  gap: 12px;
  align-items: start;
}

.option-title {
  display: grid;
  gap: 4px;
}

.option-title small {
  color: var(--green);
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.option-title strong {
  font-size: 17px;
}

.option-title span {
  color: var(--muted);
  font-size: 13px;
}

.choice-row {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  align-items: start;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

.choice-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-tick {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 2px solid #bcc8c1;
  border-radius: 5px;
  background: #fff;
}

.choice-row input:checked + .choice-tick {
  border-color: var(--green);
  background: var(--green);
}

.choice-row input:checked + .choice-tick::after {
  width: 10px;
  height: 6px;
  border-bottom: 2px solid #fff;
  border-left: 2px solid #fff;
  content: "";
  transform: rotate(-45deg) translate(1px, -1px);
}

.choice-copy {
  display: grid;
  gap: 3px;
}

.choice-copy strong {
  font-size: 15px;
  line-height: 1.25;
}

.choice-copy small {
  color: var(--muted);
  font-size: 12px;
}

.option-details {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(34, 107, 88, 0.2);
  border-radius: 8px;
  background: #f8fbf8;
}

.manual-heading {
  margin-top: 10px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.qty-input {
  text-align: right;
}

.mini-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

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

.mini-table th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.mini-table .number {
  text-align: right;
}

.mini-table th:first-child,
.mini-table td:first-child {
  width: 72px;
}

.mini-table th:nth-child(3),
.mini-table td:nth-child(3),
.mini-table th:nth-child(4),
.mini-table td:nth-child(4) {
  width: 64px;
}

.mini-table td {
  overflow-wrap: anywhere;
}

.manual-pill {
  display: inline-block;
  border-radius: 999px;
  background: #fff6df;
  color: #79520b;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 800;
}

.direct-list,
.database-list {
  display: grid;
  gap: 12px;
}

.direct-group summary,
.database-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  cursor: pointer;
  font-weight: 800;
}

.direct-group summary span,
.database-group summary span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.database-options {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.database-option h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.database-add-block,
.database-add-item {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.database-add-block {
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
}

.database-add-item {
  grid-template-columns: minmax(80px, 0.4fr) minmax(180px, 1fr) minmax(64px, 0.25fr) minmax(120px, 0.45fr) minmax(150px, 0.75fr) auto;
  margin-top: 10px;
}

.plumbing-db-grid {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.plumbing-rate-table {
  width: 100%;
  border-collapse: collapse;
}

.compact-table-shell {
  box-shadow: none;
}

.database-table {
  min-width: 860px;
}

.database-table th:first-child,
.database-table td:first-child {
  width: 110px;
}

.database-table th:nth-child(3),
.database-table td:nth-child(3) {
  width: 74px;
}

.database-table th:nth-child(4),
.database-table td:nth-child(4) {
  width: 220px;
}

.direct-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

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

.direct-table th,
table th {
  background: #f8faf8;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.direct-table .code-col {
  width: 110px;
}

.direct-table .um-col {
  width: 76px;
}

.direct-table .qty-col {
  width: 128px;
}

.direct-table .detail-col {
  width: 190px;
}

.code-input {
  min-width: 92px;
}

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

.code-missing {
  color: var(--red);
  font-weight: 800;
}

.formula-note {
  color: var(--blue);
  font-size: 12px;
}

.stacked-input {
  display: grid;
  gap: 4px;
}

.rate-input {
  min-width: 100px;
  padding: 6px 7px;
  font-size: 13px;
  text-align: right;
}

.new-item-row {
  display: grid;
  grid-template-columns: minmax(90px, 0.35fr) minmax(180px, 1fr) minmax(70px, 0.25fr) auto;
  gap: 8px;
  padding: 12px 10px;
  border-top: 1px solid var(--line);
  background: #fbfcfb;
}

.new-item-row input {
  min-width: 0;
}

.plan-section {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

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

.plan-card {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
}

.plan-card strong {
  display: block;
  font-size: 15px;
}

.plan-card ul {
  margin: 7px 0 0;
  padding-left: 18px;
}

.plan-card li + li {
  margin-top: 4px;
}

.plan-file-action {
  min-width: 112px;
  justify-content: center;
}

.plan-add-row {
  grid-template-columns: minmax(180px, 1fr) auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.preset-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: #f8fbf8;
}

.preset-panel strong,
.preset-panel span {
  display: block;
}

.preset-panel span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.preset-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.preset-button {
  min-height: 34px;
  padding: 6px 10px;
}

.plumbing-count-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 8px;
  min-width: min(620px, 100%);
}

.extras-toolbar {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: #f8fbf8;
}

.extras-toolbar label {
  max-width: 360px;
}

.approved-layout {
  display: grid;
  grid-template-columns: minmax(230px, 0.35fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.approved-list {
  display: grid;
  gap: 8px;
}

.approved-card {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 74px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}

.approved-card:hover,
.approved-card.active-project {
  border-color: var(--green);
  background: var(--surface-2);
  color: var(--ink);
}

.approved-card span,
.approved-card small {
  color: var(--muted);
}

.approved-detail {
  display: grid;
  gap: 12px;
}

.approved-detail > header,
.approved-sections {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.approved-detail > header {
  grid-template-columns: 1fr auto;
  align-items: start;
}

.approved-detail h2,
.approved-detail h3 {
  margin: 0;
}

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

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

.table-tools {
  justify-content: space-between;
}

.table-tools input {
  max-width: 360px;
}

.table-tools span {
  color: var(--muted);
  font-weight: 800;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.table-shell table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

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

.warnings-list {
  display: grid;
  gap: 12px;
}

.warning-card {
  padding: 14px;
}

.warning-card h2 {
  margin: 0 0 8px;
  font-size: 17px;
}

.warning-card p {
  margin: 0 0 10px;
  color: var(--muted);
}

.warning-card ul {
  margin: 0;
  padding-left: 19px;
}

.warning-card li + li {
  margin-top: 6px;
}

.empty-state {
  padding: 26px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--muted);
  text-align: center;
}

.hide {
  display: none !important;
}

@media (max-width: 980px) {
  .topbar,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .action-row {
    width: 100%;
  }

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

  .database-add-block,
  .database-add-item,
  .approved-layout,
  .approved-sections {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 640px) {
  main {
    width: min(100% - 20px, 1480px);
    margin-top: 12px;
  }

  .project-strip,
  .status-grid,
  .option-head,
  .plumbing-count-grid,
  .plan-grid,
  .preset-panel {
    grid-template-columns: 1fr;
  }

  .plan-card {
    align-items: stretch;
    flex-direction: column;
  }

  .plan-add-row {
    grid-template-columns: 1fr;
  }

  .preset-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .preset-actions {
    justify-content: flex-start;
  }

  .topbar {
    padding: 12px;
  }

  .brand {
    min-width: 0;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .tabs,
  .project-strip,
  .status-grid,
  .panel-heading,
  .table-tools {
    display: none !important;
  }

  .tab-panel {
    display: none !important;
  }

  #compressed {
    display: grid !important;
  }

  .table-shell {
    box-shadow: none;
    border: 0;
  }
}
