:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666;
  --border: #e0e0e0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --overdue: #fef2f2;
  --overdue-text: #dc2626;
  --paid: #f0fdf4;
  --paid-text: #16a34a;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --radius: 8px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  background: var(--surface);
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

/* Navigation Tabs */
nav {
  display: flex;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}

.tab {
  padding: 12px 20px;
  border: none;
  background: none;
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 500;
}

/* Main Content */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* Summary Cards */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-value {
  font-size: 1.5rem;
  font-weight: 600;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

th, td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

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

tbody tr:nth-child(even) {
  background: #fafafa;
}

tbody tr.clickable {
  cursor: pointer;
}

tbody tr.clickable:hover {
  background: #f0f4ff;
}

tr.overdue {
  background: var(--overdue) !important;
}

tr.overdue td:last-child {
  color: var(--overdue-text);
  font-weight: 600;
}

tr.paid {
  opacity: 0.7;
}

tr.paid td:last-child {
  color: var(--paid-text);
  font-weight: 600;
}

/* Inline payment expansion */
.payment-detail-row td {
  padding: 0;
  background: #f8fafc;
}

.inline-payments {
  padding: 12px 16px 12px 32px;
}

.inline-table {
  box-shadow: none;
  background: transparent;
}

.inline-table th, .inline-table td {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.inline-empty {
  font-size: 0.85rem;
  margin: 0;
}

/* Section Header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

/* Vendor Cards (list) */
#vendor-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.vendor-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.vendor-card.overdue {
  border-left: 4px solid var(--overdue-text);
}

.vendor-card.paid {
  border-left: 4px solid var(--paid-text);
  opacity: 0.7;
}

.vendor-info {
  flex: 1;
  min-width: 200px;
}

.vendor-info h3 {
  font-size: 1rem;
  margin-bottom: 4px;
}

.vendor-info p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

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

/* Buttons */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: #f0f0f0;
}

.btn.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.btn.primary:hover {
  background: var(--primary-hover);
}

.btn.danger {
  color: var(--danger);
  border-color: var(--danger);
}

.btn.danger:hover {
  background: var(--danger);
  color: white;
}

.btn.small {
  padding: 4px 10px;
  font-size: 0.8rem;
}

/* Forms */
form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 400px;
}

label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

input, select, textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.remaining-balance {
  font-size: 0.95rem;
  padding: 12px;
  background: #f0f4ff;
  border-radius: 6px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 420px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.modal h2 {
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.modal form {
  max-width: none;
}

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

/* Empty State */
.empty-msg {
  text-align: center;
  color: var(--text-muted);
  padding: 32px;
  font-size: 0.9rem;
}

.empty-msg[hidden] {
  display: none;
}

/* Paid-off celebration overlay */
.celebrate-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.3s ease;
}

.celebrate-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px 32px;
  text-align: center;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.celebrate-icon {
  font-size: 64px;
  margin-bottom: 12px;
}

.celebrate-card h2 {
  font-size: 1.4rem;
  margin-bottom: 8px;
  color: var(--paid-text);
}

.celebrate-card p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.confetti {
  position: fixed;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  z-index: 201;
  animation: confettiFall linear forwards;
  pointer-events: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* Responsive */
@media (max-width: 600px) {
  main {
    padding: 16px;
  }

  nav {
    padding: 0 12px;
  }

  .tab {
    padding: 10px 12px;
    font-size: 0.8rem;
  }

  th, td {
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  .vendor-card {
    flex-direction: column;
    align-items: flex-start;
  }
}
