/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Truewind zinc palette */
  --bg: #fafafa;
  --surface: #ffffff;
  --border: rgba(228,228,231,0.85);
  --border-light: #f4f4f5;
  --text: #18181b;
  --text-secondary: #52525b;
  --text-muted: #a1a1aa;
  --primary: #18181b;
  --primary-hover: #27272a;
  --primary-light: #f4f4f5;
  --accent: #18181b;
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --green-border: #bbf7d0;
  --yellow: #ca8a04;
  --yellow-bg: #fefce8;
  --yellow-border: #fef08a;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --orange: #ea580c;
  --orange-bg: #fff7ed;
  --orange-border: #fed7aa;
  --radius: 6px;
  --radius-lg: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 22px 40px -32px rgba(15,23,42,0.28);
  --transition: 150ms ease;
}

html { font-size: 15px; }
body {
  font-family: 'Geist', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
code, .mono { font-family: 'Geist Mono', ui-monospace, monospace; }

/* ===== Header ===== */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-text {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}
.logo-badge {
  font-size: 0.73rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--border-light);
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid var(--border);
}
.header-nav { display: flex; gap: 8px; align-items: center; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 0.87rem;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 500;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 10px 24px; font-size: 0.93rem; }
.btn-cta {
  background: #fff;
  color: #18181b;
  font-weight: 600;
  border-color: #fff;
  padding: 10px 24px;
}
.btn-cta:hover { background: #f4f4f5; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }
.btn-icon {
  padding: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--bg); color: var(--text-secondary); }

/* ===== Summary Bar ===== */
.summary-bar {
  max-width: 1280px;
  margin: 24px auto 0;
  padding: 0 24px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.summary-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.summary-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}
.summary-alerts { color: var(--red); }

/* ===== Main ===== */
.main {
  max-width: 1280px;
  margin: 24px auto;
  padding: 0 24px;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.empty-icon { margin-bottom: 16px; opacity: 0.6; }
.empty-state h2 { font-size: 1.2rem; font-weight: 600; margin-bottom: 8px; }
.empty-state p { color: var(--text-secondary); font-size: 0.93rem; margin-bottom: 24px; max-width: 420px; margin-left: auto; margin-right: auto; }

/* ===== Grant Cards Grid ===== */
.grants-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 20px;
}

/* ===== Grant Card ===== */
.grant-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: box-shadow var(--transition);
  cursor: pointer;
}
.grant-card:hover { box-shadow: var(--shadow-md); }

.grant-card-header {
  padding: 20px 20px 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.grant-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.grant-card-funder {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.grant-card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

/* Health Score Badge */
.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 600;
}
.health-badge-score {
  font-size: 1.05rem;
  font-weight: 700;
}
.health-good { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.health-warning { background: var(--yellow-bg); color: var(--yellow); border: 1px solid var(--yellow-border); }
.health-danger { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); }
.health-over { background: var(--orange-bg); color: var(--orange); border: 1px solid var(--orange-border); }

/* Card Body */
.grant-card-body { padding: 0 20px 16px; }

.grant-progress-section { margin-bottom: 14px; }
.grant-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.grant-progress-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }
.grant-progress-pct { font-size: 0.87rem; font-weight: 600; }
.progress-bar {
  height: 8px;
  background: var(--border-light);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.4s ease;
}
.progress-green { background: var(--green); }
.progress-yellow { background: var(--yellow); }
.progress-red { background: var(--red); }
.progress-orange { background: var(--orange); }

/* Alerts inside card */
.grant-alerts { display: flex; flex-direction: column; gap: 6px; }
.alert-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.35;
}
.alert-pill-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
}
.alert-warning { background: var(--yellow-bg); color: var(--yellow); }
.alert-warning .alert-pill-icon { background: var(--yellow); }
.alert-danger { background: var(--red-bg); color: var(--red); }
.alert-danger .alert-pill-icon { background: var(--red); }
.alert-restricted { background: var(--orange-bg); color: var(--orange); }
.alert-restricted .alert-pill-icon { background: var(--orange); }

/* Card Footer */
.grant-card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.grant-deadline { font-weight: 500; }
.grant-deadline-soon { color: var(--red); font-weight: 600; }

/* ===== CTA Banner ===== */
.cta-banner {
  max-width: 1280px;
  margin: 32px auto;
  padding: 0 24px;
}
.cta-inner {
  background: #18181b;
  border-radius: var(--radius-lg);
  padding: 32px 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
}
.cta-text h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 6px;
}
.cta-text p {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.85);
  max-width: 520px;
  line-height: 1.55;
}

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.45);
  backdrop-filter: blur(4px);
  z-index: 200;
  justify-content: center;
  align-items: flex-start;
  padding: 48px 20px;
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 680px;
  animation: modalIn 0.2s ease;
}
.modal-sm { max-width: 520px; }
.modal-lg { max-width: 840px; }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Forms */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}
.required { color: var(--red); }
.form-group input, .form-group select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition);
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}

/* Line Items Table */
.line-items-section { margin-top: 8px; }
.line-items-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.line-items-header h3 { font-size: 0.93rem; font-weight: 600; }
.line-items-table-wrap { overflow-x: auto; }
.line-items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}
.line-items-table th {
  text-align: left;
  padding: 8px 10px;
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}
.line-items-table td { padding: 6px 10px; }
.line-items-table input, .line-items-table select {
  font-family: inherit;
  font-size: 0.87rem;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  width: 100%;
}
.line-items-table input:focus, .line-items-table select:focus {
  outline: none;
  border-color: var(--primary);
}
.line-items-table .col-category { width: 35%; }
.line-items-table .col-budget { width: 20%; }
.line-items-table .col-actual { width: 20%; }
.line-items-table .col-restricted { width: 15%; }
.line-items-table .col-actions { width: 10%; text-align: center; }

/* CSV import */
.csv-instructions { font-size: 0.87rem; color: var(--text-secondary); margin-bottom: 16px; line-height: 1.55; }
.csv-instructions code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.82rem;
}
.file-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
  transition: all var(--transition);
}
.file-drop.drag-over { border-color: var(--primary); background: var(--primary-light); }
.file-drop p { margin-top: 8px; font-size: 0.87rem; }
.file-link { color: var(--primary); cursor: pointer; text-decoration: underline; }

/* Detail Modal */
.detail-section { margin-bottom: 24px; }
.detail-section h3 {
  font-size: 0.93rem;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}
.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}
.detail-table th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.detail-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}
.detail-table tr.row-over td { background: var(--red-bg); color: var(--red); font-weight: 500; }
.detail-table tr.row-warning td { background: var(--yellow-bg); }
.detail-table tr.row-restricted-alert td { background: var(--orange-bg); }
.detail-bar-cell { width: 160px; }
.detail-bar-wrap {
  height: 8px;
  background: var(--border-light);
  border-radius: 99px;
  overflow: hidden;
}
.detail-bar-fill {
  height: 100%;
  border-radius: 99px;
}

.detail-meta {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.detail-meta-item {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.detail-meta-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.detail-meta-value { font-size: 1.1rem; font-weight: 600; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .summary-bar { grid-template-columns: repeat(2, 1fr); }
  .summary-bar .summary-card:last-child { grid-column: span 2; }
  .grants-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .cta-inner { flex-direction: column; text-align: center; }
  .header-nav { gap: 4px; }
  .btn-ghost { display: none; }
  .detail-meta { grid-template-columns: 1fr; }
}
