/* ===================== 暖色主题 ===================== */
:root {
  /* 背景 / 表面 */
  --bg:            #fdf8f1;
  --bg-2:          #f8efe0;
  --surface:       #ffffff;
  --surface-soft:  #fef6e6;

  /* 文字 */
  --text:          #1c1917;
  --text-muted:    #8a7e6c;
  --text-on-dark:  #faf5ec;

  /* 边框 */
  --border:        #f0e4cf;
  --border-strong: #e0cda4;

  /* 主色（赤陶橙）+ 辅色（暖琥珀）*/
  --primary:        #c2410c;
  --primary-hover:  #9a3412;
  --primary-soft:   #fed7aa;
  --primary-ring:   rgba(194, 65, 12, 0.25);
  --accent:         #d97706;

  /* 导航：深咖啡 */
  --nav-bg:         #3f352d;
  --nav-bg-2:       #2c241e;
  --nav-text:       #e7d8c0;
  --nav-text-soft:  #b9a98e;

  /* 状态色 */
  --ok:      #65a30d; --ok-bg:   #ecfccb; --ok-text:   #3f6212;
  --warn:    #d97706; --warn-bg: #fef3c7; --warn-text: #92400e;
  --err:     #b91c1c; --err-bg:  #fee2e2; --err-text:  #991b1b;

  /* 阴影 / 圆角 */
  --shadow-sm: 0 1px 2px rgba(120, 53, 15, 0.06);
  --shadow:    0 6px 16px -8px rgba(120, 53, 15, 0.18), 0 2px 4px rgba(120, 53, 15, 0.04);
  --shadow-lg: 0 20px 48px -12px rgba(120, 53, 15, 0.28);
  --radius:    10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
}

* { box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at -10% -20%, #fcebcf 0%, transparent 60%),
    radial-gradient(1000px 500px at 110% 10%, #fde6ce 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3 { color: #2a1f14; letter-spacing: 0.2px; }
h1 { font-size: 22px; }
h2 { font-size: 20px; margin: 4px 0 16px; }
h3 { font-size: 16px; margin: 18px 0 10px; }

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

code {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: #7c2d12;
  padding: 1px 7px;
  border-radius: 4px;
  font-family: "JetBrains Mono", Consolas, "Courier New", monospace;
  font-size: 13px;
}

/* ===================== 顶部导航 ===================== */
.topnav {
  display: flex; align-items: center; gap: 4px;
  background: linear-gradient(180deg, var(--nav-bg) 0%, var(--nav-bg-2) 100%);
  color: var(--nav-text);
  padding: 10px 24px;
  box-shadow: 0 2px 8px rgba(60, 30, 0, 0.18);
  position: sticky; top: 0; z-index: 50;
}
.topnav .brand {
  font-weight: 700; letter-spacing: 0.4px;
  margin-right: 18px; color: #fde8c9;
  padding-right: 16px;
  border-right: 1px solid rgba(255,255,255,0.08);
}
.topnav a {
  color: var(--nav-text);
  text-decoration: none;
  padding: 7px 14px;
  border-radius: 999px;
  transition: background 0.15s, color 0.15s;
  font-size: 14px;
}
.topnav a:hover {
  background: rgba(253, 230, 138, 0.10);
  color: #fde8c9;
  text-decoration: none;
}
.topnav a.active {
  background: var(--primary);
  color: #fff7ed;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.10);
}
.topnav .spacer { flex: 1; }
.topnav .muted { color: var(--nav-text-soft); font-size: 13px; }
.topnav button.link {
  background: transparent; border: 1px solid transparent;
  color: var(--nav-text); cursor: pointer;
  font: inherit; padding: 6px 12px; border-radius: 999px;
}
.topnav button.link:hover {
  color: #fde8c9; border-color: rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.04);
}

/* ===================== 容器 / 主标题 ===================== */
.container { max-width: 1180px; margin: 28px auto; padding: 0 20px 60px; }

/* ===================== Flash 提示 ===================== */
.flash {
  padding: 11px 16px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  border: 1px solid transparent;
  font-size: 14px;
}
.flash-error   { background: var(--err-bg);  color: var(--err-text);  border-color: #fecaca; }
.flash-success { background: var(--ok-bg);   color: var(--ok-text);   border-color: #d9f99d; }

/* ===================== 卡片 ===================== */
.card {
  background: var(--surface);
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card label { display: block; margin: 12px 0; font-size: 14px; color: #44403c; }

/* ===================== 表单元素 ===================== */
input[type=text], input[type=password], input[type=number],
input[type=date], input:not([type]), select, textarea {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  background: #fffdf8;
  border-radius: var(--radius-sm);
  color: var(--text);
  min-width: 200px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px var(--primary-ring);
}
input::placeholder { color: #b8a98a; }

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

.toolbar { margin: 14px 0 8px; color: var(--text-muted); font-size: 14px; }

/* ===================== 按钮 ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit; font-size: 14px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s, box-shadow 0.15s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--surface-soft); border-color: var(--primary-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(180deg, #d97706 0%, var(--primary) 100%);
  color: #fff7ed;
  border-color: var(--primary-hover);
  box-shadow: 0 4px 10px -4px rgba(194, 65, 12, 0.55), inset 0 1px 0 rgba(255,255,255,0.18);
}
.btn.primary:hover {
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-hover) 100%);
  border-color: var(--primary-hover);
}
.btn.danger {
  background: #dc2626;
  color: #fff7ed;
  border-color: #991b1b;
}
.btn.danger:hover { background: #b91c1c; }

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

button.link {
  background: transparent; border: 0; cursor: pointer;
  font: inherit;
}

/* 表单中无 class 的 button：默认有点样式，不至于光秃秃 */
form button:not(.btn):not(.link) {
  font: inherit;
  padding: 6px 14px;
  margin-left: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
form button:not(.btn):not(.link):hover { background: var(--surface-soft); }

/* ===================== 表格 ===================== */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: 14px;
}
.table th, .table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.table thead th {
  background: var(--surface-soft);
  color: #6b4226;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border-strong);
}
.table tbody tr:nth-child(even) { background: #fffaf0; }
.table tbody tr:hover { background: #fdf2dc; }
.table tbody tr:last-child td { border-bottom: 0; }

/* ===================== 文案修饰 ===================== */
.muted { color: var(--text-muted); font-size: 13px; }
.warning {
  background: var(--warn-bg); color: var(--warn-text);
  padding: 12px 16px; border-radius: var(--radius);
  border: 1px solid #fde68a;
}

/* ===================== 出库扫码 ===================== */
.scan-input {
  width: 100%;
  font-size: 26px;
  padding: 16px 18px;
  border: 2px solid var(--primary);
  background: #fffdf6;
  border-radius: var(--radius);
  letter-spacing: 1px;
  font-family: "JetBrains Mono", Consolas, monospace;
  box-shadow: 0 0 0 4px var(--primary-ring), var(--shadow);
}
.scan-input:focus {
  outline: none;
  border-color: var(--primary-hover);
  box-shadow: 0 0 0 4px var(--primary-ring), 0 0 0 6px rgba(217, 119, 6, 0.10), var(--shadow);
}

.scan-feedback {
  margin-top: 14px; padding: 14px 16px; border-radius: var(--radius);
  font-size: 16px; min-height: 1.6em;
  border: 1px solid transparent;
  transition: background 0.15s;
}
.scan-feedback.ok   { background: var(--ok-bg);   color: var(--ok-text);   border-color: #d9f99d; }
.scan-feedback.warn { background: var(--warn-bg); color: var(--warn-text); border-color: #fde68a; }
.scan-feedback.err  { background: var(--err-bg);  color: var(--err-text);  border-color: #fecaca; }

/* ===================== Tab ===================== */
.tabs {
  display: flex; gap: 2px;
  margin-bottom: 16px;
  background: var(--surface-soft);
  padding: 4px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: fit-content;
}
.tab {
  background: transparent; border: 0;
  padding: 8px 18px;
  font: inherit; font-size: 14px;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,0.5); }
.tab.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.panel { display: none; }
.panel.active { display: block; }

/* ===================== 登录 / 改密 ===================== */
.login-box {
  max-width: 380px;
  margin: 100px auto 0;
  background: var(--surface);
  padding: 32px 30px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  position: relative;
}
.login-box::before {
  content: "";
  position: absolute; top: -3px; left: 24px; right: 24px;
  height: 4px; border-radius: 0 0 4px 4px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}
.login-box h1 { margin: 4px 0 16px; text-align: center; }
.login-box label { display: block; margin: 14px 0; font-size: 14px; color: #44403c; }
.login-box input { width: 100%; }
.login-box button { width: 100%; margin-top: 18px; padding: 10px 14px; font-size: 15px; }

.form-narrow {
  max-width: 460px;
  background: var(--surface);
  padding: 22px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.form-narrow label { display: block; margin: 12px 0; }
.form-narrow input { width: 100%; }

/* ===================== 杂项 ===================== */
pre {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  overflow: auto;
  font-size: 12.5px;
  font-family: "JetBrains Mono", Consolas, "Courier New", monospace;
  color: #44403c;
}

/* ===================== 模态框 ===================== */
.modal {
  position: fixed; inset: 0;
  background: rgba(41, 27, 14, 0.55);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: modalFadeIn 0.15s ease-out;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 26px 28px;
  min-width: 380px;
  max-width: 90vw;
  box-shadow: var(--shadow-lg);
  animation: modalPop 0.18s ease-out;
}
.modal-card h3 { margin: 0 0 10px 0; font-size: 17px; }
.modal-card label { display: block; margin: 12px 0; font-size: 14px; color: #44403c; }
.modal-card input { width: 100%; }
.modal-actions {
  margin-top: 18px;
  display: flex; gap: 10px; justify-content: flex-end;
}

@keyframes modalFadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes modalPop    { from { transform: scale(0.96); opacity: 0 } to { transform: scale(1); opacity: 1 } }

/* ===================== 分页器 ===================== */
#tx-pager { margin-top: 12px; color: var(--text-muted); font-size: 13px; }
#tx-pager button {
  margin-left: 6px;
  padding: 4px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit; font-size: 13px;
  color: var(--text);
}
#tx-pager button:hover { background: var(--surface-soft); border-color: var(--primary-soft); }

/* ===================== 当前库存「在库」列加粗描红 ===================== */
#cur-rows td:last-child b { color: var(--primary); }

/* ===================== 流水表「补录字段」折叠 ===================== */
.table.meta-col-hidden .col-meta { display: none; }
/* 折叠时，若该行已有补录内容，在操作列前显示一个小橙点提醒 */
.meta-dot {
  display: inline-block;
  margin-right: 6px;
  color: var(--primary);
  font-size: 14px;
  line-height: 1;
  vertical-align: middle;
  cursor: help;
}
.table:not(.meta-col-hidden) .meta-dot { display: none; }

/* ===================== 仪表盘卡片 ===================== */
.dash-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-top: 8px;
}
.dash-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  position: relative;
}
.dash-card .label { font-size: 13px; color: var(--text-muted); }
.dash-card .num   { font-size: 30px; font-weight: 700; color: var(--text); margin-top: 6px; line-height: 1.1; }
.dash-card.primary {
  background: linear-gradient(135deg, #fff7ed 0%, #fed7aa 100%);
  border-color: var(--primary-soft);
}
.dash-card.primary .num { color: var(--primary-hover); }
.dash-card.alert {
  background: #fef3c7;
  border-color: #fde68a;
}
.dash-card.alert .num { color: #92400e; }
.dash-card .link {
  position: absolute; bottom: 10px; right: 14px;
  font-size: 12px; color: var(--primary);
}

/* ===================== 图表网格 ===================== */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 16px;
  margin-top: 18px;
}
.chart-card h3 { margin-top: 0; }
.chart-card canvas {
  width: 100% !important;
  height: 260px !important;
  max-height: 280px;
}

/* ===================== 缺货预警行 + 标识 ===================== */
.row-alert { background: #fef3c7 !important; }
.row-alert td { color: #7c2d12; }
.badge-alert {
  display: inline-block;
  background: #c2410c; color: #fff;
  padding: 2px 10px; border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-zero {
  display: inline-block;
  background: #e5e5e5; color: #57534e;
  padding: 2px 10px; border-radius: 999px;
  font-size: 12px;
}

/* ===================== 批次进度条 ===================== */
.bar {
  display: inline-block;
  width: 120px; height: 8px;
  background: #f0e4cf;
  border-radius: 999px;
  overflow: hidden;
  vertical-align: middle;
  margin-right: 6px;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--primary));
}

/* ===================== 流水批量补录工具条 ===================== */
.bulk-bar {
  margin: 12px 0;
  padding: 10px 14px;
  background: var(--primary-soft);
  color: var(--primary-hover);
  border: 1px solid #fbbf24;
  border-radius: var(--radius);
  display: flex; align-items: center; gap: 10px;
}
.bulk-bar b { font-size: 16px; }

/* ===================== 型号编码链接 ===================== */
a.code-link { text-decoration: none; }
a.code-link code { transition: background 0.15s; }
a.code-link:hover code { background: var(--primary-soft); }

/* ===================== Capacitor / Android 专用 ===================== */
/* 「用摄像头扫码」按钮默认隐藏；在 Android App (Capacitor) 中才显示 */
.camera-btn { display: none; }
html.capacitor-native .camera-btn {
  display: inline-flex;
  margin-left: 8px;
  vertical-align: middle;
}
/* Android 应用里把扫码输入框设大一点便于触屏操作 */
html.capacitor-native .scan-input,
html.capacitor-native input[type=text],
html.capacitor-native input[type=number] { font-size: 18px; }

/* ===================== 移动端适配（手机 / APK） ===================== */
@media (max-width: 768px) {
  body { line-height: 1.5; }
  h1 { font-size: 19px; }
  h2 { font-size: 17px; margin: 4px 0 12px; }
  h3 { font-size: 15px; margin: 14px 0 8px; }

  /* 顶部导航：横向滚动，不再换行；适配刘海屏安全区 */
  .topnav {
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    padding-left: calc(10px + env(safe-area-inset-left, 0px));
    padding-right: calc(10px + env(safe-area-inset-right, 0px));
    gap: 2px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .topnav::-webkit-scrollbar { display: none; }
  .topnav > * { flex-shrink: 0; }
  .topnav .brand {
    margin-right: 10px;
    padding-right: 10px;
    font-size: 15px;
  }
  .topnav a, .topnav button.link {
    padding: 6px 11px;
    font-size: 13px;
    white-space: nowrap;
  }
  .topnav .spacer { flex: 0 0 8px; }
  .topnav .muted { font-size: 12px; }

  /* 主容器 */
  .container {
    margin: 14px auto;
    padding: 0 12px;
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  }

  /* 卡片 */
  .card { padding: 14px; margin-bottom: 14px; border-radius: 12px; }
  .card label { margin: 10px 0; font-size: 13px; }

  /* 表单元素：取消最小宽度，撑满父容器；字号 ≥16px 防止 iOS 聚焦缩放 */
  input[type=text], input[type=password], input[type=number],
  input[type=date], input:not([type]), select, textarea {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    padding: 9px 10px;
    font-size: 16px;
  }
  /* 覆盖个别页面通过 style="width:..." 写死的大宽度 */
  input[style*="width"], select[style*="width"] {
    width: 100% !important;
    max-width: 100% !important;
  }
  /* 库龄页阈值天数等小输入框允许保留窄宽度 */
  input[type=number][style*="6em"] { width: 6em !important; }

  /* 行内表单 → 纵向堆叠 */
  .inline-form { gap: 8px; }
  .inline-form > input,
  .inline-form > select,
  .inline-form > textarea,
  .inline-form > label { width: 100%; }
  .inline-form > button { flex: 1 1 auto; }
  .inline-form > .btn { min-height: 40px; }

  /* 按钮 */
  .btn { padding: 9px 14px; font-size: 14px; min-height: 40px; }
  .btn-sm { padding: 5px 10px; font-size: 12px; min-height: 0; }
  form button:not(.btn):not(.link) { padding: 8px 14px; min-height: 38px; }

  /* 表格：变成块级容器，横向滚动；内容不换行避免列被压扁 */
  .table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .table th, .table td {
    padding: 8px 10px;
    font-size: 13px;
  }
  .table thead th { font-size: 12px; }
  /* 表格里的小输入框（如「最低库存」）允许窄一点 */
  .table input[type=number] { width: 5em; min-width: 0; }

  /* 模态框：撑满屏幕宽度，可上下滚动 */
  .modal-card,
  .modal-card[style] {
    min-width: 0 !important;
    width: calc(100vw - 20px) !important;
    max-width: calc(100vw - 20px) !important;
    padding: 18px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    box-sizing: border-box;
  }
  .modal-card h3 { font-size: 16px; }
  .modal-actions { flex-wrap: wrap; gap: 8px; }
  .modal-actions .btn { flex: 1 1 45%; }

  /* 登录 / 改密 */
  .login-box {
    margin: 36px 14px 0;
    padding: 24px 20px;
    max-width: none;
  }
  .form-narrow { padding: 18px 16px; max-width: none; }

  /* 仪表盘卡片：两列布局 */
  .dash-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .dash-card { padding: 12px 14px; }
  .dash-card .label { font-size: 12px; }
  .dash-card .num { font-size: 22px; }
  .dash-card .link { font-size: 11px; bottom: 8px; right: 12px; }

  /* 图表网格 → 单列 */
  .charts-grid { grid-template-columns: 1fr; gap: 12px; }
  .chart-card canvas { height: 220px !important; max-height: 240px; }

  /* Tab 条横向滚动 */
  .tabs {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    padding: 8px 12px;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* 出库扫码输入框 */
  .scan-input {
    font-size: 20px;
    padding: 12px 14px;
    letter-spacing: 0.5px;
  }
  .scan-feedback { font-size: 14px; padding: 10px 12px; }

  /* 批量补录工具条 */
  .bulk-bar { flex-wrap: wrap; padding: 8px 10px; font-size: 13px; gap: 8px; }
  .bulk-bar b { font-size: 14px; }

  /* Flash 提示 */
  .flash { padding: 10px 12px; font-size: 13px; }

  /* 分页器 */
  #tx-pager { font-size: 12px; }
  #tx-pager button { padding: 5px 10px; min-height: 32px; margin-left: 4px; }

  /* pre 块 */
  pre { font-size: 12px; padding: 10px 12px; }

  /* 进度条窄一点 */
  .bar { width: 80px; }

  /* 摄像头扫码按钮：手机上独立成行 */
  html.capacitor-native .camera-btn {
    display: flex;
    width: 100%;
    margin-left: 0;
    margin-top: 6px;
    min-height: 40px;
  }
}

/* 超窄屏（≤380px 的小手机）单列仪表盘、再缩边距 */
@media (max-width: 380px) {
  .container { padding-left: 10px; padding-right: 10px; }
  .dash-cards { grid-template-columns: 1fr; }
  .topnav .brand { font-size: 14px; }
}
