:root {
  color-scheme: light;
  --ink: #16213a;
  --muted: #6b7686;
  --subtle: #8993a3;
  --line: #e2e6ec;
  --line-strong: #d7dee8;
  --panel: #ffffff;
  --page: #f6f7f9;
  --soft: #f7f9fb;
  --input: #fff9e0;
  --brand: #1f3a5f;
  --brand-dark: #14263f;
  --ok: #2c7a4b;
  --warn: #9a5b18;
  --danger: #b5442e;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-width: 0;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 66px;
  padding: 14px 26px;
  border-bottom: 1px solid #e6e9ee;
  background: #fff;
}

.carrier-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 40px;
  margin-left: auto;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.carrier-switcher > span {
  padding-left: 6px;
  color: var(--subtle);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.carrier-switcher select {
  width: auto;
  min-width: 170px;
  min-height: 32px;
  height: 32px;
  border: 1px solid #cfd7e3;
  border-radius: 7px;
  padding: 0 30px 0 10px;
  background: #fff;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 800;
  cursor: pointer;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 15px;
  font-weight: 800;
}

h3 {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px 26px 60px;
}

.quote-layout {
  display: grid;
  grid-template-columns: minmax(420px, 1.05fr) minmax(380px, 0.95fr);
  gap: 20px;
  align-items: start;
}

.column-stack {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 18px;
}

.results-column {
  position: sticky;
  top: 86px;
}

.panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  padding: 12px 18px;
  border-bottom: 1px solid #edf0f4;
}

.panel-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.panel-body {
  padding: 16px 18px;
}

.shipment-body {
  display: grid;
  gap: 16px;
}

.form-grid {
  display: grid;
  min-width: 0;
  gap: 14px;
}

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

.pricing-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding-top: 16px;
  border-top: 1px solid #f0f2f5;
}

.field {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.field > span,
.commodity-field > span {
  color: var(--subtle);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  border: 1.5px solid #dfe4eb;
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--input);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 700;
}

select {
  background: #fff;
  text-align: left;
}

input:focus,
select:focus,
button:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 2px solid #7aa3cf;
  outline-offset: 2px;
}

.input-wrap {
  position: relative;
  min-width: 0;
}

.input-wrap input {
  padding-right: 64px;
}

.unit-suffix {
  position: absolute;
  top: 50%;
  right: 8px;
  min-width: 45px;
  transform: translateY(-50%);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 900;
  line-height: 1;
  padding: 5px 6px;
  text-align: center;
}

.source-link {
  width: fit-content;
  color: var(--brand);
  font-weight: 800;
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
}

.unit-toggle {
  display: inline-flex;
  gap: 2px;
  margin: 0;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--soft);
}

.unit-toggle legend {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.unit-toggle label {
  display: block;
}

.unit-toggle input {
  position: absolute;
  width: 1px;
  min-width: 0;
  height: 1px;
  min-height: 0;
  margin: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.unit-toggle span {
  display: block;
  min-width: 66px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 11.5px;
  font-weight: 800;
  line-height: 1;
  padding: 8px 10px;
  text-align: center;
}

.unit-toggle input:checked + span {
  background: var(--brand);
  color: #fff;
}

button {
  min-height: 34px;
  border-radius: 7px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 700;
}

.ghost-button {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #3a4658;
}

.ghost-button:hover {
  background: var(--soft);
}

.primary-button {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
}

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

.fuel-card-body {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(260px, 1.1fr);
  gap: 16px;
  padding: 16px 18px;
}

.fuel-price-cell {
  display: grid;
  gap: 8px;
  border: 1px solid #cddaeb;
  border-radius: 11px;
  background: #eaf1fa;
  padding: 14px 16px;
}

.fuel-price-cell > span,
.fuel-meta span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.35;
}

.fuel-price-value {
  display: flex;
  align-items: baseline;
  gap: 5px;
  color: var(--brand);
  font-size: 24px;
  font-weight: 900;
}

.fuel-price-value input {
  width: 112px;
  min-height: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: var(--brand);
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
  text-align: left;
}

.fuel-price-value input:focus {
  outline: 0;
}

.fuel-price-value span:last-child {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.fuel-meta {
  display: grid;
  align-content: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--soft);
  padding: 12px 14px;
}

.fuel-meta div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.fuel-meta strong {
  font-size: 12.5px;
  text-align: right;
}

.fuel-status {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  border: 1px solid #c9e8d0;
  border-radius: 999px;
  background: #eaf6ef;
  color: var(--ok);
  font-size: 10.5px;
  font-weight: 900;
  padding: 4px 9px;
  white-space: nowrap;
}

.fuel-status.warn {
  border-color: #f3d58a;
  background: #fff7e6;
  color: var(--warn);
}

.fuel-status.muted {
  border-color: var(--line);
  background: var(--soft);
  color: var(--muted);
}

.commodity-list {
  display: grid;
  min-width: 0;
  gap: 12px;
  padding: 16px 18px;
}

.commodity-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fbfcfd;
  padding: 12px;
}

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

.commodity-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.commodity-field {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.commodity-field input[data-field="item"] {
  background: #fff;
  font-weight: 600;
  text-align: left;
}

.commodity-fields {
  display: grid;
  grid-template-columns: 0.7fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.dimensions-field {
  grid-column: 1 / -1;
}

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

.commodity-fields input {
  text-align: right;
}

.remove-line {
  width: 30px;
  height: 30px;
  min-height: 30px;
  margin-top: 14px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--subtle);
  font-size: 15px;
  line-height: 1;
  padding: 0;
}

.remove-line:hover:not(:disabled) {
  border-color: #f0c2b8;
  background: #fdeeea;
  color: var(--danger);
}

.remove-line:disabled {
  cursor: default;
  opacity: 0.4;
}

.commodity-output-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f3f6fa;
  padding: 8px 10px;
}

.commodity-output-row span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.commodity-output-row strong {
  font-size: 13px;
}

.summary-head {
  align-items: flex-start;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 16px 18px;
}

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--soft);
  padding: 12px 14px;
}

.primary-metric {
  grid-column: 1 / -1;
  border-color: #cddaeb;
  background: #eaf1fa;
  padding: 14px 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.35;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 17px;
  font-weight: 800;
}

.primary-metric strong {
  margin-top: 5px;
  color: var(--brand);
  font-size: 28px;
  font-weight: 900;
}

.message-list {
  display: grid;
  gap: 8px;
  padding: 0 18px 16px;
}

.message-list:empty {
  display: none;
}

.message {
  border: 1px solid #ead9a5;
  border-radius: 9px;
  background: #fff9e8;
  color: #765d20;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  padding: 10px 14px;
}

.message.danger {
  border-color: #f0c2b8;
  background: #fef2ee;
  color: #8a3a28;
}

.trace-panel > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  list-style: none;
}

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

.trace-panel > summary:hover {
  background: #fafbfc;
}

.chevron {
  color: var(--subtle);
  transition: transform 0.15s ease;
}

.trace-panel:not([open]) .chevron {
  transform: rotate(-90deg);
}

.trace-content {
  display: grid;
  gap: 14px;
  padding: 0 18px 18px;
}

.trace-group {
  overflow: hidden;
  border: 1px solid #e3e8ee;
  border-radius: 10px;
}

.trace-group h3 {
  padding: 9px 12px;
  border-bottom: 1px solid #e3e8ee;
  background: #f8fafc;
}

.kv-list {
  display: grid;
  margin: 0;
  padding: 4px 12px;
}

.kv-list div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(110px, auto);
  align-items: baseline;
  gap: 14px;
  padding: 8px 0;
  border-top: 1px solid #edf1f5;
}

.kv-list div:first-child {
  border-top: 0;
}

.kv-list dt {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.kv-list dd {
  margin: 0;
  font-size: 12.5px;
  font-weight: 800;
  text-align: right;
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .quote-layout {
    grid-template-columns: 1fr;
  }

  .results-column {
    position: static;
  }
}

@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    gap: 12px;
    min-height: 58px;
    padding: max(12px, env(safe-area-inset-top)) 12px 12px;
  }

  h1 {
    font-size: 19px;
  }

  .app-shell {
    max-width: 100%;
    padding: 14px 10px max(28px, env(safe-area-inset-bottom));
  }

  .panel {
    border-radius: 10px;
  }

  .panel-head {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 12px;
  }

  .panel-actions {
    width: 100%;
    justify-content: space-between;
  }

  .panel-body,
  .commodity-list,
  .summary-grid,
  .trace-content {
    padding-left: 12px;
    padding-right: 12px;
  }

  .route-grid,
  .pricing-grid,
  .fuel-card-body {
    grid-template-columns: 1fr;
  }

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

  .dimensions-field {
    grid-column: 1 / -1;
  }

  input,
  select,
  button {
    min-height: 42px;
    font-size: 16px;
  }

  .carrier-switcher select {
    min-height: 32px;
    font-size: 12.5px;
  }

  .unit-toggle span {
    min-height: 34px;
    padding: 11px 10px;
  }

  .remove-line {
    width: 34px;
    height: 34px;
    min-height: 34px;
    font-size: 18px;
  }
}

@media (max-width: 460px) {
  .topbar {
    align-items: flex-start;
  }

  .carrier-switcher {
    width: 100%;
    margin-left: 0;
  }

  .carrier-switcher select {
    flex: 1;
    width: 100%;
    min-width: 0;
    min-height: 38px;
    height: 38px;
    font-size: 14px;
  }

  .panel-actions,
  .unit-toggle,
  .ghost-button,
  .primary-button {
    width: 100%;
  }

  .unit-toggle label {
    flex: 1;
  }

  .commodity-card-head {
    align-items: start;
  }

  .commodity-fields,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .dimensions-field,
  .primary-metric {
    grid-column: auto;
  }

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

  .kv-list div {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .kv-list dd {
    text-align: left;
  }
}
