:root {
  --bg: #f4f2ed;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --ink: #18202a;
  --muted: #667085;
  --line: #d9dee5;
  --accent: #116a7b;
  --accent-2: #8a4f2b;
  --green: #1f7a4d;
  --red: #a13a32;
  --shadow: 0 18px 45px rgba(31, 41, 55, 0.08);
}

* {
  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;
}

.hidden {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  background: #17212c;
  color: #eef4f8;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #d8e8ea;
  color: #14333a;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #aebbc7;
  font-size: 13px;
  margin-top: 3px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #17212c;
}

.login-shell {
  width: min(100%, 430px);
}

.login-panel {
  background: #ffffff;
  border-radius: 8px;
  padding: 26px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
}

.compact-brand {
  color: var(--ink);
  margin-bottom: 24px;
}

.compact-brand span {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-status {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.user-strip {
  display: grid;
  gap: 6px;
  color: #d7e1ea;
  font-size: 13px;
}

.logout-button {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 7px;
  background: transparent;
  color: #ffffff;
  min-height: 34px;
  cursor: pointer;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  border: 0;
  color: #d7e1ea;
  background: transparent;
  text-align: left;
  padding: 11px 12px;
  border-radius: 7px;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: #263544;
  color: #ffffff;
}

.sidebar-note {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.05);
}

.sidebar-note span,
.sidebar-note strong {
  display: block;
}

.sidebar-note span {
  color: #aebbc7;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  margin-bottom: 6px;
}

.main {
  padding: 24px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 32px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(145px, 1fr)) auto repeat(2, minmax(150px, 1fr)) auto;
  gap: 10px;
  max-width: 920px;
  width: 100%;
  align-items: end;
}

label span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

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

.filter-button,
.sync-button,
.assign-button {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #ffffff;
  padding: 8px 16px;
  font-weight: 800;
  cursor: pointer;
}

.filter-button {
  min-width: 58px;
}

.filter-button.secondary {
  background: #eef5f6;
  color: #173f47;
  border: 1px solid #ccd7dc;
}

.filter-button.danger {
  background: #f8e9e7;
  color: var(--red);
  border: 1px solid #e8c5c1;
}

button:disabled,
.filter-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.sync-button {
  display: none;
}

.sync-button.visible {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.assign-control {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto;
  gap: 8px;
  max-width: 360px;
}

.assign-control select {
  min-height: 36px;
}

.assign-button {
  min-height: 36px;
  padding: 7px 12px;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric-strip article,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-strip article {
  padding: 17px 18px;
}

.metric-strip span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 7px;
}

.metric-strip strong {
  font-size: 28px;
  line-height: 1;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 18px;
  align-items: start;
}

.content-grid.settings-view {
  grid-template-columns: minmax(0, 1fr);
}

.content-grid.settings-view .side-panel {
  display: none;
}

.panel {
  min-width: 0;
}

.panel-heading {
  padding: 18px 18px 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-heading.compact {
  display: block;
}

.panel-heading h2 {
  margin-bottom: 5px;
  font-size: 18px;
}

.panel-heading p {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 0;
}

.toggle-group {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: var(--surface-2);
  flex: 0 0 auto;
}

.toggle {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 11px;
  cursor: pointer;
}

.toggle.active {
  background: var(--accent);
  color: #ffffff;
}

.item-sections {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.item-type-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

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

.section-title h3 {
  font-size: 16px;
  margin-bottom: 0;
}

.section-title span {
  color: var(--muted);
  font-size: 13px;
}

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

table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  color: var(--muted);
  background: #ffffff;
  font-size: 12px;
  text-transform: uppercase;
}

th:nth-child(1),
td:nth-child(1) {
  width: 5%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 13%;
}

th:nth-child(3),
td:nth-child(3) {
  width: 24%;
}

th:nth-child(4),
td:nth-child(4),
th:nth-child(5),
td:nth-child(5) {
  width: 10%;
}

th:nth-child(6),
td:nth-child(6) {
  width: 38%;
}

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

.number {
  text-align: right;
  white-space: nowrap;
}

.sku {
  font-weight: 800;
  color: #101828;
}

.item-cell {
  color: #344054;
}

.item-cell .sku {
  display: block;
  margin-bottom: 5px;
  font-size: 16px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.item-title {
  font-size: 14px;
  line-height: 1.35;
}

.thumb-wrap {
  position: relative;
  width: 112px;
  max-width: 100%;
}

.product-thumb {
  width: 112px;
  max-width: 100%;
  aspect-ratio: 1;
  border-radius: 7px;
  border: 1px solid #cbd5df;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.05)),
    var(--thumb-color, #d8e8ea);
  display: grid;
  place-items: center;
  overflow: hidden;
  object-fit: contain;
}

img.product-thumb {
  display: block;
  background: #ffffff;
  object-fit: contain;
}

.product-thumb span {
  color: #17212c;
  font-size: 15px;
  font-weight: 800;
  text-align: center;
  padding: 8px;
}

.thumb-fallback {
  display: none;
}

.thumb-fallback.visible {
  display: grid;
}

.image-error {
  display: none !important;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 100%;
}

.chip {
  border: 1px solid #ccd7dc;
  background: #eef5f6;
  color: #173f47;
  border-radius: 999px;
  padding: 4px 8px;
  white-space: nowrap;
  font-size: 12px;
}

.chip strong {
  font-weight: 900;
}

.chip.rank-1 {
  background: #f5c542;
  border-color: #d7a514;
  color: #231a00;
}

.chip.rank-2 {
  background: #d7dee8;
  border-color: #aeb8c5;
  color: #1f2937;
}

.chip.rank-3 {
  background: #c78642;
  border-color: #9b632b;
  color: #211003;
}

.source-mix {
  padding: 16px;
  display: grid;
  gap: 14px;
}

.coverage-box {
  margin: 0 16px 16px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #ffffff;
}

.coverage-box h3 {
  margin-bottom: 10px;
  font-size: 15px;
}

.cache-coverage {
  display: grid;
  gap: 10px;
}

.coverage-row {
  display: grid;
  gap: 3px;
}

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

.coverage-row span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.rule-box {
  display: none;
  margin: 0 16px 16px;
  padding: 14px;
  border-radius: 8px;
  background: #f7f2ec;
  border: 1px solid #e3d4c7;
}

.rule-box h3 {
  margin-bottom: 9px;
  font-size: 15px;
}

.rule-box p {
  color: #5f4b3b;
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 8px;
}

.rule-box p:last-child {
  margin-bottom: 0;
}

.mix-row {
  display: grid;
  gap: 7px;
}

.mix-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: #e4e9ee;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--accent-2);
}

.empty-state {
  padding: 34px;
  color: var(--muted);
  text-align: center;
}

.empty-state.compact {
  padding: 18px;
}

.settings-page {
  display: grid;
  gap: 16px;
}

.settings-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #ffffff;
}

.settings-card h3 {
  margin-bottom: 6px;
  font-size: 17px;
}

.settings-card p {
  color: var(--muted);
  margin-bottom: 0;
}

.access-card {
  grid-template-columns: 1fr;
}

.access-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(150px, 220px) auto;
  gap: 10px;
  align-items: end;
}

.access-list {
  display: grid;
  gap: 8px;
}

.access-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(130px, 170px) auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.access-row strong,
.access-row span {
  display: block;
}

.access-row span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: block;
    padding: 14px;
  }

  .brand,
  .sidebar-note {
    display: none;
  }

  .nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
  }

  .content-grid,
  .topbar {
    grid-template-columns: 1fr;
    display: grid;
  }

  .filters {
    max-width: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .settings-card,
  .access-form,
  .access-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 16px;
  }

  .filters,
  .metric-strip {
    grid-template-columns: 1fr;
  }

  .panel-heading,
  .section-title {
    display: grid;
  }

  h1 {
    font-size: 26px;
  }
}
