:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef4ff;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e2ef;
  --blue: #1264f6;
  --blue-dark: #0e4bb8;
  --green: #0f9f6e;
  --red: #d94343;
  --amber: #c27a11;
  --shadow: 0 18px 50px rgba(27, 39, 64, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(18, 100, 246, 0.08), transparent 38%),
    linear-gradient(225deg, rgba(15, 159, 110, 0.08), transparent 34%),
    var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: #101828;
  color: #eef4ff;
  display: flex;
  flex-direction: column;
  gap: 24px;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px 10px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
}

.brand-mark svg {
  width: 100%;
  height: 100%;
}

.brand-mark path:first-child {
  fill: #1264f6;
}

.brand-mark path:last-child {
  fill: none;
  stroke: #fff;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

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

.brand strong {
  font-size: 18px;
}

.brand span {
  margin-top: 4px;
  color: #b9c6d8;
  font-size: 12px;
}

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

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

.nav-item:hover,
.nav-item.active {
  background: #1d2939;
  color: #fff;
}

.nav-item.active {
  box-shadow: inset 3px 0 0 #3b82f6;
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  color: #a9c7ff;
  font-size: 17px;
}

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

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

.sidebar-foot span {
  color: #b9c6d8;
  font-size: 12px;
}

.sidebar-foot strong {
  margin-top: 5px;
  font-size: 14px;
}

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

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.15;
}

h2 {
  font-size: 17px;
  line-height: 1.25;
}

.topbar-actions,
.form-actions,
.toolbar,
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.ghost-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  transition: 0.18s ease;
}

.primary-button {
  padding: 0 16px;
  color: #fff;
  background: var(--blue);
  font-weight: 700;
}

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

.ghost-button {
  padding: 0 14px;
  color: var(--ink);
  background: #e8eef8;
  font-weight: 700;
}

.ghost-button:hover {
  background: #dce7f6;
}

.small {
  min-height: 36px;
  padding-inline: 12px;
  font-size: 14px;
}

.icon-button {
  width: 40px;
  padding: 0;
  color: var(--ink);
  background: #e8eef8;
  font-size: 20px;
}

.mobile-only {
  display: none;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 18px;
}

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

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 28px rgba(28, 45, 74, 0.06);
}

.metric-card {
  min-height: 132px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}

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

.metric-card strong {
  margin-top: 10px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1;
}

.metric-card small {
  margin-top: 12px;
  color: var(--green);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.75fr);
  gap: 18px;
}

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

.panel-head {
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.chart-panel canvas {
  width: 100%;
  max-height: 280px;
  display: block;
}

.task-list {
  display: grid;
  gap: 10px;
}

.task-item {
  padding: 12px;
  border-radius: 8px;
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
  background: #f3f7fd;
}

.task-item i {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 999px;
  background: var(--blue);
}

.task-item strong,
.task-item span {
  display: block;
}

.task-item span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid #edf1f7;
  text-align: left;
  white-space: nowrap;
}

th {
  color: #536178;
  background: #f7f9fc;
  font-size: 12px;
  font-weight: 700;
}

td {
  font-size: 14px;
}

.product-thumb {
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
  object-fit: cover;
  background: #f3f7fd;
}

.product-thumb.placeholder {
  display: grid;
  place-items: center;
  color: #536178;
  font-weight: 800;
}

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

.status-pill,
.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: #e9f7f1;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.tag.warn {
  background: #fff4df;
  color: var(--amber);
}

.tag.danger {
  background: #ffecec;
  color: var(--red);
}

.tag.neutral {
  background: #edf2f8;
  color: #536178;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

input,
select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(18, 100, 246, 0.12);
}

.toolbar input {
  min-width: min(360px, 100%);
  flex: 1;
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.inventory-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.inventory-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.inventory-card strong,
.inventory-card span {
  display: block;
}

.inventory-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.stock-bar {
  height: 8px;
  margin-top: 16px;
  border-radius: 999px;
  background: #e7edf6;
  overflow: hidden;
}

.stock-bar i {
  display: block;
  height: 100%;
  width: var(--stock-width);
  border-radius: inherit;
  background: var(--green);
}

.stock-bar.low i {
  background: var(--red);
}

.settings-panel {
  max-width: 920px;
}

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

label {
  display: grid;
  gap: 7px;
  color: #3a4659;
  font-size: 13px;
  font-weight: 700;
}

label input,
label select {
  width: 100%;
}

.settings-form .form-actions,
.form-grid .wide,
.modal-card .form-actions {
  grid-column: 1 / -1;
}

.secret-note {
  padding: 13px 14px;
  border: 1px dashed #9db8e8;
  border-radius: 8px;
  background: #f4f8ff;
}

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

.secret-note span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

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

.api-grid article {
  min-height: 104px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.api-grid strong,
.api-grid span {
  display: block;
}

.api-grid span {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  white-space: normal;
  word-break: break-word;
}

.modal {
  width: min(680px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(10, 18, 32, 0.48);
}

.modal-card {
  padding: 20px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-head .icon-button {
  flex: 0 0 40px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 48px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #101828;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 40;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.backdrop {
  display: none;
}

@media (max-width: 1080px) {
  .metric-grid,
  .api-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(288px, 86vw);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(10, 18, 32, 0.44);
    z-index: 15;
  }

  .mobile-only {
    display: inline-grid;
  }

  .main {
    padding: 18px 14px 24px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .topbar-actions button {
    flex: 1;
  }

  .metric-grid,
  .settings-form,
  .form-grid,
  .api-grid {
    grid-template-columns: 1fr;
  }

  .panel,
  .metric-card {
    padding: 14px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-head button,
  .panel-head select {
    width: 100%;
  }

  .toolbar input,
  .toolbar select {
    width: 100%;
  }

  table {
    min-width: 680px;
  }
}

@media (max-width: 420px) {
  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .primary-button,
  .ghost-button {
    width: 100%;
  }
}
