:root {
  color-scheme: light;
  --ink: #1d2433;
  --muted: #667085;
  --line: #d8dee8;
  --panel: #ffffff;
  --page: #f4f6f8;
  --brand: #176b87;
  --brand-dark: #0f4b60;
  --accent: #d97706;
  --good: #16804f;
  --danger: #b42318;
  --soft-blue: #e8f4f7;
  --soft-amber: #fff4df;
  --soft-green: #e9f7ef;
  --shadow: 0 14px 34px rgba(29, 36, 51, 0.09);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  background: #17212b;
  color: #f9fbfc;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #f5b84b;
  color: #17212b;
  display: grid;
  place-items: center;
  font-weight: 800;
}

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

.brand span {
  margin-top: 4px;
  color: #bfd0d8;
  font-size: 12px;
  line-height: 1.35;
}

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

.nav-item {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d9e4e9;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  text-align: left;
}

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

.icon {
  width: 24px;
  text-align: center;
  font-size: 19px;
}

.store-health {
  margin-top: auto;
  display: grid;
  gap: 13px;
}

.section-label,
.eyebrow,
.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.store-health .section-label {
  color: #b7c9d2;
}

.health-row {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  color: #d9e4e9;
}

meter {
  width: 100%;
  height: 8px;
}

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

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

.eyebrow {
  margin: 0 0 6px;
}

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

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.2;
}

.top-actions,
.dialog-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.primary-button,
.ghost-button,
.icon-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 15px;
  background: #fff;
  color: var(--ink);
}

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

.primary-button:hover {
  background: var(--brand-dark);
}

.ghost-button:hover,
.icon-button:hover {
  border-color: #a7b2c1;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-card,
.rules-grid article,
.case-table-wrap,
.case-detail,
.rules-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 18px;
  display: grid;
  gap: 8px;
}

.metric-card strong {
  font-size: 30px;
  line-height: 1;
}

.metric-card small {
  color: var(--muted);
  line-height: 1.4;
}

.metric-card.warning {
  background: var(--soft-amber);
}

.metric-card.good {
  background: var(--soft-green);
}

.metric-card.danger {
  background: #ffeceb;
}

.insight-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

.insight-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.panel-title h2 {
  font-size: 18px;
  margin-bottom: 0;
}

.count-badge {
  min-width: 34px;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: #ffe7e3;
  color: var(--danger);
  font-weight: 800;
}

.alert-list,
.bar-list,
.sku-list {
  display: grid;
  gap: 10px;
}

.alert-item,
.sku-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  display: grid;
  gap: 5px;
  background: #fbfcfd;
}

.alert-item strong,
.sku-item strong {
  font-size: 14px;
}

.alert-item span,
.sku-item span,
.bar-row span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

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

.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 700;
}

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

.bar-fill {
  height: 100%;
  min-width: 4px;
  background: var(--brand);
}

.empty-mini {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  padding: 16px;
  text-align: center;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 150px 170px 150px 130px 140px;
  gap: 10px;
  margin-bottom: 14px;
}

.search-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
}

.search-box input {
  border: 0;
  outline: 0;
  width: 100%;
  min-width: 0;
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

select,
input {
  min-height: 42px;
  padding: 0 10px;
}

textarea {
  padding: 10px;
  resize: vertical;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.55fr);
  gap: 16px;
  align-items: start;
}

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

.case-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1180px;
}

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

.case-table th {
  color: var(--muted);
  font-size: 12px;
  background: #f9fafb;
}

.case-table tr {
  transition: background 0.15s ease;
}

.case-table tbody tr:hover,
.case-table tbody tr.selected {
  background: var(--soft-blue);
}

.pill {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.high {
  background: #ffe7e3;
  color: var(--danger);
}

.pill.medium {
  background: #fff4df;
  color: #a15c00;
}

.pill.low {
  background: #e9f7ef;
  color: var(--good);
}

.platform {
  font-weight: 800;
}

.company-tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 8px;
  background: #eef6f7;
  color: var(--brand-dark);
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.amount {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.loss {
  color: var(--danger);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.loss.zero {
  color: var(--good);
}

.case-detail {
  min-height: 460px;
  padding: 18px;
  position: sticky;
  top: 20px;
}

.empty-detail {
  min-height: 420px;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  color: var(--muted);
  padding: 28px;
}

.empty-icon {
  font-size: 48px;
  color: #a9b5c2;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 16px;
}

.detail-head h2 {
  font-size: 20px;
  margin-bottom: 4px;
}

.detail-meta {
  color: var(--muted);
  font-size: 13px;
}

.detail-block {
  margin-bottom: 16px;
}

.detail-block h3 {
  margin-bottom: 8px;
  font-size: 14px;
}

.detail-block p {
  color: #3b4658;
  line-height: 1.55;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.detail-stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfd;
}

.detail-stat span,
.quick-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.detail-stat strong {
  font-size: 14px;
}

.quick-close {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.quick-close h3 {
  font-size: 14px;
  margin-bottom: 10px;
}

.quick-close .detail-actions {
  margin-top: 0;
}

.warehouse-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
}

.form-section-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

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

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

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

.photo-grid figure {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin: 0;
  overflow: hidden;
}

.photo-grid img {
  aspect-ratio: 4 / 3;
  display: block;
  object-fit: cover;
  width: 100%;
}

.photo-grid figcaption {
  color: #394456;
  font-size: 12px;
  line-height: 1.35;
  padding: 8px;
  word-break: break-word;
}

.mini-danger {
  border: 0;
  border-top: 1px solid var(--line);
  background: #fff5f4;
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
  min-height: 32px;
  width: 100%;
}

.danger-zone {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
}

.danger-zone small {
  color: var(--muted);
  line-height: 1.45;
}

.danger-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid #f2b8b5;
  background: #fff5f4;
  color: var(--danger);
  font-weight: 800;
  padding: 0 15px;
}

.danger-button:hover {
  border-color: var(--danger);
}

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

.check-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #3b4658;
  font-size: 14px;
}

.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.rules-panel {
  padding: 22px;
}

.rules-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 14px;
}

.rules-grid article {
  padding: 18px;
  box-shadow: none;
}

.rules-grid h3 {
  font-size: 16px;
}

.rules-grid p {
  color: #4e5b6d;
  line-height: 1.6;
  margin-bottom: 0;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  width: min(760px, calc(100vw - 28px));
  box-shadow: 0 28px 80px rgba(29, 36, 51, 0.25);
}

dialog::backdrop {
  background: rgba(23, 33, 43, 0.55);
}

.case-form {
  padding: 22px;
  display: grid;
  gap: 16px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 22px;
}

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

label {
  display: grid;
  gap: 7px;
  color: #394456;
  font-size: 14px;
  font-weight: 700;
}

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

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

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

  .store-health {
    display: none;
  }

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

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

  .case-detail {
    position: static;
  }
}

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

  .topbar,
  .rules-header {
    flex-direction: column;
  }

  .top-actions,
  .dialog-actions {
    width: 100%;
  }

  .top-actions button,
  .dialog-actions button {
    flex: 1;
  }

  h1 {
    font-size: 24px;
  }

  .dashboard-grid,
  .insight-grid,
  .toolbar,
  .rules-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
}
