/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --blue:      #1D4ED8;
  --blue-dark: #1e40af;
  --blue-light:#dbeafe;
  --blue-50:   #eff6ff;
  --ink:       #111827;
  --ink-soft:  #374151;
  --ink-mute:  #6b7280;
  --rule:      #e5e7eb;
  --warm:      #f9fafb;
  --paper:     #ffffff;
  --green:     #16a34a;
  --amber:     #d97706;
  --red:       #dc2626;
  --sans: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Mono', monospace;
}
html { font-size: 14px; }
body { font-family: var(--sans); color: var(--ink); background: var(--warm); line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
button { cursor: pointer; }
img { max-width: 100%; }

/* ── Layout ───────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--ink);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 10;
}
.sb-logo {
  padding: 20px 16px 18px;
  border-bottom: 1px solid #1f2937;
}
.sb-brand { display: flex; align-items: center; gap: 8px; }
.sb-brand-icon {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--blue); display: flex; align-items: center;
  justify-content: center; font-size: 14px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.sb-brand-name  { font-size: 15px; font-weight: 700; color: #fff; letter-spacing: -.01em; }
.sb-brand-by    { font-size: 10px; color: #9ca3af; letter-spacing: .04em; margin-top: 1px; }
.sb-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.sb-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 7px;
  color: #9ca3af; font-size: 13.5px; font-weight: 500;
  transition: background 140ms, color 140ms;
}
.sb-link:hover  { background: #1f2937; color: #fff; text-decoration: none; }
.sb-link.active { background: var(--blue); color: #fff; }
.sb-link svg    { width: 16px; height: 16px; flex-shrink: 0; }
.sb-foot { padding: 12px 16px; border-top: 1px solid #1f2937; }
.sb-foot .status-dot {
  display: inline-block; width: 7px; height: 7px;
  border-radius: 50%; background: var(--green); margin-right: 6px;
}
.sb-foot span { font-size: 11.5px; color: #9ca3af; }

.main { margin-left: 220px; flex: 1; display: flex; flex-direction: column; }

.topbar {
  height: 58px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  background: var(--paper); border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 5;
}
.topbar-title { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.content { padding: 28px; flex: 1; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 7px; font-size: 13.5px; font-weight: 500; border: 1px solid transparent; transition: all 140ms; }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--rule); }
.btn-ghost:hover { background: var(--warm); color: var(--ink); }
.btn-danger { background: transparent; color: var(--red); border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-icon { padding: 6px; }

/* ── Stats bar ────────────────────────────────────────────── */
.stats-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.stat-card { background: var(--paper); border: 1px solid var(--rule); border-radius: 12px; padding: 18px 20px; }
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-mute); margin-bottom: 8px; }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -.03em; line-height: 1; }
.stat-sub { font-size: 11px; color: var(--ink-mute); margin-top: 6px; }
.stat-card.accent { background: var(--blue); border-color: var(--blue-dark); }
.stat-card.accent .stat-label, .stat-card.accent .stat-sub { color: #93c5fd; }
.stat-card.accent .stat-value { color: #fff; }

/* ── Product cards ────────────────────────────────────────── */
.products-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 20px; margin-bottom: 32px; }
.product-card { background: var(--paper); border: 1px solid var(--rule); border-radius: 14px; overflow: hidden; }
.product-card-head { padding: 18px 20px 14px; border-bottom: 1px solid var(--rule); display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.product-name { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.product-meta { font-size: 12px; color: var(--ink-mute); }
.product-card-body { padding: 0; }

/* ── Grant rows ───────────────────────────────────────────── */
.grants-table { width: 100%; border-collapse: collapse; }
.grants-table th { text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-mute); padding: 9px 16px; background: var(--warm); border-bottom: 1px solid var(--rule); }
.grants-table td { padding: 11px 16px; font-size: 13px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.grants-table tr:last-child td { border-bottom: none; }
.grants-table tr:hover td { background: var(--warm); }
.grant-name { font-weight: 500; color: var(--ink); }
.grant-org  { font-size: 12px; color: var(--ink-mute); }

/* ── Badges ───────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-new   { background: var(--blue-light); color: var(--blue); border: 1px solid #93c5fd; }
.badge-seen  { background: var(--warm); color: var(--ink-mute); border: 1px solid var(--rule); }
.badge-small { background: #dcfce7; color: #166534; }
.badge-medium{ background: #fef9c3; color: #854d0e; }
.badge-large { background: #fee2e2; color: #991b1b; }
.score-badge { padding: 3px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; }
.score-hi    { background: #dcfce7; color: #166534; }
.score-med   { background: #fef9c3; color: #854d0e; }
.score-lo    { background: var(--warm); color: var(--ink-mute); }

/* ── Table (generic) ──────────────────────────────────────── */
.table-wrap { background: var(--paper); border: 1px solid var(--rule); border-radius: 12px; overflow: hidden; }
.table-head { padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--rule); }
.table-head h3 { font-size: 14px; font-weight: 600; }
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-mute); padding: 9px 16px; background: var(--warm); border-bottom: 1px solid var(--rule); }
tbody td { padding: 11px 16px; font-size: 13px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--warm); }

/* ── Forms ────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 500; color: var(--ink-soft); letter-spacing: .02em; }
.input { height: 36px; padding: 0 12px; border: 1px solid var(--rule); border-radius: 7px; background: var(--paper); color: var(--ink); outline: none; transition: border-color 140ms; width: 100%; }
.input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29,78,216,.1); }
.textarea { height: auto; min-height: 80px; padding: 8px 12px; resize: vertical; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath fill='%236b7280' d='M0 0h10L5 6z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.full { grid-column: 1/-1; }

/* ── Modal ────────────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); backdrop-filter: blur(4px); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--paper); border-radius: 14px; border: 1px solid var(--rule); padding: 28px; width: 100%; max-width: 520px; box-shadow: 0 20px 60px rgba(0,0,0,.18); }
.modal-title { font-size: 17px; font-weight: 600; margin-bottom: 20px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

/* ── Toast ────────────────────────────────────────────────── */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 11px 16px; border-radius: 9px; font-size: 13.5px; font-weight: 500; box-shadow: 0 4px 16px rgba(0,0,0,.15); animation: slideUp 200ms ease; }
.toast-ok  { background: #14532d; color: #fff; }
.toast-err { background: #7f1d1d; color: #fff; }
@keyframes slideUp { from { opacity:0; transform:translateY(6px); } }

/* ── Misc ─────────────────────────────────────────────────── */
.empty { text-align: center; padding: 40px 20px; color: var(--ink-mute); font-size: 13.5px; }
.text-mute { color: var(--ink-mute); font-size: 12px; }
.tag { display: inline-block; background: var(--blue-50); color: var(--blue); border: 1px solid var(--blue-light); padding: 1px 7px; border-radius: 4px; font-size: 11px; font-weight: 500; }
.spin { animation: spin 900ms linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert-sent   { color: var(--green); font-weight: 500; }
.alert-failed { color: var(--red); font-weight: 500; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { width: 60px; }
  .sb-brand-name, .sb-brand-by, .sb-link span { display: none; }
  .sb-link { justify-content: center; padding: 10px; }
  .main { margin-left: 60px; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .stats-bar { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}
