/* ============================================================
   Page Speed Checker – Equalza
   ============================================================ */

/* ---------- Layout ---------- */
.ps-tool {
    max-width: 900px;
    margin: 0 auto;
}

.ps-panel {
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--rl, 12px);
    padding: 28px;
    box-shadow: var(--sh, 0 1px 3px rgba(0,0,0,.06));
    margin-bottom: 20px;
}

/* ---------- Toolbar ---------- */
.ps-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.ps-device-toggle {
    display: inline-flex;
    background: var(--bg, #f5f6f8);
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
}

.ps-device-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text2, #4b5563);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .2s;
    font-family: inherit;
}

.ps-device-btn:hover { color: var(--text, #111827); }

.ps-device-btn.active {
    background: var(--surface, #fff);
    color: var(--accent, #2563eb);
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

/* ---------- URL Row ---------- */
.ps-url-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 16px;
}

.ps-field-url { flex: 1; }

.ps-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text, #111827);
    margin-bottom: 6px;
}

.ps-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    color: var(--text, #111827);
    background: var(--surface, #fff);
    transition: border-color .2s, box-shadow .2s;
    box-sizing: border-box;
}

.ps-input:focus {
    outline: none;
    border-color: var(--accent, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.ps-btn-analyze {
    padding: 12px 24px;
    font-size: 15px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ---------- Actions ---------- */
.ps-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.ps-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    cursor: pointer;
}

.ps-btn-sm {
    font-size: 13px;
    padding: 7px 14px;
}

.ps-btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* ---------- Privacy ---------- */
.ps-privacy {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: #f0fdf4;
    border-radius: 8px;
    font-size: 12px;
    color: #059669;
    font-weight: 500;
}

.ps-privacy svg { flex-shrink: 0; stroke: #059669; }

/* ---------- Loading ---------- */
.ps-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 36px 20px 28px;
}

.ps-loading-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
}

/* Animated gauge */
.ps-gauge-anim {
    width: 120px;
    height: 70px;
}

.ps-gauge-arc {
    animation: psArcFill 2.5s ease-in-out infinite;
}

.ps-gauge-needle {
    transform-origin: 60px 62px;
    animation: psNeedleSweep 2.5s ease-in-out infinite;
}

@keyframes psArcFill {
    0%   { stroke-dashoffset: 157; }
    50%  { stroke-dashoffset: 20; }
    100% { stroke-dashoffset: 157; }
}

@keyframes psNeedleSweep {
    0%   { transform: rotate(-90deg); }
    50%  { transform: rotate(80deg); }
    100% { transform: rotate(-90deg); }
}

.ps-loading-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text, #111827);
    margin: 0;
}

.ps-loading-timer {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent, #2563eb);
    font-variant-numeric: tabular-nums;
    letter-spacing: .5px;
}

/* Timeline */
.ps-timeline {
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 0;
    position: relative;
    margin-bottom: 24px;
}

.ps-timeline::before {
    content: '';
    position: absolute;
    top: 14px;
    bottom: 14px;
    width: 2px;
    background: var(--border, #e5e7eb);
}

[dir="ltr"] .ps-timeline::before,
.ps-timeline::before { left: 13px; }
[dir="rtl"] .ps-timeline::before { left: auto; right: 13px; }

.ps-timeline-step {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 0;
    position: relative;
}

.ps-step-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--surface, #fff);
    border: 2px solid var(--border, #e5e7eb);
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    transition: all .4s cubic-bezier(.4,0,.2,1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ps-step-label {
    font-size: 14px;
    color: var(--text3, #9ca3af);
    font-weight: 500;
    transition: color .3s;
}

/* Active step */
.ps-timeline-step.active .ps-step-dot {
    border-color: #2563eb;
    background: #2563eb;
    box-shadow: 0 0 0 4px rgba(37,99,235,.15);
    animation: psStepPulse 1.5s ease-in-out infinite;
}

.ps-timeline-step.active .ps-step-dot::after {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #fff;
}

.ps-timeline-step.active .ps-step-label {
    color: var(--text, #111827);
    font-weight: 600;
}

@keyframes psStepPulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(37,99,235,.15); }
    50% { box-shadow: 0 0 0 8px rgba(37,99,235,.08); }
}

/* Done step */
.ps-timeline-step.done .ps-step-dot {
    border-color: #059669;
    background: #059669;
}

.ps-timeline-step.done .ps-step-dot::after {
    content: '';
    width: 12px;
    height: 12px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center/contain no-repeat;
}

.ps-timeline-step.done .ps-step-label {
    color: #059669;
    font-weight: 500;
}

/* Progress bar */
.ps-loading-bar {
    width: 100%;
    max-width: 360px;
    height: 6px;
    background: var(--border, #e5e7eb);
    border-radius: 3px;
    overflow: hidden;
}

.ps-loading-bar-fill {
    height: 100%;
    width: 0%;
    border-radius: 3px;
    background: linear-gradient(90deg, #2563eb 0%, #7c3aed 50%, #2563eb 100%);
    background-size: 200% 100%;
    animation: psBarShimmer 1.5s ease-in-out infinite;
    transition: width .5s cubic-bezier(.4,0,.2,1);
}

@keyframes psBarShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes psSpin { to { transform: rotate(360deg); } }

/* ---------- Error ---------- */
.ps-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px 20px;
    text-align: center;
}

.ps-error p { font-size: 15px; color: #dc2626; }

/* ---------- Tested URL ---------- */
.ps-tested-url {
    font-size: 13px;
    color: var(--text2, #4b5563);
    text-align: center;
    margin-bottom: 20px;
    word-break: break-all;
}

/* ---------- Score Gauges ---------- */
.ps-gauges {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}

.ps-gauge-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.ps-gauge-canvas {
    width: 100px;
    height: 100px;
}

.ps-gauge-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text2, #4b5563);
    text-align: center;
}

/* ---------- Core Web Vitals ---------- */
.ps-section {
    margin-bottom: 20px;
}

.ps-section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text, #111827);
    margin: 0 0 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ps-section-title.ps-collapsible {
    cursor: pointer;
    user-select: none;
    padding: 10px 0;
    border-top: 1px solid var(--border, #e5e7eb);
}

.ps-section-title.ps-collapsible:hover { color: var(--accent, #2563eb); }

.ps-chevron {
    margin-inline-start: auto;
    transition: transform .2s;
    flex-shrink: 0;
}

.ps-section-title.open .ps-chevron { transform: rotate(180deg); }

.ps-count {
    font-size: 12px;
    font-weight: 500;
    background: var(--bg, #f5f6f8);
    padding: 2px 8px;
    border-radius: 10px;
    color: var(--text2, #4b5563);
}

.ps-vitals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.ps-vital-card {
    background: var(--bg, #f9fafb);
    border-radius: 10px;
    padding: 16px;
    border: 1px solid var(--border, #e5e7eb);
}

.ps-vital-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text2, #4b5563);
    margin-bottom: 6px;
}

.ps-vital-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
}

.ps-vital-value.good { color: #059669; }
.ps-vital-value.needs-work { color: #d97706; }
.ps-vital-value.poor { color: #dc2626; }

.ps-vital-rating {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    margin-top: 6px;
}

.ps-vital-rating.good { background: #ecfdf5; color: #059669; }
.ps-vital-rating.needs-work { background: #fffbeb; color: #d97706; }
.ps-vital-rating.poor { background: #fef2f2; color: #dc2626; }

/* ---------- Audit List ---------- */
.ps-audit-list {
    overflow: hidden;
    transition: max-height .3s ease;
}

.ps-audit-list.ps-collapsed { max-height: 0; }

.ps-audit-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border, #f3f4f6);
}

.ps-audit-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 5px;
}

.ps-audit-dot.good { background: #059669; }
.ps-audit-dot.needs-work { background: #d97706; }
.ps-audit-dot.poor { background: #dc2626; }
.ps-audit-dot.info { background: #6b7280; }
.ps-audit-dot.pass { background: #059669; }

.ps-audit-content { flex: 1; min-width: 0; }

.ps-audit-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text, #111827);
    margin-bottom: 2px;
}

.ps-audit-desc {
    font-size: 13px;
    color: var(--text2, #4b5563);
    line-height: 1.5;
}

.ps-audit-savings {
    font-size: 12px;
    font-weight: 600;
    color: #059669;
    margin-top: 4px;
}

.ps-audit-value {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    padding: 4px 10px;
    border-radius: 6px;
    background: var(--bg, #f5f6f8);
}

/* ---------- Modal ---------- */
.ps-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ps-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.4);
}

.ps-modal-content {
    position: relative;
    background: var(--surface, #fff);
    border-radius: 14px;
    padding: 0;
    max-width: 560px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.ps-modal-wide { max-width: 780px; }

.ps-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border, #e5e7eb);
}

.ps-modal-header h3 {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
}

.ps-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text2, #4b5563);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.ps-modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}

.ps-modal-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--border, #e5e7eb);
    display: flex;
    justify-content: flex-end;
}

/* ---------- History List ---------- */
.ps-history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border, #f3f4f6);
    cursor: pointer;
}

.ps-history-item:hover { background: var(--bg, #f9fafb); border-radius: 8px; padding: 12px 8px; margin: 0 -8px; }

.ps-history-score {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.ps-history-score.good { background: #059669; }
.ps-history-score.needs-work { background: #d97706; }
.ps-history-score.poor { background: #dc2626; }

.ps-history-info { flex: 1; min-width: 0; }

.ps-history-url {
    font-size: 14px;
    font-weight: 600;
    color: var(--text, #111827);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ps-history-meta {
    font-size: 12px;
    color: var(--text3, #9ca3af);
    margin-top: 2px;
}

.ps-history-delete {
    background: none;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 11px;
    color: #dc2626;
    cursor: pointer;
    flex-shrink: 0;
}

.ps-history-empty {
    text-align: center;
    padding: 32px;
    color: var(--text3, #9ca3af);
    font-size: 14px;
}

/* ---------- Compare ---------- */
.ps-compare-inputs {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.ps-compare-inputs .ps-field { flex: 1; min-width: 180px; }

.ps-compare-results {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 16px;
    align-items: start;
}

.ps-compare-col {
    background: var(--bg, #f9fafb);
    border-radius: 10px;
    padding: 20px;
    border: 1px solid var(--border, #e5e7eb);
}

.ps-compare-col.winner { border-color: #059669; box-shadow: 0 0 0 2px rgba(5,150,105,.15); }

.ps-compare-vs {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--text3, #9ca3af);
    padding-top: 40px;
}

.ps-compare-url {
    font-size: 13px;
    font-weight: 600;
    color: var(--text, #111827);
    margin-bottom: 12px;
    word-break: break-all;
}

.ps-compare-metric {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border, #f3f4f6);
}

.ps-compare-metric-label { color: var(--text2, #4b5563); }

.ps-compare-metric-value { font-weight: 600; }

/* ---------- Toast ---------- */
.ps-toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #202124;
    color: #fff;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transition: opacity .3s, transform .3s;
    z-index: 10001;
    pointer-events: none;
}

.ps-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---------- Loading state for buttons ---------- */
.ps-btn.loading {
    opacity: .65;
    pointer-events: none;
}

.ps-btn.loading svg {
    animation: psSpin .8s linear infinite;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 700px) {
    .ps-gauges {
        grid-template-columns: repeat(2, 1fr);
    }
    .ps-panel { padding: 18px; }
    .ps-url-row { flex-direction: column; }
    .ps-btn-analyze { width: 100%; justify-content: center; }
    .ps-vitals-grid { grid-template-columns: 1fr; }
    .ps-compare-results { grid-template-columns: 1fr; }
    .ps-compare-vs { padding: 0; }
    .ps-modal-content { width: 95%; }
}

@media (max-width: 420px) {
    .ps-gauges { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .ps-gauge-canvas { width: 80px; height: 80px; }
}

/* ============================================================
   RTL
   ============================================================ */

[dir="rtl"] .ps-tool { direction: rtl; }
[dir="rtl"] .ps-url-row { flex-direction: row-reverse; }
[dir="rtl"] .ps-audit-item { direction: rtl; }
[dir="rtl"] .ps-history-item { direction: rtl; }
[dir="rtl"] .ps-compare-inputs { direction: rtl; }

@media (max-width: 700px) {
    [dir="rtl"] .ps-url-row { flex-direction: column; }
}
