/* ============================================================
   个人欠款案件资料采集 - 移动优先 H5 样式
   ============================================================ */
:root {
  --topbar-h: 88px;     /* topbar 高度 (含 2 行) */
  --tabs-h: 48px;        /* tabs 高度 */
  --safe-pad: 12px;      /* 内容统一 padding */
  --brand: #4f46e5;      /* 主题色 */
  --bg: #f5f7fa;
  --card: #ffffff;
  --line: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* ===== 顶部: 两行 ===== */
.topbar {
  position: sticky; top: 0; z-index: 101;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 8px var(--safe-pad);
}
.topbar-main {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.brand { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.brand .logo { font-size: 20px; }
.brand h1 { font-size: 15px; font-weight: 600; }
.case-current {
  display: flex; align-items: center; gap: 4px;
  flex: 1; min-width: 0;
  background: #f3f4f6; border-radius: 4px;
  padding: 4px 8px;
}
.case-current .lbl { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.case-current code {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12px; color: var(--brand);
  font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn {
  border: 1px solid var(--line);
  background: #fff; color: var(--text);
  border-radius: 4px;
  padding: 6px 12px; font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn:hover { background: #f9fafb; }
.btn.primary:hover { background: #4338ca; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 查询框 (单独一行) */
.case-query { display: flex; gap: 6px; }
.case-query input {
  flex: 1; min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 14px;
  background: #fff;
  outline: none;
  font-family: inherit;
}
.case-query input:focus { border-color: var(--brand); }
.case-query .btn { padding: 7px 14px; flex-shrink: 0; }

/* ===== Tabs: 4 个, 紧凑 ===== */
.tabs {
  position: sticky; top: var(--topbar-h); z-index: 100;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex;
  padding: 0 var(--safe-pad);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.tab {
  flex: 1; /* 4 个 tab 平均分配宽度 */
  background: none; border: none;
  padding: 8px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab .num { font-size: 10px; color: #9ca3af; }
.tab .lbl { font-size: 13px; font-weight: 500; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab.active .num { color: var(--brand); font-weight: 600; }
.tab.has-data::after { content: " ✅"; font-size: 10px; }

/* ===== Main ===== */
main { padding: var(--safe-pad); max-width: 720px; margin: 0 auto; }
.panel {
  background: var(--card);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  margin-bottom: var(--safe-pad);
}
.panel.hidden { display: none; }
.panel h2 { font-size: 17px; margin-bottom: 8px; }
.panel h3.sub { font-size: 14px; font-weight: 600; color: #374151; margin: 14px 0 8px; }
.hint { color: var(--muted); font-size: 12px; margin-bottom: 12px; line-height: 1.5; }
.party-divider { border: none; border-top: 1px dashed var(--line); margin: 20px 0; }

/* ===== Upload zone ===== */
.upload-zone {
  position: relative;
  border: 2px dashed #d1d5db;
  border-radius: 8px;
  padding: 24px 12px;
  text-align: center;
  background: #fafbff;
  margin-bottom: 12px;
  transition: all .2s;
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--brand); background: #eef2ff; }
.upload-zone input[type=file] {
  position: absolute; inset: 0;
  opacity: 0; cursor: pointer;
}
.upload-zone p { color: var(--muted); pointer-events: none; }
.upload-zone small { display: block; font-size: 11px; color: #9ca3af; margin-top: 4px; }

/* ===== Form ===== */
.party-form, .loan-form {
  display: grid;
  grid-template-columns: 1fr;  /* 移动端默认 1 列 */
  gap: 10px;
  padding: 12px;
  background: #f9fafb;
  border-radius: 8px;
  margin-bottom: 12px;
}
.party-form label, .loan-form label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: #4b5563;
}
.party-form input, .loan-form input,
.party-form select, .loan-form select,
.party-form textarea, .loan-form textarea {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 14px;
  background: #fff;
  outline: none;
  font-family: inherit;
  width: 100%;
}
.party-form input:focus, .loan-form input:focus,
.party-form select:focus, .loan-form select:focus,
.party-form textarea:focus, .loan-form textarea:focus { border-color: var(--brand); }
.party-form .save-party, .loan-form .save-loan {
  width: 100%;
  padding: 11px;
  font-size: 15px;
  font-weight: 500;
}

/* ===== 备注 textarea ===== */
.case-note {
  display: block; width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  margin: 6px 0 0;
  resize: vertical;
  background: #fff;
}

/* 备注提交按钮: 全宽 */
.save-note {
  width: 100%;
  margin-top: 8px;
  background: #f3f4f6;
  color: #374151;
  border-color: #d1d5db;
  padding: 10px;
}
.save-note:disabled { opacity: 1; }  /* 禁用时仍显示清晰 */

/* 备注已保存的 ✅ 标记 */
.note-saved-mark {
  color: #059669;
  font-weight: 600;
  margin-left: 4px;
}

/* tab "有备注" 标记已统一到 has-data::after 的 ✅ 上, 不再单独渲染 📝 */

/* ===== 文件列表 ===== */
.files { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.files .file {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: #f9fafb; border-radius: 4px;
  font-size: 12px;
}
.files .file .thumb {
  width: 48px; height: 48px; border-radius: 4px;
  object-fit: cover; flex-shrink: 0;
  background: #fff; border: 1px solid var(--line);
}
.files .file .thumb-icon {
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; background: #eef2ff; color: var(--brand);
  width: 48px; height: 48px; border-radius: 4px; flex-shrink: 0;
}
.files .file .meta-col { flex: 1; min-width: 0; }
.files .file .name { font-family: monospace; word-break: break-all; font-weight: 500; font-size: 12px; }
.files .file .meta { color: var(--muted); font-size: 11px; margin-top: 2px; }
.files .file .actions { flex-shrink: 0; }
.files .file .actions button {
  padding: 3px 8px; font-size: 11px;
  border: 1px solid var(--line); background: #fff; border-radius: 3px; cursor: pointer;
}

/* ===== 提交确认条 ===== */
.submit-bar {
  background: linear-gradient(to top, var(--card) 70%, rgba(255,255,255,0));
  padding: 20px 0 12px; text-align: center;
}
.submit-bar .btn.big {
  width: 100%;
  padding: 14px;
  font-size: 16px; font-weight: 600;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}
.submit-bar .hint { text-align: center; margin-top: 6px; }
.hidden { display: none !important; }

.submit-confirm {
  background: #fff7ed; border: 2px solid #fb923c;
  border-radius: 12px; padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 4px 12px rgba(251, 146, 60, 0.15);
}
.submit-confirm .confirm-prompt {
  margin: 0 0 12px; color: #9a3412;
  font-size: 14px; line-height: 1.6;
}
.submit-confirm .confirm-prompt small { color: #c2410c; font-size: 12px; }
.submit-confirm .confirm-prompt b {
  color: #7c2d12; font-family: monospace;
  background: #fff; padding: 2px 6px; border-radius: 3px;
}
.submit-confirm .confirm-actions { display: flex; gap: 10px; justify-content: center; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff;
  padding: 10px 20px; border-radius: 6px;
  font-size: 14px; z-index: 1000;
  max-width: 90vw; text-align: center;
  opacity: 0; transition: opacity .3s;
  pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.error { background: #dc2626; }
.toast.success { background: #059669; }

/* ===== 自定义 modal (替代原生 prompt) ===== */
.modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-box {
  background: var(--card); border-radius: 12px;
  padding: 20px; max-width: 360px; width: 100%;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.modal-box h3 { font-size: 16px; margin-bottom: 10px; }
.modal-box .hint { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.modal-box input {
  width: 100%; padding: 10px;
  border: 1px solid var(--line); border-radius: 6px;
  font-size: 15px; font-family: inherit; outline: none;
}
.modal-box input:focus { border-color: var(--brand); }
.modal-error {
  color: #dc2626; font-size: 12px;
  margin-top: 8px; padding: 6px 8px;
  background: #fef2f2; border-radius: 4px;
}
.modal-actions {
  display: flex; gap: 10px;
  margin-top: 16px; justify-content: flex-end;
}
.modal-actions .btn { padding: 9px 20px; font-size: 14px; }

/* ===== 必填字段标红 ===== */
.party-form label.required-missing { color: #dc2626; }
.party-form label.required-missing input {
  border-color: #dc2626;
  background: #fef2f2;
}
.party-form label.required-missing::before {
  content: "⚠️ ";
}
.party-form input.shake {
  animation: shake .4s;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}

/* ===== 桌面端 (>= 720px): 表单 2 列 + topbar 单行 ===== */
@media (min-width: 720px) {
  :root { --topbar-h: 56px; }
  .topbar {
    padding: 8px 24px;
    display: flex; align-items: center; gap: 16px;
  }
  .topbar-main { margin-bottom: 0; flex: 1; }
  .case-query { max-width: 360px; flex-shrink: 0; }
  .brand h1 { font-size: 16px; }
  .tabs { padding: 0 24px; }
  .tab .lbl { font-size: 14px; }
  .tab { padding: 10px 8px; }
  .panel { padding: 24px; }
  .panel h2 { font-size: 18px; }
  .party-form { grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; }
  .party-form .save-party { grid-column: 1 / -1; }
  .loan-form { grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; }
  .loan-form h4 { grid-column: 1 / -1; font-size: 13px; color: #4b5563; margin: 0; }
  .loan-form .save-loan { grid-column: 1 / -1; }
  .upload-zone { padding: 32px 16px; }
  .submit-bar .btn.big { width: auto; padding: 14px 48px; }
  .files .file .thumb, .files .file .thumb-icon { width: 56px; height: 56px; }
  .files .file .thumb-icon { font-size: 28px; }
  .files .file .name { font-size: 13px; }
  .files .file .meta { font-size: 11px; }
}

/* ===== 小屏 (≤ 360px) ===== */
@media (max-width: 360px) {
  :root { --topbar-h: 96px; }
  .brand h1 { font-size: 14px; }
  .tab .lbl { font-size: 12px; }
  .panel { padding: 12px; }
  .panel h2 { font-size: 16px; }
  .party-form, .loan-form { padding: 10px; }
  .files .file .thumb, .files .file .thumb-icon { width: 40px; height: 40px; }
}

/* ===== 横屏 ===== */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --topbar-h: 72px; }
}