/* 发票整理助手 App 版 —— 设计体系 */
:root {
  --brand-900: #16294a;
  --brand-700: #1e3a5f;
  --brand-500: #2a5298;
  --brand-400: #4a8ade;
  --brand-100: #e8f0fe;
  --ink: #1c2b3a;
  --ink-2: #4a6fa5;
  --ink-3: #7a9cc6;
  --line: #e3ecf7;
  --bg: #f2f6fc;
  --card: #ffffff;
  --green: #0d9488;
  --amber: #d97706;
  --red: #ef4444;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(30, 58, 95, .07);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--ink); min-height: 100vh;
}
.container { max-width: 1400px; margin: 0 auto; min-height: 100vh; }
.only-mobile { display: none !important; }
.only-desktop { display: initial !important; }

/* Header */
.header {
  background: linear-gradient(135deg, var(--brand-700), var(--brand-500));
  color: #fff; padding: 14px 28px; display: flex; justify-content: space-between; align-items: center;
  border-radius: 0 0 18px 18px; box-shadow: 0 4px 20px rgba(30, 58, 95, .18);
  padding-top: calc(14px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { font-size: 30px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.2)); }
.header h1 { font-size: 19px; font-weight: 600; letter-spacing: .5px; }
.brand-sub { font-size: 11px; color: #b9cdea; letter-spacing: 2px; margin-top: 2px; }
.header-right { display: flex; align-items: center; gap: 10px; }
.icon-btn { background: rgba(255,255,255,.14); border: none; color: #fff; font-size: 16px; width: 36px; height: 36px; border-radius: 10px; cursor: pointer; transition: background .2s; }
.icon-btn:hover { background: rgba(255,255,255,.25); }
.act-badge { font-size: 12px; cursor: pointer; padding: 4px 10px; border-radius: 20px; background: rgba(255,255,255,.12); }
.act-badge.ok { color: #7dd3a0; }
.act-badge.warn { color: #fcd34d; }

.main { padding: 22px 28px 40px; }

/* 导入区 */
.upload-zone {
  border: 2px dashed #a8c4e6; border-radius: 18px; padding: 40px 24px; text-align: center;
  background: linear-gradient(135deg, #f4f9ff, #eaf2ff); cursor: pointer; transition: all .25s ease;
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--brand-500); background: #e2edff; transform: translateY(-2px); box-shadow: 0 8px 25px rgba(42,82,152,.12); }
.upload-zone .icon { font-size: 42px; margin-bottom: 10px; }
.upload-zone h3 { color: var(--brand-700); font-size: 16px; }
.upload-zone p { color: var(--ink-3); font-size: 13px; margin-top: 6px; }
.import-bar { display: flex; gap: 10px; margin: 14px 0 22px; flex-wrap: wrap; }
.btn {
  padding: 10px 18px; border: none; border-radius: 12px; font-size: 13px; font-weight: 500;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: all .2s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(0,0,0,.1); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); color: #fff; }
.btn-secondary { background: #fff; color: var(--ink-2); border: 1px solid #c4d7ef; }
.btn-warning { background: linear-gradient(135deg, #f59e0b, var(--amber)); color: #fff; }
.btn-danger { background: #fff; color: var(--red); border: 1px solid #fca5a5; }
.btn-camera { background: linear-gradient(135deg, var(--green), #0f766e); color: #fff; font-size: 15px; padding: 13px 20px; flex: 1; }

/* 进度 */
.progress-container { display: none; margin-bottom: 18px; background: var(--card); padding: 14px 18px; border-radius: var(--radius); box-shadow: var(--shadow); }
.progress-bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--brand-500), var(--brand-400)); width: 0; transition: width .3s; }
.progress-text { text-align: center; margin-top: 8px; color: var(--ink-2); font-size: 13px; }

/* 统计 */
.stats { display: none; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--card); padding: 16px; border-radius: var(--radius); text-align: center; box-shadow: var(--shadow); }
.stat-card .number { font-size: 24px; font-weight: 700; color: var(--brand-700); }
.stat-card .label { font-size: 11px; color: var(--ink-3); margin-top: 4px; letter-spacing: .5px; }

/* 筛选 */
.filter-bar { display: none; background: var(--card); padding: 12px 16px; border-radius: var(--radius); margin-bottom: 14px; box-shadow: var(--shadow); }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-input { padding: 9px 12px; border: 1px solid #c4d7ef; border-radius: 10px; font-size: 13px; background: #f8faff; }
.filter-input:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(42,82,152,.1); }
.filter-input.grow { flex: 1; min-width: 180px; }
.chip { padding: 8px 12px; border: 1px solid #c4d7ef; background: #f8faff; border-radius: 20px; font-size: 12px; color: var(--ink-2); cursor: pointer; }
.chip.active { background: #fef3c7; border-color: var(--amber); color: var(--amber); font-weight: 600; }
.multi-select { position: relative; min-width: 120px; }
.multi-select-display { padding: 9px 12px; border: 1px solid #c4d7ef; border-radius: 10px; background: #f8faff; cursor: pointer; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.multi-select-dropdown { display: none; position: absolute; top: 100%; left: 0; min-width: 100%; background: #fff; border: 1px solid #c4d7ef; border-radius: 10px; box-shadow: 0 8px 24px rgba(30,58,95,.14); z-index: 100; max-height: 240px; overflow-y: auto; margin-top: 4px; }
.multi-select.open .multi-select-dropdown { display: block; }
.multi-select-item { padding: 10px 14px; cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.multi-select-item:hover { background: #f0f5ff; }
.selected-tag { background: var(--brand-500); color: #fff; padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.placeholder { color: #999; }

/* 工具条 */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.dropdown-menu { display: none; position: absolute; background: #fff; border: 1px solid #c4d7ef; border-radius: 12px; box-shadow: 0 8px 24px rgba(30,58,95,.14); z-index: 1000; min-width: 180px; }
.dropdown-item { padding: 11px 16px; cursor: pointer; font-size: 13px; }
.dropdown-item:hover { background: #f0f5ff; }

.manual-tip { display: none; background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 10px 16px; border-radius: 10px; font-size: 13px; margin-bottom: 14px; }

/* 表格（桌面）*/
.table-container { display: none; border-radius: var(--radius); overflow: auto; margin-bottom: 20px; box-shadow: var(--shadow); background: var(--card); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); color: #fff; padding: 12px 10px; text-align: left; font-weight: 500; white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid #eef3fa; }
tr:hover { background: #f5f9ff; }
tr.warn-row { background: #fffbeb; }
.editable { cursor: text; padding: 3px 6px; border-radius: 6px; }
.editable:hover { background: #eef3fa; }
.tag { padding: 3px 9px; border-radius: 10px; font-size: 11px; font-weight: 500; white-space: nowrap; display: inline-block; }
.tag-normal { background: #eef3fa; color: var(--ink-2); }
.tag-vat { background: #fef3c7; color: var(--amber); }
.tag-digital { background: #d1fae5; color: #047857; }
.tag-dup { background: #fee2e2; color: var(--red); }
.category-select { padding: 5px 8px; border: 1px solid #c4d7ef; border-radius: 8px; font-size: 12px; background: #f8faff; }
.amount-input { width: 80px; border: none; background: transparent; padding: 3px; font-size: 13px; text-align: right; font-weight: 600; color: var(--brand-700); }
.action-btn { padding: 5px 9px; border: none; border-radius: 8px; cursor: pointer; font-size: 12px; margin-right: 4px; }
.btn-view { background: #eef3fa; color: var(--ink-2); }
.btn-del { background: #fef2f2; color: var(--red); }
.filename-link { color: var(--brand-500); text-decoration: none; }
.filename-link:hover { text-decoration: underline; }
.missing { color: var(--red); }

/* 卡片（手机）*/
.card-list { display: none; flex-direction: column; gap: 10px; margin-bottom: 20px; }
@media (min-width: 769px) { .card-list { display: none !important; } }
.inv-card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.inv-card.warn { border-left: 3px solid var(--amber); }
.inv-card .row1 { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.inv-card .fname { font-size: 13px; color: var(--brand-500); word-break: break-all; }
.inv-card .amt { font-size: 20px; font-weight: 700; color: var(--brand-700); white-space: nowrap; }
.inv-card .row2 { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; align-items: center; }
.inv-card .meta { font-size: 12px; color: var(--ink-3); }
.inv-card .fields { font-size: 13px; color: var(--ink); line-height: 1.9; }
.inv-card .fields b { color: var(--ink-3); font-weight: 400; font-size: 12px; margin-right: 4px; }
.inv-card .warn-text { font-size: 12px; color: var(--amber); margin-top: 6px; }
.inv-card .card-actions { display: flex; gap: 8px; margin-top: 10px; }
.inv-card .card-actions .action-btn { padding: 8px 14px; }

/* 空状态 / 历史 / 页脚 */
.empty-state { text-align: center; padding: 70px 20px; color: var(--ink-3); }
.empty-state .icon { font-size: 54px; margin-bottom: 14px; }
.empty-state h3 { color: var(--ink-2); margin-bottom: 6px; }
.history-section { background: var(--card); border-radius: var(--radius); padding: 16px 20px; margin-top: 18px; box-shadow: var(--shadow); }
.history-section h4 { font-size: 14px; color: var(--brand-700); margin-bottom: 10px; }
.history-item { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; overflow: hidden; }
.history-summary { padding: 11px 14px; display: flex; justify-content: space-between; align-items: center; cursor: pointer; font-size: 13px; background: #f8faff; gap: 8px; }
.history-summary .info { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.history-summary .time { color: var(--ink-3); font-size: 12px; }
.history-summary .amount { font-weight: 600; color: var(--brand-700); }
.history-summary .count { background: #eef3fa; color: var(--ink-2); padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.history-detail { display: none; padding: 10px 14px; font-size: 12px; border-top: 1px solid var(--line); max-height: 220px; overflow-y: auto; }
.history-detail.open { display: block; }
.history-detail table { font-size: 12px; }
.history-detail th { padding: 6px 8px; background: var(--brand-500); }
.history-detail td { padding: 6px 8px; }
.history-empty { text-align: center; color: var(--ink-3); font-size: 13px; padding: 16px; }
.history-del { background: none; border: none; color: #ccc; cursor: pointer; font-size: 15px; }
.history-del:hover { color: var(--red); }
.footer { text-align: center; color: var(--ink-3); font-size: 12px; margin-top: 26px; }

/* 弹窗 */
.modal-overlay { position: fixed; inset: 0; background: rgba(30,58,95,.35); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 14px; }
.modal { background: #fff; border-radius: 16px; padding: 24px; max-width: 640px; width: 100%; max-height: 86vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(30,58,95,.25); }
.modal h3 { margin-bottom: 14px; font-size: 17px; color: var(--brand-700); }
.modal-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.rule-card { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.rule-header { background: #f5f9ff; padding: 11px 14px; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.rule-name-input { flex: 1; padding: 7px 10px; border: 1px solid #c4d7ef; border-radius: 8px; font-weight: 500; font-size: 14px; min-width: 0; }
.rule-body { padding: 16px; display: none; }
.rule-body.open { display: block; }
.rule-option { margin-bottom: 12px; padding: 10px 12px; background: #f5f9ff; border-radius: 8px; font-size: 13px; }
.keywords-input { width: 100%; padding: 10px; border: 1px solid #c4d7ef; border-radius: 8px; font-size: 13px; min-height: 60px; resize: vertical; }
.keywords-hint { font-size: 11px; color: var(--ink-3); margin-top: 5px; }
.match-count { margin-top: 10px; padding: 9px 12px; background: #eef3fa; border-radius: 8px; font-size: 12px; }
.org-opts { display: flex; flex-wrap: wrap; gap: 8px; }
.org-opts label { display: flex; align-items: center; gap: 5px; padding: 7px 12px; background: #f5f5f5; border-radius: 8px; cursor: pointer; font-size: 13px; }

/* 激活页 */
.act-overlay { position: fixed; inset: 0; z-index: 10000; background: linear-gradient(135deg, var(--brand-700) 0%, var(--brand-500) 50%, var(--brand-700) 100%); display: flex; align-items: center; justify-content: center; padding: 16px; }
.act-card { background: #fff; border-radius: 20px; padding: 44px 36px; max-width: 420px; width: 100%; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.act-logo { font-size: 44px; margin-bottom: 10px; }
.act-card h2 { color: var(--brand-700); font-size: 22px; margin-bottom: 8px; }
.act-card .act-sub { color: var(--ink-3); font-size: 13px; margin-bottom: 26px; }
.act-card .act-input { width: 100%; padding: 14px 16px; border: 2px solid #c4d7ef; border-radius: 12px; font-size: 17px; text-align: center; letter-spacing: 3px; font-family: monospace; outline: none; }
.act-card .act-input:focus { border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(42,82,152,.15); }
.act-card .act-btn { width: 100%; padding: 14px; border: none; border-radius: 12px; background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer; margin-top: 14px; }
.act-card .act-msg { margin-top: 12px; font-size: 13px; min-height: 20px; }
.act-card .act-tip { color: var(--ink-3); font-size: 12px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }

/* 响应式 */
@media (max-width: 768px) {
  .only-mobile { display: initial !important; }
  .only-desktop { display: none !important; }
  .table-container { display: none !important; }
  .main { padding: 14px 14px 40px; }
  .header { padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top)); border-radius: 0 0 14px 14px; }
  .header h1 { font-size: 17px; }
  .upload-zone { padding: 26px 14px; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 12px; }
  .stat-card .number { font-size: 20px; }
  .import-bar { position: sticky; bottom: 0; z-index: 50; background: var(--bg); padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); margin-bottom: 14px; }
  .filter-row .multi-select, .filter-row select { flex: 1; }
  .btn { padding: 10px 12px; font-size: 12px; }
  .toolbar .btn { flex: 1; min-width: 40%; }
}
