:root {
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-soft: #eef4f1;
  --text: #17201c;
  --muted: #65716c;
  --border: #dce5e1;
  --accent: #14756f;
  --accent-dark: #0d5d58;
  --amber: #a96d05;
  --amber-soft: #fff4d8;
  --danger: #b33f34;
  --shadow: 0 16px 40px rgba(28, 48, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1,
.topbar p,
h2,
h3 {
  margin: 0;
}

.topbar h1 {
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.primary-button,
.ghost-button,
.icon-button {
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 38px;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  padding: 0 16px;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.ghost-button {
  background: #fff;
  color: var(--text);
  padding: 0 14px;
  font-weight: 650;
}

.action-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.icon-button {
  width: 30px;
  height: 30px;
  min-height: 30px;
  background: var(--surface-soft);
  color: var(--accent-dark);
  font-size: 20px;
  line-height: 1;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 0.82fr) minmax(620px, 1.45fr) minmax(280px, 0.73fr);
  gap: 18px;
  padding: 18px;
  align-items: start;
}

.input-panel,
.results-panel,
.summary-panel {
  min-width: 0;
}

.input-panel,
.results-panel,
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-panel {
  padding: 18px;
  display: grid;
  gap: 20px;
}

.input-panel section {
  display: grid;
  gap: 12px;
}

h2 {
  font-size: 15px;
  line-height: 1.25;
}

h3 {
  font-size: 13px;
  color: var(--muted);
}

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

.client-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

label {
  position: relative;
  display: grid;
  gap: 6px;
}

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

input,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  min-height: 40px;
  padding: 0 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 117, 111, 0.14);
}

label small {
  position: absolute;
  right: 9px;
  bottom: 11px;
  color: var(--muted);
  font-size: 11px;
}

.stacked {
  display: grid;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.opening-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid var(--border);
}

.tab-button {
  min-height: 38px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.tab-button.active {
  border-bottom-color: var(--accent);
  color: var(--accent-dark);
}

.add-row-button {
  justify-self: start;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.manual-table-wrap {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
}

.manual-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
  font-size: 12px;
}

.manual-table th,
.manual-table td {
  padding: 8px 7px;
  border-right: 1px solid var(--border);
  vertical-align: middle;
}

.manual-table th:nth-child(1),
.manual-table td:nth-child(1) {
  width: 7%;
}

.manual-table th:nth-child(2),
.manual-table td:nth-child(2) {
  width: 23%;
}

.manual-table th:nth-child(3),
.manual-table td:nth-child(3),
.manual-table th:nth-child(4),
.manual-table td:nth-child(4) {
  width: 20%;
}

.manual-table th:nth-child(5),
.manual-table td:nth-child(5) {
  width: 15%;
}

.manual-table th:nth-child(6),
.manual-table td:nth-child(6) {
  width: 15%;
  text-align: center;
}

.ancillary-table th:nth-child(2),
.ancillary-table td:nth-child(2) {
  width: 36%;
}

.ancillary-table th:nth-child(3),
.ancillary-table td:nth-child(3) {
  width: 13%;
}

.ancillary-table th:nth-child(4),
.ancillary-table td:nth-child(4),
.ancillary-table th:nth-child(5),
.ancillary-table td:nth-child(5) {
  width: 17%;
}

.ancillary-table th:nth-child(6),
.ancillary-table td:nth-child(6) {
  width: 12%;
}

.manual-table th:last-child,
.manual-table td:last-child {
  border-right: 0;
}

.manual-table th {
  position: static;
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
}

.compact-input {
  min-width: 0;
  min-height: 34px;
  padding: 0 7px;
  font-size: 12px;
  background: #fff;
}

.number-entry {
  text-align: right;
}

.table-action-button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

.table-action-button:hover {
  color: var(--danger);
  border-color: #f0d5d1;
  background: #fff7f6;
}

.table-action-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.manual-total {
  margin-top: -12px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: #fbfcfc;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.electrical-list {
  display: grid;
  gap: 11px;
}

.electrical-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) 92px 36px;
  gap: 10px;
  align-items: center;
}

.electrical-row span {
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.electrical-row input {
  min-height: 36px;
  text-align: right;
}

.electrical-row small {
  position: static;
  color: var(--muted);
  font-size: 12px;
}

.results-panel {
  overflow: hidden;
}

.results-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.results-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.results-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.rounding-note {
  border: 1px solid #ecd99e;
  background: var(--amber-soft);
  color: var(--amber);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 134px);
}

table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  text-align: left;
}

th {
  background: #f9fbfa;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
  z-index: 2;
}

td.formula {
  color: var(--muted);
  font-family: "Segoe UI Mono", Consolas, monospace;
  font-size: 12px;
}

.number {
  text-align: right;
  white-space: nowrap;
}

.rate-input {
  width: 84px;
  min-height: 32px;
  padding: 0 8px;
  text-align: right;
}

.takeoff-input {
  min-height: 32px;
  padding: 0 8px;
  font-size: 12px;
}

.summary-panel {
  display: grid;
  gap: 14px;
}

.summary-card {
  padding: 16px;
}

.summary-card h2 {
  margin-bottom: 12px;
}

.summary-card dl {
  margin: 0;
  display: grid;
  gap: 10px;
}

.summary-card dl div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.summary-card dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-card dd {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.summary-input-row dd {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.summary-input {
  width: 76px;
  min-height: 32px;
  padding: 0 8px;
  text-align: right;
  font-weight: 800;
}

.muted {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.rate-master {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
}

.rate-master-row {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 8px;
  align-items: center;
}

.rate-master-row span {
  font-size: 12px;
  color: var(--text);
  line-height: 1.25;
}

.notes-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.options-shell {
  display: grid;
  gap: 18px;
  max-width: 980px;
  margin: 0 auto;
  padding: 18px;
}

.option-card {
  display: grid;
  gap: 12px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.option-table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.option-table {
  min-width: 1040px;
}

.option-table th:nth-child(1),
.option-table td:nth-child(1) {
  width: 24%;
}

.option-table th:nth-child(2),
.option-table td:nth-child(2) {
  width: 18%;
}

.option-table th:nth-child(3),
.option-table td:nth-child(3) {
  width: 12%;
}

.option-table th:nth-child(4),
.option-table td:nth-child(4) {
  width: 22%;
}

.option-table th:nth-child(5),
.option-table td:nth-child(5) {
  width: 10%;
  text-align: center;
}

.option-table th:nth-child(6),
.option-table td:nth-child(6) {
  width: 10%;
  text-align: center;
}

.option-table th:nth-child(7),
.option-table td:nth-child(7) {
  width: 4%;
  text-align: center;
}

.option-check-cell input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.takeoff-options-table {
  min-width: 820px;
}

.takeoff-options-table th:nth-child(1),
.takeoff-options-table td:nth-child(1) {
  width: 26%;
}

.takeoff-options-table th:nth-child(2),
.takeoff-options-table td:nth-child(2) {
  width: 66%;
}

.takeoff-options-table th:nth-child(3),
.takeoff-options-table td:nth-child(3) {
  width: 8%;
  text-align: center;
}

.option-textarea {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  font-size: 12px;
  color: var(--text);
}

@media (max-width: 1220px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

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

  .input-panel section:nth-child(4),
  .input-panel section:nth-child(5) {
    grid-column: 1 / -1;
  }

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

@media (max-width: 820px) {
  .topbar,
  .workspace {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace,
  .input-panel,
  .summary-panel {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 520px) {
  .input-grid {
    grid-template-columns: 1fr;
  }

  .electrical-row {
    grid-template-columns: 1fr 84px 32px;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions button {
    flex: 1;
  }
}
