:root {
  --bg: #f5f1e8;
  --card: #fffdf6;
  --ink: #1f2329;
  --muted: #596273;
  --accent: #186f65;
  --accent-2: #d17b0f;
  --line: #d8cfbe;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 15%, #f7dcb4 0%, transparent 36%),
    radial-gradient(circle at 88% 20%, #d6eadf 0%, transparent 30%),
    linear-gradient(180deg, #fef7ea 0%, var(--bg) 100%);
  min-height: 100vh;
}

.layout {
  width: min(1040px, calc(100vw - 24px));
  margin: 20px auto 40px;
}

.login-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(520px, 100%);
}

.login-form {
  display: grid;
  gap: 14px;
}

.remember-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.remember-row input[type="checkbox"] {
  width: auto;
  max-width: none;
  min-height: 0;
  padding: 0;
  flex: 0 0 auto;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3rem);
  letter-spacing: 0.02em;
}

.hero p {
  margin: 10px 0 0;
  color: var(--muted);
  max-width: 68ch;
}

.actions {
  display: flex;
  gap: 16px;
  margin: 22px 0;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  padding: 4px 0;
}

.actions .btn {
  min-width: 160px;
  margin-inline: auto;
}

.home-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 420px;
  margin: 26px auto;
}

.home-actions .btn {
  width: 100%;
  max-width: 340px;
}

.global-notification {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 700;
  border: 1px solid #b6d7c8;
  background: #eaf7ef;
  color: #1d6a43;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: clamp(14px, 2.6vw, 20px);
  margin-bottom: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
  animation: riseIn 320ms ease-out;
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hidden {
  display: none;
}

.subtle {
  color: var(--muted);
  margin-top: 0;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 0.98rem;
  min-height: 44px;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

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

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

.secondary {
  background: #ece7d8;
  color: #243247;
}

.chip {
  background: #f2e8cc;
  color: #4d3a00;
}

.form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.95rem;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  font-size: 16px;
  width: 100%;
  max-width: 100%;
}

.form-row {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.receipt-layout {
  grid-column: 1 / -1;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.receipt-layout label:nth-child(1),
.receipt-layout label:nth-child(2),
.receipt-layout label:nth-child(3) {
  grid-column: span 2;
}

.receipt-layout label:nth-child(4),
.receipt-layout label:nth-child(5) {
  grid-column: span 3;
}

.amount-input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  font-size: 16px;
  width: min(100%, 140px);
}

.filter-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin: 8px 0 14px;
}

.billing-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  margin-top: 8px;
}

.billing-toolbar {
  margin: 12px 0 10px;
  justify-content: flex-start;
}

.billing-overview-panel {
  margin-bottom: 16px;
}

.billing-overview {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.billing-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  padding: 14px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.05);
}

.billing-card-credit {
  border-color: #4ea96a;
  background: linear-gradient(180deg, #e7f8ea, #cfeed6);
  box-shadow: 0 8px 22px rgba(78, 169, 106, 0.18);
}

.billing-card-owed {
  border-color: #cc7f7f;
  background: linear-gradient(180deg, #fff0f0, #f5dada);
  box-shadow: 0 8px 22px rgba(204, 127, 127, 0.16);
}

.billing-card h4 {
  margin: 0 0 4px;
}

.billing-card header p {
  margin: 0;
  color: var(--muted);
}

.billing-meta {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.billing-meta p {
  margin: 0;
}

.billing-card .card-actions {
  margin-top: 12px;
}

.billing-pagination {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.billing-page-indicator {
  margin: 0;
  min-width: 0;
  width: 100%;
  text-align: center;
  font-weight: 700;
  color: var(--muted);
}

.mini-panel {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #fff;
}

.mini-panel h3 {
  margin: 0 0 10px;
}

.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.json-output {
  margin-top: 12px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 12px;
  min-height: 120px;
  max-height: 360px;
  overflow: auto;
  font-size: 0.85rem;
  white-space: pre-wrap;
}

.payment-history-panel {
  min-height: 100%;
}

.payment-history {
  display: grid;
  gap: 10px;
}

.payment-history-list {
  display: grid;
  gap: 10px;
}

.payment-entry {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}

.payment-entry p {
  margin: 0 0 4px;
}

.results {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  align-items: start;
}

.list-pagination {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.list-page-indicator {
  margin: 0;
  min-width: 0;
  width: 100%;
  text-align: center;
  font-weight: 700;
  color: var(--muted);
}

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  min-height: 170px;
  display: flex;
  flex-direction: column;
}

.card h3 {
  margin: 0 0 6px;
}

.card p {
  margin: 0 0 4px;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  flex-wrap: wrap;
}

.card-actions .amount-input {
  flex: 1 1 120px;
}

.card-actions .btn {
  padding: 8px 12px;
  font-size: 0.9rem;
}

.card-actions .btn,
.card-actions .amount-input {
  min-width: 0;
}

.person-card-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.person-action {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  font-size: 0.88rem;
  border-radius: 9px;
}

.person-map-btn,
.person-edit-btn {
  background: #ece7d8;
  color: #243247;
}

.person-map-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.danger {
  background: #f4aaa4;
  color: #6b1f1a;
}

.danger:hover {
  filter: brightness(0.95);
}

.status {
  min-height: 22px;
  font-weight: 700;
  color: var(--accent-2);
}

.receipt-months-list {
  display: grid;
  gap: 10px;
}

.receipt-months-list .form-row {
  margin-top: 0;
  align-items: center;
}

.receipt-month,
.receipt-year,
.receipt-owed,
.receipt-paid {
  flex: 1 1 170px;
}

@media (max-width: 900px) {
  .form-grid,
  .filter-grid,
  .billing-grid,
  .billing-overview,
  .results {
    grid-template-columns: 1fr;
  }

  .actions,
  .home-actions {
    width: 100%;
  }

  .billing-toolbar {
    justify-content: stretch;
  }

  .billing-toolbar .btn,
  .home-actions .btn,
  .actions .btn {
    width: 100%;
  }

  .billing-card .card-actions,
  .card-actions {
    flex-direction: column;
    align-items: stretch;
  }

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

  .receipt-layout {
    grid-template-columns: 1fr;
  }

  .receipt-layout label {
    grid-column: auto;
  }

  .billing-card .card-actions .btn,
  .card-actions .btn,
  .card-actions .amount-input {
    width: 100%;
  }

  .billing-card .card-actions .amount-input {
    width: 100%;
  }
}

@media (max-width: 600px) {
  .layout {
    width: calc(100vw - 16px);
    margin: 10px auto 24px;
  }

  .hero {
    text-align: center;
  }

  .hero p {
    margin-left: auto;
    margin-right: auto;
  }

  .panel {
    border-radius: 12px;
  }

  .actions {
    flex-direction: column;
    align-items: center;
    gap: 14px;
    margin: 18px 0;
    padding: 6px 0;
  }

  .actions .btn {
    width: min(100%, 360px);
    min-width: 0;
  }

  .home-actions {
    margin: 18px auto;
    align-items: center;
    gap: 14px;
  }

  .home-actions .btn {
    max-width: 360px;
  }

  .form-row {
    flex-direction: column;
  }

  .form-row .btn {
    width: 100%;
  }

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

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

  .billing-card,
  .card,
  .payment-entry {
    padding: 12px;
  }

  .billing-page-indicator,
  .list-page-indicator {
    font-size: 0.95rem;
  }

  .billing-pagination,
  .list-pagination {
    gap: 8px;
  }

  .billing-pagination .btn,
  .list-pagination .btn {
    flex: 1 1 120px;
  }

  .card-actions {
    gap: 10px;
  }

  .card-actions .btn,
  .card-actions .amount-input {
    width: 100%;
  }
}
