:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --line: #e3e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --warn: #dc2626;
  --ok: #16a34a;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", sans-serif;
  line-height: 1.5;
}

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

header h1 {
  margin: 0;
  font-size: 26px;
}
header .sub {
  margin: 4px 0 0;
  color: var(--muted);
}

/* 요약 카드 */
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 20px 0 8px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.card-label { color: var(--muted); font-size: 13px; }
.card-value { font-size: 20px; font-weight: 700; margin-top: 6px; }
.card-value.accent { color: var(--accent); }
.card-value.warn { color: var(--warn); }

.meta {
  color: var(--muted);
  font-size: 13px;
  margin: 8px 2px 20px;
}

/* 패널 */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 18px; }
.head-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.year-select {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}

/* 테이블 */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th { color: var(--muted); font-weight: 600; background: #fafbfe; }
td.empty { text-align: center; color: var(--muted); }
.amount { font-weight: 700; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}
.badge.paid { background: #dcfce7; color: var(--ok); }
.badge.unpaid { background: #fee2e2; color: var(--warn); }

/* 내 기기 이름 바 */
.identity-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.identity-bar label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.identity-bar input { min-width: 180px; }
.identity-bar .hint { margin: 0; }
.identity-bar .user-info { font-size: 14px; }
.logout-btn { padding: 6px 12px; font-size: 13px; text-decoration: none; }

/* 납부 처리자 정보 (누가/어느 기기에서 눌렀는지) */
.paid-audit {
  grid-column: 1 / -1;
  background: #eef4ff;
  border: 1px solid #d3e0ff;
  border-radius: 8px;
  padding: 8px 10px;
  color: #1e3a8a;
}

/* 입금 계좌 + 복사 버튼 */
.acct-cell { white-space: nowrap; }
.acct { font-family: "Consolas", "Menlo", monospace; margin-right: 8px; }
.copy-btn { padding: 4px 10px; font-size: 12px; }
.muted { color: var(--muted); }

/* 합계/경고 표시 */
.warn-text { color: var(--warn); }
.foot-row td { background: #fafbfe; border-top: 2px solid var(--line); }
tfoot td { padding: 10px 12px; }
.inline-form select {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
}
.ln-name, .ln-principal { width: 100%; }

/* 클릭 가능한 이자 내역 행 */
.rec-row { cursor: pointer; }
.rec-row:hover { background: #f5f8ff; }
.rec-row.open { background: #eef4ff; }
.caret { color: var(--muted); font-size: 11px; margin-right: 2px; }

/* 상세 내역 행 */
.detail-row > td { background: #f8fafc; padding: 0; }
.detail {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 24px;
  padding: 14px 18px;
  font-size: 13px;
  color: var(--text);
}
.detail > div { white-space: normal; }
.detail span {
  display: inline-block;
  min-width: 68px;
  color: var(--muted);
  font-weight: 600;
}
.detail .formula {
  grid-column: 1 / -1;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: "Consolas", "Menlo", monospace;
}

/* 버튼 / 폼 */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--warn); border-color: #f3c2c2; }

.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.inline-form input { flex: 1; min-width: 120px; }

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}
.grid-form label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 4px; }

input {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
}

.hint { color: var(--muted); font-size: 12px; margin: 12px 0 0; }

/* 토스트 */
footer { position: fixed; bottom: 20px; left: 0; right: 0; text-align: center; pointer-events: none; }
.toast {
  display: inline-block;
  background: #111827;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.25s;
}
.toast.show { opacity: 0.95; }

/* ======================= 모바일 반응형 ======================= */
@media (max-width: 640px) {
  .wrap { padding: 16px 12px 72px; }
  header h1 { font-size: 22px; }

  /* 요약 카드 2열 */
  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card { padding: 13px; }
  .card-value { font-size: 17px; }

  .panel { padding: 14px; }
  .panel-head h2 { font-size: 16px; }

  /* 내 기기 이름 바 세로 정렬 */
  .identity-bar { flex-direction: column; align-items: stretch; }
  .identity-bar label { justify-content: space-between; }
  .identity-bar input { min-width: 0; flex: 1; }

  /* 폼 요소 세로로 쌓기 */
  .inline-form { flex-direction: column; }
  .inline-form input, .inline-form select { width: 100%; flex: none; }
  .grid-form { grid-template-columns: 1fr 1fr; }
}

/* 표를 카드형으로 쌓기 (좁은 화면) */
@media (max-width: 600px) {
  .table-scroll thead { display: none; }
  .table-scroll table,
  .table-scroll tbody,
  .table-scroll tfoot,
  .table-scroll tr { display: block; width: 100%; }

  .table-scroll tbody tr,
  .table-scroll tfoot tr {
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 10px;
    background: #fff;
    overflow: hidden;
  }
  .table-scroll .foot-row { background: #f5f8ff; }

  .table-scroll td { display: block; border: none; }

  /* 라벨이 있는 셀: 좌측 라벨 + 우측 값 */
  .table-scroll td[data-label] {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 9px 13px;
    white-space: normal;
    text-align: right;
    border-bottom: 1px solid #f1f3f7;
  }
  .table-scroll td[data-label]:last-child { border-bottom: none; }
  .table-scroll td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    text-align: left;
    flex: 0 0 auto;
  }
  /* 라벨이 빈 셀(버튼 등)은 라벨 숨김 */
  .table-scroll td[data-label=""]::before { content: ""; }

  /* 입력/버튼이 있는 셀은 값 영역이 늘어나도록 */
  .table-scroll td[data-label] input,
  .table-scroll td[data-label] select { flex: 1 1 auto; min-width: 0; width: auto; }
  .table-scroll td[data-label=""] { justify-content: flex-end; gap: 8px; }

  /* 상세(펼침) 행은 그대로 블록 */
  .detail-row td { padding: 0 !important; display: block; }
  .detail-row td[data-label]::before { content: ""; }
  .detail { grid-template-columns: 1fr; }

  /* 계좌: 라벨 좌 / (계좌+복사) 우로 묶기 */
  .acct-wrap { display: inline-flex; align-items: center; gap: 8px; }
  .acct { margin-right: 0; }

  .hide-mobile { display: none !important; }
  .empty { text-align: center !important; }
}
