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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --green: #16a34a;
    --yellow: #ca8a04;
    --red: #dc2626;
    --gray: #6b7280;
    --gray-light: #f3f4f6;
    --gray-border: #e5e7eb;
    --bg: #ffffff;
    --bg-alt: #f9fafb;
    --text: #111827;
    --text-light: #6b7280;
    --relevant-bg: #eff6ff;
    --relevant-border: #bfdbfe;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text);
    background: var(--bg-alt);
    line-height: 1.5;
    font-size: 14px;
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 20px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Navbar ===== */
.navbar {
    background: var(--bg);
    border-bottom: 1px solid var(--gray-border);
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}
.navbar .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.nav-brand {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
}
.nav-brand:hover { text-decoration: none; }
.nav-links { display: flex; gap: 20px; }
.nav-link {
    color: var(--text);
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 4px;
}
.nav-link:hover {
    background: var(--gray-light);
    text-decoration: none;
}

/* ===== Hero ===== */
.hero {
    text-align: center;
    padding: 80px 0 60px;
}
.hero h1 {
    font-size: 48px;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 8px;
}
.hero-sub {
    font-size: 20px;
    color: var(--text-light);
    margin-bottom: 32px;
}
.hero-links {
    display: flex;
    gap: 16px;
    justify-content: center;
}

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    padding: 10px 24px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 14px;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
}
.btn:hover { text-decoration: none; }
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}
.btn-outline:hover { background: var(--primary); color: #fff; }

/* ===== Features ===== */
.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    padding: 40px 0 80px;
}
.feature-card {
    background: var(--bg);
    border: 1px solid var(--gray-border);
    border-radius: var(--radius);
    padding: 28px;
}
.feature-card h3 {
    font-size: 18px;
    margin-bottom: 8px;
}
.feature-card p {
    color: var(--text-light);
    margin-bottom: 16px;
    font-size: 14px;
}

/* ===== Page Header ===== */
.page-header {
    padding: 32px 0 16px;
}
.page-header h1 {
    font-size: 24px;
    font-weight: 700;
}
.page-header p {
    color: var(--text-light);
    margin-top: 4px;
}

/* ===== Stats Bar ===== */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
.stat-item {
    background: var(--bg);
    border: 1px solid var(--gray-border);
    border-radius: var(--radius);
    padding: 16px 20px;
    text-align: center;
}
.stat-value {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}
.stat-label {
    display: block;
    font-size: 13px;
    color: var(--text-light);
    margin-top: 2px;
}
.stat-open .stat-value { color: var(--green); }
.stat-deadline .stat-value { color: var(--yellow); }
.stat-relevant .stat-value { color: var(--primary); }
.stat-important .stat-value { color: #ea580c; }

/* ===== Filter Bar ===== */
.filter-bar {
    background: var(--bg);
    border: 1px solid var(--gray-border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 16px;
}
.filter-row {
    display: flex;
    gap: 16px;
    align-items: end;
    flex-wrap: wrap;
}
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.filter-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
}
.filter-group select,
.filter-group input[type="text"] {
    padding: 8px 12px;
    border: 1px solid var(--gray-border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--bg);
    min-width: 160px;
}
.filter-group input[type="text"] {
    min-width: 240px;
}
.filter-toggle {
    margin-left: auto;
}
.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px 0;
    font-size: 14px !important;
    font-weight: 500 !important;
    color: var(--text) !important;
    text-transform: none !important;
}
.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* ===== Table ===== */
.table-wrap {
    background: var(--bg);
    border: 1px solid var(--gray-border);
    border-radius: var(--radius);
    overflow-x: auto;
}
.grants-table {
    width: 100%;
    border-collapse: collapse;
}
.grants-table th {
    background: var(--gray-light);
    padding: 10px 14px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    white-space: nowrap;
    border-bottom: 1px solid var(--gray-border);
}
.grants-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--gray-border);
    vertical-align: top;
}
.grants-table tbody tr:hover {
    background: var(--gray-light);
}
.grants-table tbody tr.relevant {
    background: var(--relevant-bg);
    border-left: 3px solid var(--primary);
}
.grants-table tbody tr.relevant:hover {
    background: #dbeafe;
}

.col-imp { width: 70px; text-align: center; }
.col-status { width: 70px; }
.col-title { min-width: 280px; }
.col-org { width: 140px; }
.col-deadline { width: 110px; }
.col-amount { width: 120px; }
.col-applicant { width: 80px; }
.col-source { width: 90px; }

/* Importance stars */
.imp-stars {
    color: #f59e0b;
    font-size: 13px;
    letter-spacing: -1px;
    cursor: default;
    white-space: nowrap;
}
.imp-stars .empty { color: #e5e7eb; }
.imp-high {
    background: #fff7ed;
    border-left: 3px solid #ea580c;
}
.imp-high:hover {
    background: #ffedd5;
}

/* Status badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-open { background: #dcfce7; color: #166534; }
.badge-upcoming { background: #fef9c3; color: #854d0e; }
.badge-closed { background: #f3f4f6; color: #6b7280; }
.badge-unknown { background: #f3f4f6; color: #9ca3af; }

/* Title cell */
.grant-title {
    font-weight: 500;
    color: var(--text);
    line-height: 1.4;
}
.grant-title a {
    color: var(--text);
}
.grant-title a:hover {
    color: var(--primary);
}
.grant-keywords {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.keyword-tag {
    display: inline-block;
    padding: 1px 6px;
    background: #dbeafe;
    color: var(--primary);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

/* Deadline */
.deadline-text { font-size: 13px; }
.d-day {
    font-size: 12px;
    font-weight: 600;
    margin-top: 2px;
}
.d-day.urgent { color: var(--red); }
.d-day.soon { color: var(--yellow); }
.d-day.normal { color: var(--text-light); }

/* Applicant badges */
.applicant-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.app-vitar { background: #dbeafe; color: #1e40af; }
.app-gregori { background: #fce7f3; color: #9d174d; }
.app-both { background: #f0fdf4; color: #166534; }

/* Source */
.source-tag {
    display: inline-block;
    padding: 2px 8px;
    background: var(--gray-light);
    border-radius: 4px;
    font-size: 12px;
    color: var(--text-light);
}

/* Loading */
.loading {
    text-align: center;
    color: var(--text-light);
    padding: 40px;
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 20px 0 40px;
}
.pagination button {
    padding: 8px 14px;
    border: 1px solid var(--gray-border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
}
.pagination button:hover {
    background: var(--gray-light);
}
.pagination button.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ===== Footer ===== */
.footer {
    border-top: 1px solid var(--gray-border);
    padding: 20px 0;
    text-align: center;
    color: var(--text-light);
    font-size: 13px;
    margin-top: 40px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
    }
    .filter-row {
        flex-direction: column;
    }
    .filter-group select,
    .filter-group input[type="text"] {
        min-width: 100%;
    }
    .filter-toggle {
        margin-left: 0;
    }
    .col-amount, .col-org {
        display: none;
    }
    .hero h1 { font-size: 32px; }
}
