:root {
    --bg-primary: #f8f9fa;
    --bg-card: #ffffff;
    --bg-header: #1a1a2e;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-on-dark: #ffffff;
    --color-canyon: #4C72B0;
    --color-tophat: #DD8452;
    --positive: #28a745;
    --negative: #dc3545;
    --gap: 16px;
    --radius: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

.dashboard-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--gap);
}

.dashboard-header {
    background: white;
    color: var(--text-primary);
    padding: 24px 28px;
    border-radius: var(--radius);
    margin-bottom: var(--gap);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

.site-logo {
    height: 60px;
    width: auto;
}

.powered-by {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: opacity 0.2s;
}

.powered-by:hover {
    opacity: 0.7;
}

.lunia-logo {
    height: 24px;
    width: auto;
    opacity: 0.9;
}

.dashboard-header h1 {
    font-size: 26px;
    font-weight: 600;
    margin-bottom: 4px;
}

.dashboard-header p {
    font-size: 14px;
    color: var(--text-secondary);
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 16px;
}

.last-update {
    font-size: 13px;
    color: var(--text-secondary);
}

.refresh-btn {
    background: var(--bg-header);
    border: 1px solid var(--bg-header);
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.refresh-btn:hover {
    background: #0f0f1c;
    border-color: #0f0f1c;
}

.refresh-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.site-selector {
    background: var(--bg-card);
    padding: 16px 20px;
    border-radius: var(--radius);
    margin-bottom: var(--gap);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.site-selector label {
    font-size: 13px;
    font-weight: 600;
    margin-right: 12px;
    color: var(--text-secondary);
}

.site-selector select {
    padding: 8px 12px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    background: white;
}

.date-range-selector {
    background: var(--bg-card);
    padding: 16px 20px;
    border-radius: var(--radius);
    margin-bottom: var(--gap);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    gap: 16px;
}

.date-range-selector label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.date-range-buttons {
    display: flex;
    gap: 8px;
}

.range-btn {
    padding: 8px 16px;
    border: 1px solid #dee2e6;
    background: white;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
}

.range-btn:hover {
    background: #f8f9fa;
    border-color: #adb5bd;
}

.range-btn.active {
    background: var(--bg-header);
    color: white;
    border-color: var(--bg-header);
}

.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--gap);
    margin-bottom: var(--gap);
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.kpi-label {
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    font-weight: 600;
}

.kpi-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    line-height: 1;
}

.kpi-change {
    font-size: 13px;
    font-weight: 500;
}

.kpi-change.positive {
    color: var(--positive);
}

.kpi-change.negative {
    color: var(--negative);
}

.chart-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: var(--gap);
    margin-bottom: var(--gap);
}

.chart-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.chart-container.chart-large {
    grid-column: 1 / -1;
}

.chart-container h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.chart-container canvas {
    /* Do NOT force height directly on canvas — it breaks Chart.js hit detection.
       Height is controlled by the .chart-canvas-wrap div below instead. */
    display: block;
    width: 100% !important;
}

/* Wrapper div that gives each chart its height — Chart.js fills this via maintainAspectRatio:false */
.chart-canvas-wrap {
    position: relative;
    height: 280px;
}

.keywords-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    margin-bottom: var(--gap);
}

.keywords-header {
    margin-bottom: 16px;
}

.keywords-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.keywords-count {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 14px;
}

.keywords-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.keyword-search-input {
    padding: 8px 14px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 14px;
    width: 220px;
    outline: none;
    transition: border-color 0.2s;
}

.keyword-search-input:focus {
    border-color: #4C72B0;
}

.keyword-type-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.type-filter-btn {
    padding: 6px 12px;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    background: white;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--text-secondary);
}

.type-filter-btn:hover {
    background: #f0f0f0;
}

.type-filter-btn.active {
    background: #212529;
    color: white;
    border-color: #212529;
}

.table-container {
    overflow-x: auto;
}

.keywords-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.keywords-table thead th {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid #dee2e6;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.keywords-table thead th.sortable {
    cursor: pointer;
    user-select: none;
}

.keywords-table thead th.sortable:hover {
    color: var(--text-primary);
}

.keywords-table tbody td {
    padding: 9px 12px;
    border-bottom: 1px solid #f0f0f0;
}

.keywords-table tbody tr:hover {
    background: #f8f9fa;
}

.keywords-table tbody tr:last-child td {
    border-bottom: none;
}

.type-badge {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.position-badge {
    padding: 3px 8px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 12px;
    white-space: nowrap;
}

.position-badge.pos-top3 {
    background: #d4edda;
    color: #155724;
}

.position-badge.pos-top10 {
    background: #d1ecf1;
    color: #0c5460;
}

.position-badge.pos-lower {
    background: #e9ecef;
    color: var(--text-primary);
}

.change-cell {
    white-space: nowrap;
    font-size: 12px;
}

.impressions-cell {
    white-space: nowrap;
    font-size: 12px;
    color: var(--text-secondary);
    text-align: right;
}

.source-live {
    color: #28a745;
    font-size: 11px;
    font-weight: 600;
}

.source-pdf {
    color: #6c757d;
    font-size: 11px;
}

.url-code {
    background: #f8f9fa;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: var(--text-secondary);
    max-width: 200px;
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

/* Pagination */
.keywords-pagination {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.page-btn {
    padding: 6px 12px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: white;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.page-btn:hover {
    background: #f0f0f0;
}

.page-btn.active {
    background: #4C72B0;
    color: white;
    border-color: #4C72B0;
}

.page-info {
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: 6px;
}

/* Keywords / Opportunities tab bar */
.kw-tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #e9ecef;
    margin-bottom: 20px;
}

.kw-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.15s, border-color 0.15s;
}

.kw-tab:hover {
    color: var(--text-primary);
}

.kw-tab.active {
    color: #4C72B0;
    border-bottom-color: #4C72B0;
    font-weight: 600;
}

/* Opportunities info bar */
.opportunities-info {
    background: #f0f4ff;
    border: 1px solid #d1e0ff;
    border-radius: 6px;
    padding: 10px 16px;
    font-size: 13px;
    color: #2c4a8c;
    margin-bottom: 14px;
    line-height: 1.5;
}

/* Score badge */
.score-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.score-high { background: #d4edda; color: #155724; }
.score-med  { background: #fff3cd; color: #856404; }
.score-low  { background: #e9ecef; color: #495057; }

.dashboard-footer {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
    font-size: 12px;
}

@media (max-width: 768px) {
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-meta {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
    }

    .kpi-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .chart-row {
        grid-template-columns: 1fr;
    }

    .chart-container.chart-large {
        grid-column: 1;
    }
}

@media print {
    body {
        background: white;
    }

    .dashboard-container {
        max-width: none;
    }

    .refresh-btn,
    .site-selector {
        display: none;
    }

    .chart-container {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #dee2e6;
    }
}

/* Traffic chart header + summary panel */
.traffic-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}
.traffic-header h3 { margin: 0; }
.traffic-summary {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    align-items: flex-start;
}
.traffic-stat {
    font-size: 0.82em;
    line-height: 1.4;
}
.traffic-stat-label {
    display: block;
    color: #999;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.85em;
}
.traffic-stat-value {
    color: #333;
}
.traffic-stat-pdf .traffic-stat-value {
    color: #888;
}
