:root {
    --bg-page: #f8fafc;
    --bg-surface: #ffffff;
    --bg-muted: #f1f5f9;
    --bg-hover: #e2e8f0;
    --border-color: #e2e8f0;
    --border-strong: #cbd5e1;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --accent: #00ACA1;
    --accent-hover: #008F86;
    --accent-text: #007A72;
    --accent-soft: #E6F7F6;
    --accent-border: #99E0DB;
    --accent-ring: rgba(0, 172, 161, 0.18);
    --radius-sm: 6px;
    --radius-md: 10px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.12), 0 4px 10px -3px rgba(15, 23, 42, 0.06);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-page);
    -webkit-font-smoothing: antialiased;
}

main {
    max-width: 95dvw;
    margin: 0 auto;
    padding: 24px 20px 64px;
}

/* Page Header */
#pr-tool-container > header {
    margin-bottom: 18px;
}

#pr-tool-container > header h1 {
    margin: 0 0 6px;
    font-size: clamp(1.5rem, 2.5vw, 2rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

#pr-tool-container > header p {
    margin: 0;
    color: var(--text-secondary);
}

/* Notched-Label Pill Filter Bar */
.filters {
    margin-bottom: 18px;
    padding-top: 8px;
}

.filters-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
}

.filter-group {
    position: relative;
    display: inline-flex;
}

.filter-notched-label {
    position: absolute;
    top: -7px;
    left: 12px;
    z-index: 2;
    padding: 0 5px;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    line-height: 1.3;
    color: #334155;
    background-color: var(--bg-surface);
    border-radius: 4px;
    pointer-events: none;
}

.dropdown-trigger {
    height: 44px;
    padding: 2px 14px 0 16px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 400;
    color: var(--text-secondary);
    background-color: var(--bg-surface);
    border: 1.5px solid var(--accent);
    border-radius: 14px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    white-space: nowrap;
    transition: border-color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

.dropdown-trigger:hover {
    background-color: var(--bg-page);
    border-color: var(--accent-hover);
    box-shadow: 0 3px 8px rgba(0, 172, 161, 0.12);
}

.custom-dropdown.has-selection .dropdown-trigger {
    color: var(--text-primary);
    font-weight: 500;
}

.custom-dropdown.is-open .dropdown-trigger,
.dropdown-trigger:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring), 0 2px 6px rgba(15, 23, 42, 0.06);
}

.trigger-text {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.trigger-chevron {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    color: #334155;
    transition: transform 160ms ease;
}

.custom-dropdown.is-open .trigger-chevron {
    transform: rotate(180deg);
}

/* Dropdown Popover Menu */
.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 280px;
    width: max-content;
    max-width: min(380px, 92vw);
    padding: 12px 14px 14px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    z-index: 50;
}

.custom-dropdown.is-open .dropdown-menu {
    display: block;
}

.dropdown-search-wrap {
    margin-bottom: 8px;
}

.dropdown-search {
    width: 100%;
    height: 34px;
    padding: 0 11px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    background-color: var(--bg-page);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    outline: none;
}

.dropdown-search:focus {
    border-color: var(--accent);
    background-color: var(--bg-surface);
}

.dropdown-options {
    max-height: 250px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-right: 2px;
}

.dropdown-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    font-size: 14px;
    font-weight: 400;
    color: #334155;
    text-decoration: none;
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
    transition: background-color 100ms ease, color 100ms ease;
}

.dropdown-item:hover {
    background-color: var(--bg-muted);
    color: var(--text-primary);
}

.dropdown-item.is-selected {
    background-color: var(--accent-soft);
    color: var(--accent-text);
    font-weight: 600;
}

.dropdown-item.is-hidden {
    display: none;
}

.dropdown-item-text {
    line-height: 1.35;
}

.dropdown-footer {
    margin-top: 10px;
    padding-top: 4px;
}

.dropdown-apply-btn {
    width: 100%;
    height: 40px;
    padding: 0 18px;
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 600;
    color: #ffffff;
    background-color: var(--accent);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color 120ms ease, transform 80ms ease;
}

.dropdown-apply-btn:hover {
    background-color: var(--accent-hover);
}

.dropdown-apply-btn:active {
    transform: scale(0.99);
}

/* Reset Button */
.filter-actions {
    display: flex;
    align-items: center;
}

.filter-reset-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    padding: 0 16px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-secondary);
    background-color: var(--bg-surface);
    border: 1.5px solid var(--border-strong);
    border-radius: 14px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
    text-decoration: none;
    white-space: nowrap;
    transition: border-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

.filter-reset-btn:hover {
    border-color: var(--accent);
    color: var(--accent-text);
}

/* Upgrade / Paywall Teaser Banner */
.upgrade-banner {
    margin: 0 0 16px;
    padding: 13px 18px;
    background: var(--accent-soft);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.upgrade-banner p {
    margin: 0;
    font-size: 14px;
    color: var(--text-primary);
}

.upgrade-btn {
    display: inline-flex;
    align-items: center;
    margin-left: 4px;
    padding: 4px 12px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: #ffffff;
    background-color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    cursor: pointer;
    vertical-align: baseline;
    transition: background-color 120ms ease, border-color 120ms ease;
}

.upgrade-btn:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
}

/* Data Table & Channel Avatars */
.table-wrapper {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    transition: opacity 150ms ease;
}

#pr-tool-container.htmx-request .table-wrapper {
    opacity: 0.55;
    pointer-events: none;
}

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

caption {
    caption-side: top;
    text-align: left;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
}

thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-muted);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
}

thead th a {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

thead th a:hover,
thead th[aria-sort="ascending"] a,
thead th[aria-sort="descending"] a {
    color: var(--accent-text);
}

thead th[aria-sort="ascending"] a,
thead th[aria-sort="descending"] a {
    font-weight: 700;
}

tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 100ms ease;
}

tbody tr:last-child {
    border-bottom: none;
}

tbody tr:hover {
    background-color: var(--bg-page);
}

tbody td {
    padding: 12px 14px;
    color: var(--text-primary);
    vertical-align: middle;
    white-space: nowrap;
}

tbody td:first-child,
thead th:first-child {
    color: var(--text-muted);
    width: 44px;
    text-align: center;
}

tbody td:nth-child(2) {
    max-width: 300px;
}

.channel-link {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    max-width: 100%;
    color: var(--text-primary);
    text-decoration: none;
}

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

.channel-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background-color: var(--bg-muted);
    border: 1px solid var(--border-color);
}

.channel-avatar-fallback {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-text);
    background-color: var(--accent-soft);
    border: 1px solid var(--accent-border);
}

.channel-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

tbody td:nth-child(3) {
    color: var(--text-muted);
    font-size: 13px;
}

thead th:nth-child(n+6),
tbody td:nth-child(n+6) {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* AEO Key Takeaways & Q&A Section */
.aeo-insights {
    margin-top: 28px;
    display: grid;
    gap: 16px;
}

.aeo-summary-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    box-shadow: var(--shadow-sm);
}

.aeo-summary-card h2 {
    margin: 0 0 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.aeo-summary-card p {
    margin: 0;
    font-size: 14.5px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.aeo-faq-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 14px;
}

.aeo-faq-item {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
}

.aeo-faq-item summary {
    list-style: none;
    cursor: pointer;
}

.aeo-faq-item summary::-webkit-details-marker {
    display: none;
}

.aeo-faq-item h3 {
    margin: 0 0 6px;
    font-size: 14.5px;
    font-weight: 700;
    color: var(--accent-text);
}

.aeo-faq-item p {
    margin: 0;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--text-secondary);
}

/* Responsive Breakpoints */
@media (max-width: 768px) {
    main {
        padding: 16px 12px 48px;
    }

    .dropdown-menu {
        min-width: 250px;
        max-width: 90vw;
    }

    thead th:nth-child(2),
    tbody td:nth-child(2) {
        position: sticky;
        left: 0;
        z-index: 1;
        background: inherit;
        box-shadow: 2px 0 4px rgba(15, 23, 42, 0.04);
    }

    thead th:nth-child(2) {
        background: var(--bg-muted);
        z-index: 3;
    }

    tbody td:nth-child(2) {
        background: var(--bg-surface);
    }

    tbody tr:hover td:nth-child(2) {
        background: var(--bg-page);
    }
}