/* ============================================================
   基础布局与组件（全部消费 themes.css 的变量）
   ============================================================ */

* { box-sizing: border-box; }

/* hidden 属性必须能压过组件自身的 display，否则 topbar/user-chip 会漏出来 */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: break-word;
}

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

h1 { font-size: 22px; margin: 0 0 6px; font-weight: 700; letter-spacing: -.2px; }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 15px; margin: 0 0 8px; font-weight: 650; }
p { margin: 0 0 12px; }
.muted { color: var(--ink-2); }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; }

/* ---------- 首屏加载 ---------- */
.boot {
  position: fixed; inset: 0; z-index: 999;
  display: grid; place-items: center;
  background: var(--bg);
}
.boot.hide { opacity: 0; pointer-events: none; transition: opacity .25s; }
.boot-inner { text-align: center; color: var(--ink-2); }
.spinner {
  width: 30px; height: 30px; margin: 0 auto 12px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px;
  background: var(--header-bg);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 32px; height: 32px; flex: 0 0 32px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  border-radius: var(--radius-sm);
  font-weight: 800; font-size: 13px; letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11px; color: var(--ink-2); }

.nav { display: flex; gap: 4px; align-items: center; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 8px 14px; border-radius: var(--btn-radius);
  color: var(--ink); font-size: 14px; white-space: nowrap;
  border: 1px solid transparent; text-decoration: none;
}
.nav a:hover { background: var(--accent-soft); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.avatar {
  width: 26px; height: 26px; flex: 0 0 26px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 50%; font-size: 12px; font-weight: 700;
}
.user-name { max-width: 90px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--panel);
  border-radius: var(--btn-radius); cursor: pointer; font-size: 15px;
}
.icon-btn:hover { background: var(--accent-soft); }

.theme-picker { position: relative; }
.theme-menu {
  position: absolute; right: 0; top: 40px; z-index: 60;
  min-width: 148px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.theme-menu-title { font-size: 11px; color: var(--ink-2); padding: 6px 10px 4px; }
.theme-menu button {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px; border: none; background: none;
  color: var(--ink); font-size: 13px; cursor: pointer;
  border-radius: var(--radius-sm); font-family: inherit;
}
.theme-menu button:hover { background: var(--accent-soft); }
.theme-menu button.on { color: var(--accent); font-weight: 650; }
.theme-menu-sep { height: 1px; background: var(--line); margin: 5px 0; }

/* ---------- 容器 ---------- */
.container { max-width: 1080px; margin: 0 auto; padding: 22px 20px 80px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.card-head h1, .card-head h2 { margin: 0; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; min-height: 40px;
  border: 1px solid transparent; border-radius: var(--btn-radius);
  background: var(--accent); color: var(--accent-ink);
  font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.ghost { background: transparent; color: var(--accent); border-color: var(--line); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.plain { background: var(--panel-2); color: var(--ink); border-color: var(--line); }
.btn.plain:hover { background: var(--accent-soft); }
.btn.danger { background: #c0392b; color: #fff; }
.btn.danger:hover { background: #a5302a; }
.btn.sm { padding: 7px 13px; min-height: 34px; font-size: 13px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

.btn-ghost {
  padding: 7px 13px; min-height: 34px;
  border: 1px solid var(--line); background: transparent;
  color: var(--ink); border-radius: var(--btn-radius);
  font-size: 13px; cursor: pointer; font-family: inherit;
}
.btn-ghost:hover { background: var(--accent-soft); }

/* ---------- 表单 ---------- */
.form { max-width: 420px; }
.form.wide { max-width: 720px; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--ink-2); margin-top: 5px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; min-height: 40px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel); color: var(--ink);
  font-size: 14px; font-family: inherit;
}
textarea { min-height: 78px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}
input[type="checkbox"] { width: auto; min-height: auto; margin: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 140px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--line);
}
.switch-row:last-child { border-bottom: none; }
.switch-row .txt strong { display: block; font-size: 14px; }
.switch-row .txt span { font-size: 12px; color: var(--ink-2); }

/* 开关 */
.switch { position: relative; width: 46px; height: 26px; flex: 0 0 46px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2; }
.switch i {
  position: absolute; inset: 0; background: var(--line);
  border-radius: 999px; transition: background .18s;
}
.switch i::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; background: #fff; border-radius: 50%;
  transition: transform .18s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); }

/* ---------- 标签 / 徽章 ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 650; white-space: nowrap;
}
.badge.ok { background: #e6f3ec; color: #2f6b4f; }
.badge.warn { background: #fbf2e2; color: #7a5618; }
.badge.danger { background: #fbeceb; color: #8c3a3a; }
.badge.muted { background: var(--panel-2); color: var(--ink-2); }
[data-mode="dark"] .badge.ok { background: #17351f; color: #7fce9f; }
[data-mode="dark"] .badge.warn { background: #3a2c12; color: #e3bd7a; }
[data-mode="dark"] .badge.danger { background: #3d1f1f; color: #e59a94; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: var(--radius-sm);
  background: var(--panel-2); color: var(--ink-2);
  font-size: 12px; border: 1px solid var(--line);
}

/* ---------- 提示条 ---------- */
.note {
  font-size: 12.5px; color: var(--ink-2);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px; margin-top: 12px;
}
.note.warn { background: #fbf2e2; border-color: #f0dcb8; color: #7a5618; }
.note.danger { background: #fbeceb; border-color: #f0c8c4; color: #8c3a3a; }
.note.ok { background: #e9f5ee; border-color: #c6e2d3; color: #2f6b4f; }
[data-mode="dark"] .note.warn { background: #33270f; border-color: #4d3d16; color: #e3bd7a; }
[data-mode="dark"] .note.danger { background: #351b1b; border-color: #4d2a2a; color: #e59a94; }
[data-mode="dark"] .note.ok { background: #16301f; border-color: #24472f; color: #7fce9f; }

/* ---------- 登录诊断 ---------- */
.diag-row {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 7px 0; border-bottom: 1px dashed var(--line);
  font-size: 13px;
}
.diag-row:last-child { border-bottom: 0; }
.diag-k { flex: 0 0 132px; color: var(--ink-2); }
.diag-v { flex: 1; font-family: ui-monospace, Consolas, monospace; word-break: break-all; }

/* ---------- 表格 ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 560px; }
table.tbl th, table.tbl td {
  text-align: left; padding: 10px 12px;
  border-bottom: 1px solid var(--line); vertical-align: middle;
}
table.tbl th { color: var(--ink-2); font-weight: 650; font-size: 12.5px; white-space: nowrap; }
table.tbl tbody tr:hover { background: var(--panel-2); }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: none; }
.tbl-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- 统计卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--ink-2); }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat.accent .value { color: var(--accent); }

/* ---------- 空状态 ---------- */
.empty { text-align: center; padding: 44px 16px; color: var(--ink-2); }
.empty .ico { font-size: 34px; margin-bottom: 10px; opacity: .55; }
.empty p { margin: 0 0 14px; font-size: 13.5px; }

/* ---------- 板块网格 ---------- */
.sections { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.section-card {
  display: block; padding: 18px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  color: var(--ink); text-decoration: none; transition: transform .14s, box-shadow .14s;
}
.section-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.section-card .ico { font-size: 24px; }
.section-card h3 { margin: 8px 0 4px; }
.section-card p { font-size: 12.5px; color: var(--ink-2); margin: 0; }

/* ---------- 标签页 ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab {
  padding: 9px 15px; cursor: pointer; font-size: 14px; color: var(--ink-2);
  border: none; background: none; border-bottom: 2px solid transparent;
  font-family: inherit; white-space: nowrap;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 650; }

/* ---------- 登录 / 待审批 ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-logo {
  width: 52px; height: 52px; margin: 0 auto 14px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  border-radius: var(--radius); font-weight: 800; font-size: 18px;
}
.auth-card h1 { text-align: center; font-size: 20px; }
.auth-card .subtitle { text-align: center; margin-bottom: 20px; }
.auth-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 18px; }
.auth-tab {
  padding: 9px 4px; border: 1px solid var(--line); background: var(--panel);
  border-radius: var(--btn-radius); cursor: pointer; font-size: 13px;
  font-family: inherit; color: var(--ink); white-space: nowrap;
}
.auth-tab.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 650; }

.center-page { max-width: 560px; margin: 40px auto; text-align: center; }
.center-page .card { text-align: left; }
.big-ico { font-size: 46px; margin-bottom: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 42px; transform: translateX(-50%) translateY(10px);
  z-index: 200; max-width: min(88vw, 460px);
  background: #2b2f36; color: #fff; padding: 11px 18px;
  border-radius: var(--radius-sm); font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #8c3a3a; }

/* ---------- 弹层 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 150;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .45);
  padding: 20px; overflow-y: auto;
}
.modal-box {
  background: var(--panel); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; padding: 22px;
  max-height: 88vh; overflow-y: auto;
}
.modal-box h3 { margin-bottom: 14px; font-size: 16px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* ---------- 报销单打印 ---------- */
.print-doc {
  background: #fff; color: #000; padding: 22px;
  width: 210mm; min-height: 297mm; margin: 0 auto;
  font-size: 13px; line-height: 1.7;
}
.print-doc h1, .print-doc h2, .print-doc h3 { color: #000; }
.rp-title { text-align: center; font-size: 20px; font-weight: 800; letter-spacing: 4px; margin: 0 0 4px; }
.rp-subtitle { text-align: center; font-size: 12px; color: #555; margin-bottom: 16px; }
.rp-meta { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 12.5px; }
.rp-meta td { padding: 5px 4px; border: 1px solid #999; }
.rp-meta td.k { width: 88px; background: #f0f0f0; font-weight: 600; text-align: center; }
.rp-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.rp-table th, .rp-table td { border: 1px solid #666; padding: 5px 6px; }
.rp-table th { background: #f0f0f0; text-align: center; font-weight: 700; }
.rp-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.rp-table tr.sub td { background: #f7f7f7; font-weight: 600; }
.rp-total { margin-top: 12px; display: flex; justify-content: space-between; align-items: center; border: 1px solid #666; padding: 9px 12px; font-size: 13px; }
.rp-words { font-weight: 700; letter-spacing: 1px; }
.rp-sign { margin-top: 26px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.rp-sign div { border: 1px solid #999; padding: 26px 8px 8px; text-align: center; font-size: 12px; color: #444; }
.rp-foot { margin-top: 14px; font-size: 11px; color: #666; display: flex; justify-content: space-between; }

@media print {
  body { background: #fff !important; }
  .topbar, .boot, .toast, .modal, .no-print { display: none !important; }
  .container { padding: 0 !important; margin: 0 !important; max-width: none !important; }
  .print-doc { width: auto; min-height: auto; padding: 0; margin: 0; }
  @page { size: A4; margin: 14mm 12mm; }
}

/* ---------- 响应式 ---------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 9px 14px; gap: 10px; }
  .topbar-left { order: 1; flex: 1 1 auto; }
  .topbar-right { order: 2; }
  .nav { order: 3; flex: 1 0 100%; padding-bottom: 2px; }
  .brand-sub { display: none; }
  .container { padding: 16px 14px 70px; }
  .card { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .user-name { display: none; }
  .form { max-width: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat .value { font-size: 19px; }
  h1 { font-size: 19px; }
  .btn { min-height: 42px; }
  input, select, textarea { min-height: 42px; font-size: 16px; /* 防 iOS 缩放 */ }
  .print-doc { width: 100%; padding: 4px; }
  .rp-sign { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr; }
  .auth-tabs { grid-template-columns: 1fr; }
}
