:root {
  --page: #e8edf4;
  --phone: #f7f8fb;
  --card: #ffffff;
  --text: #182033;
  --muted: #7a8494;
  --line: #e2e7ef;
  --blue: #1677ff;
  --green: #18a058;
  --red: #d93025;
  --card-radius: 14px;
  --wallet-bg: linear-gradient(135deg, #172033, #24405f);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--page);
  color: var(--text);
}

.phone {
  width: min(430px, 100vw);
  height: min(900px, 100vh);
  background: var(--phone);
  overflow: auto;
  border: 10px solid #111827;
  border-radius: 34px;
  box-shadow: 0 22px 70px rgba(23, 32, 51, 0.25);
}

.screen {
  min-height: 100%;
  padding: 16px;
}

.app-shell {
  padding-bottom: 86px;
}

.hidden {
  display: none;
}

.login-hero {
  padding: 58px 6px 24px;
}

.app-icon {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 16px;
  background: var(--green);
  color: #fff;
  font-size: 28px;
  font-weight: 800;
}

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

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

.login-hero p {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.6;
}

.login-card,
.card,
.user-strip,
.inventory-top,
.stats article {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
}

.login-card {
  display: grid;
  gap: 15px;
  padding: 18px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

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

textarea {
  resize: vertical;
  min-height: 118px;
}

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

button.light {
  background: #eaf2ff;
  color: #0f5fd3;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.compact-header {
  position: sticky;
  top: 0;
  z-index: 4;
  padding: 10px 0 12px;
  background: var(--phone);
}

.app-title {
  margin-bottom: 6px;
  color: var(--text);
  font-size: 20px;
  line-height: 1.2;
  font-weight: 900;
}

.app-header span,
.user-strip span,
.card-title span,
.stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.app-header h2 {
  margin-top: 4px;
  font-size: 24px;
}

.app-header button,
.user-strip button {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 9px 12px;
  font-weight: 600;
}

.user-strip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-avatar {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #eaf2ff;
  color: #0f5fd3;
  font-weight: 900;
}

.user-avatar.large {
  width: 58px;
  height: 58px;
  font-size: 22px;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

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

.tab-page {
  display: none;
}

.tab-page.active {
  display: block;
}

.warehouse-card {
  margin-bottom: 0;
}

.profile-card {
  margin-top: 0;
}

.wallet-card {
  margin-top: 12px;
  padding: 18px;
  border-radius: 16px;
  background: var(--wallet-bg);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.wallet-card span {
  display: block;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
}

.wallet-card strong {
  display: block;
  margin-top: 8px;
  font-size: 34px;
  line-height: 1;
}

.wallet-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
}

.wallet-meta b {
  font-size: 15px;
}

.wallet-link {
  width: 100%;
  margin-top: 14px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.bill-card {
  margin-top: 0;
}

.bill-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.back-btn {
  padding: 8px 10px;
  background: #eef4ff;
  color: #0f5fd3;
}

.bill-header h3 {
  margin-bottom: 3px;
}

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

.bill-summary {
  padding: 16px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.bill-summary span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.bill-summary strong {
  display: block;
  margin-top: 6px;
  font-size: 30px;
}

.bill-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.bill-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.bill-row span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.bill-row b {
  color: var(--blue);
  font-size: 18px;
  white-space: nowrap;
}

.profile-head {
  display: flex;
  align-items: center;
  gap: 13px;
}

.profile-head h3 {
  margin-bottom: 4px;
  font-size: 19px;
}

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

.profile-avatar-preview {
  width: 108px;
  height: 108px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fbfcff;
  color: var(--muted);
  font-size: 13px;
}

.profile-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.logout-wide {
  width: 100%;
  margin-top: 12px;
  background: #fff;
  color: var(--red);
  border: 1px solid #f4c7c3;
}

.tabbar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px -4px -4px;
  padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(247, 248, 251, 0.96);
  backdrop-filter: blur(10px);
}

.tabbar button {
  padding: 10px 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
}

.tabbar button.active {
  background: #eaf2ff;
  color: #0f5fd3;
  border-color: #cfe0ff;
}

.inventory-top {
  padding: 12px;
  margin-bottom: 10px;
}

.stock-groups {
  display: grid;
  gap: 8px;
}

.stock-card {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
}

.stock-card-title {
  margin-bottom: 7px;
  font-weight: 800;
  font-size: 13px;
  line-height: 1.2;
}

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

.color-chip {
  min-width: 0;
  padding: 6px;
  border-radius: 9px;
  background: #fff;
  border: 1px solid var(--line);
}

.stock-photo {
  width: 100%;
  height: 58px;
  overflow: hidden;
  border-radius: 7px;
  margin-bottom: 6px;
  background: #f3f6fb;
}

.stock-photo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.stock-photo-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: #0f5fd3;
  font-weight: 800;
  font-size: 18px;
}

.color-chip span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-chip strong {
  display: block;
  margin-top: 3px;
  font-size: 18px;
  line-height: 1;
}

.color-chip.low strong {
  color: var(--red);
}

.stats article {
  padding: 12px;
}

.stats strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.card {
  padding: 15px;
  margin-top: 12px;
}

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

h3 {
  font-size: 17px;
}

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

.empty {
  display: grid;
  place-items: center;
  min-height: 86px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 12px;
}

.list {
  display: grid;
  gap: 9px;
}

.item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

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

.item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.qty {
  color: var(--blue);
  font-weight: 800;
  white-space: nowrap;
}

.qty.plus {
  color: var(--green);
}

.qty.minus {
  color: var(--red);
}

.tag {
  display: inline-block;
  margin-right: 7px;
  padding: 3px 6px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
  vertical-align: 1px;
}

.tag.in {
  color: #0f7a3a;
  background: #e7f8ef;
}

.tag.out {
  color: #b3261e;
  background: #fdeceb;
}

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

.stock-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.stock-row:last-child {
  border-bottom: 0;
}

.stock-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stock-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.stock-num {
  min-width: 52px;
  text-align: right;
  font-weight: 800;
}

.low .stock-num {
  color: var(--red);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 8px);
  max-width: min(360px, calc(100vw - 36px));
  padding: 10px 13px;
  border-radius: 999px;
  background: rgba(24, 32, 51, 0.92);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: 0.18s ease;
  font-size: 14px;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 460px) {
  body {
    display: block;
    background: var(--phone);
  }

  .phone {
    width: 100vw;
    height: 100vh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
}
