:root {
  --bg: #f7f4ed;
  --panel: #fffdf8;
  --line: #d5c9b8;
  --text: #2f2416;
  --primary: #0b6e4f;
  --warn: #9c2f2f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans KR", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, #efe3cd 0%, var(--bg) 50%, #f2eee3 100%);
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 12px;
}

.auth-card {
  width: min(100%, 420px);
}

.auth-copy {
  margin: 0 0 14px;
  color: #6b5a43;
}

.auth-error {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f8dfdf;
  color: #7e2323;
  font-weight: 700;
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-submit {
  margin-top: 8px;
  width: 100%;
}

.auth-link {
  display: inline-block;
  margin-top: 10px;
}

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(11, 110, 79, 0.96);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(47, 36, 22, 0.18);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.toast-hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(-6px);
}

.container {
  max-width: 900px;
  margin: 24px auto 40px;
  padding: 0 12px;
}

.top-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.nav-link {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text);
  background: #efe5d3;
  border: 1px solid #dccdb6;
  font-weight: 700;
}

.nav-link.active {
  background: #1e3f36;
  border-color: #1e3f36;
  color: #fff;
}

.nav-logout-form {
  margin-left: auto;
}

.nav-button {
  font-family: inherit;
  border: 1px solid #dccdb6;
}

h1 {
  margin: 0 0 12px;
}

h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

section {
  margin-bottom: 16px;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip input {
  display: none;
}

.chip span,
.money-btn {
  display: inline-block;
  border: 1px solid #8e7f67;
  background: #f4eee1;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  user-select: none;
}

.chip input:checked + span {
  background: #1e3f36;
  color: #fff;
  border-color: #1e3f36;
}

.money-reset-btn {
  background: #eadfcb;
  color: #6d4f27;
}

.money-btn:hover,
.chip span:hover {
  filter: brightness(0.97);
}

input[type="text"],
input[type="password"] {
  width: 100%;
  border: 1px solid #b9ab94;
  border-radius: 8px;
  padding: 10px;
  font-size: 1rem;
  margin-top: 6px;
}

.file-input,
.filter-field select {
  width: 100%;
  border: 1px solid #b9ab94;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
  background: #fffdf8;
  margin-top: 6px;
}

.amount-korean {
  min-height: 44px;
  margin-top: 10px;
  padding: 10px 14px;
  border: 1px solid #d7c298;
  border-radius: 10px;
  background: #fff6df;
  color: #8b2e00;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.actions .primary {
  min-width: 220px;
}

.actions-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button,
.ghost {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
}

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

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

.ghost {
  background: #ded4c2;
  color: var(--text);
}

.hidden {
  display: none;
}

.sub-input.hidden {
  display: none;
}

.honeypot {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 70vh;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

th,
td {
  border-bottom: 1px solid #e4d9c7;
  padding: 8px;
  text-align: left;
  white-space: nowrap;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #f6eddd;
  z-index: 1;
}

.sort-link {
  color: inherit;
  text-decoration: none;
  font-weight: 700;
}

.sort-link:hover {
  color: var(--primary);
}

.sms-sent-row td {
  background: #dcefe5;
}

.empty {
  text-align: center;
  color: #6b5a43;
}

.top-actions {
  margin-bottom: 12px;
}

.top-actions-right {
  margin-left: auto;
}

.sms-toggle-form {
  margin: 0;
}

.sms-toggle-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid #d3c4af;
  border-radius: 999px;
  background: #f2ebdf;
  font-size: 1rem;
  line-height: 1;
  text-decoration: none;
}

.sms-toggle-btn.is-sent {
  background: #0b6e4f;
  border-color: #0b6e4f;
  color: #f8fff9;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
  opacity: 1;
}

.sms-toggle-btn.is-pending {
  background: #efe7dc;
  border-color: #d9cdbf;
  color: #9a8f80;
  opacity: 0.52;
}

.sms-toggle-btn:hover {
  filter: brightness(0.98);
}

.sms-toggle-readonly {
  cursor: default;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(47, 36, 22, 0.45);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 760px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 16px;
  border-radius: 16px;
  background: #fffdf8;
  border: 1px solid #d8c9b2;
  box-shadow: 0 18px 40px rgba(47, 36, 22, 0.24);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
}

.modal-form section:last-of-type {
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.summary-bar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 14px;
  border: 1px solid #d9ccb8;
  border-radius: 10px;
  background: #fff8ea;
}

.summary-bar strong {
  color: var(--primary);
}

.activity-log-table th,
.activity-log-table td {
  vertical-align: top;
  white-space: normal;
  font-size: 0.82rem;
  line-height: 1.45;
}

.activity-detail-cell {
  min-width: 120px;
  white-space: normal;
  word-break: break-word;
}

.log-delete-btn {
  padding: 5px 8px;
  font-size: 0.78rem;
  white-space: nowrap;
}

.list-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.filter-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: end;
  margin-bottom: 12px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
}

.filter-field span {
  font-weight: 700;
}

.selected-files {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.empty-files,
.muted {
  color: #6b5a43;
}

.contact-cell {
  min-width: 132px;
  white-space: normal;
  font-size: 0.9rem;
  line-height: 1.35;
}

.contact-cell div + div {
  margin-top: 4px;
}

.affiliation-cell {
  min-width: 112px;
  max-width: 112px;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
  line-height: 1.35;
}

.name-col {
  width: 90px;
}

.name-cell {
  max-width: 90px;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.filter-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.file-pill {
  display: inline-block;
  max-width: 180px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #efe5d3;
  border: 1px solid #d8c6aa;
  color: var(--text);
  font-size: 0.88rem;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.attachment-link {
  text-decoration: none;
}

.attachment-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid #d8c6aa;
  background: #fff7e9;
}

.modal-attachment-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-attachment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.attachment-manage-link {
  display: inline-block;
  max-width: 320px;
  color: var(--text);
  text-decoration: none;
  word-break: break-word;
}

.expense-description-cell {
  white-space: normal;
  min-width: 220px;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.overview-card {
  padding: 18px 16px;
}

.overview-label {
  margin: 0 0 10px;
  color: #6b5a43;
  font-weight: 700;
}

.overview-value {
  display: block;
  font-size: 1.8rem;
  line-height: 1.1;
}

.overview-meta {
  display: inline-block;
  margin-top: 10px;
  color: #6b5a43;
  font-size: 0.95rem;
}

.income-card {
  background: linear-gradient(135deg, #eff7f1 0%, #f8fbf7 100%);
}

.expense-card {
  background: linear-gradient(135deg, #fbf0e8 0%, #fffaf6 100%);
}

.balance-card {
  background: linear-gradient(135deg, #edf3f8 0%, #fafcff 100%);
}

.balance-card.is-negative {
  background: linear-gradient(135deg, #faece8 0%, #fff7f4 100%);
}

.balance-card .overview-value {
  color: var(--primary);
}

.balance-card.is-negative .overview-value {
  color: var(--warn);
}

.overview-panel {
  margin-bottom: 12px;
}

.overview-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.overview-panel-head h2 {
  margin: 0;
}

.overview-bars {
  display: grid;
  gap: 14px;
}

.overview-bar-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 12px;
  align-items: center;
}

.overview-bar-label {
  display: grid;
  gap: 4px;
}

.overview-bar-track {
  position: relative;
  height: 18px;
  border-radius: 999px;
  background: #efe7dc;
  overflow: hidden;
}

.overview-bar-fill {
  height: 100%;
  border-radius: 999px;
}

.income-fill {
  background: linear-gradient(90deg, #1e8c68 0%, #0b6e4f 100%);
}

.expense-fill {
  background: linear-gradient(90deg, #d48b58 0%, #b86532 100%);
}

.positive {
  color: var(--primary);
  font-weight: 700;
}

.negative {
  color: var(--warn);
  font-weight: 700;
}

.expense-rank-list {
  display: grid;
  gap: 12px;
}

.expense-rank-item {
  padding: 12px;
  border: 1px solid #eadfcf;
  border-radius: 12px;
  background: #fffcf6;
}

.expense-rank-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}

.expense-rank-head strong {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.expense-rank-value {
  flex: none;
  font-size: 0.92rem;
  font-weight: 700;
  color: #7a4a21;
}

.expense-rank-bar-row {
  margin-bottom: 8px;
}

.expense-rank-track {
  height: 16px;
}

.expense-rank-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.84rem;
  line-height: 1.35;
  color: #6b5a43;
}

@media (max-width: 640px) {
  .container {
    margin-top: 14px;
  }

  .card {
    padding: 10px;
  }

  .chip span,
  .money-btn,
  button,
  .ghost,
  .nav-link {
    padding: 8px 10px;
    font-size: 0.9rem;
  }

  .attachment-thumb {
    width: 56px;
    height: 56px;
  }

  .amount-korean {
    min-height: 40px;
    font-size: 1rem;
  }

  .actions {
    align-items: stretch;
  }

  .actions .primary {
    min-width: 0;
    width: 100%;
  }

  .actions-right {
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
  }

  .summary-bar {
    gap: 8px;
  }

  .filter-field {
    min-width: 0;
    width: 100%;
  }

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

  .overview-bar-row {
    grid-template-columns: 1fr;
  }

}
