/* ===== 全局 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #2563eb; --primary-dark: #1d4ed8;
  --bg: #f5f6fa; --card: #fff; --text: #1f2937; --muted: #6b7280;
  --border: #e5e7eb; --ok: #16a34a; --warn: #d97706; --danger: #dc2626;
  --radius: 12px;
}
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
  padding-bottom: 70px;
}
a { color: var(--primary); text-decoration: none; }
h2 { font-size: 20px; }
.muted { color: var(--muted); font-size: 13px; }
.text-warn { color: var(--warn); font-weight: 600; }

/* ===== 顶栏 ===== */
.topbar { position: sticky; top: 0; z-index: 100; background: var(--primary); color: #fff; }
.topbar-inner { max-width: 960px; margin: 0 auto; padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; }
.brand { font-weight: 700; font-size: 17px; }
.user-box { display: flex; align-items: center; gap: 10px; }
.user-name { font-size: 14px; }

/* ===== 布局 ===== */
.container { max-width: 960px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; }
.section-title { margin: 18px 0 10px; font-size: 16px; color: var(--muted); }

/* ===== 卡片 ===== */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 10px; }
.card-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.todo-card { display: flex; justify-content: space-between; align-items: center; padding: 16px; }
.todo-label { font-size: 14px; }
.todo-count { font-size: 26px; font-weight: 700; color: var(--primary); }
.warn-card { display: flex; justify-content: space-between; align-items: center; }
.warn-card .card-title { font-weight: 600; }
.warn-qty { color: var(--warn); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ===== 按钮 ===== */
.btn { display: inline-block; padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer; font-size: 14px; background: #e5e7eb; color: var(--text); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warn { background: #f59e0b; color: #fff; }
.btn-warn:hover { background: #d97706; }
.btn-block { width: 100%; padding: 12px; font-size: 16px; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn:active { transform: scale(.98); }

/* ===== 表单 ===== */
.form-item { margin-bottom: 14px; }
.form-item label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.form-item input, .form-item select, .form-item textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 15px; background: #fff;
}
.form-item input:focus, .form-item select:focus, .form-item textarea:focus { outline: none; border-color: var(--primary); }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.form-inline { display: flex; gap: 10px; flex-wrap: wrap; }
.form-inline .grow { flex: 1; min-width: 140px; }
.req { color: var(--danger); }

/* ===== 搜索 ===== */
.search-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.search-bar input { flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }

/* ===== 表格 ===== */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.table { width: 100%; border-collapse: collapse; min-width: 560px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; white-space: nowrap; }
.table th { background: #f9fafb; color: var(--muted); font-weight: 600; font-size: 13px; }
.table tr:last-child td { border-bottom: none; }

/* ===== 状态 ===== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; background: #e5e7eb; color: var(--muted); }
.badge-ok { background: #dcfce7; color: var(--ok); }
.badge-warn { background: #fef3c7; color: var(--warn); }
.badge-danger { background: #fee2e2; color: var(--danger); }
.badge-info { background: #dbeafe; color: var(--primary); }

/* ===== 提示 ===== */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.alert-error { background: #fee2e2; color: var(--danger); }
.alert-success { background: #dcfce7; color: var(--ok); }
.alert-info { background: #dbeafe; color: var(--primary); }
.alert-warning { background: #fef3c7; color: #92400e; }

/* ===== 登录页 ===== */
.login-body { background: linear-gradient(135deg, #2563eb, #1e40af); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { background: #fff; border-radius: 16px; padding: 32px 24px; width: 100%; max-width: 380px; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.login-logo { font-size: 44px; text-align: center; }
.login-box h1 { font-size: 18px; text-align: center; margin: 10px 0 20px; }
/* AI 助理风格登录页 */
.login-ai-box { padding: 28px 24px 24px; text-align: center; }
.login-ai { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 18px; }
.login-ai-avatar { width: 72px; height: 72px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 10px rgba(37,99,235,.25); object-fit: cover; }
.login-ai-name { font-size: 17px; font-weight: bold; color: var(--text); }
.login-ai-intro { font-size: 13px; color: var(--muted); line-height: 1.7; }
.login-ai-box .form { text-align: left; }
.login-tip { margin-top: 14px; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.6; }

.login-brand { text-align: center; margin-bottom: 4px; }
.login-brand-icon { font-size: 42px; line-height: 1; }
.login-box .login-brand-name { font-size: 26px; font-weight: 800; text-align: center; margin: 8px 0 4px; line-height: 1.35; background: linear-gradient(135deg, #2563eb, #7c3aed); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: #2563eb; }
.login-brand-sub { font-size: 12px; color: var(--muted); text-align: center; letter-spacing: 1px; }
.login-divider { height: 1px; background: var(--border); margin: 16px 0; }


/* ===== 底部导航（手机） ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; padding: 8px 0 12px; z-index: 100;
  max-width: 960px; margin: 0 auto;
}
.nav-item { display: flex; flex-direction: column; align-items: center; font-size: 12px; color: var(--muted); padding: 4px 10px; }
.nav-item.active { color: var(--primary); font-weight: 600; }

/* ===== 电脑端适配 ===== */
@media (min-width: 768px) {
  body { padding-bottom: 20px; }
  .bottom-nav { position: static; margin-top: 20px; }
}

/* ===== 单据列表 ===== */
.filter-tabs { display: flex; gap: 8px; margin-bottom: 14px; overflow-x: auto; padding-bottom: 4px; }
.filter-tabs .tab { padding: 6px 14px; border-radius: 20px; background: #fff; border: 1px solid var(--border); font-size: 13px; color: var(--muted); white-space: nowrap; }
.filter-tabs .tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.order-card { display: block; }
.order-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.order-no { font-weight: 700; }
.order-body { font-size: 13px; color: var(--text); }
.order-total { margin-top: 8px; font-weight: 700; color: var(--primary); font-size: 16px; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }

/* ===== 明细行 ===== */
.item-row { display: grid; grid-template-columns: 1.2fr 1fr 1fr 1fr auto; gap: 8px; padding: 10px 0; border-bottom: 1px dashed var(--border); align-items: center; }
.item-row .row-main { grid-column: 1 / -1; position: relative; }
.item-row input { padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; width: 100%; box-sizing: border-box; }
.item-row select.wh { padding: 9px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; width: 100%; background: #fff; color: var(--text); box-sizing: border-box; }
.item-row .note { grid-column: 1 / 4; }
.item-row .stock-hint { grid-column: 4 / 5; align-self: center; text-align: right; font-size: 12px; color: var(--muted); }
.item-row .amount { font-weight: 700; color: var(--primary); text-align: right; padding: 0 4px; min-width: 60px; }
.suggest { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--border); border-radius: 8px; z-index: 50; max-height: 220px; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.suggest-nav { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--border); background: #f9fafb; }
.suggest-arrow { width: 30px; height: 28px; padding: 0; border: 1px solid var(--border); border-radius: 5px; background: #fff; color: var(--text); cursor: pointer; }
.suggest-item { padding: 8px 12px; font-size: 13px; cursor: pointer; border-bottom: 1px solid #f3f4f6; }
.suggest-item:hover { background: #eff6ff; }
.suggest-item.active { background: #dbeafe; }
.fp-wrap { position: relative; }
.fp-wrap .fp-list { display: none; }
.fp-hint { margin-top: 2px; font-size: 12px; color: #059669; }
.s-code { color: var(--primary); font-weight: 600; margin-right: 6px; }

/* ===== 照片 ===== */
.photo-list { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.photo-thumb { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

/* ===== 初始化清单 ===== */
.init-list { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.init-card { display: flex; align-items: center; gap: 10px; }
.init-icon { font-size: 22px; }
.init-label { font-size: 14px; }
.init-done { opacity: .55; }
.init-done .init-label { text-decoration: line-through; }

/* ===== 权限管理 ===== */
.perm-table { min-width: 720px; }
.perm-cell { text-align: center; }
.check { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.check input { display: none; }
.check span { width: 22px; height: 22px; border: 2px solid #d1d5db; border-radius: 5px; display: inline-block; position: relative; }
.check input:checked + span { background: var(--primary); border-color: var(--primary); }
.check input:checked + span::after { content: "✓"; color: #fff; position: absolute; left: 3px; top: -1px; font-size: 15px; font-weight: 700; }
/* ================= 顶部主菜单 ================= */
.top-menu {
  display: flex;
  overflow-x: auto;
  background: #fff;
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.top-menu::-webkit-scrollbar { display: none; }
.m-item {
  flex: 0 0 auto;
  padding: 11px 13px;
  font-size: 13px;
  white-space: nowrap;
  text-decoration: none;
  border-bottom: 3px solid transparent;
  opacity: .85;
}
.m-item.active { font-weight: 700; opacity: 1; border-bottom-color: currentColor; }
.m-blue   { color: #2563eb; }
.m-green  { color: #16a34a; }
.m-orange { color: #ea580c; }
.m-purple { color: #9333ea; }
.m-cyan   { color: #0891b2; }
.m-red    { color: #dc2626; }
.m-brown  { color: #92400e; }
.m-indigo { color: #4f46e5; }
.m-teal   { color: #0d9488; }
.m-gray   { color: #64748b; }
.m-slate  { color: #475569; }
.m-pink   { color: #db2777; }
.m-yellow { color: #ca8a04; }
.m-blue2  { color: #1d4ed8; }
.m-gold   { color: #b45309; }
.m-navy   { color: #1e3a8a; }
.m-violet { color: #7c3aed; }
.m-dark   { color: #111827; }
/* ================= 手机端优化：横屏 + 触屏 + 输入 ================= */
/* 输入控件 ≥16px，避免 iOS 聚焦自动放大 */
input, select, textarea { font-size: 16px; }
/* 触屏大触控目标（≥44px） */
@media (pointer: coarse), (max-width: 768px) {
  .btn { min-height: 44px; padding: 10px 18px; }
  .btn-sm { min-height: 40px; padding: 8px 12px; }
  .form-item input, .form-item select, .form-item textarea {
    min-height: 46px; font-size: 16px; padding: 10px 12px;
  }
  .item-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 12px 0;
    align-items: stretch;
  }
  .item-row .row-main,
  .item-row .note,
  .item-row .stock-hint {
    grid-column: 1 / -1;
  }
  .item-row input, .item-row select.wh { min-height: 44px; font-size: 15px; }
  .item-row .amount {
    min-height: 44px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    background: #f9fafb;
  }
  .item-row .del {
    width: 100%;
  }
  .top-menu .m-item { padding: 13px 14px; font-size: 15px; }
  .table th, .table td { padding: 12px; font-size: 15px; }
  .card { padding: 14px; }
  .search-bar input { min-height: 44px; font-size: 16px; }
  .suggest-item { padding: 12px 10px; font-size: 15px; }
}
/* 触屏按下反馈 */
.touch-active { opacity: .75; transform: scale(.98); }

/* OCR 智能名称推荐 */
.ocr-cands { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 2px 0; font-size: 12px; }
.ocr-cand { background: #eef4ff; border: 1px solid #c7d7f7; border-radius: 999px; padding: 4px 10px; font-size: 12px; color: #1d4ed8; cursor: pointer; }
.ocr-cand:hover { background: #dbeafe; }
.ocr-alias-box { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 2px 0; font-size: 12px; }
.ocr-alias-box .muted { line-height: 1.5; }
.ocr-cand[disabled] { opacity: .7; cursor: default; }

/* ===== 更小屏（<=480px）适配加固：避免手机端显示混乱 ===== */
@media (max-width: 480px) {
  .container { padding: 12px 10px; }
  .topbar-inner { padding: 8px 10px; }
  .page-head h2 { font-size: 18px; }
  .form-actions { flex-direction: column; }
  .form-actions .btn, .form-actions .btn-primary { width: 100%; }
  .search-bar { flex-direction: column; }
  .search-bar .btn { width: 100%; }
  .login-box { padding: 24px 16px; }
  .ai-body { padding: 0 8px 8px; }
  .ai-bar-title { font-size: 14px; }
  .ai-bar-right .ai-trad-link { font-size: 12px; padding: 5px 8px; }
  .ai-bubble { max-width: 92%; }
  .ai-welcome { max-width: 88%; }
  .ai-input-bar input[type=text] { min-width: 0; flex-basis: 120px; }
  .ai-icon-btn { width: 38px; height: 38px; font-size: 16px; }
  .ai-send { width: 50px; height: 38px; }
  .dw-grid { grid-template-columns: 1fr 1fr; }
  .dw-grid a { padding: 9px 4px; }
  .card { padding: 12px; }
  .table th, .table td { padding: 9px 8px; font-size: 13px; }
  .head-actions { width: 100%; justify-content: flex-end; }
  .chat-box { padding: 8px; }
}
@media (max-width: 360px) {
  .m-item { padding: 11px 9px; font-size: 13px; }
  .ai-topbar { padding: 0 8px; }
  .ai-bar-btn { width: 34px; height: 34px; font-size: 17px; }
  .login-ai-avatar { width: 62px; height: 62px; }
  .login-ai-name { font-size: 16px; }
}
