:root {
  --bg: #f5f7f0;
  --surface: #ffffff;
  --surface-strong: #edf1e5;
  --ink: #20231f;
  --muted: #687063;
  --line: rgba(32, 35, 31, .13);
  --accent: #c93d5a;
  --accent-dark: #9f2841;
  --green: #2f8b6c;
  --blue: #2d6f98;
  --gold: #b67b23;
  --danger: #b74545;
  --shadow: 0 18px 54px rgba(31, 35, 28, .1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .56;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 70px;
  padding: 14px clamp(18px, 4vw, 56px);
  border-bottom: 1px solid rgba(32, 35, 31, .08);
  background: rgba(245, 247, 240, .92);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 900;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #20231f;
  color: #fff;
  font-size: 12px;
  font-weight: 950;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: 22px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 780;
}

.app-nav a[aria-current="page"],
.app-nav a:hover,
.app-nav a:focus-visible {
  color: var(--accent-dark);
}

.pricing-shell {
  display: grid;
  gap: 18px;
  padding: clamp(18px, 4vw, 42px);
}

.page-head,
.toolbar,
.table-section,
.guard-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.page-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, auto);
  gap: 16px;
  align-items: end;
  padding: 24px;
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(32px, 5vw, 58px);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(22px, 3vw, 32px);
  line-height: 1.08;
  letter-spacing: 0;
}

.run-status {
  justify-self: end;
  max-width: 340px;
  padding: 10px 12px;
  border: 1px solid rgba(47, 139, 108, .22);
  border-radius: 8px;
  background: #f2faf5;
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
  line-height: 1.35;
}

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

.summary-card {
  display: grid;
  gap: 7px;
  min-height: 96px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

.summary-card strong {
  font-size: 26px;
  line-height: 1;
}

.summary-card.ready strong {
  color: var(--green);
}

.summary-card.warn strong {
  color: var(--gold);
}

.summary-card.updated strong {
  color: var(--blue);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1.3fr) repeat(3, minmax(150px, .62fr)) auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

input,
select {
  width: 100%;
  min-height: 42px;
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus {
  border-color: rgba(201, 61, 90, .48);
  outline: none;
  box-shadow: 0 0 0 3px rgba(201, 61, 90, .12);
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button,
.pagination button,
.row-actions button,
.row-actions a,
.composition-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  min-width: 0;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 900;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

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

.secondary-button,
.ghost-button,
.pagination button,
.row-actions button,
.row-actions a,
.composition-link {
  background: #fff;
  color: var(--ink);
}

.guard-panel {
  display: grid;
  gap: 5px;
  padding: 14px 16px;
  border-color: rgba(183, 123, 35, .28);
  background: #fff9ed;
  color: #7a5419;
}

.guard-panel[hidden] {
  display: none;
}

.guard-panel strong {
  color: var(--gold);
}

.table-section {
  overflow: hidden;
}

.table-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.table-head > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

.table-wrap {
  position: relative;
  overflow-x: auto;
}

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

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid rgba(32, 35, 31, .08);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f8faf4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 950;
}

td {
  font-size: 14px;
}

.product-cell {
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr);
  gap: 11px;
  align-items: center;
  min-width: 300px;
}

.product-thumb {
  position: relative;
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  overflow: hidden;
  border-radius: 8px;
  background: linear-gradient(135deg, #f6d2da, #fff7f1 58%, #cadfd7);
}

.product-thumb::before {
  content: "";
  width: 28px;
  height: 28px;
  border: 2px solid rgba(32, 35, 31, .28);
  border-radius: 6px 6px 13px 13px;
  background: rgba(255, 255, 255, .62);
  transform: rotate(-8deg);
}

.product-thumb.tone-2 {
  background: linear-gradient(135deg, #d7e9f2, #fff 56%, #f2d7b5);
}

.product-thumb.tone-3 {
  background: linear-gradient(135deg, #dbe8cc, #fff4f6 58%, #e7c4cf);
}

.product-thumb.tone-4 {
  background: linear-gradient(135deg, #ead6b5, #fff 58%, #cde3ef);
}

.product-main {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.product-main a {
  width: max-content;
  max-width: 100%;
  overflow: hidden;
  color: var(--ink);
  font-weight: 920;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-main a:hover,
.product-main a:focus-visible {
  color: var(--accent-dark);
}

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

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  max-width: 160px;
  padding: 6px 9px;
  border-radius: 8px;
  background: #eef5ef;
  color: var(--green);
  font-size: 12px;
  font-weight: 950;
  line-height: 1.2;
}

.status-badge.missing_cost,
.status-badge.missing_profit {
  background: #fff4e5;
  color: #8a5b19;
}

.status-badge.updated {
  background: #ecf5fb;
  color: var(--blue);
}

.money {
  font-weight: 920;
  white-space: nowrap;
}

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

.price-diff {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.price-diff.up {
  color: var(--green);
}

.price-diff.down {
  color: var(--danger);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 190px;
}

.row-actions button,
.row-actions a {
  min-height: 36px;
  padding: 8px 10px;
  font-size: 12px;
}

.row-actions .update-row {
  border-color: rgba(201, 61, 90, .32);
  color: var(--accent-dark);
}

.composition-link {
  width: 100%;
  min-height: 40px;
  margin: -6px 0 12px;
  color: var(--accent-dark);
}

.empty-state {
  padding: 28px;
  color: var(--muted);
  font-weight: 900;
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.pagination {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
  padding: 14px 20px;
}

.pagination span {
  min-width: 150px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  text-align: center;
}

.calc-drawer,
.confirm-modal {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: none;
  background: rgba(32, 35, 31, .42);
}

.calc-drawer.open,
.confirm-modal.open {
  display: grid;
}

.calc-drawer {
  justify-content: end;
}

.drawer-panel {
  width: min(520px, 100vw);
  min-height: 100%;
  overflow-y: auto;
  padding: 22px;
  background: #fff;
  box-shadow: -20px 0 60px rgba(0, 0, 0, .16);
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
  background: #fff;
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
}

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

.calc-grid span,
.calc-total,
.component-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf4;
}

.calc-grid span {
  display: grid;
  gap: 6px;
  min-height: 78px;
  padding: 12px;
}

.calc-grid small,
.calc-total span,
.component-row small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.calc-grid b {
  font-size: 20px;
}

.calc-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  margin-bottom: 10px;
  padding: 12px;
}

.calc-total strong {
  font-size: 22px;
  white-space: nowrap;
}

.calc-total.target {
  border-color: rgba(47, 139, 108, .26);
  background: #f2faf5;
}

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

.component-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
}

.component-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-status {
  min-height: 24px;
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 850;
  line-height: 1.45;
}

.confirm-modal {
  place-items: center;
  padding: 16px;
}

.confirm-panel {
  display: grid;
  gap: 14px;
  width: min(480px, 100%);
  padding: 22px;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.confirm-panel p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(201, 61, 90, .24);
  outline-offset: 3px;
}

@media (max-width: 1120px) {
  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .toolbar .primary-button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-nav {
    display: none;
  }

  .page-head {
    grid-template-columns: 1fr;
  }

  .run-status {
    justify-self: stretch;
  }

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

  .table-head,
  .confirm-actions {
    display: grid;
  }

  .pagination {
    justify-content: stretch;
  }

  .pagination button {
    flex: 1;
  }
}

@media (max-width: 560px) {
  .app-header {
    min-height: 64px;
    padding: 12px 14px;
  }

  .brand span:last-child {
    max-width: 145px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .pricing-shell {
    padding: 14px;
  }

  .page-head,
  .toolbar,
  .table-head,
  .drawer-panel,
  .confirm-panel {
    padding: 16px;
  }

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

  .calc-total,
  .component-row {
    display: grid;
  }

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