:root {
  color-scheme: light;
  --bg: #eef2f5;
  --surface: #ffffff;
  --surface-2: #f7fafb;
  --ink: #202124;
  --muted: #626b74;
  --line: #d7dce2;
  --brand: #1590a8;
  --brand-2: #2e6f48;
  --gold: #d18c2f;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(28, 38, 48, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root.dark {
  color-scheme: dark;
  --bg: #111820;
  --surface: #18232c;
  --surface-2: #202d36;
  --ink: #edf3f6;
  --muted: #aab7c0;
  --line: #33434e;
  --brand: #35afc8;
  --brand-2: #78c293;
  --gold: #e1a94d;
  --danger: #ff8d7f;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--ink);
  margin: 0;
}

.login-screen {
  align-items: center;
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
}

.login-panel {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
}

.login-brand {
  color: var(--ink);
  margin-bottom: 8px;
}

button,
input,
select {
  font: inherit;
}

button,
.docs-link {
  align-items: center;
  background: var(--brand);
  border: 0;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #202a32;
  color: #fff;
  display: grid;
  gap: 24px;
  grid-template-rows: auto 1fr auto;
  padding: 20px;
}

.brand-lockup,
.user-card {
  align-items: center;
  display: flex;
  gap: 12px;
}

.user-card .sign-out-button {
  margin-left: auto;
  min-height: 34px;
  padding: 6px 9px;
}

.user-permissions {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  margin: 8px 0;
}

.user-permissions .check-field {
  min-height: 38px;
}

.user-create-form {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 18px;
}

.user-create-form h3 {
  margin: 0;
}

.user-fields {
  margin-bottom: 6px;
}

.brand-logo {
  background: #fff;
  border-radius: 8px;
  flex: 0 0 auto;
  height: 44px;
  object-fit: contain;
  width: 44px;
}

.user-card span {
  align-items: center;
  background: var(--brand);
  border-radius: 8px;
  display: flex;
  font-weight: 900;
  height: 44px;
  justify-content: center;
  width: 44px;
}

.brand-lockup p,
.user-card p {
  color: #b9c5cc;
  font-size: 12px;
  font-weight: 800;
  margin: 0 0 3px;
  text-transform: uppercase;
}

.brand-lockup strong {
  font-size: 22px;
}

.nav-list {
  align-content: start;
  display: grid;
  gap: 8px;
}

.nav-list button {
  background: transparent;
  color: #c7d2d8;
  justify-content: flex-start;
}

.nav-list button.active,
.nav-list button:hover {
  background: rgba(53, 175, 200, 0.18);
  color: #fff;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar,
.section-title,
.panel-heading,
.topbar-actions {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.hidden {
  display: none !important;
}

.topbar {
  margin-bottom: 18px;
}

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

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

h1 {
  font-size: 34px;
  line-height: 1.1;
  margin-bottom: 0;
}

h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

.icon-button {
  min-width: 42px;
  padding: 8px;
}

.secondary-button {
  background: #44515b;
}

.danger-button {
  background: var(--danger);
}

.primary-action {
  min-height: 48px;
  width: 100%;
}

.quick-bid-actions {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.quick-bid-actions button {
  align-self: center;
  min-height: 44px;
}

.quick-bid-actions .action-status {
  grid-column: 1 / -1;
}

.form-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.action-status {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  min-height: 18px;
  text-transform: uppercase;
}

.action-status[data-state="working"] {
  color: var(--brand);
}

.action-status[data-state="success"] {
  color: var(--brand-2);
}

.action-status[data-state="error"] {
  color: var(--danger);
}

.saved-bid-row {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto auto;
  margin-bottom: 12px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.component-editor {
  display: grid;
  gap: 10px;
}

.component-editor h3 {
  font-size: 14px;
  margin: 0;
}

.component-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

.component-row {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) 96px;
  padding: 9px;
  text-transform: none;
}

.component-row span {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  gap: 2px;
  min-width: 0;
}

.component-row strong {
  color: var(--ink);
}

.bid-layout {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(360px, 480px) minmax(0, 1fr);
}

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

.assembly-rule-form {
  margin-bottom: 18px;
  width: 100%;
}

.gas-appliance-rate-form {
  margin: 18px 0;
}

.gas-appliance-rate-list {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.gas-rate-row {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) 150px;
  padding: 10px 12px;
  text-transform: none;
}

.gas-rate-row > span:first-child {
  color: var(--ink);
}

.currency-input {
  align-items: center;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
}

.currency-input > span {
  color: var(--muted);
  padding: 0 8px;
}

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

.assembly-parts-field {
  grid-row: span 3;
}

.assembly-parts-field select[multiple] {
  min-height: 260px;
}

.field-tip {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: none;
}

.field-tip kbd {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  font-family: inherit;
  font-size: 11px;
  padding: 1px 5px;
}

.condition-editor {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  padding-top: 14px;
}

.rule-condition-list {
  display: grid;
  gap: 10px;
}

.rule-condition-row {
  align-items: end;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(120px, 0.8fr) minmax(180px, 1.2fr) minmax(140px, 0.8fr) minmax(150px, 1fr) auto;
  padding: 10px;
}

.rule-condition-row .link-button {
  margin-bottom: 4px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.intake-panel {
  display: grid;
  gap: 20px;
}

.admin-form {
  display: grid;
  gap: 14px;
}

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

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

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

input,
select {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  min-height: 40px;
  min-width: 0;
  padding: 8px 10px;
  text-transform: none;
}

select[multiple] {
  min-height: 132px;
}

.status-pill,
.confidence {
  background: rgba(21, 144, 168, 0.12);
  border: 1px solid rgba(21, 144, 168, 0.28);
  border-radius: 999px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 900;
  padding: 6px 9px;
  text-transform: uppercase;
  white-space: nowrap;
}

.choice-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

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

.appliance-choice,
.check-field {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 70px;
  min-height: 42px;
  padding: 7px 9px;
  text-transform: none;
}

.check-field {
  grid-template-columns: 18px minmax(0, 1fr);
}

.appliance-choice input,
.check-field input {
  min-height: 18px;
  padding: 0;
}

.systems-list {
  display: grid;
  gap: 10px;
}

.record-list {
  display: grid;
  gap: 10px;
}

.record-list.compact {
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.rule-scope-group {
  border-bottom: 1px solid var(--line);
}

.record-group-heading {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  padding: 8px 4px;
  user-select: none;
}

.record-group-heading::marker {
  content: "";
}

.record-group-heading::before {
  color: var(--brand);
  content: "+";
  font-size: 16px;
  font-weight: 900;
  width: 14px;
}

.rule-scope-group[open] > .record-group-heading::before {
  content: "-";
}

.record-group-heading h3 {
  font-size: 15px;
  margin: 0;
}

.record-group-heading span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-left: auto;
  text-transform: uppercase;
}

.rule-record-list {
  border-top: 1px solid var(--line);
  display: grid;
}

.rule-record {
  align-items: center;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(260px, 1.1fr) minmax(260px, 1fr) 72px auto;
  min-height: 48px;
  padding: 7px 10px;
}

.rule-record:last-child {
  border-bottom: 0;
}

.rule-identity {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.rule-identity strong,
.rule-identity span,
.rule-parts {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-identity span {
  color: var(--brand);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.rule-parts {
  color: var(--muted);
  margin: 0;
}

.rule-confidence {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.rule-actions {
  flex-wrap: nowrap;
  gap: 5px;
  margin-top: 0;
}

.rule-actions button {
  min-height: 30px;
  padding: 5px 8px;
}

.assembly-group-row td {
  background: color-mix(in srgb, var(--brand) 10%, var(--surface));
  border-top: 2px solid var(--brand);
  color: var(--ink);
  font-weight: 800;
}

.assembly-group-row td:first-child {
  padding-left: 14px;
}

.assembly-group-row small {
  color: var(--muted);
  display: inline;
  margin-left: 10px;
}

.record-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 5px;
  padding: 12px;
}

.record-card span {
  color: var(--brand);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.record-card p {
  margin-bottom: 0;
}

.record-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.record-actions button {
  min-height: 32px;
  padding: 6px 10px;
}

.empty-note {
  margin: 0;
}

.source-note {
  font-size: 13px;
  margin: 0;
}

.product-category-list {
  display: grid;
  gap: 14px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.product-page-list {
  max-height: none;
}

.product-category {
  display: grid;
  gap: 8px;
}

.product-category h3 {
  color: var(--brand);
  font-size: 13px;
  letter-spacing: 0;
  margin: 0;
  text-transform: uppercase;
}

.product-table {
  min-width: 560px;
}

.product-table th:nth-child(1),
.product-table td:nth-child(1) {
  width: 180px;
}

.product-table th:nth-child(3),
.product-table td:nth-child(3) {
  text-align: right;
  width: 110px;
}

.system-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 12px;
}

.system-card-title {
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.system-card-title span,
td small {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
}

.results-column {
  align-content: start;
  display: grid;
  gap: 18px;
}

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

.summary-strip article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 7px;
  min-height: 92px;
  padding: 16px;
}

.summary-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.summary-strip strong {
  font-size: 26px;
}

.review-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.review-questions span {
  background: rgba(209, 140, 47, 0.14);
  border: 1px solid rgba(209, 140, 47, 0.32);
  border-radius: 999px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  padding: 7px 10px;
}

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

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

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

th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.confidence.high {
  color: var(--brand-2);
}

.confidence.medium {
  color: var(--gold);
}

.link-button {
  background: transparent;
  color: var(--danger);
  min-height: 0;
  padding: 0;
}

.qty-input {
  min-height: 34px;
  padding: 5px 8px;
  text-align: right;
  width: 86px;
}

@media (max-width: 1100px) {
  .app-shell,
  .bid-layout,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto;
  }

  .nav-list {
    display: flex;
    overflow: auto;
  }

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

  .rule-record {
    grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto;
  }

  .rule-confidence {
    display: none;
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 16px;
  }

  .topbar,
  .section-title,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .field-grid,
  .system-grid,
  .constants-grid,
  .gas-appliance-rate-list,
  .toggle-row,
  .saved-bid-row,
  .quick-bid-actions,
  .summary-strip {
    grid-template-columns: 1fr;
  }

  .rule-condition-row {
    grid-template-columns: 1fr;
  }

  .rule-record {
    align-items: start;
    grid-template-columns: 1fr;
  }

  .rule-parts {
    white-space: normal;
  }
}
