:root {
  --bg: #f4efe8;
  --surface: rgba(255, 252, 248, 0.9);
  --surface-soft: rgba(255, 255, 255, 0.72);
  --ink: #1f2429;
  --muted: #66707a;
  --line: rgba(120, 107, 91, 0.16);
  --accent: #1f6a57;
  --accent-soft: rgba(31, 106, 87, 0.12);
  --warn: #b4543d;
  --warn-soft: rgba(180, 84, 61, 0.12);
  --shadow: 0 18px 44px rgba(52, 39, 25, 0.08);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Pretendard Variable", "SUIT Variable", "Noto Sans KR", "Apple SD Gothic Neo", system-ui, sans-serif;
  color: var(--ink);
  word-break: keep-all;
  overflow-wrap: anywhere;
  background:
    radial-gradient(circle at top left, rgba(202, 146, 105, 0.2), transparent 30%),
    linear-gradient(180deg, #fbf7f1 0%, var(--bg) 100%);
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

.bg-orb {
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(28px);
  opacity: 0.75;
}

.bg-orb-a {
  top: 3rem;
  right: 4rem;
  width: 18rem;
  height: 18rem;
  background: rgba(31, 106, 87, 0.11);
}

.bg-orb-b {
  bottom: 4rem;
  left: 3rem;
  width: 14rem;
  height: 14rem;
  background: rgba(214, 158, 120, 0.16);
}

.app-shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.title-block h1,
.panel-head h2 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

.title-block h1 {
  font-size: clamp(1.58rem, 2.9vw, 2.2rem);
}

.subtle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.topbar-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.chip-strong {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(31, 106, 87, 0.2);
  font-weight: 700;
}

.page {
  display: grid;
  gap: 20px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}

.stat-card,
.panel {
  border: 1px solid rgba(120, 107, 91, 0.1);
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.stat-card {
  padding: 18px 20px;
}

.stat-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.stat-value {
  margin-top: 8px;
  font-size: clamp(1.45rem, 2.6vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -0.04em;
}

.stat-sub {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.is-negative .stat-value {
  color: var(--warn);
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.72fr) minmax(320px, 0.88fr);
  gap: 20px;
}

.panel {
  padding: 18px;
}

.panel-wide {
  min-width: 0;
}

.side-stack {
  display: grid;
  gap: 20px;
}

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

.panel-head-stacked {
  align-items: stretch;
  justify-content: flex-start;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-title-set {
  display: grid;
  gap: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 16px;
  border: 1px solid rgba(120, 107, 91, 0.2);
  border-radius: 12px;
  background: #fffdfa;
  color: var(--ink);
  cursor: pointer;
  transition: transform 140ms ease, background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.58;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover {
  background: #185746;
}

.btn-danger {
  background: var(--warn);
  border-color: var(--warn);
  color: #fff;
  font-weight: 600;
}

.btn-danger:hover {
  background: #9a4935;
}

.btn-ghost {
  background: #fffdfa;
}

.btn-small {
  height: 34px;
  min-width: 64px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 0.86rem;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) repeat(2, minmax(150px, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.field span {
  color: var(--muted);
  font-size: 0.84rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(120, 107, 91, 0.18);
  border-radius: 14px;
  background: #fffdfa;
  color: var(--ink);
}

.field input,
.field select {
  height: 46px;
  padding: 0 14px;
}

.field textarea {
  resize: vertical;
  min-height: 84px;
  padding: 12px 14px;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.status-filter:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid rgba(31, 106, 87, 0.24);
  outline-offset: 2px;
}

.status-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-filter {
  border: 1px solid rgba(120, 107, 91, 0.18);
  background: #fffdfa;
  color: var(--muted);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
  transition: transform 150ms ease, background-color 150ms ease, color 150ms ease;
}

.status-filter:hover {
  transform: translateY(-1px);
}

.status-filter.is-active {
  background: var(--accent-soft);
  border-color: rgba(31, 106, 87, 0.2);
  color: var(--accent);
  font-weight: 700;
}

.table-wrap {
  overflow: auto;
  margin-top: 14px;
  border: 1px solid rgba(120, 107, 91, 0.12);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.74);
}

table {
  width: 100%;
  min-width: 1020px;
  border-collapse: separate;
  border-spacing: 0;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 13px 14px;
  background: rgba(248, 242, 235, 0.96);
  color: var(--muted);
  text-align: left;
  font-size: 0.82rem;
  font-weight: 700;
  border-bottom: 1px solid rgba(120, 107, 91, 0.12);
}

tbody td {
  padding: 14px;
  border-bottom: 1px solid rgba(120, 107, 91, 0.08);
  vertical-align: middle;
  font-size: 0.92rem;
  line-height: 1.44;
  background: rgba(255, 255, 255, 0.84);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.align-right {
  text-align: right;
}

.align-center {
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.badge-완납 {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-부분납 {
  background: rgba(214, 158, 120, 0.16);
  color: #9a5f2b;
}

.badge-미납 {
  background: var(--warn-soft);
  color: var(--warn);
}

.memo-tag {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(214, 158, 120, 0.16);
  color: #8b5f33;
  font-size: 0.8rem;
  font-weight: 600;
}

.category-list,
.compact-list,
.mobile-list {
  display: grid;
  gap: 12px;
}

.category-card,
.compact-item,
.mobile-card,
.empty-state {
  padding: 14px;
  border: 1px solid rgba(120, 107, 91, 0.12);
  border-radius: 18px;
  background: var(--surface-soft);
}

.category-top,
.compact-top,
.mobile-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.category-name,
.compact-name,
.mobile-title {
  font-weight: 700;
  letter-spacing: -0.02em;
}

.progress {
  margin: 10px 0 8px;
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(31, 106, 87, 0.08);
}

.progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1f6a57 0%, #4a8f7d 100%);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 0.84rem;
}

.compact-list {
  min-height: 80px;
}

.empty-state {
  color: var(--muted);
}

.mobile-list {
  display: none;
  margin-top: 14px;
}

.mobile-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  margin-top: 12px;
}

.mobile-meta dt {
  color: var(--muted);
  font-size: 0.8rem;
}

.mobile-meta dd {
  margin: 4px 0 0;
  font-weight: 600;
}

.mobile-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(22, 25, 28, 0.42);
}

.modal-panel,
.confirm-panel {
  position: relative;
  z-index: 1;
  width: min(720px, calc(100vw - 26px));
  border-radius: 20px;
  border: 1px solid rgba(120, 107, 91, 0.16);
  background: #fffdf9;
  box-shadow: 0 24px 48px rgba(24, 27, 31, 0.18);
}

.modal-panel {
  padding: 18px;
}

.confirm-panel {
  width: min(360px, calc(100vw - 26px));
  padding: 18px;
}

.confirm-panel h3 {
  margin: 0;
}

.confirm-panel p {
  margin: 10px 0 14px;
  color: var(--muted);
}

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

.modal-head h3 {
  margin: 0;
  font-size: 1.12rem;
}

.icon-btn {
  height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid rgba(120, 107, 91, 0.2);
  background: #fffdfa;
  cursor: pointer;
}

.modal-form {
  display: grid;
  gap: 12px;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-error {
  margin: 0;
  min-height: 1.15rem;
  color: var(--warn);
  font-size: 0.9rem;
}

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

.modal-actions .btn-danger {
  margin-right: auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 14px);
  opacity: 0;
  z-index: 30;
  max-width: calc(100vw - 24px);
  padding: 10px 14px;
  border-radius: 11px;
  background: rgba(31, 106, 87, 0.94);
  color: #fff;
  box-shadow: 0 12px 30px rgba(24, 27, 31, 0.26);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.is-error {
  background: rgba(180, 84, 61, 0.95);
}

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

  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  .app-shell {
    width: min(100vw - 16px, 100%);
    padding-top: 18px;
    padding-bottom: 22px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-chips {
    justify-content: flex-start;
  }

  .panel {
    padding: 14px;
    border-radius: 20px;
  }

  .panel-title-row {
    align-items: stretch;
  }

  .btn {
    width: 100%;
  }

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

  .table-wrap {
    display: none;
  }

  .mobile-list {
    display: grid;
  }

  .modal-panel {
    padding: 14px;
  }

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

@media (prefers-reduced-motion: no-preference) {
  .stat-card,
  .panel,
  .mobile-card,
  .category-card,
  .compact-item {
    animation: rise-in 360ms ease both;
  }

  @keyframes rise-in {
    from {
      opacity: 0;
      transform: translateY(9px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}
