:root {
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-2: #eef4f0;
  --ink: #1f2724;
  --muted: #66736f;
  --line: #d9e1dc;
  --green: #28735c;
  --green-soft: #e0f0e9;
  --amber: #a86514;
  --amber-soft: #fff0d6;
  --red: #b3343f;
  --red-soft: #fae5e7;
  --blue: #2f6690;
  --blue-soft: #dfeef7;
  --shadow: 0 18px 42px rgba(31, 39, 36, 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;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  background: #17211e;
  color: #f2f7f4;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand-block {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: #2e6f57;
  border-radius: 8px;
  font-weight: 800;
}

.brand-name {
  font-weight: 760;
}

.brand-subtitle,
.panel-note {
  color: rgba(242, 247, 244, 0.66);
  font-size: 12px;
  line-height: 1.35;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  text-align: left;
  color: rgba(242, 247, 244, 0.78);
  background: transparent;
}

.nav-item:hover,
.nav-item.is-active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.nav-subitem {
  min-height: 34px;
  margin-left: 18px;
  padding-left: 14px;
  font-size: 13px;
  color: rgba(242, 247, 244, 0.68);
}

.sidebar-panel {
  margin-top: auto;
  padding: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.panel-label {
  font-size: 11px;
  text-transform: uppercase;
  color: rgba(242, 247, 244, 0.58);
  font-weight: 700;
}

.marketplace {
  margin: 6px 0;
  font-weight: 720;
}

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

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

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

h1 {
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

.topbar p,
.section-header p,
.metric-copy {
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.45;
}

.topbar-actions,
.section-header,
.status-tabs {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.secondary-button,
.icon-button,
.text-button {
  min-height: 36px;
  border-radius: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.primary-button {
  background: var(--green);
  border-color: var(--green);
  color: #ffffff;
  font-weight: 700;
}

.compact-button {
  width: fit-content;
  margin-top: 4px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--green);
  font-weight: 700;
}

.filters {
  display: grid;
  grid-template-columns: 150px 180px 160px minmax(220px, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.history-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 220px;
  gap: 12px;
  margin-bottom: 14px;
}

.product-form {
  display: grid;
  grid-template-columns: 120px 150px 150px 150px minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.history-layout {
  display: grid;
  gap: 14px;
}

.history-nav {
  display: flex;
  gap: 8px;
}

.history-nav button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 800;
}

.history-nav button.is-active {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-soft);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

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

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

.metric-card {
  padding: 18px;
  border-top: 4px solid var(--blue);
}

.metric-card.critical {
  border-top-color: var(--red);
}

.metric-card.warning {
  border-top-color: var(--amber);
}

.metric-card.healthy {
  border-top-color: var(--green);
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-value {
  margin-top: 8px;
  font-size: 34px;
  font-weight: 820;
}

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

.workspace {
  min-width: 0;
  padding: 18px;
}

.section-header {
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-header.compact {
  margin-bottom: 10px;
}

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

.clear-state {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  border-radius: 8px;
  background: var(--green-soft);
}

.clear-state strong {
  color: var(--green);
}

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

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

.history-table {
  min-width: 1080px;
}

.product-table {
  min-width: 1080px;
}

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

.product-table th,
.product-table td {
  padding: 4px 8px;
  font-size: 12px;
}

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

tbody tr {
  border-left: 4px solid transparent;
}

tbody tr:hover,
tbody tr.is-selected {
  background: #f8fbf9;
}

tbody tr.is-selected {
  border-left-color: var(--green);
}

.product-cell {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: center;
}

.mini-thumb,
.product-thumb {
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.mini-thumb {
  width: 34px;
  height: 34px;
}

.product-title {
  font-weight: 760;
  font-size: 12px;
  line-height: 1.2;
}

.product-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.product-actions .text-button {
  min-height: 24px;
  padding: 0 4px;
  font-size: 11px;
}

.compact-action {
  min-height: 24px;
  padding: 0 8px;
  font-size: 11px;
}

.danger-action {
  color: var(--red);
}

.product-meta,
.detail-asin,
.change-meta,
.change-time,
.time-cell span {
  color: var(--muted);
  font-size: 12px;
}

.time-cell {
  display: grid;
  gap: 2px;
}

.time-cell strong {
  font-size: 13px;
}

.history-row td {
  padding-top: 8px;
  padding-bottom: 8px;
}

.history-row {
  cursor: pointer;
}

.history-value {
  display: block;
  width: 100%;
  max-width: 320px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-detail-row td {
  padding: 0 10px 10px;
  background: #f8fbf9;
}

.history-detail {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.history-detail span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.history-detail p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.history-diff {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.scan-log {
  display: grid;
  gap: 6px;
}

.scan-log-row {
  display: grid;
  grid-template-columns: 180px 110px 1fr 1fr 110px;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  font-size: 13px;
}

.scan-log-row span {
  color: var(--muted);
}

.scan-log-row.has-errors {
  cursor: pointer;
}

.scan-log-row.has-errors:hover {
  border-color: var(--amber);
  background: var(--amber-soft);
}

.scan-log-detail {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: var(--surface);
  font-size: 12px;
}

.scan-log-error {
  display: grid;
  grid-template-columns: 120px 120px 90px 1fr;
  gap: 8px;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 760;
}

.pill.critical {
  background: var(--red-soft);
  color: var(--red);
}

.pill.warning {
  background: var(--amber-soft);
  color: var(--amber);
}

.pill.healthy {
  background: var(--green-soft);
  color: var(--green);
}

.pill.info {
  background: var(--blue-soft);
  color: var(--blue);
}

.pill.review {
  background: var(--green-soft);
  color: var(--green);
}

.status-dot {
  width: 10px;
  height: 10px;
  display: inline-block;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.status-dot.is-off {
  background: var(--muted);
  box-shadow: 0 0 0 3px var(--surface-2);
}

.text-button:disabled {
  color: var(--muted);
  cursor: default;
  opacity: 0.6;
}

.review-toggle {
  min-height: 28px;
  min-width: 86px;
  border: 1px solid var(--blue);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.review-toggle.is-reviewed {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
}

.review-toggle:disabled {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--muted);
  cursor: default;
}

.detail-panel {
  min-width: 0;
  padding: 18px;
}

.detail-product {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.product-thumb {
  width: 84px;
  height: 84px;
}

.detail-brand {
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 16px;
}

.detail-stats div {
  padding: 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 4px;
}

.detail-stats div:nth-child(2n) {
  border-right: 0;
}

.detail-stats div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.detail-stats span {
  color: var(--muted);
  font-size: 12px;
}

.change-card {
  padding-top: 4px;
}

.change-list,
.audit-log {
  display: grid;
  gap: 6px;
}

.change-item,
.audit-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fbfcfb;
}

.change-title,
.audit-title,
.change-summary {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  font-weight: 760;
}

.change-summary {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.change-summary::before {
  content: "+";
  width: 16px;
  color: var(--green);
  font-weight: 800;
}

.change-item.is-open .change-summary::before,
.audit-item.is-open .change-summary::before {
  content: "-";
}

.change-summary span:first-of-type {
  flex: 1;
}

.change-summary-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.audit-title {
  font-size: 13px;
}

.change-time {
  margin-top: 3px;
  font-weight: 700;
}

.change-item .change-meta,
.change-item .diff,
.audit-item .change-meta,
.audit-item .diff {
  display: none;
}

.change-item.is-open .change-meta,
.change-item.is-open .diff,
.audit-item.is-open .change-meta,
.audit-item.is-open .diff {
  display: grid;
}

.change-item.is-open .change-meta,
.audit-item.is-open .change-meta {
  margin-top: 6px;
}

.diff {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.4;
}

.old-value,
.new-value {
  padding: 7px 8px;
  border-radius: 8px;
}

.old-value {
  background: var(--red-soft);
}

.new-value {
  background: var(--green-soft);
}

.empty-state {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfb;
  font-size: 13px;
}

.lower-panel {
  margin-top: 18px;
}

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

.settings-grid div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.settings-grid span {
  color: var(--muted);
  font-size: 12px;
}

.is-hidden {
  display: none;
}

.status-tabs {
  padding: 4px;
  border-radius: 8px;
  background: var(--surface-2);
}

.status-tabs button {
  min-height: 32px;
  border: 0;
  border-radius: 7px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
}

.status-tabs button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(31, 39, 36, 0.08);
}

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

  .sidebar {
    position: static;
    min-height: auto;
  }

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

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

@media (max-width: 760px) {
  .main-content {
    padding: 18px;
  }

  .topbar,
  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .filters,
  .history-filters,
  .product-form,
  .content-grid,
  .metric-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

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

  .history-detail,
  .history-diff,
  .scan-log-error,
  .scan-log-row {
    grid-template-columns: 1fr;
  }

  .nav-list {
    grid-template-columns: 1fr 1fr;
  }

  h1 {
    font-size: 25px;
  }
}
