:root {
  --ink: #221b1d;
  --muted: #756a67;
  --line: #e8dfd9;
  --paper: #f8f3ed;
  --panel: #ffffff;
  --wine: #8b1a1a;
  --rose: #b24b59;
  --gold: #c8a96e;
  --green: #16875b;
  --shadow: 0 18px 50px rgba(64, 37, 29, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  letter-spacing: 0;
}

button, input, select { font: inherit; }

button, .primary-action {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

button:hover { border-color: var(--gold); box-shadow: 0 2px 8px rgba(200, 169, 110, 0.2); }

.primary-action {
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, #8B1A1A 0%, #C8A96E 100%);
  font-weight: 750;
  box-shadow: 0 2px 8px rgba(139, 26, 26, 0.3);
}
.primary-action:hover {
  box-shadow: 0 4px 16px rgba(139, 26, 26, 0.4);
  transform: translateY(-1px);
}

.danger-action {
  margin-right: auto;
  color: #c62828;
  border-color: #ef9a9a;
  background: linear-gradient(135deg, #fff5f5, #ffebee);
}

.danger-action:hover {
  border-color: #d34b3c;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(139, 26, 26, 0.9), rgba(200, 169, 110, 0.82)),
    repeating-linear-gradient(120deg, #6c0f17 0 22px, #18181b 22px 44px, #bd9d5f 44px 66px, #1f7a86 66px 88px);
}

.login-shell {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  background: #fff;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 28px 90px rgba(33, 19, 16, 0.28);
}

.login-panel { padding: 44px; }

.brand-mark {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, var(--wine), var(--gold));
  border-radius: 16px;
  font-weight: 800;
  margin-bottom: 22px;
}

.brand-mark.small {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  margin: 0;
  font-size: 13px;
}

.login-panel h1 { margin: 0 0 8px; font-size: 30px; }
.login-panel p { margin: 0 0 30px; color: var(--muted); }

.form-field, .form-grid label {
  display: grid;
  gap: 8px;
}

.form-field { margin-bottom: 18px; }

.form-field label, .form-grid label {
  color: #554a47;
  font-weight: 650;
  font-size: 13px;
}

.form-field input, .form-grid input, .form-grid select, .toolbar-row input {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  outline: none;
}

.form-field input:focus, .form-grid input:focus, .form-grid select:focus, .toolbar-row input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(200, 169, 110, 0.16);
}

.login-message {
  min-height: 20px;
  margin-top: 14px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.login-visual {
  min-height: 520px;
  padding: 42px;
  background:
    linear-gradient(rgba(35, 20, 18, 0.26), rgba(35, 20, 18, 0.45)),
    repeating-linear-gradient(120deg, #6c0f17 0 22px, #18181b 22px 44px, #bd9d5f 44px 66px, #1f7a86 66px 88px);
}

.fabric-board { display: grid; grid-template-columns: repeat(2, 120px); gap: 14px; }
.swatch { height: 150px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.42), 0 14px 35px rgba(0,0,0,.2); }
.swatch.red { background: linear-gradient(135deg, #8b1a1a, #d95267); }
.swatch.blue { background: linear-gradient(135deg, #123a6b, #3aa4be); }
.swatch.black { background: linear-gradient(135deg, #0c0c10, #55505a); }
.swatch.gold { background: linear-gradient(135deg, #a67a2e, #f1d48b); }

.visual-card {
  width: min(320px, calc(100% - 42px));
  margin-top: 22px;
  padding: 18px;
  border-radius: 8px;
  background: rgba(255,255,255,.92);
  box-shadow: var(--shadow);
}
.visual-card strong, .visual-card span { display: block; }
.visual-card span { margin-top: 6px; color: var(--muted); }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  padding: 22px;
  background: #231718;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand span { color: #cdbfba; font-size: 12px; }

.sidebar nav { display: grid; gap: 8px; }
.sidebar nav a {
  color: #d9d0cc;
  text-decoration: none;
  padding: 12px 14px;
  border-radius: 8px;
}
.sidebar nav a.active, .sidebar nav a:hover { background: rgba(255,255,255,.1); color: #fff; }

.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #d9d0cc;
  font-size: 13px;
}
.sidebar-foot button { min-height: 32px; color: #fff; background: transparent; border-color: rgba(255,255,255,.25); }

.app-main {
  margin-left: 248px;
  padding: 28px;
}

.topbar, .toolbar-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}
.topbar { margin-bottom: 18px; }
.topbar h1 { margin: 0 0 6px; font-size: 28px; }
.topbar p, .toolbar-row p { margin: 0; color: var(--muted); }
.topbar-actions { display: flex; gap: 10px; }

.simple-hero {
  min-height: 156px;
  border-radius: 8px;
  padding: 26px 28px;
  background:
    linear-gradient(110deg, rgba(139,26,26,.96), rgba(35,23,24,.86)),
    repeating-linear-gradient(90deg, #8b1a1a 0 70px, #1f8a87 70px 126px, #c8a96e 126px 178px);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.simple-hero span { display: block; color: #f0d9b0; margin-bottom: 10px; }
.simple-hero strong { display: block; max-width: 720px; font-size: 24px; line-height: 1.35; }

.flow-line {
  display: grid;
  grid-template-columns: repeat(2, 110px);
  gap: 10px;
}
.flow-line b {
  display: grid;
  place-items: center;
  min-height: 48px;
  border-radius: 8px;
  background: rgba(255,255,255,.13);
  border: 1px solid rgba(255,255,255,.18);
}

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

.kpi-card, .product-card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi-card { padding: 18px; }
.kpi-card span { display: block; color: var(--muted); font-size: 13px; }
.kpi-card strong { display: block; margin-top: 8px; font-size: 24px; }

.toolbar-row {
  align-items: center;
  margin: 22px 0 12px;
}
.toolbar-row h2 { margin: 0 0 5px; }
.toolbar-row input { width: min(340px, 100%); }

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

.product-card {
  padding: 10px;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  grid-template-rows: auto auto auto;
  gap: 8px 10px;
  align-items: center;
}
.product-card.low { border-color: #f0b8a8; background: #fff8f5; }
.product-card h3 { margin: 3px 0 0; font-size: 16px; }
.product-card span { color: var(--muted); font-size: 12px; }

.product-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  grid-row: 1 / span 2;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border-color: #efe3dc;
  background: #f8f3ed;
}

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

.image-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  color: var(--muted);
}

.image-placeholder strong {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(135deg, var(--wine), var(--gold));
  font-size: 15px;
}

.image-placeholder span {
  color: var(--muted);
  font-size: 11px;
}

.stock-number {
  justify-self: end;
  display: flex;
  flex-direction: column;
  align-items: end;
  gap: 2px;
}
.stock-number strong {
  color: var(--wine);
  font-size: 28px;
  line-height: 1;
}

.price-row {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 7px;
  border-top: 1px solid #f0e8e3;
}

.card-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: .8fr 1fr 1fr;
  gap: 7px;
}
.card-actions .primary-action { display: inline-flex; align-items: center; justify-content: center; }

.two-column {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 18px;
}

.sales-panel {
  grid-column: 1 / -1;
}

.logs-panel {
  grid-column: 1 / -1;
}

.inventory-table-panel {
  margin-top: 18px;
}

.low-row {
  background: #fff8f5;
}

.low-row td:first-child {
  color: var(--wine);
  font-weight: 750;
}

.table-actions {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.table-actions button {
  min-height: 30px;
  padding: 0 10px;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
  padding: 24px 8px;
}
.panel { padding: 18px; min-width: 0; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-head h2 { margin: 0; font-size: 18px; }
.panel-head span { color: var(--muted); font-size: 13px; }

.table-wrap { overflow: auto; }
table { width: 100%; min-width: 520px; border-collapse: collapse; }
th, td {
  padding: 10px 8px;
  border-bottom: 1px solid #f0e8e3;
  text-align: left;
  font-size: 13px;
}
th { color: var(--muted); font-weight: 750; }

.pill {
  display: inline-flex;
  min-width: 28px;
  height: 24px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 750;
}
.pill.in { color: var(--green); background: #eaf8f1; }
.pill.out { color: var(--wine); background: #fff0ec; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(35,23,24,.42);
}
.modal-backdrop.active { display: flex; }
.stock-modal {
  width: min(560px, 100%);
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 28px 90px rgba(33,19,16,.3);
  padding: 22px;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}
.modal-head h2 { margin: 0 0 6px; }
.modal-head p { margin: 0; color: var(--muted); }
.icon-button {
  width: 36px;
  height: 36px;
  min-height: 36px;
  border-radius: 50%;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.modal-image-field {
  grid-column: 1 / -1;
}

.modal-image-picker {
  width: 132px;
  aspect-ratio: 1 / 1;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border-color: #efe3dc;
  background: #f8f3ed;
}

.modal-image-picker img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.variant-panel {
  display: grid;
  gap: 14px;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.filter-row label {
  display: grid;
  gap: 7px;
  color: #554a47;
  font-weight: 650;
  font-size: 13px;
}

.filter-row select {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
}

.variant-list {
  display: grid;
  gap: 10px;
  max-height: 360px;
  overflow: auto;
}

.variant-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid #f0e8e3;
  border-radius: 8px;
  background: #fffaf6;
}

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

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

.variant-card > div:last-child {
  display: flex;
  gap: 8px;
}

.full-width {
  width: 100%;
}

.empty-state {
  margin: 0;
  padding: 18px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
}
.modal-message {
  min-height: 20px;
  margin-top: 12px;
  color: var(--wine);
  font-size: 13px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}


/* ============================================
   移动端全面适配 - 综合优化版
   ============================================ */

/* ---------- 平板 / 小屏 (≤1024px) ---------- */
@media (max-width: 1024px) {
  .product-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .two-column {
    grid-template-columns: 1fr 1fr;
  }
}

/* ---------- 手机竖屏 (≤768px) ---------- */
@media (max-width: 768px) {
  /* === 全局 === */
  html, body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  /* === 侧边栏 → 顶部导航 === */
  .sidebar {
    position: fixed;
    top: 0; left: 0; right: 0;
    width: 100%; height: auto;
    z-index: 1000;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    gap: 6px;
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    border-bottom: 1px solid rgba(200, 169, 110, 0.3);
    border-right: none;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  }
  .sidebar-brand { display: none; }
  .sidebar-foot { display: none; }
  .sidebar nav {
    display: flex;
    gap: 2px;
    flex: 1;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .sidebar nav a {
    white-space: nowrap;
    font-size: 13px;
    padding: 10px 12px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.7);
    transition: all 0.2s;
    border-radius: 6px;
  }
  .sidebar nav a:hover,
  .sidebar nav a.active {
    color: #C8A96E;
    background: rgba(200, 169, 110, 0.1);
  }

  /* === 主内容区 === */
  .app-main {
    margin-left: 0;
    margin-top: 52px;
    padding: 12px 10px 24px;
    min-height: calc(100vh - 52px);
  }
  .page {
    padding-bottom: 20px;
  }

  /* === 顶部操作栏 === */
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 0 12px;
    margin-bottom: 8px;
  }
  .topbar h1 {
    font-size: 20px;
    line-height: 1.2;
  }
  .topbar p {
    font-size: 12px;
    color: #888;
  }
  .topbar-actions {
    width: 100%;
    display: flex;
    gap: 8px;
  }
  .topbar-actions button {
    flex: 1;
    padding: 12px 16px;
    font-size: 14px;
    min-height: 44px;
    border-radius: 10px;
  }

  /* === KPI 卡片 === */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px;
  }
  .kpi-card {
    padding: 14px 16px;
    border-radius: 12px;
    min-height: 80px;
  }
  .kpi-card span {
    font-size: 12px;
  }
  .kpi-card strong {
    font-size: 20px;
  }

  /* === 搜索工具栏 === */
  .toolbar-row {
    flex-direction: column;
    gap: 10px;
  }
  .toolbar-row h2 {
    font-size: 18px;
  }
  .toolbar-row input {
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
    min-height: 44px;
    border-radius: 10px;
  }

  /* === 商品卡片 === */
  .product-grid {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }
  .product-card {
    grid-template-columns: 90px minmax(0, 1fr) !important;
    max-width: none !important;
    padding: 10px;
    gap: 8px 12px;
    border-radius: 12px;
  }
  .product-card .product-image {
    width: 90px !important;
    height: 90px !important;
    border-radius: 10px;
  }
  .product-card h3 {
    font-size: 16px;
    margin: 4px 0 2px;
  }
  .product-card .card-body span {
    font-size: 12px;
  }
  .product-card .stock-number strong {
    font-size: 22px;
  }
  .product-card .card-actions {
    grid-template-columns: 1fr 1fr 1.3fr !important;
    gap: 8px;
  }
  .product-card .card-actions button {
    min-height: 42px;
    font-size: 14px;
    border-radius: 8px;
    padding: 8px 6px;
  }

  /* === 表格 === */
  .panel {
    border-radius: 12px;
    overflow: hidden;
  }
  .panel-head {
    padding: 14px 16px;
  }
  .panel-head h2 {
    font-size: 17px;
  }
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -10px;
    padding: 0 10px;
    scrollbar-width: thin;
  }
  .table-wrap::-webkit-scrollbar {
    height: 4px;
  }
  .table-wrap::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 2px;
  }
  table.sortable {
    min-width: 650px;
    font-size: 13px;
  }
  table.sortable th {
    font-size: 12px;
    padding: 10px 8px;
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: #f5f1ed;
    z-index: 1;
  }
  table.sortable td {
    font-size: 13px;
    padding: 10px 8px;
    white-space: nowrap;
  }

  /* === 规格弹窗 === */
  .stock-modal {
    width: 96%;
    max-width: 480px;
    max-height: 90vh;
    margin: 5vh auto;
    border-radius: 16px;
  }
  .modal-head {
    padding: 16px 20px;
  }
  .modal-head h2 {
    font-size: 17px;
  }
  .form-grid {
    padding: 16px 20px;
    gap: 12px;
  }
  .form-grid label {
    font-size: 14px;
  }
  .form-grid input,
  .form-grid select {
    font-size: 16px;
    padding: 12px;
    min-height: 48px;
    border-radius: 8px;
    -webkit-appearance: none;
  }
  .modal-actions {
    padding: 12px 20px 20px;
    flex-direction: column;
    gap: 8px;
  }
  .modal-actions button {
    width: 100%;
    padding: 14px;
    font-size: 15px;
    min-height: 48px;
    border-radius: 10px;
  }

  /* === 规格列表弹窗 === */
  .variant-panel {
    gap: 10px;
  }
  .variant-panel .filter-row {
    padding: 12px 20px;
    gap: 10px;
  }
  .variant-list {
    max-height: 45vh;
  }
  .variant-card {
    flex-direction: column;
    align-items: flex-start;
    padding: 14px;
    margin: 0 20px;
    border-radius: 10px;
  }
  .variant-card > div:last-child {
    width: 100%;
    margin-top: 10px;
    gap: 8px;
  }
  .variant-card > div:last-child button {
    flex: 1;
    min-height: 40px;
    font-size: 13px;
    border-radius: 8px;
  }

  /* === 行操作按钮 === */
  .row-actions {
    flex-direction: column;
    gap: 4px;
  }
  .row-actions button {
    width: 100%;
    min-height: 36px;
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 6px;
  }

  /* === 两列改单列 === */
  .two-column {
    grid-template-columns: 1fr !important;
  }

  /* === 底部安全距离 (iPhone X+) === */
  @supports (padding-bottom: env(safe-area-inset-bottom)) {
    .app-main {
      padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }
    .modal-actions {
      padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
  }
}

/* ---------- 小屏手机 (≤480px) ---------- */
@media (max-width: 480px) {
  /* 侧边栏导航更紧凑 */
  .sidebar nav a {
    font-size: 12px;
    padding: 8px 10px;
  }
  .app-main {
    margin-top: 48px;
    padding: 8px 8px 20px;
  }

  /* KPI 更紧凑 */
  .kpi-grid {
    gap: 8px;
  }
  .kpi-card {
    padding: 10px 12px;
    min-height: 70px;
  }
  .kpi-card strong {
    font-size: 18px;
  }

  /* 商品卡片 */
  .product-card .product-image {
    width: 80px !important;
    height: 80px !important;
  }
  .product-card .card-actions button {
    min-height: 40px;
    font-size: 13px;
  }

  /* 表格字体更小 */
  table.sortable {
    font-size: 12px;
    min-width: 600px;
  }
  table.sortable th,
  table.sortable td {
    padding: 8px 6px;
  }
}
