:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --panel-soft: #fafafc;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e3e8;
  --blue: #0071e3;
  --blue-dark: #0062c4;
  --green: #0a7d33;
  --green-bg: #e7f6ec;
  --red: #c4271f;
  --red-bg: #fdecea;
  --amber: #8a5a00;
  --amber-bg: #fff4d6;
  --gray-bg: #f0f0f2;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 30px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f11;
    --panel: #1a1a1d;
    --panel-soft: #212125;
    --text: #f5f5f7;
    --muted: #9a9aa0;
    --line: #2e2e33;
    --blue: #2997ff;
    --blue-dark: #1a86ec;
    --green: #4cd07d;
    --green-bg: rgba(76, 208, 125, 0.14);
    --red: #ff7a72;
    --red-bg: rgba(255, 122, 114, 0.14);
    --amber: #f0c05a;
    --amber-bg: rgba(240, 192, 90, 0.14);
    --gray-bg: #2a2a2f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

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

.app {
  min-height: 100vh;
}

.boot {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--blue);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Auth ---------- */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 12px;
  background: linear-gradient(160deg, #2f9bff, #0062c4);
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 6px 16px rgba(0, 113, 227, 0.3);
}

.brand-mark svg {
  width: 24px;
  height: 24px;
  display: block;
}

.auth-card h1 {
  font-size: 24px;
  letter-spacing: -0.02em;
}

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

.auth-card form {
  margin-top: 8px;
}

.auth-note {
  margin-top: 18px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}

.link-btn {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 0;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 12.5px;
  text-decoration: underline;
  cursor: pointer;
}

.link-btn:hover {
  color: var(--text);
}

/* ---------- Layout ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}

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

.brand h1 {
  font-size: 18px;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.brand .sub {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 26px 24px 90px;
}

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

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
}

.stat .label {
  font-size: 12.5px;
  color: var(--muted);
}

.stat .value {
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.03em;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.stat .value.green {
  color: var(--green);
}

.stat .value.red {
  color: var(--red);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-head h2 {
  font-size: 16px;
  letter-spacing: -0.01em;
}

.panel-head .hint {
  color: var(--muted);
  font-size: 12.5px;
}

.add-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.add-row .grow {
  flex: 1 1 320px;
}

.add-row .name {
  flex: 0 1 200px;
}

/* ---------- Forms ---------- */

.field {
  display: block;
  margin-bottom: 14px;
}

.field > span {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 18%, transparent);
}

.add-row .field {
  margin-bottom: 0;
}

/* ---------- Store picker ---------- */

.store-picker {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}

.store-search {
  display: flex;
  gap: 8px;
  align-items: center;
}

.store-search input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  outline: none;
}

.store-search input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 18%, transparent);
}

.store-results {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.store-result {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 10px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 12.5px;
  line-height: 1.35;
  text-align: left;
}

.store-result:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.store-result .sub {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px 5px 11px;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-size: 12px;
}

.chip button {
  background: none;
  border: 0;
  color: inherit;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
  opacity: 0.85;
}

.chip button:hover {
  opacity: 1;
}

.store-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.store-chip {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--gray-bg);
  color: var(--muted);
}

.store-chip.in {
  background: var(--green-bg);
  color: var(--green);
}

.store-chip.out {
  background: var(--red-bg);
  color: var(--red);
}

.store-chip.warn {
  background: var(--amber-bg);
  color: var(--amber);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--gray-bg);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: color-mix(in srgb, var(--gray-bg) 80%, var(--text) 8%);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}

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

.btn-ghost {
  background: transparent;
  border-color: var(--line);
}

.btn-ghost:hover {
  background: var(--panel-soft);
}

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: transparent;
}

.btn-danger:hover {
  background: var(--red-bg);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12.5px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
}

.icon-btn:hover {
  background: var(--panel-soft);
}

/* ---------- Products ---------- */

.products {
  display: grid;
  gap: 14px;
}

.product-card {
  display: flex;
  gap: 18px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.product-thumb {
  width: 104px;
  height: 104px;
  flex: none;
  border-radius: 14px;
  object-fit: contain;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.product-thumb.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 28px;
}

.product-body {
  flex: 1;
  min-width: 0;
}

.product-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.product-title {
  font-size: 16.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.product-title a {
  color: inherit;
}

.product-title a:hover {
  color: var(--blue);
  text-decoration: none;
}

.pill {
  margin-left: auto;
  flex: none;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--gray-bg);
  color: var(--muted);
  white-space: nowrap;
}

.pill.in {
  background: var(--green-bg);
  color: var(--green);
}

.pill.out {
  background: var(--red-bg);
  color: var(--red);
}

.pill.warn {
  background: var(--amber-bg);
  color: var(--amber);
}

.meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12.5px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.meta .dot::before {
  content: "·";
  margin-right: 8px;
}

.note {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--amber);
  background: var(--amber-bg);
  border-radius: 9px;
  padding: 6px 10px;
  display: inline-block;
}

.history {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 34px;
  margin: 12px 0 14px;
}

.history .bar {
  width: 9px;
  border-radius: 3px;
  background: var(--gray-bg);
  min-height: 4px;
}

.history .bar.in {
  background: var(--green);
}

.history .bar.out {
  background: color-mix(in srgb, var(--muted) 35%, transparent);
}

.history-empty {
  color: var(--muted);
  font-size: 12px;
  margin: 12px 0 14px;
}

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

.auto-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--muted);
  user-select: none;
  cursor: pointer;
}

.auto-toggle input {
  accent-color: var(--blue);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.empty-state strong {
  display: block;
  color: var(--text);
  font-size: 15px;
  margin-bottom: 6px;
}

.empty-state code {
  display: inline-block;
  margin-top: 10px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}

/* ---------- Push log ---------- */

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

.log-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 11px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  font-size: 12.5px;
}

.log-item .mark {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  color: #fff;
  background: var(--green);
}

.log-item.fail .mark {
  background: var(--red);
}

.log-item .time {
  margin-left: auto;
  color: var(--muted);
  white-space: nowrap;
  font-size: 12px;
}

.log-item .detail {
  color: var(--muted);
  margin-top: 2px;
  overflow-wrap: anywhere;
}

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

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fade 0.15s ease;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.modal {
  width: 100%;
  max-width: 540px;
  max-height: 88vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3);
  padding: 22px;
  animation: pop 0.16s ease;
}

@keyframes pop {
  from {
    transform: translateY(6px) scale(0.99);
    opacity: 0;
  }
}

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

.modal-head h2 {
  font-size: 18px;
  letter-spacing: -0.02em;
}

.modal-head .icon-btn {
  margin-left: auto;
}

.modal hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 22px 0;
}

.modal h3 {
  font-size: 14.5px;
  margin-bottom: 10px;
}

.modal .hint {
  color: var(--muted);
  font-size: 12.5px;
  margin: -6px 0 12px;
  line-height: 1.6;
}

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

.code-row code {
  flex: 1 1 240px;
  padding: 9px 11px;
  border-radius: 9px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.settings-status {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: -4px;
  margin-bottom: 12px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(560px, calc(100vw - 40px));
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(29, 29, 31, 0.92);
  color: #fff;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.18s ease;
}

.toast.error {
  background: #b3261e;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

/* ---------- Responsive ---------- */

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

  .container {
    padding: 18px 16px 70px;
  }

  .topbar-inner {
    padding: 10px 16px;
    flex-wrap: wrap;
  }

  .brand .sub {
    display: none;
  }

  .product-card {
    gap: 14px;
    padding: 14px;
  }

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

  .product-head {
    flex-wrap: wrap;
  }

  .pill {
    margin-left: 0;
  }

  .auth-card {
    padding: 24px;
  }
}
