:root {
  --primary: #4f46e5;
  --primary-light: #818cf8;
  --primary-dark: #3730a3;
  --bg: #f9fafb;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --green: #059669;
  --green-bg: #d1fae5;
  --yellow: #d97706;
  --yellow-bg: #fef3c7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --bg-card: #1f2937;
    --bg-input: #374151;
    --text: #f3f4f6;
    --text-secondary: #9ca3af;
    --border: #374151;
    --green-bg: #064e3b;
    --yellow-bg: #78350f;
    --red-bg: #7f1d1d;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 72px;
}

#app { max-width: 600px; margin: 0 auto; padding: 16px; }

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin-bottom: 16px;
}
.app-header h1 { font-size: 1.25rem; color: var(--primary); }
.year-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.875rem;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-title { font-size: 0.75rem; text-transform: uppercase; color: var(--text-secondary); letter-spacing: 0.05em; margin-bottom: 4px; }
.card-value { font-size: 1.5rem; font-weight: 700; }

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  text-decoration: none;
  color: #fff;
}
.btn:active { opacity: 0.8; }
.btn-primary { background: var(--primary); }
.btn-green { background: var(--green); }
.btn-red { background: var(--red); }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; margin-top: 12px; }

/* Badge / Status */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-gray { background: var(--border); color: var(--text-secondary); }
.status-indicator {
  width: 10px; height: 10px; border-radius: 50%; display: inline-block;
}
.status-green { background: var(--green); }
.status-yellow { background: var(--yellow); }
.status-red { background: var(--red); }

/* Progress Bar */
.progress-wrap {
  background: var(--border);
  border-radius: 6px;
  height: 10px;
  overflow: hidden;
  margin: 6px 0;
}
.progress-bar {
  height: 100%;
  border-radius: 6px;
  transition: width 0.3s ease;
}
.progress-green { background: var(--green); }
.progress-yellow { background: var(--yellow); }
.progress-red { background: var(--red); }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.95rem;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(79,70,229,0.2); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 60px; }
.toggle-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.toggle-group button {
  flex: 1;
  padding: 8px;
  border: none;
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.toggle-group button.active {
  background: var(--primary);
  color: #fff;
}

/* Lists */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.list-item:active { border-color: var(--primary); }
.list-item-info { flex: 1; min-width: 0; }
.list-item-name { font-weight: 600; font-size: 0.95rem; }
.list-item-sub { font-size: 0.8rem; color: var(--text-secondary); margin-top: 2px; }
.list-item-badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.list-item-amount { font-weight: 700; font-size: 0.95rem; white-space: nowrap; }

/* Alerts */
.alert {
  padding: 12px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-size: 0.85rem;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.alert-warning { background: var(--yellow-bg); color: var(--yellow); border: 1px solid var(--yellow); }
.alert-danger { background: var(--red-bg); color: var(--red); border: 1px solid var(--red); }
.alert-info { background: rgba(79,70,229,0.1); color: var(--primary); border: 1px solid var(--primary); }
.alert-dismiss {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: inherit;
  opacity: 0.7;
}

/* Sections */
.section-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 20px 0 10px;
  padding: 6px 12px;
  border-radius: var(--radius);
}
.section-red { background: var(--red-bg); color: var(--red); }
.section-yellow { background: var(--yellow-bg); color: var(--yellow); }
.section-green { background: var(--green-bg); color: var(--green); }

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 6px 0;
  z-index: 100;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.nav-item.active { color: var(--primary); }
.nav-icon { font-size: 1.25rem; line-height: 1; }

/* Search */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.search-bar input { flex: 1; }

/* Question cards */
.question-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.question-card p { font-size: 0.9rem; margin-bottom: 8px; font-weight: 500; }
.question-options { display: flex; gap: 8px; }
.question-options button {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
}
.question-options button.selected-yes { background: var(--green); color: #fff; border-color: var(--green); }
.question-options button.selected-no { background: var(--red); color: #fff; border-color: var(--red); }
.question-options button.selected-unsure { background: var(--yellow); color: #fff; border-color: var(--yellow); }

/* Category header */
.category-header {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 16px 0 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--primary);
}

/* Risk indicator */
.risk-meter {
  text-align: center;
  padding: 12px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-weight: 700;
  font-size: 1rem;
}
.risk-low { background: var(--green-bg); color: var(--green); }
.risk-medium { background: var(--yellow-bg); color: var(--yellow); }
.risk-high { background: var(--red-bg); color: var(--red); }

/* Modal / overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 500px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-content h3 { margin-bottom: 12px; }

/* Template box */
.template-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  margin: 8px 0;
}

/* Utility */
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.empty-state { text-align: center; padding: 32px 16px; color: var(--text-secondary); }
.hidden { display: none !important; }

/* Payment list item */
.payment-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.payment-item:last-child { border-bottom: none; }
.payment-meta { font-size: 0.8rem; color: var(--text-secondary); }
.payment-amount { font-weight: 700; }

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.filter-chip {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 0.75rem;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 500;
}
.filter-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

@media (min-width: 480px) {
  .summary-grid { grid-template-columns: repeat(4, 1fr); }
  .btn-group { justify-content: flex-start; }
}
