:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1a1d21;
  --text2: #6b7280;
  --line: #eceef1;
  --primary: #2f6bff;
  --primary-dark: #2456d6;
  --green: #10a54a;
  --green-bg: #e6f7ee;
  --orange: #e8830c;
  --orange-bg: #fdf1e2;
  --red: #e5484d;
  --red-bg: #fdebec;
  --gray-bg: #eef0f3;
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
.hidden { display: none !important; }
button { font-family: inherit; border: none; cursor: pointer; background: none; }
input, select, textarea { font-family: inherit; font-size: 15px; }

/* ---------- 通用 ---------- */
.view-center { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text2); gap: 12px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn-primary {
  width: 100%; padding: 12px; border-radius: 10px; background: var(--primary); color: #fff;
  font-size: 16px; font-weight: 500; transition: opacity .15s;
}
.btn-primary:disabled { opacity: .5; }
.btn-primary:not(:disabled):active { background: var(--primary-dark); }
.btn-outline { padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: var(--text); font-size: 14px; }
.btn-danger-text { color: var(--red); }

/* ---------- 登录 ---------- */
.login-box { width: 100%; max-width: 380px; padding: 48px 28px; }
.login-logo { font-size: 44px; text-align: center; }
.login-box h1 { font-size: 22px; text-align: center; margin-top: 8px; }
.login-sub { text-align: center; color: var(--text2); font-size: 13px; margin: 6px 0 28px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field-err { color: var(--red); font-size: 12px; margin-top: 4px; min-height: 16px; }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; }
.code-row button { white-space: nowrap; padding: 0 14px; border-radius: 10px; background: var(--gray-bg); color: var(--primary); font-size: 14px; }
.code-row button:disabled { color: var(--text2); }
.login-error { color: var(--red); font-size: 13px; text-align: center; margin-top: 12px; min-height: 18px; }
.login-hint { color: var(--text2); font-size: 12px; text-align: center; margin-top: 8px; }

/* ---------- 主框架 ---------- */
#view-app { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: rgba(255,255,255,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 17px; font-weight: 600; }
.topbar-user { font-size: 13px; color: var(--text2); }
#main { flex: 1; padding: 12px 14px 90px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex;
  background: rgba(255,255,255,.95); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text2); font-size: 12px; position: relative; }
.tab.active { color: var(--primary); }
.tab-icon { font-size: 20px; }
.badge {
  position: absolute; top: 4px; right: calc(50% - 26px); min-width: 16px; height: 16px; border-radius: 8px;
  background: var(--red); color: #fff; font-size: 10px; line-height: 16px; padding: 0 4px;
}
#fab-add {
  position: fixed; right: 18px; bottom: 84px; z-index: 10; width: 52px; height: 52px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 26px; box-shadow: 0 4px 14px rgba(47,107,255,.4);
}

/* ---------- 台账 ---------- */
.search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.search-row input {
  flex: 1; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: #fff; outline: none;
}
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chip {
  flex-shrink: 0; padding: 5px 13px; border-radius: 999px; background: #fff; border: 1px solid var(--line);
  font-size: 13px; color: var(--text2);
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.item-card {
  background: var(--card); border-radius: var(--radius); padding: 13px 14px; margin-bottom: 10px;
  border: 1px solid var(--line);
}
.item-card:active { background: #fafbfc; }
.item-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.item-name { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-code { color: var(--text2); font-size: 12px; margin-top: 2px; }
.item-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 13px; color: var(--text2); }

.tag { flex-shrink: 0; padding: 3px 9px; border-radius: 6px; font-size: 12px; font-weight: 500; }
.tag-in_stock { background: var(--green-bg); color: var(--green); }
.tag-pending { background: var(--orange-bg); color: var(--orange); }
.tag-lent { background: var(--red-bg); color: var(--red); }
.tag-cancelled { background: var(--gray-bg); color: var(--text2); }

.empty { text-align: center; color: var(--text2); padding: 60px 0; font-size: 14px; }

/* ---------- 审批 ---------- */
.section-title { font-size: 14px; font-weight: 600; color: var(--text2); margin: 16px 2px 8px; }
.req-card { background: var(--card); border-radius: var(--radius); padding: 13px 14px; margin-bottom: 10px; border: 1px solid var(--line); }
.req-head { display: flex; justify-content: space-between; align-items: center; }
.req-item { font-weight: 600; }
.req-line { font-size: 13px; color: var(--text2); margin-top: 4px; }
.req-actions { display: flex; gap: 8px; margin-top: 10px; }
.req-actions button { flex: 1; padding: 9px; border-radius: 9px; font-size: 14px; font-weight: 500; }
.btn-approve { background: var(--primary); color: #fff; }
.btn-reject { background: var(--gray-bg); color: var(--red); }

.tag-pending_owner, .tag-pending_keeper { background: var(--orange-bg); color: var(--orange); }
.tag-approved { background: var(--red-bg); color: var(--red); }
.tag-returned { background: var(--green-bg); color: var(--green); }
.tag-rejected { background: var(--gray-bg); color: var(--text2); }

/* ---------- 我的 ---------- */
.me-card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 18px 16px; margin-bottom: 12px; }
.me-row { display: flex; justify-content: space-between; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.me-row:last-child { border-bottom: none; }
.me-row .k { color: var(--text2); }
.role-tag { padding: 2px 8px; border-radius: 6px; font-size: 12px; }
.role-admin { background: var(--red-bg); color: var(--red); }
.role-staff { background: var(--gray-bg); color: var(--text2); }
.btn-logout { width: 100%; padding: 12px; border-radius: 10px; background: #fff; border: 1px solid var(--line); color: var(--red); font-size: 15px; margin-top: 12px; }

/* ---------- 模态 ---------- */
#modal-mask {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
#modal-card {
  width: 100%; max-width: 520px; max-height: 86vh; overflow-y: auto;
  background: var(--bg); border-radius: 16px 16px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: slideup .22s ease;
}
@keyframes slideup { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 2px; position: sticky; top: 0; background: var(--bg); }
.modal-head h2 { font-size: 17px; }
.modal-close { font-size: 20px; color: var(--text2); padding: 4px 8px; }
.modal-body { padding-bottom: 8px; }

.detail-grid { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 4px 14px; margin-bottom: 12px; }
.d-row { display: flex; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.d-row:last-child { border-bottom: none; }
.d-row .k { width: 84px; flex-shrink: 0; color: var(--text2); }
.d-row .v { flex: 1; word-break: break-all; }

.timeline { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 14px 16px; }
.tl-item { position: relative; padding: 0 0 16px 18px; }
.tl-item:last-child { padding-bottom: 2px; }
.tl-item::before { content: ""; position: absolute; left: 4px; top: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--primary); }
.tl-item::after { content: ""; position: absolute; left: 7px; top: 19px; bottom: 2px; width: 1px; background: var(--line); }
.tl-item:last-child::after { display: none; }
.tl-action { font-size: 14px; font-weight: 500; }
.tl-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }

.action-bar { display: flex; gap: 10px; margin-top: 14px; }
.action-bar button { flex: 1; padding: 12px; border-radius: 10px; font-size: 15px; font-weight: 500; }

/* ---------- 标签 / 字典管理 ---------- */
.mini-tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--gray-bg); color: var(--text2); font-size: 12px; margin: 0 6px 4px 0; }
.item-tags { margin-top: 6px; }
.select-btn { width: 100%; text-align: left; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 15px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tags-panel { margin-top: 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 8px 14px; }
.tag-check { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.field-hint { font-size: 12px; color: var(--text2); margin-top: 4px; }
.btn-dict { display: block; margin: 0 0 12px; }
.dict-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 2px 14px; }
.dict-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.dict-row:last-child { border-bottom: none; }
.dict-del { color: var(--red); font-size: 13px; padding: 4px 8px; }
.dict-add { display: flex; gap: 8px; margin: 10px 0 20px; }
.dict-add input { flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; outline: none; }
.dict-add button { padding: 0 18px; border-radius: 10px; background: var(--primary); color: #fff; font-size: 14px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 200;
  background: rgba(20,22,26,.88); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px;
  max-width: 80vw; text-align: center; animation: fadein .2s;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
