:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #475569;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --warn: #f59e0b;
  --danger: #ef4444;
  --good: #10b981;
  --recovery: #a855f7;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard",
    "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body {
  padding-top: calc(56px + var(--safe-top));
  padding-bottom: var(--safe-bottom);
}

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(56px + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  padding-right: 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}

#borrower-select {
  flex: 1;
  height: 40px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px;
  padding-right: 36px;
}

#install-btn {
  height: 36px;
  padding: 0 12px;
  background: var(--accent);
  color: #082f49;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
}

.summary {
  padding: 12px 14px 4px;
}

.summary .borrower-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.summary .borrower-id {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--surface);
  padding: 2px 8px;
  border-radius: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.badge-recovery { background: rgba(168, 85, 247, 0.18); color: var(--recovery); }
.badge-bank { background: var(--surface-2); color: var(--text); }
.badge-cat { background: rgba(56, 189, 248, 0.15); color: var(--accent); }

.summary .summary-line {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.summary .summary-claim {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 13px;
}
.summary-claim .item {
  flex: 1;
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 10px;
}
.summary-claim .label { color: var(--text-dim); font-size: 11px; }
.summary-claim .value { font-weight: 700; font-size: 14px; margin-top: 2px; }

.tabs {
  position: sticky;
  top: calc(56px + var(--safe-top));
  z-index: 20;
  display: flex;
  overflow-x: auto;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  padding: 12px 14px;
  position: relative;
  white-space: nowrap;
}
.tabs button.active {
  color: var(--text);
}
.tabs button.active::after {
  content: "";
  position: absolute;
  left: 10px; right: 10px;
  bottom: 0;
  height: 3px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
}

.content {
  padding: 12px 14px 24px;
}

.subtabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.subtabs::-webkit-scrollbar { display: none; }
.subtabs button {
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.subtabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #082f49;
}

.card {
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.card h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.card .preline {
  white-space: pre-line;
  font-size: 14px;
  color: var(--text);
}

.kv {
  display: grid;
  grid-template-columns: minmax(80px, max-content) 1fr;
  column-gap: 12px;
  row-gap: 6px;
  font-size: 14px;
}
.kv dt {
  color: var(--text-dim);
  font-weight: 500;
}
.kv dd {
  margin: 0;
  font-weight: 600;
  word-break: break-word;
}

.address-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.address-row .addr {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
  word-break: keep-all;
}
.address-row a.map-btn {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  background: var(--accent);
  color: #082f49;
  padding: 6px 10px;
  border-radius: 8px;
  text-decoration: none;
}

.table-wrap {
  overflow-x: auto;
  margin: 0 -14px;
  padding: 0 14px;
  -webkit-overflow-scrolling: touch;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 520px;
}
table.data th, table.data td {
  border-bottom: 1px solid var(--border);
  padding: 8px 8px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
table.data th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  background: var(--surface);
  position: sticky;
  top: 0;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.wrap { white-space: normal; min-width: 160px; }

.gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.gallery .thumb {
  position: relative;
  width: 100%;
  padding-top: 75%;
  background: var(--surface-2);
  border-radius: 8px;
  overflow: hidden;
  cursor: zoom-in;
}
.gallery .thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 18px 0 8px;
}

.empty {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 24px;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}
.lightbox[hidden],
[hidden] { display: none !important; }
.lightbox img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
}
.lightbox-close {
  position: absolute;
  top: calc(8px + var(--safe-top));
  right: 12px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 24px;
  font-weight: 300;
}
.lightbox-caption {
  color: var(--text-dim);
  font-size: 12px;
  padding: 0 16px;
  text-align: center;
}

.amount { font-variant-numeric: tabular-nums; }
.amount.big { font-weight: 700; }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.card-head h3 { margin: 0; }

.copy-btn {
  background: var(--accent);
  color: #082f49;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: 12px;
  padding: 6px 12px;
  white-space: nowrap;
}
.copy-btn:active { transform: scale(0.97); }

.summary-cards, .parcel-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mini-card, .parcel-card {
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.parcel-card { cursor: pointer; }
.parcel-card:active { background: rgba(56, 189, 248, 0.12); }

.mini-head, .parcel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.mini-id, .parcel-no {
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.mini-type, .parcel-type {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.mini-count {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: auto;
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 999px;
}

.mini-addr, .parcel-addr {
  font-size: 13px;
  color: var(--accent);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  margin: 4px 0 8px;
  word-break: keep-all;
  line-height: 1.45;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 12px;
}
.parcel-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 12px;
}

.mc {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  padding: 2px 0;
  border-bottom: 1px dashed rgba(71, 85, 105, 0.4);
}
.mc-label {
  font-size: 12px;
  color: var(--text-dim);
}
.mc-value {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  word-break: keep-all;
}

.hint {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
  text-align: right;
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(24px + var(--safe-bottom));
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 200;
}
.toast.show { opacity: 1; }

.case-card {
  border-left: 3px solid var(--surface-2);
  padding-left: 10px;
  margin-bottom: 10px;
}
.case-card.본건 { border-left-color: var(--accent); }
.case-card .case-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 4px;
}
.case-card .case-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.fin-table tr td:first-child { color: var(--text-dim); font-weight: 500; }

.recovery-section h4 {
  margin: 14px 0 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--recovery);
}
