:root {
  --bg: #fdfbf9;
  --text: #1a1a19;
  --accent: #c2410c;
  --border: #e0e0e0;
  --high: #15803d;
  --medium: #a16207;
  --low: #475569;
  --urgent: #ef4444;
}

* {
  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);
  line-height: 1.5;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--text);
}

h1 {
  font-size: 24px;
  font-weight: 800;
}
.subtitle {
  color: #666;
  font-size: 14px;
}

.stats {
  display: flex;
  gap: 24px;
  font-size: 14px;
}

.stat {
  text-align: center;
}
.stat-value {
  font-size: 28px;
  font-weight: 800;
}
.stat-label {
  color: #666;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.tab {
  padding: 8px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: #666;
  border-radius: 4px;
}

.tab:hover {
  background: #f0f0f0;
}
.tab.active {
  background: var(--text);
  color: var(--bg);
}

/* Filters */
.filters {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.filter-group label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: #666;
}
.filter-spacer {
  flex: 1;
}
.filter-status-note {
  align-self: center;
}

select,
input[type="text"] {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  background: white;
}

input[type="text"] {
  width: 200px;
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}

.btn-primary {
  background: var(--text);
  color: var(--bg);
}
.btn-secondary {
  background: #f0f0f0;
  color: var(--text);
}
.btn-accent {
  background: var(--accent);
  color: white;
}
.btn:hover {
  opacity: 0.9;
}

/* Focus styles for accessibility */
.btn:focus,
select:focus,
input:focus,
.tab:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
tr[data-grant-id]:focus,
.timeline-item:focus,
.quick-action-item:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Table View */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

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

th {
  font-weight: 600;
  background: #f8f8f8;
  cursor: pointer;
  user-select: none;
}

th:hover {
  background: #f0f0f0;
}
th.sorted::after {
  content: " ▼";
  font-size: 10px;
}
th.sorted.asc::after {
  content: " ▲";
}

tr:hover {
  background: #fafafa;
}
#grants-table tbody tr[data-grant-id] {
  cursor: pointer;
}

.fit-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.fit-HIGH,
.fit-PERFECT {
  background: var(--high);
  color: white;
}
.fit-MEDIUM {
  background: var(--medium);
  color: var(--text);
}
.fit-LOW {
  background: var(--low);
  color: white;
}

/* Category badges */
.cat-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}
.cat-federal {
  background: #dbeafe;
  color: #1d4ed8;
}
.cat-state {
  background: #fef3c7;
  color: #92400e;
}
.cat-corporate {
  background: #e0e7ff;
  color: #4338ca;
}
.cat-foundation {
  background: #f3e8ff;
  color: #7c3aed;
}
.cat-heritage {
  background: #fce7f3;
  color: #be185d;
}
.cat-local {
  background: #ccfbf1;
  color: #0d9488;
}
.cat-education {
  background: #fef9c3;
  color: #ca8a04;
}
.cat-service_club {
  background: #fee2e2;
  color: #dc2626;
}
.cat-university {
  background: #cffafe;
  color: #0891b2;
}
.cat-association {
  background: #f1f5f9;
  color: #475569;
}
.cat-accessibility {
  background: #d1fae5;
  color: #059669;
}
.cat-media {
  background: #ffe4e6;
  color: #e11d48;
}
.cat-other {
  background: #f1f5f9;
  color: #64748b;
}

/* Quick actions panel */
.quick-actions {
  background: linear-gradient(135deg, #fef2f2 0%, #fff7ed 100%);
  border: 2px solid var(--urgent);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 20px;
}
.quick-actions h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--urgent);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.quick-actions h3::before {
  content: "!";
  background: var(--urgent);
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.quick-actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
}
.quick-action-item {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.2s;
}
.quick-action-item:hover {
  border-color: var(--accent);
}
.quick-action-date {
  font-size: 11px;
  color: var(--urgent);
  font-weight: 700;
}
.quick-action-name {
  font-weight: 600;
  font-size: 13px;
  margin: 4px 0;
}
.quick-action-amount {
  font-size: 12px;
  color: #666;
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.status-not_started {
  background: #f0f0f0;
  color: #666;
}
.status-researching {
  background: #dbeafe;
  color: #1d4ed8;
}
.status-writing {
  background: #fef3c7;
  color: #92400e;
}
.status-submitted {
  background: #d1fae5;
  color: #065f46;
}
.status-awarded {
  background: var(--high);
  color: white;
}
.status-declined {
  background: #fee2e2;
  color: #991b1b;
}

.deadline-urgent {
  color: var(--urgent);
  font-weight: 700;
}
.deadline-soon {
  color: var(--accent);
  font-weight: 600;
}
.deadline-muted {
  color: #666;
}
.deadline-past {
  color: #999;
  text-decoration: line-through;
}
.deadline-chip {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  vertical-align: middle;
}
.deadline-confirmed {
  background: #dcfce7;
  color: #166534;
}
.deadline-verify {
  background: #fef3c7;
  color: #92400e;
}
.deadline-forecast {
  background: #e0e7ff;
  color: #3730a3;
}
.error-hint {
  margin-top: 12px;
  font-size: 12px;
}

.amount {
  font-family: monospace;
}

.grant-link {
  color: var(--accent);
  text-decoration: none;
}
.grant-link:hover {
  text-decoration: underline;
}

/* Calendar View */
.calendar-view {
  display: none;
}
.calendar-view.active {
  display: block;
}

.timeline {
  position: relative;
  padding-left: 120px;
}

.timeline-month {
  margin-bottom: 24px;
}

.month-header {
  position: absolute;
  left: 0;
  width: 100px;
  font-weight: 700;
  font-size: 14px;
}

.timeline-items {
  border-left: 2px solid var(--border);
  padding-left: 20px;
}

.timeline-item {
  position: relative;
  padding: 12px 16px;
  margin-bottom: 8px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.timeline-item:hover {
  border-color: var(--accent);
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -27px;
  top: 18px;
  width: 12px;
  height: 12px;
  background: var(--bg);
  border: 2px solid var(--accent);
  border-radius: 50%;
}

.timeline-item.urgent::before {
  background: var(--urgent);
  border-color: var(--urgent);
}

.timeline-date {
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
}

.timeline-title {
  font-weight: 600;
}
.timeline-amount {
  font-size: 13px;
  color: #666;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: white;
  border-radius: 12px;
  width: 90%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 20px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #666;
}

.modal h2 {
  font-size: 20px;
  margin-bottom: 8px;
}
.modal h3 {
  font-size: 14px;
  margin: 16px 0 8px;
  color: #666;
  text-transform: uppercase;
}
.modal-source {
  color: #666;
}
.fit-reason {
  background: #f0fdf4;
  padding: 12px;
  border-radius: 8px;
  border-left: 4px solid var(--high);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.detail-item label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  color: #666;
  margin-bottom: 4px;
}

.detail-item .value {
  font-weight: 600;
}

.requirements-list,
.eligibility-list {
  list-style: none;
  padding: 0;
}

.requirements-list li,
.eligibility-list li {
  padding: 4px 0;
  padding-left: 20px;
  position: relative;
}

.requirements-list li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--accent);
}
.eligibility-list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--high);
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.tracker-section {
  background: #f8f8f8;
  padding: 16px;
  border-radius: 8px;
  margin-top: 16px;
}
.tracker-section h3 {
  margin-top: 0;
}
.notes-label {
  display: block;
  margin-top: 12px;
}

.tracker-section select {
  width: 100%;
  margin-top: 8px;
}

.tracker-section textarea {
  width: 100%;
  margin-top: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  body {
    padding: 12px;
  }

  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .stats {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  .stat-value {
    font-size: 20px;
  }
  .stat-label {
    font-size: 11px;
  }

  h1 {
    font-size: 20px;
  }

  .filters {
    gap: 8px;
  }

  .filter-group {
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
  }

  .filter-group label {
    margin-bottom: 2px;
  }

  select,
  input[type="text"] {
    width: 100%;
    padding: 12px;
    font-size: 16px; /* Prevents iOS zoom */
  }

  .btn {
    padding: 12px 16px;
    flex: 1;
  }

  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Table: horizontal scroll with sticky first column */
  table {
    font-size: 13px;
  }
  th,
  td {
    padding: 10px 8px;
    white-space: nowrap;
  }

  /* Timeline adjustments */
  .timeline {
    padding-left: 0;
  }
  .month-header {
    position: relative;
    width: 100%;
    margin-bottom: 8px;
  }
  .timeline-items {
    margin-left: 16px;
  }

  /* Modal full-screen on mobile */
  .modal {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    padding: 16px;
  }

  .detail-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .modal-actions {
    flex-wrap: wrap;
  }

  .modal-actions .btn {
    flex: 1 1 45%;
  }

  /* Quick actions */
  .quick-actions-grid {
    grid-template-columns: 1fr;
  }

  .quick-action-item {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .modal-actions .btn {
    flex: 1 1 100%;
  }
}

/* Print Styles */
@media print {
  body {
    padding: 0;
  }
  .filters,
  .tabs,
  .btn,
  .modal-overlay,
  .quick-actions,
  .freshness-banner,
  .active-filters,
  .skip-link {
    display: none !important;
  }
  header {
    border-bottom: 1px solid #000;
  }
  table {
    font-size: 11px;
  }
  th,
  td {
    padding: 6px;
  }
  .fit-badge,
  .status-badge {
    border: 1px solid #000;
    background: white !important;
    color: #000 !important;
  }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #666;
}

.empty-state h3 {
  margin-bottom: 8px;
}

/* Loading spinner */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: #666;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.loading-text {
  margin-top: 16px;
  font-size: 14px;
}

/* Active filters display */
.active-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.active-filters:empty {
  display: none;
}
.filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--text);
  color: var(--bg);
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
}
.filter-tag button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  opacity: 0.7;
}
.filter-tag button:hover {
  opacity: 1;
}

/* Save feedback */
.save-feedback {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--high);
  font-weight: 600;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s;
}
.save-feedback.show {
  opacity: 1;
}

.freshness-banner {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  color: #78350f;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Sort hints */
.sort-hint {
  opacity: 0.3;
  font-size: 10px;
  margin-left: 4px;
}
th.sorted .sort-hint {
  opacity: 0;
}
th:hover .sort-hint {
  opacity: 0.6;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 1000;
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
  border: 2px solid var(--text);
  border-radius: 4px;
}
.skip-link:focus {
  left: 16px;
}

.foundations-view { display: none; }
.foundations-view.active { display: block; }
