/* === Variables === */
:root {
    --sidebar-width: 260px;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #3b82f6;
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --bg-light: #f1f5f9;
    --text-dark: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --card-shadow: 0 1px 3px rgba(0,0,0,.1);
    --panel-bg: #ffffff;
    --panel-soft: #f8fafc;
}

/* === Login Page === */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 1rem;
}

.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 2.5rem;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-icon {
    font-size: 2.5rem;
    color: var(--primary);
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-dark);
    margin: .5rem 0 .25rem;
}

/* === Sidebar === */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow-y: auto;
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    font-size: 1.2rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: .75rem;
    border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-header i {
    font-size: 1.4rem;
    color: var(--primary);
}

.sidebar-nav {
    list-style: none;
    padding: .5rem 0;
    margin: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.sidebar-nav li.mt-auto {
    margin-top: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1.5rem;
    color: #cbd5e1;
    text-decoration: none;
    transition: background .2s, color .2s;
    font-size: .9rem;
}

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-link.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
}

.sidebar-link i {
    font-size: 1.1rem;
    width: 1.25rem;
    text-align: center;
}

/* === Main Content === */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    background: var(--bg-light);
    padding: 2rem;
}

.content-header {
    margin-bottom: 1.5rem;
}

.content-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: .5rem;
}

/* === Pages === */
.page-content {
    display: none;
}

.page-content.active {
    display: block;
}

/* === Cards === */
.card {
    border: none;
    border-radius: 8px;
    box-shadow: var(--card-shadow);
}

/* === Results === */
.ad-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    transition: box-shadow .2s;
}

.ad-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,.1);
}

.ad-card .ad-label {
    display: inline-block;
    background: #fef3c7;
    color: #92400e;
    font-size: .7rem;
    font-weight: 700;
    padding: .15rem .5rem;
    border-radius: 4px;
    text-transform: uppercase;
    margin-bottom: .5rem;
}

.ad-card .ad-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-dark);
    margin-bottom: .35rem;
}

.ad-card .ad-description {
    color: var(--text-dark);
    font-size: .9rem;
    margin-bottom: .35rem;
    line-height: 1.5;
}

.ad-card .ad-url {
    color: #16a34a;
    font-size: .85rem;
    word-break: break-all;
}

.results-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: .75rem;
    margin-bottom: 1rem;
}

.summary-tile {
    background: linear-gradient(180deg, #fff 0%, #fbfdff 100%);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1rem 1rem .9rem;
    box-shadow: var(--card-shadow);
    position: relative;
    overflow: hidden;
}

.summary-tile::before {
    content: "";
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), #0ea5e9);
}

.summary-tile .summary-label {
    font-size: .72rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
    letter-spacing: .04em;
}

.summary-tile .summary-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-top: .25rem;
    line-height: 1.15;
}

.summary-tile .summary-note {
    font-size: .8rem;
    color: var(--text-muted);
    margin-top: .25rem;
}

.payload-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1rem;
    box-shadow: var(--card-shadow);
}

.payload-panel-title {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: .75rem;
}

.payload-json {
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    font-size: .8rem;
    line-height: 1.45;
    max-height: 60vh;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.payload-item-kv {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: .5rem .75rem;
    align-items: start;
    font-size: .9rem;
}

.payload-item-kv .k {
    color: var(--text-muted);
    font-weight: 600;
}

.payload-item-kv .v {
    color: var(--text-dark);
    word-break: break-word;
}

.payload-section {
    margin-top: 1rem;
}

.payload-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.payload-chip {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .35rem .65rem;
    border-radius: 999px;
    background: var(--panel-soft);
    border: 1px solid var(--border-color);
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-dark);
}

.payload-chip-info {
    background: #e0f2fe;
    border-color: #bae6fd;
    color: #075985;
}

.payload-chip-commercial {
    background: #fef3c7;
    border-color: #fde68a;
    color: #92400e;
}

.payload-chip-transactional {
    background: #dcfce7;
    border-color: #bbf7d0;
    color: #166534;
}

.payload-chip-navigational {
    background: #e5e7eb;
    border-color: #d1d5db;
    color: #374151;
}

.btn-payload {
    white-space: nowrap;
}

.ad-links {
    margin-top: .75rem;
    padding-top: .75rem;
    border-top: 1px dashed var(--border-color);
}

.ad-link-item {
    padding: .5rem 0 .5rem 1rem;
    border-left: 3px solid var(--border-color);
    margin-bottom: .5rem;
}

.ad-link-item .link-label {
    font-size: .7rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: .25rem;
}

.ad-link-item .link-title {
    font-weight: 600;
    font-size: .95rem;
    color: var(--primary-dark);
}

.ad-link-item .link-description {
    font-size: .85rem;
    color: var(--text-dark);
}

.ad-link-item .link-url {
    font-size: .8rem;
    color: #16a34a;
    word-break: break-all;
}

.ad-results-table th {
    font-size: .8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
    background: #fff;
}

.ad-results-table td {
    vertical-align: middle;
    font-size: .9rem;
    background: #fff;
}

.ad-links-row td {
    background: #f8fafc;
    border-top: 0;
}

.ad-links-inline {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    padding: .25rem 0 .5rem;
}

.ad-sitelink-pill {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem;
    border: 1px solid var(--border-color);
    background: #fff;
    border-radius: 999px;
    padding: .35rem .7rem;
    font-size: .8rem;
}

.ad-sitelink-pill a {
    color: var(--primary-dark);
    text-decoration: none;
}

.ad-sitelink-pill a:hover {
    text-decoration: underline;
}

/* === No Results === */
.no-results {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.no-results i {
    font-size: 3rem;
    margin-bottom: 1rem;
    display: block;
}

/* === History Table === */
#history-table th {
    font-size: .8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

#history-table td {
    vertical-align: middle;
    font-size: .9rem;
}

/* === Select2 Overrides === */
.select2-container--bootstrap-5 .select2-selection {
    min-height: 38px;
}

/* === Loading Overlay === */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-overlay .spinner-wrapper {
    background: #fff;
    padding: 2rem 3rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,.3);
}

.loading-overlay .spinner-border {
    width: 2.5rem;
    height: 2.5rem;
    color: var(--primary);
}

.loading-overlay p {
    margin-top: 1rem;
    font-weight: 600;
    color: var(--text-dark);
}

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .3s;
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
}

/* === Buttons === */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

/* === Pagination === */
.pagination .page-link {
    color: var(--primary);
}

.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
}

/* === Keyword Results Tables === */
.kw-results-table th {
    font-size: .8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
    background: #fff;
}

.kw-results-table td {
    vertical-align: middle;
    font-size: .9rem;
    background: #fff;
}

.competition-high {
    color: #dc2626;
    font-weight: 600;
}

.competition-medium {
    color: #ea580c;
    font-weight: 600;
}

.competition-low {
    color: #16a34a;
    font-weight: 600;
}

/* === Monthly Searches Table === */
#kw4kw-monthly-area .table {
    margin-bottom: 0;
}

#kw4kw-monthly-area .table th {
    font-size: .8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
}

#kw4kw-monthly-area .table td {
    font-size: .85rem;
}

/* === Type Badges in History === */
.badge-type {
    font-size: .75rem;
    font-weight: 500;
    padding: .3em .6em;
}

/* === Competitors Domain Table === */
.comp-results-table th {
    font-size: .8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
    background: #fff;
}

.comp-results-table td {
    vertical-align: middle;
    font-size: .9rem;
    background: #fff;
}

.comp-domain-cell a {
    color: var(--primary-dark);
    text-decoration: none;
    font-weight: 600;
}

.comp-domain-cell a:hover {
    text-decoration: underline;
}

.comp-copy-btn {
    color: var(--text-muted);
    font-size: .75rem;
}

.comp-copy-btn:hover {
    color: var(--primary);
}

.comp-movement .badge {
    font-size: .7rem;
    font-weight: 500;
}

.comp-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: .75rem;
    margin-bottom: 1rem;
}

.payload-modal-content .modal-header {
    border-bottom: 1px solid var(--border-color);
}

.payload-modal-content .modal-footer {
    border-top: 1px solid var(--border-color);
}

/* === Domain Intersection Tables === */
.di-results-table th {
    font-size: .8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
    background: #fff;
}

.di-results-table td {
    vertical-align: middle;
    font-size: .9rem;
    background: #fff;
}

.di-expandable:hover {
    background-color: #f0f4ff;
}

.detail-row {
    background-color: #f8f9ff !important;
}

.detail-row:hover {
    background-color: #f8f9ff !important;
}

.detail-row .card.detail-card {
    border: 1px solid var(--border-color);
    box-shadow: none;
}

.detail-row .card-header {
    background: #f1f5f9;
    font-size: .85rem;
}

.winner-me {
    color: #16a34a;
    font-size: 1.1rem;
}

.winner-them {
    color: #dc2626;
    font-size: 1.1rem;
}

.winner-tie {
    color: #eab308;
    font-size: 1.1rem;
}

.sitelink-list {
    margin-top: .5rem;
    padding-top: .5rem;
    border-top: 1px dashed var(--border-color);
}

.sitelink-list ul {
    list-style: none;
    padding-left: 0;
}

.sitelink-list li {
    padding: .15rem 0;
    font-size: .8rem;
}

/* === Trends Chart === */
.trends-chart-container {
    position: relative;
    height: 400px;
    width: 100%;
}
