:root {
  color-scheme: dark;
  --bg-1: #0f0f0f;
  --bg-2: #191919;
  --panel: rgba(29, 29, 29, 0.9);
  --text: #f2f2f2;
  --muted: #9a9a9a;
  --line: rgba(255, 255, 255, 0.14);
  --brand: #c62828;
  --accent: #ffffff;
  --warn: #c62828;
  --ok: #4caf50;
  --radius: 20px;
  --shadow: 0 24px 55px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Bricolage Grotesque", "Segoe UI", sans-serif;
  font-size: 19.8px;
  background:
    radial-gradient(circle at 12% 5%, rgba(198, 40, 40, 0.2), transparent 35%),
    radial-gradient(circle at 92% 14%, rgba(255, 255, 255, 0.06), transparent 30%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2));
  min-height: 100vh;
  overflow: hidden;
}

body.drag-selecting {
  cursor: crosshair;
  user-select: none;
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.08;
  background-image: radial-gradient(rgba(255, 255, 255, 0.2) 0.6px, transparent 0.6px);
  background-size: 3px 3px;
}

button,
input {
  font: inherit;
}

select {
  font: inherit;
}

.shell {
  width: min(2800px, calc(100% - 12px));
  margin: 8px auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: calc(100vh - 16px);
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.hero {
  padding: 20px;
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1.6fr) minmax(760px, 1.4fr);
  align-items: start;
}

.hero-title {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  min-height: 120px;
}

.top-left-logo {
  width: 115.2px;
  height: 115.2px;
  object-fit: contain;
  flex: 0 0 auto;
}

.eyebrow,
.side-label,
.meta,
.metric-label {
  margin: 0;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.88rem;
  font-family: "IBM Plex Mono", Consolas, monospace;
}

.hero .eyebrow {
  font-size: 2.464rem;
  font-family: "Bricolage Grotesque", "Segoe UI", sans-serif;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
  width: auto;
  text-align: left;
}

h1 {
  margin: 6px 0 0;
  font-size: clamp(2.2rem, 5vw, 4.51rem);
  line-height: 0.95;
  max-width: 15ch;
}

.lead {
  color: var(--muted);
  max-width: 70ch;
}

.actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 9px;
  justify-content: flex-end;
  align-items: center;
  align-content: start;
  align-self: start;
  overflow-x: visible;
  width: 100%;
  justify-self: end;
}

.actions .meta {
  width: auto;
  margin-top: 0;
  margin-left: 8px;
  white-space: nowrap;
}

#tableMeta {
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 12px;
  row-gap: 2px;
  white-space: normal;
  align-items: center;
}

#tableMeta .meta-label {
  text-align: left;
}

#tableMeta .meta-value {
  text-align: right;
  font-weight: 700;
  padding-right: 10px;
}

.actions .btn {
  min-height: 31px;
  font-size: 0.66em;
  padding: 0 10px;
  white-space: nowrap;
}

.btn {
  min-height: 46px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(52, 52, 52, 0.92);
  color: var(--text);
  font-weight: 700;
  padding: 0 16px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(130deg, var(--brand), #8f1f1f);
  box-shadow: 0 10px 26px rgba(198, 40, 40, 0.35);
}

.btn-danger {
  background: linear-gradient(130deg, #df3232, var(--warn));
  color: #fff;
  border-color: transparent;
}

.metrics {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.metric {
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.metric-value {
  margin: 0;
  font-size: clamp(1.54rem, 2vw, 2.09rem);
  font-weight: 800;
  text-align: left;
  white-space: nowrap;
}

.metric-label {
  white-space: nowrap;
  font-size: 1.26rem;
  text-align: right;
}

.layout {
  display: grid;
  grid-template-columns: minmax(289px, 0.765fr) minmax(0, 2.9fr);
  overflow: hidden;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 16px;
  display: grid;
  align-content: start;
  gap: 14px;
  background: rgba(16, 16, 16, 0.6);
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.sidebar .metrics {
  padding: 10px 12px;
  grid-template-columns: 1fr;
  gap: 0;
}

.sidebar .metric {
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  border-radius: 0;
  padding: 9px 8px;
  min-height: 0;
}

.sidebar .metric + .metric {
  border-top: 1px solid var(--line);
}

.sidebar .metric-label {
  font-size: 1rem;
}

.sidebar .metric-value {
  font-size: clamp(1.2rem, 1.8vw, 1.6rem);
}

.field {
  display: grid;
  gap: 6px;
}

input {
  min-height: 48px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(15, 15, 15, 0.88);
  color: var(--text);
  padding: 0 13px;
}

.filter-list {
  display: grid;
  gap: 8px;
}

.sidebar .filter-list {
  gap: 4px;
}

.sidebar .filter-block {
  margin-top: 0;
}

.filter-pill {
  border: 1px solid var(--line);
  background: rgba(25, 25, 25, 0.86);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 10px 10px 13px;
  text-align: left;
  cursor: pointer;
}

.sidebar .filter-pill {
  border-radius: 8px;
  padding: 5px 7px 5px 9px;
  font-size: 0.86em;
}

.sidebar .field > span,
.sidebar .side-label,
.sidebar .meta {
  padding-left: 13px;
}

.filter-pill.active {
  border-color: rgba(198, 40, 40, 0.65);
  background: linear-gradient(135deg, rgba(198, 40, 40, 0.24), rgba(255, 255, 255, 0.06));
}

.sidebar .editor {
  margin-top: 0;
}

.editor {
  display: grid;
  gap: 10px;
}

.calc-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.calc-item {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  gap: 4px;
  background: rgba(0, 0, 0, 0.2);
}

.calc-item span {
  font-size: 0.825rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.calc-item strong {
  font-size: 1.155rem;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.field-grid .field.full {
  grid-column: auto;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.main-table {
  padding: 16px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
  min-height: 0;
}

.table-head {
  display: flex;
  flex-direction: column;
  justify-content: stretch;
  align-items: stretch;
  gap: 8px;
}

.purchased-quick-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 2px 0;
}

.purchased-filter-btn {
  min-height: 32px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(32, 32, 32, 0.9);
  color: var(--text);
  padding: 0 12px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.purchased-filter-btn.active {
  border-color: rgba(198, 40, 40, 0.75);
  background: linear-gradient(130deg, rgba(198, 40, 40, 0.36), rgba(255, 255, 255, 0.08));
}

.table-tools {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: nowrap;
  overflow-x: visible;
  overflow-y: visible;
  width: 100%;
}

.sort-tools {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 8px;
  flex: 0 0 auto;
}

.sort-field select {
  min-height: 46px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(15, 15, 15, 0.88);
  color: var(--text);
  padding: 0 12px;
}

.table-search-field {
  min-width: 260px;
  flex: 0 0 35%;
  max-width: 35%;
}

.table-search-field input {
  min-width: 0;
  width: 100%;
}

.sort-field {
  min-width: 190px;
  flex: 0 0 220px;
}

.bulk-purchased-field {
  min-width: 200px;
  flex: 0 0 240px;
}

.bulk-purchased-field input {
  min-height: 46px;
}

.table-tools .field > span {
  padding-left: 13px;
}

#bulkPurchasedButton,
#deleteSelectedButton {
  flex: 0 0 auto;
  align-self: center;
}

#tableMeta {
  flex: 0 0 auto;
  align-self: center;
}

@media (min-width: 1600px) {
  .layout {
    grid-template-columns: minmax(306px, 0.68fr) minmax(0, 3.4fr);
  }

  .hero {
    grid-template-columns: minmax(0, 1.8fr) minmax(900px, 1.4fr);
  }
}

@media (min-width: 2560px) {
  .shell {
    width: min(3800px, calc(100% - 24px));
    margin: 8px auto;
    height: calc(100vh - 16px);
    gap: 18px;
  }

  .hero {
    padding: 26px;
    grid-template-columns: minmax(0, 1.5fr) minmax(1300px, 1.5fr);
    gap: 26px;
  }

  .top-left-logo {
    width: 140px;
    height: 140px;
  }

  .hero .eyebrow {
    font-size: clamp(2.66rem, 3vw, 4.06rem);
  }

  .metrics {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 14px;
  }

  .layout {
    grid-template-columns: minmax(442px, 0.765fr) minmax(0, 3.6fr);
  }

  .sidebar,
  .main-table {
    padding: 24px;
  }

  .table-tools {
    gap: 16px;
  }

  .table-search-field {
    min-width: 700px;
    flex: 0 0 39%;
    max-width: none;
  }

  .sort-field {
    min-width: 250px;
    flex: 0 0 280px;
  }

  .bulk-purchased-field {
    min-width: 280px;
    flex: 0 0 340px;
  }

  #tableMeta {
    column-gap: 22px;
    row-gap: 4px;
    font-size: 1.02rem;
  }

  table {
    min-width: 1400px;
  }

  th,
  td {
    padding: 8px 16px;
  }

  .table-wrap {
    max-height: none;
  }
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: auto;
  height: 100%;
  max-height: none;
  background: rgba(20, 20, 20, 0.86);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
  font-size: 0.7em;
}

th,
td {
  padding: 0 11px;
  border-bottom: 1px solid var(--line);
  text-align: center;
  line-height: 0.9;
}

tbody td {
  font-size: 1.3em;
  line-height: 0.69;
}

th:first-child,
td:first-child {
  width: 34px;
  text-align: center;
}

td.cell-product {
  text-align: left;
  width: 24%;
  max-width: 24%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

th.col-product {
  width: 24%;
  max-width: 24%;
}

.th-sortable {
  padding: 0;
}

.th-sort-button {
  width: 100%;
  min-height: 32px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 8px;
}

.th-sort-indicator {
  display: inline-block;
  width: 12px;
  text-align: center;
  color: var(--accent);
  font-size: 0.554rem;
}

thead th {
  position: sticky;
  top: 0;
  background: #232323;
  z-index: 1;
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 0.693rem;
  text-align: center;
}

tr:hover td {
  background: rgba(198, 40, 40, 0.12);
}

tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.03);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(76, 175, 80, 0.62);
  color: #ffffff;
  font-size: 0.92rem;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-family: "IBM Plex Mono", Consolas, monospace;
  background: rgba(76, 175, 80, 0.4);
}

.badge.low {
  border-color: rgba(255, 152, 0, 0.72);
  background: rgba(255, 152, 0, 0.42);
}

.badge.zero {
  border-color: rgba(198, 40, 40, 0.8);
  background: rgba(198, 40, 40, 0.5);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
}

.row-btn {
  width: 25px;
  height: 25px;
  min-height: 25px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: rgba(43, 43, 43, 0.9);
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.row-btn svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.row-btn-danger {
  color: #ff8b8b;
  border-color: rgba(198, 40, 40, 0.45);
}

.row-btn-danger:hover {
  background: rgba(198, 40, 40, 0.22);
}

@media (max-width: 1100px) {
  body {
    overflow: auto;
  }

  .hero,
  .layout {
    grid-template-columns: 1fr;
  }

  .shell {
    height: auto;
    min-height: auto;
    grid-template-rows: auto auto auto;
    margin: 16px auto 30px;
  }

  .top-left-logo {
    width: 105.6px;
    height: 105.6px;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-y: visible;
    overflow-x: visible;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-head {
    flex-direction: column;
    align-items: stretch;
  }

  .table-tools {
    display: grid;
    justify-items: stretch;
  }

  .table-search-field {
    min-width: 0;
  }

  .sort-tools {
    grid-template-columns: 1fr;
  }

  .main-table {
    min-height: auto;
  }

  .table-wrap {
    height: auto;
    max-height: 66vh;
  }
  th,
  td {
    padding: 2.8px 16px;
}

@media (max-width: 640px) {
  .shell {
    width: calc(100% - 14px);
    margin-top: 8px;
  }

  .field-grid,
  .metrics {
    grid-template-columns: 1fr;
  }
}
