/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Design Tokens */
:root {
    --button-outline: rgba(0,0,0, .10);
    --badge-outline: rgba(0,0,0, .05);
    --opaque-button-border-intensity: -8;
    --elevate-1: rgba(0,0,0, .03);
    --elevate-2: rgba(0,0,0, .08);
    
    --background: 0 0% 98%;
    --foreground: 217 32% 17%;
    --border: 220 13% 91%;
    --card: 0 0% 100%;
    --card-foreground: 217 32% 17%;
    --card-border: 220 13% 88%;
    --primary: 217 91% 60%;
    --primary-foreground: 0 0% 98%;
    --secondary: 220 13% 93%;
    --secondary-foreground: 217 32% 17%;
    --muted: 220 9% 96%;
    --muted-foreground: 220 9% 46%;
    --accent: 220 13% 94%;
    --accent-foreground: 217 32% 17%;
    --destructive: 0 84% 60%;
    --destructive-foreground: 0 0% 98%;
    --chart-1: 217 91% 60%;
    --chart-2: 142 76% 36%;
    --chart-3: 38 92% 50%;
    --chart-4: 0 84% 60%;
    --chart-5: 262 83% 58%;
    
    --font-sans: Inter, sans-serif;
    --radius: 0.5rem;
    --shadow-sm: 0px 1px 2px 0px rgba(0, 0, 0, 0.05), 0px 1px 3px 0px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0px 10px 15px -3px rgba(0, 0, 0, 0.1), 0px 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.dark {
    --button-outline: rgba(255,255,255, .10);
    --badge-outline: rgba(255,255,255, .05);
    --opaque-button-border-intensity: 9;
    --elevate-1: rgba(255,255,255, .04);
    --elevate-2: rgba(255,255,255, .09);
    
    --background: 220 13% 9%;
    --foreground: 220 9% 88%;
    --border: 220 13% 15%;
    --card: 220 13% 11%;
    --card-foreground: 220 9% 88%;
    --card-border: 220 13% 16%;
    --primary: 217 91% 60%;
    --primary-foreground: 220 13% 9%;
    --secondary: 220 13% 16%;
    --secondary-foreground: 220 9% 88%;
    --muted: 220 13% 13%;
    --muted-foreground: 220 9% 60%;
    --accent: 220 13% 14%;
    --accent-foreground: 220 9% 88%;
    --destructive: 0 84% 60%;
    --destructive-foreground: 220 13% 9%;
    --chart-1: 217 91% 75%;
    --chart-2: 142 76% 55%;
    --chart-3: 38 92% 65%;
    --chart-4: 0 84% 75%;
    --chart-5: 262 83% 73%;
}

/* Base Typography */
body {
    font-family: var(--font-sans);
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
    padding-bottom: 6rem; /* Space for fixed CTA button */
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (min-width: 1024px) {
    .grid-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Header */
.header {
    margin-bottom: 2rem;
}

.page-title {
    font-size: 1.875rem;
    font-weight: bold;
    color: hsl(var(--foreground));
    margin-bottom: 0.5rem;
}

.page-subtitle {
    color: hsl(var(--muted-foreground));
}

/* Card Component */
.card {
    background-color: hsl(var(--card));
    border: 1px solid hsl(var(--card-border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: 1.5rem 1.5rem 0;
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: hsl(var(--card-foreground));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.card-content {
    padding: 1.5rem;
}

/* Badge Component */
.badge {
    display: inline-flex;
    align-items: center;
    border-radius: calc(var(--radius) * 0.5);
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.badge.secondary {
    background-color: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
}

.badge.critical {
    background-color: hsl(var(--chart-4) / 0.1);
    color: hsl(var(--chart-4));
    border-color: hsl(var(--chart-4) / 0.2);
}

.badge.warning {
    background-color: hsl(var(--chart-3) / 0.1);
    color: hsl(var(--chart-3));
    border-color: hsl(var(--chart-3) / 0.2);
}

.badge.info {
    background-color: hsl(var(--chart-1) / 0.1);
    color: hsl(var(--chart-1));
    border-color: hsl(var(--chart-1) / 0.2);
}

.badge.authority-high {
    background-color: hsl(var(--chart-2) / 0.1);
    color: hsl(var(--chart-2));
    border-color: hsl(var(--chart-2) / 0.2);
}

.badge.authority-medium {
    background-color: hsl(var(--chart-3) / 0.1);
    color: hsl(var(--chart-3));
    border-color: hsl(var(--chart-3) / 0.2);
}

/* Button Component */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid transparent;
    padding: 0.5rem 1rem;
    min-height: 2.25rem;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    text-decoration: none;
    gap: 0.5rem;
}

.btn:disabled {
    pointer-events: none;
    opacity: 0.5;
}

.btn.btn-outline {
    border-color: hsl(var(--border));
    background-color: transparent;
    color: hsl(var(--foreground));
}

.btn.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    min-height: 2.75rem;
}

/* Progress Bar Component */
.progress-bar {
    width: 100%;
    height: 0.5rem;
    background-color: hsl(var(--secondary));
    border-radius: var(--radius);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: hsl(var(--primary));
    transition: width 0.3s ease-in-out;
}

.progress-fill.high {
    background-color: hsl(var(--chart-2));
}

.progress-fill.medium {
    background-color: hsl(var(--chart-3));
}

.progress-fill.low {
    background-color: hsl(var(--chart-4));
}

/* Keyword Rankings Styles */
.rankings-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.ranking-item {
    text-align: center;
    padding: 1rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    cursor: pointer;
}

.ranking-count {
    font-size: 1.5rem;
    font-weight: bold;
    color: hsl(var(--foreground));
    margin-bottom: 0.25rem;
}

.ranking-label {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    margin-bottom: 0.5rem;
}

.ranking-change {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    font-size: 0.75rem;
}

.ranking-change.positive {
    color: hsl(var(--chart-2));
}

.ranking-change.negative {
    color: hsl(var(--chart-4));
}

.trend-icon {
    width: 1rem;
    height: 1rem;
}

/* Traffic Metrics Styles */
.traffic-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.traffic-stat {
    text-align: left;
}

.stat-label {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.875rem;
    font-weight: bold;
}

.stat-value.current {
    color: hsl(var(--foreground));
}

.stat-value.potential {
    color: hsl(var(--chart-2));
}

.traffic-increase {
    space-y: 0.75rem;
}

.increase-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.increase-label {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

.increase-value {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: hsl(var(--chart-2));
}

/* Health Score Styles */
.health-score {
    text-align: center;
    margin-bottom: 1.5rem;
}

.gauge-container {
    position: relative;
    display: inline-block;
    width: 256px;
    height: 144px;
    margin: 0 auto;
}

.gauge-meter {
    width: 100%;
    height: 100%;
}

.gauge-progress {
    transition: stroke-dashoffset 1.5s ease-in-out;
    animation: gaugeAnimation 2s ease-out;
}

.gauge-label {
    font-size: 10px;
    fill: hsl(var(--muted-foreground));
    font-family: var(--font-sans);
}

.gauge-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -20%);
    text-align: center;
}

.score-display {
    font-size: 3rem;
    font-weight: bold;
    color: hsl(var(--chart-3));
    margin-bottom: 0.25rem;
    line-height: 1;
}

.score-label {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
}

@keyframes gaugeAnimation {
    0% {
        stroke-dashoffset: 267.1;
    }
    100% {
        stroke-dashoffset: 66.8;
    }
}

.health-breakdown {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.breakdown-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.breakdown-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
}

.breakdown-value {
    font-weight: 500;
}

/* Issues Styles */
.issues-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.issue-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    cursor: pointer;
}

.issue-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.125rem;
}

.issue-icon.critical {
    color: hsl(var(--chart-4));
}

.issue-icon.warning {
    color: hsl(var(--chart-3));
}

.issue-icon.info {
    color: hsl(var(--chart-1));
}

.issue-content {
    flex: 1;
    min-width: 0;
}

.issue-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.issue-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
}

.issue-description {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.external-link {
    color: hsl(var(--muted-foreground));
    flex-shrink: 0;
}

/* Backlink Styles */
.backlink-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.backlink-stat .stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: hsl(var(--foreground));
    margin-bottom: 0.25rem;
}

.backlink-stat .stat-value.authority {
    color: hsl(var(--chart-3));
}

.backlink-stat .stat-label {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

.quality-distribution,
.recent-backlinks {
    margin-bottom: 1.5rem;
}

.section-subtitle {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
}

.quality-breakdown {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.quality-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.quality-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
}

.quality-label.high {
    color: hsl(var(--chart-2));
}

.quality-label.medium {
    color: hsl(var(--chart-3));
}

.quality-label.low {
    color: hsl(var(--chart-4));
}

.quality-value {
    font-weight: 500;
}

.backlinks-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.backlink-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    cursor: pointer;
}

.backlink-content {
    flex: 1;
    min-width: 0;
}

.backlink-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.backlink-domain {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.backlink-anchor {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.backlink-date {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
}

/* Recommendations Styles */
.recommendations-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.recommendation-item {
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    overflow: hidden;
}

.recommendation-toggle {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    color: inherit;
    font: inherit;
}

.chevron {
    margin-top: 0.25rem;
    transition: transform 0.2s ease-in-out;
}

.recommendation-toggle[aria-expanded="true"] .chevron {
    transform: rotate(90deg);
}

.recommendation-header {
    flex: 1;
    min-width: 0;
}

.recommendation-title-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.recommendation-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
}

.recommendation-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.recommendation-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out;
}

.recommendation-content.open {
    max-height: 500px;
}

.recommendation-description {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    padding: 0 0.75rem 0.75rem 2.5rem;
}

.recommendation-steps {
    padding: 0 0.75rem 0.75rem 2.5rem;
}

.steps-title {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.steps-list {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    padding-left: 1rem;
    margin-bottom: 0.5rem;
}

.steps-list li {
    margin-bottom: 0.25rem;
}

.recommendation-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 0.5rem;
}

.estimated-time {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

/* Fixed CTA Button */
.fixed-cta {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 50;
}

.fixed-cta .btn {
    box-shadow: var(--shadow-lg);
    transition: box-shadow 0.3s ease-in-out;
}

.fixed-cta .btn:hover {
    box-shadow: 0px 20px 25px -5px rgba(0, 0, 0, 0.15), 0px 10px 10px -5px rgba(0, 0, 0, 0.08);
}

.sparkles-icon,
.arrow-icon {
    width: 1.25rem;
    height: 1.25rem;
}

/* Elevation Utilities */
.hover-elevate {
    position: relative;
    z-index: 0;
    transition: all 0.2s ease-in-out;
}

.hover-elevate::after {
    content: "";
    pointer-events: none;
    position: absolute;
    inset: 0;
    border-radius: inherit;
    z-index: 1;
    background-color: transparent;
    transition: background-color 0.2s ease-in-out;
}

.hover-elevate:hover::after {
    background-color: var(--elevate-1);
}

.active-elevate-2 {
    position: relative;
    z-index: 0;
}

.active-elevate-2::after {
    content: "";
    pointer-events: none;
    position: absolute;
    inset: 0;
    border-radius: inherit;
    z-index: 1;
    background-color: transparent;
    transition: background-color 0.2s ease-in-out;
}

.active-elevate-2:active::after {
    background-color: var(--elevate-2);
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1rem 0.75rem;
        padding-bottom: 5rem;
    }
    
    .page-title {
        font-size: 1.5rem;
    }
    
    .rankings-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .traffic-stats {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .backlink-stats {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        text-align: left;
    }
    
    .recommendation-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .fixed-cta {
        bottom: 1rem;
        right: 1rem;
        left: 1rem;
    }
    
    .fixed-cta .btn {
        width: 100%;
        justify-content: center;
    }
}