:root {
  --navy: #0b3948;
  --teal: #0e7490;
  --aqua: #14b8a6;
  --bg: #f4f8f9;
  --card-bg: #ffffff;
  --text: #17262b;
  --text-muted: #5a6b70;
  --border: #dbe6e8;
}

* { box-sizing: border-box; }

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

header.hero {
  background: linear-gradient(135deg, var(--navy), var(--teal));
  color: #fff;
  padding: 2.25rem 1.5rem 2rem;
}

.hero-inner {
  max-width: 1100px;
  margin: 0 auto;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.1rem;
}

.site-nav a {
  color: #dceff1;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
}

.site-nav a:hover {
  background: rgba(255, 255, 255, 0.12);
}

.site-nav a.active {
  background: #fff;
  color: var(--navy);
  border-color: #fff;
}

.hero-inner .eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  color: #a9e0e6;
  font-weight: 600;
}

.hero-inner h1 {
  margin: 0.35rem 0 0.5rem;
  font-size: clamp(1.5rem, 3vw, 2.1rem);
}

.hero-inner p {
  margin: 0;
  max-width: 68ch;
  color: #dceff1;
  line-height: 1.5;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.65rem 0.2rem;
  margin-right: 1.25rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}

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

.tab-btn.active {
  color: var(--teal);
  border-bottom-color: var(--teal);
}

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.panel h2 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
}

.panel .hint {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

#search {
  flex: 1 1 240px;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
}

#sort {
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: #fff;
}

#category-chips,
#level-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

#level-chips {
  margin-bottom: 1rem;
}

.chip {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-size: 0.83rem;
  cursor: pointer;
  color: var(--text);
}

.chip.active {
  background: var(--chip-color, var(--teal));
  border-color: var(--chip-color, var(--teal));
  color: #fff;
  font-weight: 600;
}

#result-count {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
}

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.2rem 1.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.card-top {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.4rem;
  align-items: start;
}

.card-headline h3 {
  margin: 0 0 0.15rem;
  font-size: 1.02rem;
  line-height: 1.3;
}

.agency {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.level {
  font-style: italic;
}

.status-pill {
  grid-column: 1 / -1;
  justify-self: start;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  margin-top: 0.25rem;
}

.level-pill {
  grid-column: 1 / -1;
  justify-self: start;
  background: #fff;
  border: 1px solid;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
}

.summary {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
}

.why-fit {
  background: #eef8f7;
  border-left: 3px solid var(--aqua);
  padding: 0.5rem 0.7rem;
  font-size: 0.83rem;
  line-height: 1.45;
  border-radius: 0 6px 6px 0;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 0.8rem;
  font-size: 0.8rem;
}

.meta-label {
  display: block;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.1rem;
}

.deadline {
  font-size: 0.85rem;
  padding-top: 0.2rem;
  border-top: 1px dashed var(--border);
}

.deadline.rolling {
  color: #1a7f37;
  font-weight: 600;
}

.deadline.contact {
  color: #a15c00;
  font-weight: 600;
}

.deadline-note {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag {
  font-size: 0.68rem;
  border: 1px solid;
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.source-link {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
  background: var(--teal);
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  margin-bottom: 0.6rem;
}

.source-link:hover {
  background: var(--navy);
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}

footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem 2.5rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.6;
}

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

/* --- Gantt / timeline tab --- */

#gantt-wrap {
  overflow-x: auto;
}

.gantt-svg {
  min-width: 720px;
  width: 100%;
  height: auto;
  font-family: inherit;
}

.gantt-row-label {
  font-size: 11px;
  fill: var(--text);
}

.gantt-month-label {
  font-size: 11px;
  fill: var(--text-muted);
}

.gantt-gridline {
  stroke: var(--border);
  stroke-width: 1;
}

.gantt-today-line {
  stroke: #d1394a;
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

.gantt-today-label {
  font-size: 10px;
  fill: #d1394a;
  font-weight: 700;
}

.gantt-varies-label {
  font-size: 11px;
  font-style: italic;
  fill: var(--text-muted);
}

.gantt-notes-label {
  font-size: 11px;
  fill: var(--text-muted);
  font-style: italic;
}

.gantt-notes-label.has-note {
  fill: var(--navy);
  font-style: normal;
  font-weight: 600;
}

.gantt-bar {
  rx: 4;
  ry: 4;
}

.gantt-row {
  cursor: pointer;
}

.gantt-row:hover .gantt-row-label,
.gantt-row:focus-visible .gantt-row-label {
  text-decoration: underline;
  fill: var(--teal);
}

.gantt-row:hover .gantt-row-hit {
  fill: rgba(14, 116, 144, 0.06);
}

.gantt-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.9rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.gantt-legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.gantt-legend-swatch {
  width: 18px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
  flex-shrink: 0;
}

#period-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.period-row {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) auto;
  gap: 0.3rem 1rem;
  align-items: baseline;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.period-row:hover,
.period-row:focus-visible {
  border-color: var(--teal);
  background: #f0fafa;
  outline: none;
}

.period-row .period-name {
  font-weight: 700;
  font-size: 0.9rem;
}

.period-row .period-agency {
  font-size: 0.76rem;
  color: var(--text-muted);
  grid-column: 1 / -1;
}

.period-note {
  grid-column: 1 / -1;
  font-size: 0.8rem;
  color: var(--navy);
  font-weight: 600;
  margin-top: 0.25rem;
}

.period-note-empty {
  color: var(--text-muted);
  font-weight: 400;
  font-style: italic;
}

.period-row .period-value {
  font-size: 0.82rem;
  text-align: right;
  white-space: nowrap;
}

.period-row .period-value.approx {
  color: #a15c00;
}

.period-type-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  margin-left: 0.4rem;
  vertical-align: middle;
}

/* --- Grant detail modal --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 57, 72, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4vh 1rem;
  overflow-y: auto;
  z-index: 1000;
}

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

.modal-panel {
  background: var(--card-bg);
  border-radius: 12px;
  max-width: 640px;
  width: 100%;
  padding: 1.5rem 1.5rem 1.75rem;
  position: relative;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.modal-panel .card-top,
.modal-panel .summary,
.modal-panel .why-fit,
.modal-panel .meta-grid,
.modal-panel .deadline,
.modal-panel .deadline-note,
.modal-panel .tags,
.modal-panel .source-link {
  margin-bottom: 0.7rem;
}

.modal-panel > div > *:first-child {
  margin-top: 0;
}

.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
}

.modal-close:hover {
  color: var(--navy);
}

/* --- Personal notes field --- */

.notes-field {
  border-top: 1px dashed var(--border);
  padding-top: 0.6rem;
  margin-top: 0.2rem;
}

.notes-field label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.notes-field .notes-desc-label {
  margin-top: 0.6rem;
}

.notes-field textarea,
.notes-field input[type="text"] {
  width: 100%;
  resize: vertical;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fffdf5;
  color: var(--text);
}

.notes-field textarea:focus,
.notes-field input[type="text"]:focus {
  outline: none;
  border-color: var(--teal);
  background: #fff;
}

.notes-status {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  min-height: 1em;
}

.notes-status-error {
  color: #b5642b;
  font-weight: 600;
}
