* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --primary: #1677ff;
  --primary-hover: #4096ff;
  --text: #1f1f1f;
  --text-secondary: #8c8c8c;
  --border: #e8e8e8;
  --green: #52c41a;
  --orange: #fa8c16;
  --blue: #1677ff;
  --red: #ff4d4f;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.mobile-list {
  display: none;
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #e8f1ff 0%, #f0f2f5 50%, #fff 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 10px;
  padding: 32px 28px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.login-card h1 {
  font-size: 22px;
  text-align: center;
  margin-bottom: 8px;
}

.login-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.login-error {
  background: #fff2f0;
  border: 1px solid #ffccc7;
  color: var(--red);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
  text-align: center;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.login-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}

.login-form input:focus {
  border-color: var(--primary);
}

.login-btn {
  width: 100%;
  margin-top: 20px;
  padding: 10px;
  font-size: 15px;
}

.header {
  background: var(--card);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.menu-toggle {
  display: none;
}

.header-menu {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-outline {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

a.btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.btn-danger {
  background: none;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 13px;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 32px;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  font-family: inherit;
}

.btn-action .btn-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.btn-action-edit {
  color: var(--primary);
  background: #e6f4ff;
  border-color: #91caff;
}

.btn-action-edit:hover {
  background: #bae0ff;
  border-color: var(--primary);
}

.btn-action-del {
  color: var(--red);
  background: #fff2f0;
  border-color: #ffccc7;
}

.btn-action-del:hover {
  background: #ffccc7;
  border-color: var(--red);
}

.btn-danger-fill {
  background: var(--red);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}

.btn-danger-fill:hover {
  background: #ff7875;
}

.detail-card-content {
  max-width: 680px;
}

.detail-card-content .modal-header {
  padding: 10px 14px;
}

.detail-card-content .modal-header h2 {
  font-size: 15px;
}

.detail-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  padding: 10px 14px 12px;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 6px 8px;
  background: #fafafa;
  border-radius: 6px;
  border: 1px solid #f0f0f0;
}

.detail-item-full {
  grid-column: 1 / -1;
}

.detail-item-full .detail-value {
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-label {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.2;
}

.detail-value {
  font-size: 13px;
  color: var(--text);
  line-height: 1.35;
  word-break: break-word;
}

.detail-actions {
  display: flex;
  width: 100%;
  padding: 12px 14px;
  margin-top: 0;
  gap: 8px;
  justify-content: flex-start;
  align-items: stretch;
  border-top: 1px solid var(--border);
}

.detail-action-btn {
  flex: 1;
  min-height: 40px;
  justify-content: center;
  font-size: 14px;
}

.detail-actions .btn-outline {
  padding: 8px 12px;
}

.detail-actions .btn-primary {
  padding: 8px 12px;
}

.detail-actions .btn-action-del {
  padding: 8px 12px;
}

.confirm-content {
  max-width: 400px;
}

.confirm-message {
  padding: 20px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}

.confirm-content .form-actions {
  padding: 0 20px 20px;
}

.password-form-body {
  padding: 0 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.password-form-body label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}

.password-form-body input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}

.password-form-body input:focus {
  border-color: var(--primary);
}

.mobile-card {
  display: none;
}

.mobile-empty {
  display: none;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  padding: 20px 24px;
}

.stat-card {
  background: var(--card);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 22px;
  font-weight: 600;
}

.stat-value.green { color: var(--green); }
.stat-value.orange { color: var(--orange); }
.stat-value.blue { color: var(--blue); }

.toolbar {
  padding: 0 24px 16px;
}

.toolbar-card {
  background: var(--card);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1;
  user-select: none;
}

.filter-chips {
  display: flex;
  gap: 0;
  padding: 3px;
  background: #f0f2f5;
  border-radius: 10px;
}

.filter-chip {
  flex: 1;
  min-height: 36px;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.2;
  cursor: pointer;
  transition: color 0.2s, background 0.2s, box-shadow 0.2s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.filter-chip:hover:not(.active) {
  color: var(--text);
}

.filter-chip.active {
  background: var(--card);
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.filter-chip:focus-visible {
  outline: 2px solid #91caff;
  outline-offset: 1px;
}

.table-wrap {
  margin: 0 24px 24px;
  background: var(--card);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  background: #fafafa;
  padding: 12px 10px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  user-select: none;
}

.data-table th.col-draggable {
  cursor: grab;
}

.data-table th.col-draggable:active {
  cursor: grabbing;
}

.data-table th.col-dragging {
  opacity: 0.45;
}

.data-table th.col-drag-over {
  background: #e6f4ff;
  box-shadow: inset 0 -2px 0 var(--primary);
}

.data-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table td.remark-cell {
  max-width: 240px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: visible;
  text-overflow: unset;
}

.data-table tbody tr.data-row {
  cursor: pointer;
}

.data-table tbody tr.data-row:hover {
  background: #f5f9ff;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.badge-yes {
  background: #f6ffed;
  color: var(--green);
  border: 1px solid #b7eb8f;
}

.badge-no {
  background: #fff7e6;
  color: var(--orange);
  border: 1px solid #ffd591;
}

.money {
  font-family: "SF Mono", Consolas, monospace;
  font-weight: 500;
}

.money-warn {
  color: var(--orange);
  font-weight: 600;
}

.has-tip {
  cursor: help;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

.interest-tooltip {
  position: fixed;
  z-index: 1000;
  display: none;
  min-width: 180px;
  max-width: 360px;
  padding: 8px 10px;
  background: #1f1f1f;
  color: #fff;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-line;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.interest-tooltip.show {
  display: block;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--card);
  border-radius: 10px;
  width: 90%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 16px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
}

#recordForm {
  padding: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}

label.full-width {
  margin-top: 14px;
  grid-column: 1 / -1;
}

label input,
label select,
label textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  outline: none;
}

label input:focus,
label select:focus,
label textarea:focus {
  border-color: var(--primary);
}

#interestAmountWrap.hidden,
#interestDiscountWrap.hidden {
  display: none;
}

.tag-interest {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  background: #f0f5ff;
  color: var(--primary);
  white-space: nowrap;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.empty-row td {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

@media (max-width: 768px) {
  body {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .login-card {
    margin: 16px;
    padding: 24px 20px;
  }

  .header {
    padding: 12px 14px;
    padding-top: calc(12px + env(safe-area-inset-top, 0));
  }

  .header-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .menu-toggle {
    display: inline-flex;
    min-height: 40px;
    min-width: 52px;
    align-items: center;
    justify-content: center;
  }

  .header-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    left: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    z-index: 120;
  }

  .header.menu-open .header-menu {
    display: flex;
  }

  .header-menu .btn,
  .header-menu a.btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }

  #btnAdd {
    min-height: 40px;
    flex: 1;
  }

  .stats {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 12px 14px;
  }

  .stat-card {
    padding: 12px;
  }

  .stat-label {
    font-size: 12px;
  }

  .stat-value {
    font-size: 17px;
  }

  .toolbar {
    padding: 0 14px 12px;
  }

  .toolbar-card {
    padding: 12px;
    gap: 12px;
  }

  .filter-chip {
    min-height: 40px;
    font-size: 13px;
    padding: 8px 6px;
  }

  .table-wrap {
    display: none;
  }

  .mobile-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0 14px 20px;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .mobile-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--card);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 12px;
    cursor: pointer;
  }

  .mobile-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .mobile-card-borrower {
    font-size: 15px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-card-meta,
  .mobile-card-sub {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
  }

  .mobile-card-sub .money {
    color: var(--text);
  }

  .mobile-empty {
    display: block;
    text-align: center;
    padding: 48px 16px;
    color: var(--text-secondary);
    background: var(--card);
    border-radius: 10px;
    box-shadow: var(--shadow);
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  label input,
  label select,
  label textarea,
  .password-form-body input {
    font-size: 16px;
    min-height: 44px;
  }

  label textarea {
    min-height: 88px;
  }

  .modal {
    align-items: flex-end;
    padding: 0;
  }

  .modal-content {
    width: 100%;
    max-width: none;
    border-radius: 12px 12px 0 0;
    max-height: 92vh;
    margin: 0;
  }

  .detail-card-content {
    max-width: none;
  }

  .detail-card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 8px;
    padding: 10px 12px 12px;
  }

  .detail-actions {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  }

  .detail-action-btn {
    min-height: 44px;
  }

  #recordForm {
    padding: 14px;
  }

  .form-actions {
    margin-top: 14px;
  }

  .form-actions .btn {
    min-height: 44px;
    flex: 1;
  }

  .confirm-content .form-actions {
    padding: 0 14px calc(14px + env(safe-area-inset-bottom, 0));
  }

  .interest-tooltip {
    max-width: calc(100vw - 24px);
    pointer-events: auto;
  }
}

@media (max-width: 380px) {
  .stats {
    grid-template-columns: 1fr;
  }

  .detail-card {
    grid-template-columns: 1fr;
  }
}
