/*
 * Profit Labs Customer Portal — combined stylesheet.
 * Mirrors profit-labs-seo/assets/portal/portal.css + rankings.css from
 * the WordPress plugin (which we're porting from). View-only fork:
 * no Add/Delete/Recheck UI, no project settings, no Present Mode, no
 * agency-internal cost / billing data, no debug overlays.
 */

* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0; min-height: 100%;
    background: #f4f6f9;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: #1d2327;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
a { color: #2271b1; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header chrome ────────────────────────────────────────────────────── */

.xpr-portal-header {
    display: flex; align-items: center; gap: 20px;
    padding: 12px 28px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 1px 0 rgba(0,0,0,.02);
    position: sticky; top: 0; z-index: 50;
}
.xpr-portal-brand {
    display: flex; align-items: center; gap: 10px;
    color: inherit; text-decoration: none;
    flex-shrink: 0;
}
.xpr-portal-brand:hover { text-decoration: none; }
.xpr-portal-logo {
    max-height: 36px; max-width: 160px; object-fit: contain;
    display: block;
}
.xpr-portal-mark {
    width: 32px; height: 32px; border-radius: 8px;
    background: linear-gradient(135deg, #2271b1, #135e96);
    color: #fff; font-weight: 700; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.xpr-portal-name { font-weight: 700; font-size: 15px; color: #0f172a; }

.xpr-portal-projectbar {
    display: flex; align-items: center;
    margin-left: 8px;
    padding-left: 20px;
    border-left: 1px solid #e2e8f0;
    min-width: 0;
}

.xpr-project-switcher { position: relative; }
.xpr-project-switcher-btn,
.xpr-project-switcher-static {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 10px;
    background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;
    font-family: inherit; font-size: 13px; color: #0f172a;
    cursor: pointer; max-width: 280px;
}
.xpr-project-switcher-btn:hover { border-color: #cbd5e1; background: #fff; }
.xpr-project-switcher-static { cursor: default; background: transparent; border-color: transparent; padding-left: 0; }
.xpr-project-switcher.is-open .xpr-project-switcher-btn {
    border-color: #2271b1;
    box-shadow: 0 0 0 2px rgba(34,113,177,.15);
}
.xpr-project-switcher-logo {
    width: 24px; height: 24px; border-radius: 5px;
    object-fit: contain; background: #fff;
    border: 1px solid #e2e8f0; padding: 2px;
    flex-shrink: 0;
}
.xpr-project-switcher-mark {
    width: 24px; height: 24px; border-radius: 5px;
    background: linear-gradient(135deg, #6366f1, #4338ca);
    color: #fff; font-weight: 700; font-size: 11px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.xpr-project-switcher-name {
    font-weight: 600; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
    min-width: 0;
}
.xpr-project-switcher-caret { color: #94a3b8; font-size: 10px; }
.xpr-project-switcher-menu {
    position: absolute; top: calc(100% + 6px); left: 0;
    background: #fff; border: 1px solid #e2e8f0;
    border-radius: 10px; box-shadow: 0 10px 30px rgba(15,23,42,.10);
    list-style: none; margin: 0; padding: 4px;
    min-width: 280px; max-width: 360px;
    max-height: 360px; overflow-y: auto;
    z-index: 100;
}
.xpr-project-switcher-menu li { margin: 0; padding: 0; }
.xpr-project-switcher-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: 6px;
    font-size: 13px; color: #1d2327; text-decoration: none;
}
.xpr-project-switcher-item:hover { background: #f1f5f9; text-decoration: none; }
.xpr-project-switcher-item.is-current { background: #f0f6fc; color: #135e96; font-weight: 600; }
.xpr-project-switcher-tick { margin-left: auto; color: #2271b1; }

.xpr-portal-nav {
    display: flex; gap: 4px; flex: 1;
    align-items: center; justify-content: flex-start;
    margin-left: 4px;
}
.xpr-portal-nav-link {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 12px; border-radius: 8px;
    font-size: 13px; font-weight: 500; color: #475569;
}
.xpr-portal-nav-link:hover { background: #f1f5f9; text-decoration: none; color: #1d2327; }
.xpr-portal-nav-link.is-active {
    background: #f0f6fc; color: #135e96;
    font-weight: 600;
}
.xpr-portal-nav-icon { font-size: 14px; }

.xpr-portal-user { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.xpr-portal-email { font-size: 12px; color: #64748b; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xpr-portal-logout {
    font-size: 12px; color: #64748b; padding: 6px 12px;
    border: 1px solid #e2e8f0; border-radius: 6px;
}
.xpr-portal-logout:hover { color: #1d2327; border-color: #cbd5e1; text-decoration: none; }

@media (max-width: 880px) {
    .xpr-portal-header { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
    .xpr-portal-projectbar { padding-left: 0; border-left: 0; margin-left: 0; }
    .xpr-portal-nav { width: 100%; order: 4; }
    .xpr-portal-user { margin-left: auto; }
}

.xpr-portal-main {
    max-width: 1240px; margin: 0 auto; padding: 32px;
}
.xpr-portal-footer {
    text-align: center; padding: 24px;
    color: #94a3b8; font-size: 12px;
}

body.is-anon {
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
    min-height: 100vh;
    display: flex; flex-direction: column; justify-content: center;
}
body.is-anon .xpr-portal-main {
    width: 100%; max-width: 460px; padding: 16px;
}
body.is-anon .xpr-portal-footer { padding: 12px; }

/* ── Cards / login ────────────────────────────────────────────────────── */

.xpr-card {
    background: #fff; border: 1px solid #e2e8f0; border-radius: 14px;
    box-shadow: 0 1px 3px rgba(15,23,42,.04);
    padding: 28px;
}

.xpr-login-card { padding: 32px; }
.xpr-login-mark {
    width: 48px; height: 48px; border-radius: 12px;
    background: linear-gradient(135deg, #2271b1, #135e96);
    color: #fff; font-weight: 700; font-size: 20px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 18px;
}
.xpr-login-logo {
    max-height: 56px; max-width: 220px; object-fit: contain;
    display: block; margin-bottom: 18px;
}
.xpr-login-card h1 {
    margin: 0 0 8px; font-size: 22px; line-height: 1.25;
    color: #0f172a; font-weight: 700;
}
.xpr-login-lead {
    margin: 0 0 22px; color: #64748b; font-size: 14px; line-height: 1.55;
}
.xpr-login-error {
    background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
    padding: 10px 14px; border-radius: 8px; font-size: 13px;
    margin-bottom: 16px;
}
.xpr-login-label {
    display: block; font-size: 12px; font-weight: 600;
    color: #334155; margin-bottom: 6px; letter-spacing: .02em;
}
#xpr-login-email {
    width: 100%; padding: 11px 14px; font-size: 15px;
    border: 1px solid #cbd5e1; border-radius: 8px;
    background: #fff; transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
#xpr-login-email:focus {
    outline: none; border-color: #2271b1;
    box-shadow: 0 0 0 3px rgba(34,113,177,.15);
}
.xpr-login-submit {
    width: 100%; margin-top: 16px;
    padding: 12px; font-size: 15px; font-weight: 600;
}
.xpr-login-status {
    margin-top: 12px; font-size: 13px; min-height: 18px;
    text-align: center;
}
.xpr-login-status.is-success { color: #047857; }
.xpr-login-status.is-error { color: #b91c1c; }
.xpr-login-tips {
    margin: 8px 0 0; padding-left: 18px; color: #475569;
    font-size: 13px; line-height: 1.7;
}
.xpr-login-foot {
    margin: 22px 0 0; font-size: 11px; color: #94a3b8;
    text-align: center;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */

.xpr-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; font-size: 13px; font-weight: 600;
    border-radius: 8px; border: 1px solid transparent;
    cursor: pointer; transition: background .15s, border-color .15s, transform .05s;
    text-decoration: none;
    font-family: inherit;
}
.xpr-btn:active { transform: translateY(1px); }
.xpr-btn:disabled { opacity: .55; cursor: not-allowed; }
.xpr-btn-primary { background: #2271b1; color: #fff; border-color: #1e6299; }
.xpr-btn-primary:hover { background: #135e96; text-decoration: none; }
.xpr-btn-secondary { background: #fff; color: #1d2327; border-color: #cbd5e1; }
.xpr-btn-secondary:hover { background: #f8fafc; border-color: #94a3b8; text-decoration: none; }

/* ── Empty / 404 states ──────────────────────────────────────────────── */

.xpr-empty {
    text-align: center; padding: 60px 20px;
    color: #64748b;
}
.xpr-empty-icon { font-size: 48px; margin-bottom: 12px; }
.xpr-empty h3 { margin: 0 0 6px; color: #1d2327; font-size: 17px; }
.xpr-empty p { margin: 0; font-size: 14px; }

/* ── Rankings page ───────────────────────────────────────────────────── */

.xpr-portal-main:has(.xpr-page-rankings) {
    max-width: none;
    padding: 24px 32px 56px;
}

[hidden] { display: none !important; }

.xpr-page-rankings .xpr-card {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: none;
    padding: 18px 20px 20px;
    margin-bottom: 16px;
}

.xpr-rank-header {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 16px; flex-wrap: wrap;
    margin: 0 0 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
}
.xpr-rank-header-meta { min-width: 0; flex: 1 1 auto; }
.xpr-rank-header-meta h1 {
    margin: 0 0 4px; font-size: 20px; line-height: 1.2;
    color: #1d2327; font-weight: 700; word-break: break-word;
}
.xpr-rank-title-icon {
    display: inline-block; margin-right: 4px;
    font-size: 18px; vertical-align: -2px;
}
.xpr-rank-domain {
    display: inline-block; font-size: 12px; color: #64748b;
    border-bottom: 1px dashed #cbd5e1; padding-bottom: 1px;
}
.xpr-rank-domain:hover { color: #2271b1; border-bottom-color: #2271b1; text-decoration: none; }
.xpr-rank-header-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ── Stats summary ──────────────────────────────────────────────────── */

.xpr-rank-stats {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px; margin-bottom: 16px;
}
.xpr-stat-card {
    background: #fff; border: 1px solid #ddd; border-radius: 8px;
    padding: 14px 12px 12px; text-align: center;
    transition: border-color .15s, box-shadow .15s, transform .05s;
    cursor: default;
}
.xpr-stat-card[data-metric] { cursor: pointer; }
.xpr-stat-card[data-metric]:hover {
    border-color: #2271b1;
    box-shadow: 0 1px 6px rgba(34,113,177,.15);
}
.xpr-stat-card.is-active {
    border-color: #2271b1;
    box-shadow: 0 1px 0 #2271b1, 0 0 0 1px #2271b1, 0 4px 14px rgba(34,113,177,.18);
}
.xpr-stat-val {
    font-size: 28px; font-weight: 700; color: #1d2327;
    line-height: 1; margin-bottom: 3px;
}
.xpr-stat-lbl {
    font-size: 11px; text-transform: uppercase; color: #646970;
    letter-spacing: .04em; font-weight: 600;
}
.xpr-stat-pct { font-size: 11px; color: #999; margin-top: 2px; }

.xpr-stat-card[data-metric="top1"]    .xpr-stat-val { color: #46b450; }
.xpr-stat-card[data-metric="top3"]    .xpr-stat-val { color: #46b450; }
.xpr-stat-card[data-metric="top5"]    .xpr-stat-val { color: #00bcd4; }
.xpr-stat-card[data-metric="top10"]   .xpr-stat-val { color: #0073aa; }
.xpr-stat-card[data-metric="top100"]  .xpr-stat-val { color: #555; }
.xpr-stat-card[data-metric="avg_pos"] .xpr-stat-val { color: #8e44ad; }

/* ── Range pill row ──────────────────────────────────────────────────── */

.xpr-range-group { display: inline-flex; gap: 0; flex-wrap: wrap; }
.xpr-range-btn {
    background: #fff; border: 1px solid #c3c4c7;
    border-right-width: 0;
    padding: 4px 10px; font-size: 11px; font-weight: 500;
    color: #50575e; cursor: pointer;
    font-family: inherit; line-height: 1.4;
}
.xpr-range-btn:first-child { border-radius: 4px 0 0 4px; }
.xpr-range-btn:last-child  { border-radius: 0 4px 4px 0; border-right-width: 1px; }
.xpr-range-btn:hover { background: #f6f7f7; color: #1d2327; }
.xpr-range-btn.is-active {
    background: #2271b1; border-color: #2271b1; color: #fff;
    font-weight: 600; position: relative; z-index: 1;
}

/* ── Trend chart ─────────────────────────────────────────────────────── */

.xpr-trend-card { padding: 16px 20px 14px; }
.xpr-trend-title {
    font-size: 13px; font-weight: 600; color: #1d2327; margin: 0 0 10px;
}
.xpr-trend-controls {
    display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
    margin-bottom: 12px;
}
.xpr-chart-wrap { position: relative; height: 280px; }
.xpr-chart-wrap canvas { max-width: 100%; }

/* ── Keyword table ───────────────────────────────────────────────────── */

.xpr-table-card { padding: 0; margin-bottom: 20px; }
.xpr-table-toolbar {
    display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
    padding: 12px 14px; border-bottom: 1px solid #f0f0f1;
    background: #fafafa;
}
.xpr-table-toolbar input[type="search"] {
    padding: 5px 10px; font-size: 13px;
    border: 1px solid #c3c4c7; border-radius: 4px;
    min-width: 240px; font-family: inherit;
}
.xpr-table-toolbar input[type="search"]:focus {
    outline: none; border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
}
.xpr-table-meta {
    margin-left: auto; font-size: 11px; color: #646970;
}

.xpr-table-wrap { overflow-x: auto; }
.xpr-keyword-table {
    width: 100%; border-collapse: collapse; font-size: 13px;
}
.xpr-keyword-table thead {
    background: #f6f7f7; border-bottom: 2px solid #ddd;
}
.xpr-keyword-table th {
    text-align: left; padding: 10px 12px; font-size: 12px;
    color: #1d2327; font-weight: 600;
    border-bottom: 2px solid #ddd; white-space: nowrap;
    user-select: none;
}
.xpr-keyword-table th.col-day1 { text-align: center; }
/* Position / Maps headers right-align over the rank numbers. The body
   numbers sit one delta-gutter (36px) + gap (5px) in from the cell's
   right edge, so pad the header right by that much to keep the label
   directly above the numbers (mirrors the admin keyword table). */
.xpr-keyword-table th.col-pos,
.xpr-keyword-table th.col-maps { text-align: right; padding-right: 47px; }
.xpr-keyword-table th.col-volume { text-align: right; }
.xpr-keyword-table th.col-trend  { text-align: right; width: 130px; }

.xpr-keyword-table td {
    padding: 8px 12px; border-bottom: 1px solid #f0f0f1;
    vertical-align: middle;
}
.xpr-keyword-table tbody tr:hover td { background: #fafbfc; }
.xpr-keyword-table .col-keyword { font-weight: 500; color: #1d2327; max-width: 280px; }
.xpr-keyword-table .col-day1 { text-align: center; }
.xpr-keyword-table .col-pos,
.xpr-keyword-table .col-maps { text-align: right; }
.xpr-keyword-table .col-volume { text-align: right; color: #50575e; }
.xpr-keyword-table .col-url { font-size: 11px; max-width: 240px; }
.xpr-keyword-table .col-url a {
    color: #2271b1; display: inline-block;
    max-width: 170px; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; vertical-align: bottom;
}
.xpr-keyword-table .col-trend {
    text-align: right; white-space: nowrap; padding: 6px 12px;
}
.xpr-keyword-table .col-checked {
    font-size: 11px; color: #646970; white-space: nowrap;
}
.xpr-pos-empty { color: #ccc; }

/* ── Position chips + inline rank-change ──────────────────────────────
   Ported verbatim from the admin keyword table
   (rank-keyword-table-styles.blade.php). The rank number and its change
   delta share ONE column: a colored chip + a fixed-width delta gutter to
   its right that is ALWAYS reserved (empty when there's no movement) so
   every rank number's right edge lines up across rows. */
.xpr-keyword-table .xpr-pos {
    display: inline-block; min-width: 32px; text-align: center;
    font-weight: 700; font-size: 13px; padding: 2px 6px;
    border-radius: 4px; line-height: 1.4;
}
.xpr-keyword-table .xpr-pos-top3  { background: #edfaee; color: #2e7d32; }
.xpr-keyword-table .xpr-pos-top10 { background: #e3f2fd; color: #1565c0; }
.xpr-keyword-table .xpr-pos-top30 { color: #1d2327; }
.xpr-keyword-table .xpr-pos-low   { color: #888; }
.xpr-keyword-table .xpr-pos-none  { color: #ccc; font-weight: 400; }
.xpr-change-up   { color: #46b450; font-weight: 600; font-size: 12px; }
.xpr-change-down { color: #d63638; font-weight: 600; font-size: 12px; }
.xpr-pos-wrap {
    display: inline-flex; align-items: baseline; justify-content: flex-end;
    gap: 5px; width: 100%; font-variant-numeric: tabular-nums;
}
.xpr-pos-wrap > .xpr-pos { flex: 0 0 auto; }
.xpr-pos-delta {
    flex: 0 0 auto; width: 36px; text-align: left;
    font-size: 11px; font-weight: 700; letter-spacing: -.2px;
    line-height: 1.4; white-space: nowrap;
}
/* Keep the active device's pos-wrap a flex row — the global
   `.is-device-mobile .kw-mobile { display: inline }` rule would otherwise
   collapse the delta gutter when the Mobile tab is active. */
.xpr-keyword-table.is-device-mobile .xpr-pos-wrap.kw-mobile { display: inline-flex; }
.xpr-table-empty {
    padding: 32px; text-align: center; color: #94a3b8; font-size: 13px;
}

/* ── 30-day sparkline (rendered client-side from data-history) ───────── */
.xpr-spark {
    display: inline-flex; align-items: flex-end; gap: 1px;
    height: 24px; vertical-align: middle;
}
.xpr-spark-bar {
    width: 6px; min-height: 2px; border-radius: 1px;
    background: #eee;
}
.xpr-spark-bar-empty { height: 2px; background: #eee; }
.xpr-spark-bar-top3  { background: #46b450; }
.xpr-spark-bar-top10 { background: #2271b1; }
.xpr-spark-bar-top30 { background: #dba617; }
.xpr-spark-bar-low   { background: #d63638; }

/* ── Per-keyword cell icons (copy + history graph) ───────────────────
   Ports the admin keyword cell (rank-keyword-table-styles.blade.php
   .xpr-kw-cell / .xpr-kw-actions / .xpr-kw-copy-btn / .xpr-kw-history-btn).
   The portal table is read-only, so there's no pin star or target-URL
   button — just the keyword text + copy + history-chart icons. */
.xpr-keyword-table .col-keyword .xpr-kw-cell {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    min-width: 0;
}
.xpr-kw-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.xpr-kw-actions {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}
.xpr-kw-copy-btn,
.xpr-kw-history-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
    cursor: pointer;
    color: #c3c4c7;
    opacity: .75;
    vertical-align: middle;
    transition: color .15s, opacity .15s;
}
.xpr-kw-copy-btn svg,
.xpr-kw-history-btn svg { width: 13px; height: 13px; }
.xpr-kw-copy-btn:hover,
.xpr-kw-history-btn:hover { color: #2271b1; opacity: 1; }
.xpr-kw-copy-btn.copied { color: #46b450; opacity: 1; }

/* ── Per-keyword history modal (ports the admin Chart.js history modal) ── */
.xpr-rank-modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 100000;
    display: flex; justify-content: center; align-items: center;
    padding: 20px;
}
.xpr-rank-modal-card {
    background: #fff;
    border-radius: 10px;
    padding: 28px 32px;
    max-width: 95vw;
    box-shadow: 0 8px 30px rgba(0,0,0,.2);
    position: relative;
}
.xpr-rank-modal-card-history { width: 760px; }
.xpr-rank-modal-title    { margin: 0 0 6px; font-size: 16px; font-weight: 600; color: #1d2327; }
.xpr-rank-modal-subtitle { margin: 0 0 14px; font-size: 12px; color: #646970; }
.xpr-rank-modal-close {
    position: absolute; top: 12px; right: 14px;
    background: none; border: none;
    font-size: 22px; cursor: pointer; color: #666; line-height: 1;
}
.xpr-rank-modal-close:hover { color: #d63638; }
.xpr-kw-hist-chips {
    display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap;
}
.xpr-kw-hist-chip {
    background: #f6f7f7; border: 1px solid #c3c4c7;
    border-radius: 14px; padding: 4px 10px;
    font-size: 11px; color: #50575e;
    cursor: pointer; transition: all .15s;
}
.xpr-kw-hist-chip:hover {
    background: #e8f0fe; border-color: #2271b1; color: #2271b1;
}
.xpr-kw-hist-chip-active {
    background: #2271b1 !important; border-color: #2271b1 !important;
    color: #fff !important;
}
.xpr-kw-hist-canvas-wrap { position: relative; height: 320px; }
.xpr-kw-hist-empty {
    text-align: center; padding: 60px 20px;
    color: #646970; font-size: 13px;
}

@media (max-width: 1100px) {
    .xpr-portal-main:has(.xpr-page-rankings) { padding: 22px 24px 48px; }
}
@media (max-width: 720px) {
    .xpr-portal-main:has(.xpr-page-rankings) { padding: 16px 14px 32px; }
    .xpr-rank-header h1 { font-size: 18px; }
    .xpr-rank-stats { grid-template-columns: repeat(2, 1fr); }
    .xpr-chart-wrap { height: 220px; }
    .xpr-table-toolbar input[type="search"] { min-width: 0; flex: 1; }
}
