/* 应收账款台账 - Cloudflare Pages 静态前端 */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --border: #e5e5ea;
  --text: #1c1c1e;
  --subtext: #8e8e93;
  --blue: #007aff;
  --blue-dark: #0051d5;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --purple: #af52de;
  --shadow: 0 8px 30px rgba(28, 28, 30, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 14px;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ---------------- 登录页 ---------------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 10%, rgba(0, 122, 255, 0.18), transparent 34%),
    radial-gradient(circle at 85% 90%, rgba(175, 82, 222, 0.16), transparent 36%),
    linear-gradient(135deg, #f7f9ff 0%, #eef1f8 100%);
}

.login-card {
  width: min(440px, 100%);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 24px;
  box-shadow: 0 24px 70px rgba(28, 28, 30, 0.16);
  padding: 36px 34px 30px;
  backdrop-filter: blur(16px);
}

.login-logo {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--blue), #5ac8fa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-bottom: 18px;
}

.login-card h1 { font-size: 26px; margin: 0 0 8px; letter-spacing: -0.5px; }
.login-card p { color: var(--subtext); line-height: 1.6; margin: 0 0 22px; }
.login-card label { display: block; font-weight: 600; margin-bottom: 8px; }
.login-card .hint { font-size: 12px; color: var(--subtext); line-height: 1.6; margin-top: 14px; }
.login-error {
  display: none;
  background: #fff2f1;
  color: var(--red);
  border: 1px solid #ffd4d0;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  line-height: 1.5;
}
.login-error.show { display: block; }

/* ---------------- 通用控件 ---------------- */
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, .12);
}
.textarea { min-height: 76px; resize: vertical; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: transform .08s, background .15s, border-color .15s;
  font-weight: 600;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: #f7f7fa; }
.btn-danger { background: #fff0ef; border-color: #ffd4d0; color: var(--red); }
.btn-danger:hover { background: #ffe4e1; }
.btn-success { background: #eafaf0; border-color: #c8f0d6; color: #1d8a42; }
.btn-ghost { background: transparent; color: var(--subtext); }
.btn-ghost:hover { background: rgba(0,0,0,.04); }
.btn-sm { padding: 6px 9px; font-size: 12px; border-radius: 8px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------------- 应用框架 ---------------- */
.app { min-height: 100vh; }
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.app-header-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon {
  width: 40px; height: 40px; border-radius: 13px;
  background: linear-gradient(135deg, var(--blue), #5ac8fa);
  display: flex; align-items: center; justify-content: center;
  font-size: 21px; flex: none;
}
.brand h1 { font-size: 18px; margin: 0; letter-spacing: -0.3px; }
.brand small { color: var(--subtext); font-size: 12px; }
.header-spacer { flex: 1; }
.conn {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--subtext); font-size: 12px; white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c7c7cc; }
.dot.ok { background: var(--green); box-shadow: 0 0 0 4px rgba(52,199,89,.13); }
.dot.err { background: var(--red); box-shadow: 0 0 0 4px rgba(255,59,48,.13); }

.app-nav {
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
}
.tab-btn {
  border: 0;
  background: transparent;
  color: var(--subtext);
  padding: 13px 14px 12px;
  border-bottom: 2px solid transparent;
  font-weight: 600;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

.app-main {
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade-in .18s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h2 { margin: 0 0 4px; font-size: 24px; letter-spacing: -0.5px; }
.page-head p { margin: 0; color: var(--subtext); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- 卡片 / 指标 ---------------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: 0 2px 10px rgba(28,28,30,.03);
}
.kpi .label { color: var(--subtext); font-size: 12px; margin-bottom: 8px; }
.kpi .value { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.kpi .value.red { color: var(--red); }
.kpi .value.green { color: #1d8a42; }
.kpi .value.blue { color: var(--blue); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 16px; }
.card-head {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.card-head h3 { margin: 0; font-size: 15px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px 18px; }
.card-note {
  padding: 10px 18px 12px;
  border-top: 1px dashed var(--border);
  color: var(--subtext);
  font-size: 12px;
  line-height: 1.7;
}

.filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filters .input { max-width: 280px; }
.filters .select { max-width: 190px; }
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: #fcfcfe;
}
.toolbar .spacer { flex: 1; }
.toolbar-divider { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--subtext);
  font-size: 12px;
  white-space: nowrap;
}
input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
  cursor: pointer;
}
table.data th.check-col, table.data td.check-col {
  width: 38px;
  min-width: 38px;
  text-align: center;
  padding-left: 8px;
  padding-right: 8px;
}
.muted { color: var(--subtext); }
.small { font-size: 12px; }

/* ---------------- 表格 ---------------- */
.table-wrap { width: 100%; overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}
table.data th, table.data td {
  padding: 11px 12px;
  border-bottom: 1px solid #f0f0f4;
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}
table.data th {
  color: var(--subtext);
  font-size: 12px;
  font-weight: 600;
  background: #fafafc;
  position: sticky;
  top: 0;
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--blue); }
table.data th.sorted { color: var(--blue); background: #f2f8ff; }
table.data tbody tr:hover { background: #fafcff; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.actions { text-align: right; }
table.data tr.red-row td { color: var(--subtext); }
table.data tr.red-row td:nth-child(5) { color: var(--orange); }
.row-actions { display: inline-flex; gap: 5px; }
.empty {
  padding: 46px 20px;
  text-align: center;
  color: var(--subtext);
}
.empty .big { font-size: 34px; margin-bottom: 10px; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #f2f2f7;
  color: var(--subtext);
}
.badge.red { background: #fff0ef; color: var(--red); }
.badge.green { background: #eafaf0; color: #1d8a42; }
.badge.blue { background: #eaf4ff; color: var(--blue); }
.badge.orange { background: #fff6e8; color: #a96300; }

/* ---------------- 弹窗 ---------------- */
.modal-root { position: fixed; inset: 0; z-index: 100; display: none; }
.modal-root.show { display: block; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(18, 18, 20, .42);
  backdrop-filter: blur(3px);
}
.modal {
  position: relative;
  width: min(760px, calc(100vw - 28px));
  max-height: calc(100vh - 50px);
  margin: 24px auto;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 30px 90px rgba(0,0,0,.26);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal.wide { width: min(1080px, calc(100vw - 28px)); }
.modal-head {
  padding: 17px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: #fcfcfe;
}
.icon-btn {
  border: 0; background: #f2f2f7; color: var(--subtext);
  width: 32px; height: 32px; border-radius: 9px; font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: #e8e8ee; color: var(--text); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; color: #3a3a3c; }
.field .req { color: var(--red); }
.form-note { color: var(--subtext); font-size: 12px; line-height: 1.6; margin-top: 10px; }

.progress {
  height: 7px;
  background: #f0f0f4;
  border-radius: 99px;
  overflow: hidden;
  margin: 12px 0 6px;
}
.progress > span { display: block; height: 100%; width: 0; background: var(--blue); transition: width .15s; }

/* ---------------- 详情 ---------------- */
.detail-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.detail-summary .kpi { padding: 12px 14px; box-shadow: none; }
.detail-summary .kpi .value { font-size: 17px; }
.detail-tabs { display: flex; gap: 6px; margin: 8px 0 12px; }
.detail-tab {
  border: 1px solid var(--border); background: #fff; border-radius: 9px;
  padding: 7px 12px; font-weight: 600; color: var(--subtext);
}
.detail-tab.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.detail-section { display: none; }
.detail-section.active { display: block; }

/* ---------------- Toast ---------------- */
.toast-root {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 40px));
}
.toast {
  background: #1c1c1e;
  color: #fff;
  border-radius: 11px;
  padding: 12px 14px;
  box-shadow: 0 12px 30px rgba(0,0,0,.2);
  line-height: 1.45;
  animation: toast-in .2s ease;
  word-break: break-word;
}
.toast.success { background: #1d8a42; }
.toast.error { background: #d92c20; }
.toast.warn { background: #a96300; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .app-header-inner { padding: 12px 14px; }
  .app-nav { padding: 0 14px; }
  .app-main { padding: 14px; }
  .brand small { display: none; }
  .conn span { display: none; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 12px; }
  .kpi .value { font-size: 18px; }
  .page-head h2 { font-size: 20px; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-summary { grid-template-columns: 1fr 1fr; }
  .filters .input, .filters .select { max-width: none; flex: 1 1 150px; }
  .modal { margin: 10px auto; max-height: calc(100vh - 20px); }
  .modal-body { padding: 15px; }
}
