/* === Reset & Variables === */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
:root {
  --bg: #fefce8;
  --bg-card: #ffffff;
  --violet: #7c3aed;
  --violet-light: #ede9fe;
  --violet-dark: #5b21b6;
  --green: #059669;
  --green-light: #d1fae5;
  --green-dark: #047857;
  --text: #1e1b4b;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* === Header === */
.app-header {
  background: linear-gradient(135deg, var(--violet) 0%, var(--violet-dark) 100%);
  color: #fff;
  padding: 2rem 1.5rem;
  text-align: center;
}
.header-inner { max-width: 900px; margin: 0 auto; }
.logo { display: flex; align-items: center; justify-content: center; gap: 0.5rem; }
.logo-icon { font-size: 2rem; }
.logo h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
.tagline { opacity: 0.9; margin-top: 0.25rem; font-size: 1.05rem; }

/* === Main Layout === */
.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 2rem;
  align-items: start;
}
@media (max-width: 900px) {
  .app-main { grid-template-columns: 1fr; }
}

/* === Panel Card === */
.panel-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 1.5rem;
}
.panel-card h2 { font-size: 1.35rem; color: var(--violet-dark); margin-bottom: 0.25rem; }
.panel-desc { color: var(--text-muted); font-size: 0.92rem; margin-bottom: 1.25rem; }

/* === Multi-step Form === */
.form-step { display: none; }
.form-step.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.form-step h3 {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 1.05rem; margin-bottom: 1rem; color: var(--text);
}
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--violet); color: #fff; font-size: 0.85rem; font-weight: 600;
}
.optional-tag {
  font-size: 0.75rem; background: var(--violet-light); color: var(--violet);
  padding: 2px 8px; border-radius: 999px; font-weight: 500;
}

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.3rem; }
.req { color: #ef4444; }
.form-group input,
.form-group select {
  width: 100%; padding: 0.6rem 0.75rem; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 0.95rem; background: #fff;
  transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(124,58,237,0.1); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.65rem 1.25rem; border: none; border-radius: var(--radius-sm);
  font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.btn-next, .btn-submit { background: var(--violet); color: #fff; width: 100%; }
.btn-next:hover, .btn-submit:hover { background: var(--violet-dark); }
.btn-back { background: var(--violet-light); color: var(--violet); }
.btn-back:hover { background: #ddd6fe; }
.btn-row { display: flex; gap: 0.75rem; }
.btn-row .btn-back { flex: 0 0 auto; }
.btn-row .btn-next, .btn-row .btn-submit { flex: 1; }
.btn-filter { background: var(--violet); color: #fff; padding: 0.5rem 1rem; font-size: 0.85rem; }
.btn-filter:hover { background: var(--violet-dark); }
.btn-clear-filter { background: transparent; color: var(--text-muted); padding: 0.5rem 0.75rem; font-size: 0.85rem; }
.btn-clear-filter:hover { color: var(--text); }
.btn-export { background: var(--green); color: #fff; padding: 0.5rem 1rem; font-size: 0.85rem; }
.btn-export:hover { background: var(--green-dark); }
.btn-subscribe { background: var(--violet); color: #fff; padding: 0.65rem 1.5rem; white-space: nowrap; }
.btn-subscribe:hover { background: var(--violet-dark); }

.btn-spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* Step Indicators */
.step-indicators { display: flex; justify-content: center; gap: 0.5rem; margin-top: 1.25rem; }
.step-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--border); transition: background 0.3s;
}
.step-dot.active { background: var(--violet); }

/* === Empty State === */
.empty-state { text-align: center; padding: 3rem 1.5rem; }
.empty-icon { font-size: 4rem; margin-bottom: 1rem; }
.empty-state h2 { font-size: 1.5rem; color: var(--violet-dark); margin-bottom: 0.5rem; }
.empty-state p { color: var(--text-muted); max-width: 500px; margin: 0 auto 2rem; }
.stat-row { display: flex; gap: 2rem; justify-content: center; flex-wrap: wrap; }
.stat-item { text-align: center; }
.stat-num { display: block; font-size: 1.5rem; font-weight: 700; color: var(--violet); }
.stat-label { font-size: 0.82rem; color: var(--text-muted); }

/* === Loading === */
.loading-state { text-align: center; padding: 4rem 1.5rem; }
.loading-spinner {
  width: 48px; height: 48px; border: 4px solid var(--violet-light);
  border-top-color: var(--violet); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 1.5rem;
}
.loading-state h2 { color: var(--violet-dark); margin-bottom: 0.5rem; }
.loading-state p { color: var(--text-muted); }

/* === Results Summary === */
.results-summary {
  display: flex; align-items: center; gap: 2rem; flex-wrap: wrap;
  background: var(--bg-card); border-radius: var(--radius); padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow); margin-bottom: 1rem;
}
.summary-stat { text-align: center; }
.summary-num { display: block; font-size: 1.5rem; font-weight: 700; color: var(--violet); }
.summary-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.results-summary .btn-export { margin-left: auto; }

/* Profile Summary */
.profile-summary {
  background: var(--violet-light); border-radius: var(--radius-sm);
  padding: 0.85rem 1.1rem; margin-bottom: 1rem; font-size: 0.92rem;
  color: var(--violet-dark); line-height: 1.5; border-left: 4px solid var(--violet);
}

/* === Filter Bar === */
.filter-bar {
  display: flex; align-items: flex-end; gap: 0.75rem; flex-wrap: wrap;
  background: var(--bg-card); border-radius: var(--radius); padding: 1rem 1.25rem;
  box-shadow: var(--shadow); margin-bottom: 1.5rem;
}
.filter-group { display: flex; flex-direction: column; gap: 0.2rem; }
.filter-group label { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.filter-group input, .filter-group select {
  padding: 0.4rem 0.6rem; border: 1.5px solid var(--border);
  border-radius: 6px; font-size: 0.88rem; width: 130px;
}
.filter-group input:focus, .filter-group select:focus { border-color: var(--violet); outline: none; }

/* === Chart === */
.chart-container {
  background: var(--bg-card); border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow); margin-bottom: 1.5rem; max-height: 280px;
}

/* === Cards Grid === */
.cards-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.grant-card {
  background: var(--bg-card); border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow); transition: box-shadow 0.2s, transform 0.2s;
  position: relative; overflow: hidden;
  border-top: 4px solid var(--violet);
}
.grant-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }

.card-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 0.75rem; }
.card-header h3 { font-size: 1.05rem; color: var(--text); line-height: 1.3; flex: 1; margin-right: 0.5rem; }

.match-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 48px; height: 48px; border-radius: 50%;
  font-size: 1rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.match-high { background: var(--green); }
.match-mid { background: #f59e0b; }
.match-low { background: #ef4444; }

.card-org { font-size: 0.88rem; color: var(--text-muted); margin-bottom: 0.5rem; }

.card-amount {
  font-size: 1.35rem; font-weight: 700; color: var(--green-dark); margin-bottom: 0.5rem;
}

.card-meta { display: flex; gap: 1rem; margin-bottom: 0.75rem; font-size: 0.85rem; color: var(--text-muted); }
.card-meta span { display: flex; align-items: center; gap: 0.25rem; }

.card-tags { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.75rem; }
.card-tag {
  background: var(--violet-light); color: var(--violet); font-size: 0.75rem;
  padding: 2px 8px; border-radius: 999px; font-weight: 500;
}

.card-desc { font-size: 0.88rem; color: var(--text-muted); margin-bottom: 0.75rem; line-height: 1.5; }

.card-footer { display: flex; justify-content: space-between; align-items: center; }
.card-link {
  color: var(--violet); font-weight: 600; font-size: 0.88rem;
  text-decoration: none; transition: color 0.2s;
}
.card-link:hover { color: var(--violet-dark); text-decoration: underline; }
.card-renewable {
  font-size: 0.78rem; padding: 2px 8px; border-radius: 999px;
  font-weight: 600;
}
.renewable-yes { background: var(--green-light); color: var(--green-dark); }
.renewable-no { background: #fee2e2; color: #991b1b; }

.competition-tag {
  font-size: 0.75rem; padding: 2px 8px; border-radius: 999px;
  font-weight: 500; margin-left: 0.35rem;
}
.competition-low { background: var(--green-light); color: var(--green-dark); }
.competition-moderate { background: #fef3c7; color: #92400e; }
.competition-high { background: #fee2e2; color: #991b1b; }

/* === History === */
.history-section {
  max-width: 1280px; margin: 0 auto; padding: 0 1.5rem 2rem;
}
.history-inner {
  background: var(--bg-card); border-radius: var(--radius); padding: 1.5rem;
  box-shadow: var(--shadow);
}
.history-inner h2 { font-size: 1.2rem; color: var(--violet-dark); margin-bottom: 1rem; }
.history-list { display: flex; flex-direction: column; gap: 0.5rem; }
.history-empty { color: var(--text-muted); font-size: 0.92rem; }

.history-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border-radius: var(--radius-sm);
  background: var(--bg); border: 1px solid var(--border); cursor: pointer;
  transition: background 0.2s;
}
.history-item:hover { background: var(--violet-light); }
.history-item-info { display: flex; gap: 1rem; align-items: center; }
.history-field { font-weight: 600; color: var(--text); }
.history-detail { font-size: 0.85rem; color: var(--text-muted); }
.history-date { font-size: 0.82rem; color: var(--text-muted); }
.history-matches {
  background: var(--green-light); color: var(--green-dark);
  padding: 2px 10px; border-radius: 999px; font-size: 0.82rem; font-weight: 600;
}

/* === Footer === */
.app-footer {
  background: linear-gradient(135deg, var(--violet-dark) 0%, #312e81 100%);
  color: #fff; padding: 3rem 1.5rem; margin-top: 1rem;
}
.footer-inner { max-width: 600px; margin: 0 auto; text-align: center; }
.footer-cta h2 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.footer-cta p { opacity: 0.85; margin-bottom: 1.25rem; }
.subscribe-form { display: flex; gap: 0.5rem; justify-content: center; max-width: 420px; margin: 0 auto; }
.subscribe-form input {
  flex: 1; padding: 0.65rem 1rem; border: 2px solid rgba(255,255,255,0.3);
  border-radius: var(--radius-sm); font-size: 0.95rem; background: rgba(255,255,255,0.1);
  color: #fff;
}
.subscribe-form input::placeholder { color: rgba(255,255,255,0.5); }
.subscribe-form input:focus { outline: none; border-color: rgba(255,255,255,0.6); }
.subscribe-msg { margin-top: 0.75rem; font-size: 0.92rem; }
.subscribe-msg.success { color: #a7f3d0; }
.subscribe-msg.error { color: #fca5a5; }
.footer-meta { margin-top: 2rem; opacity: 0.6; font-size: 0.85rem; }
.footer-meta a { color: #fff; }

/* === No Results === */
.no-results {
  text-align: center; padding: 2rem; color: var(--text-muted);
  grid-column: 1 / -1;
}

/* === Responsive === */
@media (max-width: 900px) {
  .panel-card { position: static; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-group input, .filter-group select { width: 100%; }
  .results-summary { flex-direction: column; gap: 1rem; text-align: center; }
  .results-summary .btn-export { margin-left: 0; }
  .subscribe-form { flex-direction: column; }
}
