:root {
  color-scheme: light;
  --bg: #f3f3f0;
  --bg-grid: rgba(0, 0, 0, 0.045);
  --surface: #ffffff;
  --surface-2: #ededeb;
  --surface-3: #f8f8f6;
  --ink: #080808;
  --muted: #6a6a66;
  --line: #d5d5d0;
  --line-strong: #111111;
  --inverse: #ffffff;
  --accent: #111111;
  --status-ok: #111111;
  --status-warn: #686868;
  --status-fast: #000000;
  --status-soft: #eeeeeb;
  --shadow: 0 18px 36px rgba(0, 0, 0, 0.07);
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #050505;
  --bg-grid: rgba(255, 255, 255, 0.07);
  --surface: #0d0d0d;
  --surface-2: #171717;
  --surface-3: #101010;
  --ink: #f5f5ef;
  --muted: #9c9c95;
  --line: #2b2b2b;
  --line-strong: #f4f4ee;
  --inverse: #050505;
  --accent: #f4f4ee;
  --status-ok: #f4f4ee;
  --status-warn: #bdbdb7;
  --status-fast: #ffffff;
  --status-soft: #191919;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px),
    var(--bg);
  background-size: 64px 64px;
  font-family: "Helvetica Neue", Helvetica, Arial, ui-sans-serif, system-ui, sans-serif;
  font-weight: 300;
  transition: background-color 420ms ease, color 420ms ease;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 520ms;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

button,
input,
select {
  font: inherit;
}

button,
input,
select,
.control-band,
.metric-tile,
.panel,
.system-status,
.theme-toggle,
.switch-control,
.segmented,
.segment,
.badge,
.feed-item,
.stock-bar,
th,
td {
  transition:
    background-color 360ms ease,
    color 360ms ease,
    border-color 360ms ease,
    box-shadow 360ms ease,
    opacity 360ms ease;
}

.app-shell {
  width: min(1480px, calc(100% - 36px));
  margin: 0 auto;
  padding: 24px 0 34px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line-strong);
}

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

.eyebrow {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
  font-weight: 300;
}

h1 {
  max-width: 820px;
  font-size: clamp(2.35rem, 5vw, 5rem);
  line-height: 0.96;
}

h2 {
  font-size: 1rem;
}

.system-status,
.theme-toggle {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  gap: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 400;
}

.system-status {
  padding: 0 13px;
}

.theme-toggle {
  justify-content: center;
  width: 42px;
  padding: 0;
  cursor: pointer;
}

.theme-toggle:hover,
.ghost-action:hover,
.primary-action:hover {
  background: var(--ink);
  color: var(--inverse);
}

.theme-icon {
  position: relative;
  display: block;
  width: 17px;
  height: 17px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  transform: rotate(0deg);
  transition:
    border-radius 360ms ease,
    box-shadow 360ms ease,
    transform 420ms cubic-bezier(0.22, 1, 0.36, 1),
    background-color 360ms ease;
}

.theme-icon::before {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background:
    linear-gradient(currentColor, currentColor) center top / 1px 4px no-repeat,
    linear-gradient(currentColor, currentColor) center bottom / 1px 4px no-repeat,
    linear-gradient(90deg, currentColor, currentColor) left center / 4px 1px no-repeat,
    linear-gradient(90deg, currentColor, currentColor) right center / 4px 1px no-repeat;
  opacity: 0;
  transform: scale(0.7) rotate(35deg);
  transition: opacity 360ms ease, transform 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

body[data-theme="dark"] .theme-icon {
  border-radius: 50%;
  background: currentColor;
  box-shadow: inset -6px -2px 0 0 var(--surface);
  transform: rotate(-28deg);
}

body[data-theme="light"] .theme-icon::before {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.pulse {
  width: 8px;
  height: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: transparent;
}

.system-status.running .pulse {
  background: var(--ink);
}

.control-band {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto minmax(112px, 0.45fr) auto auto minmax(150px, 0.8fr) auto;
  align-items: end;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: var(--shadow);
}

.control-group {
  display: grid;
  gap: 7px;
}

label,
.switch-control span {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 500;
  text-transform: uppercase;
}

select,
input[type="text"],
input[list],
input[type="number"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
  font-weight: 300;
}

select:focus,
input:focus {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 1px var(--line-strong);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 82px);
  min-height: 42px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface-2);
}

.segment {
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  font-weight: 400;
  cursor: pointer;
}

.segment.active {
  background: var(--ink);
  color: var(--inverse);
}

.primary-action,
.ghost-action {
  min-height: 42px;
  border-radius: 3px;
  padding: 0 16px;
  font-weight: 400;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.primary-action {
  border: 1px solid var(--line-strong);
  background: var(--ink);
  color: var(--inverse);
}

.primary-action:hover {
  background: var(--surface);
  color: var(--ink);
}

.ghost-action {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.switch-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  gap: 12px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
}

.switch-control input {
  width: 38px;
  height: 20px;
  accent-color: var(--ink);
}

.speed-control input {
  width: 100%;
  accent-color: var(--ink);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.metric-tile {
  min-height: 94px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.04);
}

.metric-tile span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 400;
  text-transform: uppercase;
}

.metric-tile strong {
  display: block;
  margin-top: 10px;
  font-size: 2.55rem;
  font-weight: 300;
  line-height: 0.95;
}

.metric-tile.urgent strong {
  color: var(--ink);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.8fr);
  gap: 12px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.05);
}

.inventory-panel {
  grid-column: 1 / 2;
}

.chart-panel,
.intelligence-panel,
.feed-panel {
  grid-column: 2 / 3;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 68px;
  padding: 15px;
  border-bottom: 1px solid var(--line);
}

.panel-heading > span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
  text-align: right;
}

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

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

th,
td {
  padding: 14px 15px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
}

td {
  font-weight: 350;
}

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

tbody tr:hover {
  background: var(--surface-3);
}

.product-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.swatch {
  width: 10px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
}

.subtle {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 300;
}

.mini-tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin: 0 5px 5px 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 7px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 300;
}

.metadata-card {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.metadata-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.metadata-title span {
  font-size: 1.35rem;
  font-weight: 300;
}

.metadata-title strong {
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 6px 9px;
  font-size: 0.75rem;
  font-weight: 400;
}

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

.metadata-grid div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 9px;
  background: var(--surface-3);
}

.metadata-grid dt {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 400;
  text-transform: uppercase;
}

.metadata-grid dd {
  margin: 5px 0 0;
  font-size: 0.9rem;
  font-weight: 300;
  overflow-wrap: anywhere;
}

.reasoning-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.reasoning-strip span {
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 6px 8px;
  font-size: 0.76rem;
  font-weight: 300;
}

.decision-rationale {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.stock-bar {
  width: 100%;
  max-width: 160px;
  height: 8px;
  margin-top: 7px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface-2);
}

.stock-bar span {
  display: block;
  height: 100%;
  background: var(--ink);
  transition: width 420ms ease, background-color 360ms ease;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 0 9px;
  font-size: 0.74rem;
  font-weight: 400;
}

.badge.hold {
  background: var(--surface);
  color: var(--ink);
}

.badge.restock {
  background: var(--status-soft);
  color: var(--status-warn);
}

.badge.fast {
  background: var(--ink);
  color: var(--inverse);
}

.badge.alert {
  background: var(--surface-2);
  color: var(--ink);
  border-style: dashed;
}

.chart-panel canvas {
  display: block;
  width: 100%;
  height: 260px;
  padding: 12px;
}

.decision-feed {
  display: grid;
  max-height: 365px;
  gap: 8px;
  margin: 0;
  padding: 12px;
  overflow-y: auto;
  list-style: none;
}

.feed-item {
  display: grid;
  grid-template-columns: 6px 1fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-3);
}

.feed-marker {
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: transparent;
  transition: background-color 360ms ease, border-color 360ms ease;
}

.feed-item.restock .feed-marker {
  background: var(--muted);
}

.feed-item.fast .feed-marker {
  background: var(--ink);
}

.feed-item.alert .feed-marker {
  background: repeating-linear-gradient(
    45deg,
    var(--ink),
    var(--ink) 2px,
    transparent 2px,
    transparent 5px
  );
}

.feed-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 400;
}

.feed-action {
  margin-top: 5px;
  font-weight: 400;
}

.feed-reason {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 300;
}

@media (max-width: 1100px) {
  .control-band,
  .metrics-grid,
  .workspace {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inventory-panel,
  .intelligence-panel,
  .chart-panel,
  .feed-panel {
    grid-column: auto;
  }

  .inventory-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 680px);
    padding-top: 14px;
  }

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

.topbar-actions,
.system-status,
.theme-toggle {
    width: 100%;
  }

  .theme-toggle {
    width: 42px;
  }

  .control-band,
  .metrics-grid,
  .workspace {
    grid-template-columns: 1fr;
  }

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

  .metric-tile {
    min-height: 78px;
  }
}
