:root {
  color-scheme: light;
  --ink: #221f20;
  --muted: #66706e;
  --line: #d9dfdc;
  --paper: #ffffff;
  --wash: #f3f5f2;
  --teal: #009a92;
  --teal-dark: #00756f;
  --red: #f23b32;
  --grey: #9ca1a1;
  --yellow: #fff21f;
  --shadow: 0 18px 50px rgba(34, 31, 32, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(34, 31, 32, 0.05) 0 50%, rgba(0, 154, 146, 0.1) 50% 100%),
    var(--wash);
  color: var(--ink);
}

.app-shell,
.app-shell * {
  max-width: 100%;
}

button,
input {
  min-width: 0;
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  gap: 16px;
  padding: 16px clamp(12px, 3vw, 36px) 28px;
}

.deck-title {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: white;
}

.deck-title p,
.section-head p,
.product-card p,
.quote-line span,
.grand-total-card small,
.empty-state span {
  color: var(--muted);
}

h1 {
  font-size: clamp(28px, 4vw, 48px);
  line-height: 0.95;
}

.deck-title p {
  color: rgba(255, 255, 255, 0.78);
}

.grand-total-card {
  display: grid;
  align-content: center;
  gap: 4px;
  min-height: 112px;
  padding: 18px 22px;
  color: white;
  border-radius: 8px;
  background:
    radial-gradient(circle at 88% 26%, var(--yellow) 0 22px, transparent 23px),
    linear-gradient(135deg, var(--ink) 0 44%, var(--red) 44% 58%, var(--teal) 58% 100%);
  box-shadow: var(--shadow);
}

.grand-total-card span {
  color: rgba(255, 255, 255, 0.75);
  font-weight: 700;
}

.grand-total-card strong {
  font-size: clamp(38px, 5vw, 62px);
  line-height: 1;
}

.grand-total-card small {
  color: rgba(255, 255, 255, 0.78);
  font-weight: 700;
}

.control-deck {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(0, 2.2fr) minmax(220px, 1.15fr);
  grid-template-areas:
    "title categories search"
    "title periods search";
  gap: 12px;
  align-items: stretch;
  padding: 14px clamp(16px, 3vw, 36px);
  background:
    linear-gradient(90deg, var(--ink) 0 38%, var(--red) 38% 48%, var(--grey) 48% 70%, var(--teal) 70% 100%);
  border-bottom: 1px solid rgba(34, 31, 32, 0.18);
  border-radius: 8px;
}

.deck-title {
  grid-area: title;
  align-self: center;
}

.search-wrap {
  grid-area: search;
  align-self: center;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.search-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.segment-row,
.period-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 8px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
}

.segment-row {
  grid-area: categories;
}

.period-row {
  grid-area: periods;
}

.segment,
.period,
.toggle-pill {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  padding: 0 10px;
  white-space: nowrap;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
}

.segment {
  font-size: 12px;
  letter-spacing: 0;
}

.period,
.toggle-pill {
  font-size: 12px;
}

.segment.active,
.period.active {
  background: var(--teal);
  color: white;
}

.catalog,
.quote {
  min-width: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.catalog {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  max-height: min(720px, 72vh);
}

.quote {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.section-head.compact {
  padding: 0 0 14px;
}

h2 {
  font-size: 22px;
}

.ghost-button {
  border: 0;
  background: transparent;
  color: var(--red);
  font-weight: 800;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  min-height: 300px;
  padding: 24px;
  text-align: center;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  overflow: auto;
  padding: 10px;
  min-height: 0;
}

.product-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  aspect-ratio: 1;
  min-height: 210px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.product-card h3 {
  font-size: 17px;
  line-height: 1.2;
}

.product-card p {
  margin-top: 7px;
  font-size: 13px;
  line-height: 1.3;
}

.product-card strong {
  align-self: end;
  font-size: 20px;
}

.product-actions {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: grid;
  grid-template-rows: 58px 58px;
  gap: 12px;
  align-self: end;
}

.category-icon {
  width: 58px;
  height: 58px;
  object-fit: contain;
  opacity: 0.95;
}

.add-product,
.square-button {
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 8px;
  background: var(--teal);
  color: white;
  font-size: 24px;
  font-weight: 900;
}

.add-product {
  align-self: end;
}

.quote-lines {
  display: grid;
  gap: 8px;
  min-height: 90px;
  overflow: auto;
}

.quote-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px auto 32px;
  align-items: center;
  gap: 9px;
  padding: 10px;
  background: var(--wash);
  border-radius: 8px;
}

.line-title b {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-title span {
  display: block;
  margin-top: 3px;
  font-size: 12px;
}

.quote-line > strong {
  white-space: nowrap;
}

.qty-control {
  display: grid;
  grid-template-columns: 30px 1fr 30px;
  min-height: 36px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.qty-control button,
.remove-line {
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 900;
}

.qty-control input {
  width: 100%;
  border: 0;
  outline: 0;
  text-align: center;
}

.remove-line {
  width: 32px;
  height: 32px;
  color: var(--red);
}

.manual-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 95px 42px;
  gap: 8px;
}

.manual-form input {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  outline: 0;
}

.adjustments {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.adjustments label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.adjustments span {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.adjustments input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}

.totals-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.totals-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.totals-list dt {
  color: var(--muted);
}

.totals-list dd {
  margin: 0;
  font-weight: 900;
}

.final-row {
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.quote-actions {
  display: flex;
  gap: 8px;
}

.primary-button,
.secondary-button {
  min-height: 46px;
  flex: 1;
  border-radius: 8px;
  font-weight: 900;
}

.primary-button {
  border: 0;
  background: var(--teal);
  color: white;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}

@media (max-width: 1320px) {
  .control-deck {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "title"
      "categories"
      "periods"
      "search";
  }

  .segment-row,
  .period-row {
    display: grid;
    overflow: visible;
  }

  .segment-row {
    grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  }

  .period-row {
    grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  }
}

@media (max-width: 620px) {
  body {
    background: var(--wash);
  }

  .app-shell {
    display: grid;
    gap: 10px;
    padding: 10px 8px 18px;
  }

  h1 {
    font-size: 34px;
  }

  .deck-title p {
    font-size: 13px;
    line-height: 1.25;
  }

  .grand-total-card {
    min-height: 88px;
    padding: 14px 16px;
  }

  .grand-total-card strong {
    font-size: 44px;
  }

  .control-deck {
    gap: 8px;
    padding: 10px;
    background: var(--ink);
  }

  .search-wrap {
    min-height: 46px;
  }

  .search-wrap input {
    font-size: 16px;
  }

  .segment-row,
  .period-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    overflow: visible;
    padding: 6px;
  }

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

  .segment,
  .period {
    min-height: 44px;
    padding: 0 8px;
    white-space: normal;
    line-height: 1.05;
  }

  .segment {
    font-size: 11px;
  }

  .period {
    font-size: 11px;
  }

  .toggle-pill {
    font-size: 13px;
  }

  .catalog,
  .quote {
    border-radius: 8px;
  }

  .catalog {
    max-height: 560px;
  }

  .section-head {
    padding: 14px;
  }

  .section-head.compact {
    padding-bottom: 12px;
  }

  .product-grid {
    grid-template-columns: 1fr;
    padding: 8px;
    gap: 8px;
  }

  .product-card {
    aspect-ratio: auto;
    min-height: 150px;
    padding: 12px;
  }

  .product-card {
    grid-template-columns: minmax(0, 1fr) 52px;
  }

  .product-actions {
    grid-template-rows: 52px 52px;
    gap: 10px;
  }

  .category-icon,
  .add-product {
    width: 52px;
    height: 52px;
  }

  .product-card h3 {
    font-size: 18px;
  }

  .product-card strong {
    font-size: 22px;
  }

  .square-button {
    width: 48px;
    height: 48px;
  }

  .quote-line {
    grid-template-columns: minmax(0, 1fr) 108px 36px;
    gap: 8px;
  }

  .quote-line > strong {
    grid-column: 1 / -1;
  }

  .manual-form,
  .adjustments {
    grid-template-columns: 1fr;
  }

  .quote-actions {
    flex-direction: column;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }
}

@media (max-width: 390px) {
  h1 {
    font-size: 30px;
  }

  .grand-total-card strong {
    font-size: 40px;
  }

  .segment,
  .period {
    font-size: 12px;
  }

  .quote-line {
    grid-template-columns: 1fr;
  }

  .qty-control {
    max-width: 150px;
  }

  .remove-line {
    justify-self: end;
  }
}

@media print {
  .control-deck,
  .catalog,
  .manual-form,
  .quote-actions,
  .ghost-button,
  .qty-control button,
  .remove-line {
    display: none !important;
  }

  body {
    background: white;
  }

  .app-shell,
  .control-deck {
    display: block;
  }

  .quote,
  .grand-total-card {
    box-shadow: none;
  }
}
