:root {
  --bg: #f5f7f9;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7785;
  --line: #dce3ea;
  --dark: #17212b;
  --blue: #2563eb;
  --green: #138a5b;
  --red: #c2413c;
  --amber: #a86d16;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

a {
  color: inherit;
}

.sidebar {
  width: 220px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  background: var(--dark);
  color: #fff;
}

.brand {
  padding: 4px 6px 22px;
}

.brand strong {
  display: block;
  font-size: 22px;
  letter-spacing: 0;
}

.brand span,
.account span {
  color: #aab6c4;
}

nav {
  display: grid;
  gap: 6px;
}

nav a {
  padding: 10px 12px;
  border-radius: 8px;
  color: #d9e2ec;
  text-decoration: none;
}

nav a.active,
nav a:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.account {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 14px 6px 0;
}

.account a {
  color: #fff;
  text-decoration: none;
}

.shell {
  flex: 1;
  min-width: 0;
  padding: 28px;
}

.topbar,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

.topbar p,
.panel-head span,
label span {
  color: var(--muted);
}

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}

button:hover {
  filter: brightness(0.95);
}

.button-link:hover {
  filter: brightness(0.95);
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.filter-form,
.inline-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-form {
  margin: 18px 0;
}

.filter-form input {
  width: 150px;
}

.notice {
  margin: 16px 0;
  padding: 11px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.notice.success {
  border-color: #b7dec9;
  color: var(--green);
}

.notice.error {
  border-color: #efc0bf;
  color: var(--red);
}

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

.form-grid {
  grid-template-columns: repeat(2, minmax(260px, 1fr));
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(23, 33, 43, 0.04);
}

.metric {
  padding: 18px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

.metric.income strong,
.amount.income {
  color: var(--green);
}

.metric.expend strong,
.amount.expend {
  color: var(--red);
}

.metric.profit strong {
  color: var(--blue);
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(300px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.chart-panel {
  min-width: 0;
}

.pie-chart-wrap {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  margin-top: 18px;
}

.pie-chart {
  position: relative;
  width: 180px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--chart-bg);
  box-shadow: inset 0 0 0 1px rgba(23, 33, 43, 0.06);
}

.pie-chart::after {
  position: absolute;
  inset: 43px;
  content: "";
  border-radius: 50%;
  background: var(--panel);
  box-shadow: 0 0 0 1px rgba(23, 33, 43, 0.04);
}

.pie-chart span {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
}

.chart-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  min-width: 0;
}

.legend-row {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr);
  align-items: center;
  gap: 4px 7px;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
}

.legend-row strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-row > span:not(.legend-dot) {
  grid-column: 2;
}

.legend-row em {
  grid-column: 2;
  color: var(--text);
  font-style: normal;
  font-weight: 800;
  text-align: left;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.chart-empty {
  padding: 40px 0;
}

.panel {
  padding: 18px;
  margin-bottom: 18px;
}

.stack-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.narrow-form {
  max-width: 520px;
}

.text-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 700;
}

label {
  display: grid;
  gap: 6px;
}

.table-wrap {
  margin-top: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.compact table {
  min-width: 620px;
}

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

th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
}

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

.empty {
  text-align: center;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-width: 44px;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}

.pill.income {
  background: #eaf7f0;
  color: var(--green);
}

.pill.expend {
  background: #fff0ee;
  color: var(--red);
}

.link-danger {
  padding: 6px 8px;
  background: transparent;
  color: var(--red);
}

.ghost {
  background: #eef3f7;
  color: var(--text);
}

.muted {
  background: #f5f7f9;
  color: var(--muted);
}

.small-btn {
  padding: 7px 10px;
  font-size: 13px;
}

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

.product-table-wrap table {
  min-width: 900px;
}

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

.product-cell small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.thumb,
.detail-cover {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
  background: #f8fafc;
}

.detail-cover {
  width: 96px;
  height: 96px;
}

.empty-thumb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
}

.sku-count {
  display: inline-flex;
  min-width: 36px;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 8px;
  background: #eef3f7;
  font-weight: 800;
}

.product-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.product-title-cell h2 {
  margin-bottom: 6px;
}

.product-title-cell p {
  color: var(--muted);
}

.sku-edit-table {
  min-width: 1040px;
}

.sku-edit-table input {
  min-width: 110px;
}

.sku-edit-table input[type="checkbox"],
.delete-check input {
  width: auto;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.sku-image-picker {
  position: relative;
  display: inline-flex;
  cursor: pointer;
}

.sku-image-picker .thumb {
  transition: border-color 0.15s ease, filter 0.15s ease;
}

.sku-image-picker:hover .thumb {
  border-color: var(--blue);
  filter: brightness(0.92);
}

.sku-image-hint {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  border-radius: 6px;
  padding: 2px 4px;
  background: rgba(23, 33, 43, 0.72);
  color: #fff;
  font-size: 12px;
  text-align: center;
  pointer-events: none;
}

.delete-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.new-sku-row {
  background: #fbfcfd;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  padding: 12px 0;
  background: linear-gradient(to top, var(--bg) 70%, rgba(245, 247, 249, 0));
}

.category-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.category-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.category-readonly {
  justify-content: flex-start;
  min-height: 42px;
  font-weight: 700;
}

.category-edit-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.category-edit-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.login-page {
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(420px, calc(100vw - 32px));
}

.login-panel {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(23, 33, 43, 0.1);
}

.login-title {
  margin-bottom: 22px;
}

.login-title span {
  color: var(--blue);
  font-weight: 900;
}

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

@media (max-width: 860px) {
  body {
    display: block;
  }

  .sidebar {
    width: auto;
    min-height: auto;
  }

  .shell {
    padding: 18px;
  }

  .topbar,
  .panel-head,
  .filter-form,
  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-form input {
    width: 100%;
  }

  .metrics,
  .form-grid,
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .pie-chart-wrap {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .chart-legend {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .legend-row {
    grid-template-columns: 9px minmax(0, 1fr);
    align-items: start;
  }

  .legend-row > span:not(.legend-dot) {
    grid-column: 2;
  }

  .legend-row em {
    grid-column: 2;
    text-align: left;
  }
}
