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

:root {
    --color-bg: #f5f7fa;
    --color-surface: #ffffff;
    --color-primary: #1a5c2e;
    --color-primary-light: #2d8a47;
    --color-accent: #e8a838;
    --color-danger: #d9534f;
    --color-text: #1a1a2e;
    --color-text-muted: #6b7280;
    --color-border: #e2e8f0;
    --color-favorite: #f59e0b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

html { font-size: 15px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

/* ── Header ── */
.app-header {
    background: var(--color-primary);
    color: white;
    padding: 0 1.25rem;
    height: 52px;
    max-height: 52px;
    display: flex;
    align-items: center;
    gap: 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-md);
    flex-wrap: nowrap;
    overflow: visible;
}
.header-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 700;
    font-size: 1.05rem;
    color: white;
    white-space: nowrap;
    letter-spacing: -0.01em;
    margin-right: 1.5rem;
    flex-shrink: 0;
    height: 100%;
}
.header-brand:hover { text-decoration: none; opacity: 0.88; }
.brand-logo {
    flex-shrink: 0;
    display: block;
}
.header-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex: 1;
    flex-wrap: nowrap;
}
.nav-link {
    color: rgba(255,255,255,0.75);
    font-size: 0.82rem;
    font-weight: 500;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover { color: white; background: rgba(255,255,255,0.12); text-decoration: none; }
.nav-link.active { color: white; background: rgba(255,255,255,0.18); text-decoration: none; }

/* Auth nav links — hidden until Clerk confirms authentication */
.auth-nav { display: none; }

/* Right-side auth area */
#header-auth {
    margin-left: auto;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 0.5rem;
    flex-shrink: 0;
    flex-wrap: nowrap !important;
    height: 52px;
}
#header-auth > * {
    flex-shrink: 0;
    display: inline-flex !important;
    align-items: center !important;
}
#header-auth div, #header-auth div > div {
    display: inline-flex !important;
    align-items: center !important;
}

/* Clerk user avatar — far right */
#header-user {
    margin-left: 0.75rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

/* Header auth buttons */
.header-btn {
    padding: 0.35rem 0.85rem;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}
.btn-sign-in {
    color: rgba(255,255,255,0.9);
    background: rgba(255,255,255,0.1);
}
.btn-sign-in:hover {
    background: rgba(255,255,255,0.2);
    color: white;
    text-decoration: none;
}
.btn-create-account {
    color: #1a1a2e;
    background: var(--color-accent);
}
.btn-create-account:hover {
    background: #d4952f;
    color: #1a1a2e;
    text-decoration: none;
}
.hub-link {
    background: rgba(232,168,56,0.2) !important;
}
.hub-link:hover {
    background: rgba(232,168,56,0.35) !important;
}

/* ── Main ── */
.app-main {
    flex: 1;
    padding: 1rem;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
}

/* ── Footer ── */
.app-footer {
    text-align: center;
    padding: 1rem;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    border-top: 1px solid var(--color-border);
}
.app-footer a { color: var(--color-text-muted); text-decoration: underline; }

/* ── Cards ── */
.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 1rem;
}
.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--color-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ── Search Bar ── */
.search-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.search-bar input, .search-bar select {
    flex: 1;
    min-width: 120px;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--color-surface);
}
.search-bar input:focus, .search-bar select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(26,92,46,0.15);
}
.search-bar button {
    padding: 0.6rem 1.25rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: 500;
}
.search-bar button:hover { background: var(--color-primary-light); }

/* ── Lake List ── */
.lake-list { list-style: none; }
.lake-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid var(--color-border);
    gap: 0.75rem;
    transition: background 0.15s;
}
.lake-item:last-child { border-bottom: none; }
.lake-item:hover { background: #f8fafb; }
.lake-item-body { flex: 1; min-width: 0; }
.lake-item-name {
    font-weight: 600;
    color: var(--color-text);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.lake-item-meta {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.15rem;
}
.lake-item-badges { display: flex; gap: 0.25rem; flex-shrink: 0; }

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 99px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-survey { background: #dbeafe; color: #1e40af; }
.badge-map { background: #d1fae5; color: #065f46; }
.badge-invasive { background: #fee2e2; color: #991b1b; }
.badge-stocking { background: #fef3c7; color: #92400e; }

/* ── Favorite Star ── */
.fav-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.3rem;
    color: var(--color-border);
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.15s, transform 0.15s;
}
.fav-btn:hover { transform: scale(1.15); }
.fav-btn.active { color: var(--color-favorite); }

/* ── Pagination ── */
.pagination {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}
.pagination button, .pagination span {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    font-size: 0.85rem;
    cursor: pointer;
}
.pagination button:hover { background: #f1f5f9; }
.pagination button.active { background: var(--color-primary); color: white; border-color: var(--color-primary); }
.pagination button:disabled { opacity: 0.4; cursor: default; }

/* ── Profile Header ── */
.profile-header {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
    color: white;
    padding: 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}
.profile-header h1 {
    font-size: 1.4rem;
    margin-bottom: 0.25rem;
}
.profile-header .subtitle {
    opacity: 0.85;
    font-size: 0.85rem;
}
.profile-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background 0.15s;
}
.btn-light { background: rgba(255,255,255,0.2); color: white; }
.btn-light:hover { background: rgba(255,255,255,0.3); text-decoration: none; }
.btn-accent { background: var(--color-accent); color: #1a1a2e; }
.btn-accent:hover { background: #d4952f; text-decoration: none; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text);
}
.btn-outline:hover { background: #f1f5f9; text-decoration: none; }
.btn-danger { background: var(--color-danger); color: white; }

/* ── Stat Grid ── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.stat-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.75rem;
    text-align: center;
}
.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--color-primary);
}
.stat-label {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ── Data Table ── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.data-table th {
    text-align: left;
    padding: 0.5rem;
    border-bottom: 2px solid var(--color-border);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-muted);
}
.data-table td {
    padding: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}
.data-table tr:last-child td { border-bottom: none; }

/* ── Species List ── */
.species-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    list-style: none;
}
.species-chip {
    background: #f1f5f9;
    padding: 0.2rem 0.6rem;
    border-radius: 99px;
    font-size: 0.78rem;
    color: var(--color-text);
}
.species-chip.invasive {
    background: #fee2e2;
    color: #991b1b;
}

/* ── Access List ── */
.access-item {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--color-border);
}
.access-item:last-child { border-bottom: none; }
.access-type {
    font-weight: 600;
    font-size: 0.85rem;
}
.access-detail {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 0.15rem;
}

/* ── PDF Embed ── */
.pdf-embed {
    width: 100%;
    height: 500px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
}

/* ── Narrative ── */
.narrative {
    font-size: 0.88rem;
    line-height: 1.65;
    color: var(--color-text);
    padding: 0.75rem;
    background: #fafbfc;
    border-radius: var(--radius);
    border-left: 3px solid var(--color-primary);
    margin-bottom: 0.75rem;
}

/* ── Survey Accordion ── */
.survey-toggle {
    width: 100%;
    background: #f8fafb;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.65rem 0.75rem;
    text-align: left;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}
.survey-toggle:hover { background: #f1f5f9; }
.survey-toggle .arrow { transition: transform 0.2s; }
.survey-toggle.open .arrow { transform: rotate(90deg); }
.survey-body {
    display: none;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    margin-top: -0.5rem;
    margin-bottom: 0.75rem;
}
.survey-body.open { display: block; }

/* ── Chart Container ── */
.chart-container {
    position: relative;
    width: 100%;
    max-height: 300px;
    margin-bottom: 1rem;
}

/* ── Favorites Section ── */
.favorites-section {
    border: 2px solid var(--color-favorite);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    background: #fffbeb;
}
.favorites-section .card-title { color: var(--color-favorite); }

/* ── Regulation Box ── */
.reg-box {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}
.reg-species {
    font-weight: 600;
    color: #92400e;
}

/* ── Loading Spinner ── */
.spinner {
    display: inline-block;
    width: 1.2rem;
    height: 1.2rem;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--color-text-muted);
}
.empty-state p { margin-top: 0.5rem; font-size: 0.9rem; }

/* ── Crawl Banner ── */
.crawl-banner {
    background: #fef3c7;
    border: 1px solid #fbbf24;
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ── Resource Links ── */
.resource-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.5rem;
}
.resource-link {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.75rem;
    background: #f8fafb;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    color: var(--color-text);
}
.resource-link:hover { background: #f1f5f9; text-decoration: none; }
.resource-link.unavailable {
    opacity: 0.4;
    pointer-events: none;
}

/* ── Fish Compare ── */
.wide-layout .app-main { max-width: 1200px; }
.fish-hero {
    background: linear-gradient(135deg, var(--color-primary), #1e6b3a);
    color: white;
    padding: 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}
.fish-hero h2 { font-size: 1.3rem; margin-bottom: 0.15rem; }
.fish-hero p { opacity: 0.85; font-size: 0.85rem; }
.species-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.species-btn {
    padding: 0.45rem 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: 99px;
    background: var(--color-surface);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--color-text);
}
.species-btn:hover {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}
.active-species {
    display: flex;
    align-items: center;
}
.sortable-th {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.sortable-th:hover { color: var(--color-primary); }
.sortable-th::after { content: ' \2195'; font-size: 0.7em; opacity: 0.4; }
.num-cell { text-align: right; font-variant-numeric: tabular-nums; }
.top-rank td:first-child { border-left: 3px solid var(--color-primary); }
.top-rank { background: #f0fdf4; }

/* ── Mobile adjustments ── */
@media (max-width: 480px) {
    html { font-size: 14px; }
    .app-main { padding: 0.5rem; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .search-bar { flex-direction: column; }
    .search-bar input, .search-bar select { min-width: unset; }
    .profile-header h1 { font-size: 1.2rem; }
    .pdf-embed { height: 350px; }
}

/* ── Locked Nav Tabs ── */
.nav-locked {
    opacity: 0.45;
    pointer-events: auto;
    position: relative;
    padding-left: 1.35rem !important;
}
.nav-locked::before {
    content: "";
    display: inline-block;
    width: 11px;
    height: 11px;
    margin-right: 0.15rem;
    position: absolute;
    left: 0.15rem;
    top: 50%;
    transform: translateY(-50%);
    background: currentColor;
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='11' width='18' height='11' rx='2' ry='2'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E");
    -webkit-mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='11' width='18' height='11' rx='2' ry='2'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E");
    mask-size: contain;
    mask-repeat: no-repeat;
}
.nav-locked:hover {
    opacity: 0.65;
}

/* ── Upgrade / Paywall Page ── */
.upgrade-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    padding: 2rem 1rem;
}
.upgrade-card {
    background: var(--color-surface, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    max-width: 480px;
    width: 100%;
    text-align: center;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}
.upgrade-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(26, 92, 46, 0.08);
    color: var(--color-primary, #1a5c2e);
    margin-bottom: 1.25rem;
}
.upgrade-headline {
    font-size: 1.5rem;
    font-weight: 800;
    margin: 0 0 0.5rem 0;
    color: var(--color-text, #111);
    letter-spacing: -0.01em;
}
.upgrade-description {
    font-size: 0.92rem;
    color: var(--color-text-muted, #6b7280);
    margin: 0 0 1.25rem 0;
    line-height: 1.5;
}
.upgrade-tier {
    margin-bottom: 1.5rem;
}
.tier-badge {
    display: inline-block;
    padding: 0.3rem 0.9rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.tier-badge.tier-pro {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
}
.tier-badge.tier-elite {
    background: linear-gradient(135deg, #7c3aed, #5b21b6);
    color: #fff;
}
.upgrade-highlights {
    list-style: none;
    padding: 0;
    margin: 0 0 1.75rem 0;
    text-align: left;
}
.upgrade-highlights li {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.45rem 0;
    font-size: 0.88rem;
    color: var(--color-text, #374151);
    line-height: 1.4;
}
.upgrade-highlights li svg {
    flex-shrink: 0;
    margin-top: 0.15rem;
    color: var(--color-primary, #1a5c2e);
}
.upgrade-cta {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}
.upgrade-btn-back {
    display: inline-block;
    padding: 0.6rem 1.5rem;
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--color-text, #374151);
    text-decoration: none;
    transition: all 0.15s ease;
}
.upgrade-btn-back:hover {
    background: var(--color-primary, #1a5c2e);
    color: #fff;
    border-color: var(--color-primary, #1a5c2e);
}

@media (max-width: 600px) {
    .upgrade-card { padding: 1.75rem 1.25rem; }
    .upgrade-headline { font-size: 1.25rem; }
    .upgrade-icon { width: 60px; height: 60px; }
    .upgrade-icon svg { width: 36px; height: 36px; }
    .nav-locked { padding-left: 1.1rem !important; }
    .nav-locked::before { width: 9px; height: 9px; }
}

/* ── Survey Upgrade CTA (lake profile) ── */
.survey-upgrade-cta {
    border: 1px solid #e5d5a0;
    border-radius: var(--radius);
    background: linear-gradient(135deg, #fffef5 0%, #fef9e7 100%);
    padding: 1.25rem 1.5rem;
}
.survey-upgrade-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 0.5rem;
}
.survey-upgrade-header svg {
    color: #b45309;
    flex-shrink: 0;
}
.survey-upgrade-desc {
    font-size: 0.84rem;
    color: var(--color-text-muted);
    line-height: 1.55;
    margin: 0 0 0.85rem 0;
}
.survey-upgrade-features {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem 1.25rem;
    margin-bottom: 1rem;
}
.survey-upgrade-feat {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--color-text);
}
.survey-upgrade-feat svg {
    color: var(--color-primary);
    flex-shrink: 0;
}
.survey-upgrade-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.survey-upgrade-btn {
    padding: 0.5rem 1.25rem;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
}
.survey-upgrade-btn:hover { opacity: 0.9; transform: translateY(-1px); }
@media (max-width: 480px) {
    .survey-upgrade-features { grid-template-columns: 1fr; }
}

/* Locked badge on buttons */
.locked-badge {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--color-accent);
    color: #1a1a2e;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    margin-left: 0.35rem;
    vertical-align: middle;
}
.fav-btn-locked {
    opacity: 0.85;
    cursor: pointer;
}

/* Upgrade toast */
.upgrade-toast {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%) translateY(1rem);
    background: #1a1a2e;
    color: #fff;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.82rem;
    line-height: 1.45;
    box-shadow: var(--shadow-md);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    max-width: 360px;
    text-align: center;
}
.upgrade-toast.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

/* ── Plan Comparison Modal ── */
.plan-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    padding: 1rem;
}
.plan-modal-overlay.open { display: flex; }
.plan-modal {
    background: var(--color-surface);
    border-radius: 16px;
    padding: 2rem 1.5rem;
    max-width: 780px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    position: relative;
}
.plan-modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 0.25rem 0.5rem;
    line-height: 1;
}
.plan-modal-close:hover { color: var(--color-text); }
.plan-modal-title {
    text-align: center;
    font-size: 1.35rem;
    font-weight: 800;
    margin: 0 0 0.25rem 0;
    letter-spacing: -0.01em;
}
.plan-modal-subtitle {
    text-align: center;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin: 0 0 1.5rem 0;
}
.plan-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}
.plan-card {
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 1.25rem 1rem;
    text-align: center;
    position: relative;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.plan-card:hover {
    border-color: var(--color-primary);
    box-shadow: 0 2px 12px rgba(26,92,46,0.1);
}
.plan-card.plan-popular {
    border-color: var(--color-accent);
    box-shadow: 0 2px 16px rgba(232,168,56,0.15);
}
.plan-card.plan-current {
    border-color: var(--color-primary);
    background: rgba(26,92,46,0.03);
}
.plan-popular-label {
    position: absolute;
    top: -0.6rem;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.15rem 0.7rem;
    border-radius: 10px;
    white-space: nowrap;
}
.plan-current-label {
    position: absolute;
    top: -0.6rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-primary);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.15rem 0.7rem;
    border-radius: 10px;
    white-space: nowrap;
}
.plan-name {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0.5rem 0 0.15rem 0;
}
.plan-tagline {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    margin: 0 0 1rem 0;
    line-height: 1.4;
}
.plan-features {
    list-style: none;
    padding: 0;
    margin: 0;
    text-align: left;
}
.plan-features li {
    display: flex;
    align-items: flex-start;
    gap: 0.45rem;
    padding: 0.3rem 0;
    font-size: 0.8rem;
    line-height: 1.35;
}
.plan-features li.included { color: var(--color-text); }
.plan-features li.excluded { color: var(--color-text-muted); opacity: 0.5; }
.plan-features li.inherited { color: var(--color-text-muted); font-style: italic; }
.plan-check {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    margin-top: 1px;
}
.plan-check.yes { color: var(--color-primary); }
.plan-check.no { color: var(--color-border); }
.plan-modal-footer {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* Plan comparison inline (upgrade page) */
.plan-compare-inline {
    margin-top: 2rem;
}
.plan-compare-inline .plan-grid {
    max-width: 780px;
    margin: 0 auto;
}

/* Upgrade CTA with "Compare Plans" link */
.upgrade-cta-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 1rem;
    flex-wrap: wrap;
}
.compare-plans-link {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-primary);
    cursor: pointer;
    background: none;
    border: none;
    text-decoration: underline;
    padding: 0.4rem 0;
}
.compare-plans-link:hover { color: var(--color-primary-light); }

/* Plan upgrade buttons */
.plan-upgrade-btn {
    display: block;
    width: 100%;
    margin-top: 1rem;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 8px;
    background: var(--color-primary);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
}
.plan-upgrade-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.plan-upgrade-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.plan-card.plan-popular .plan-upgrade-btn {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}
.plan-free-label {
    margin-top: 1rem;
    font-size: 0.78rem;
    color: var(--color-text-muted);
    font-style: italic;
}

/* Upgrade page checkout button */
.upgrade-checkout-btn {
    display: inline-block;
    padding: 0.75rem 2rem;
    border: none;
    border-radius: 10px;
    background: var(--color-primary);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s, box-shadow 0.15s;
    box-shadow: 0 4px 12px rgba(26,92,46,0.2);
}
.upgrade-checkout-btn:hover {
    opacity: 0.92;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(26,92,46,0.3);
}

@media (max-width: 600px) {
    .plan-grid { grid-template-columns: 1fr; gap: 0.75rem; }
    .plan-modal { padding: 1.5rem 1rem; }
    .plan-modal-title { font-size: 1.15rem; }
}

/* ── Print / Export ── */
@media print {
    .app-header, .app-footer, .fav-btn, .profile-actions,
    .search-bar, .pagination, .btn { display: none !important; }
    .app-main { max-width: 100%; padding: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
    .pdf-embed { height: 700px; }
}
