/* =======================================
    src/css/tools/redirect.css
    Styling cho Redirect Analyzer Tool
========================================== */

/* =========================================
   1. REDIRECT CHAIN (Visual Path)
========================================== */
.redirect-chain {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.redirect-step {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    position: relative;
}

/* Đường nối dọc giữa các step */
.redirect-step:not(:last-child)::after {
    content: '';
    position: absolute;
    left: calc(var(--space-4) + 1.5px);
    top: calc(var(--space-5) + 3rem);
    width: 2px;
    height: calc(100% - 3rem);
    background: var(--color-border);
}

/* NODE: hình tròn màu theo status */
.redirect-step__node {
    flex-shrink: 0;
    width: var(--space-9);
    height: var(--space-9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-bold);
    color: var(--white);
    z-index: 1;
    margin-top: var(--space-1);
    box-shadow: var(--shadow-sm);
}

.redirect-step__node--2xx   { background-color: var(--green-600); }
.redirect-step__node--301   { background-color: var(--yellow-500); color: var(--slate-900); }
.redirect-step__node--302   { background-color: var(--orange-500); }
.redirect-step__node--3xx   { background-color: var(--orange-400); }
.redirect-step__node--4xx   { background-color: var(--red-600); }
.redirect-step__node--5xx   { background-color: var(--red-800); }
.redirect-step__node--loop  { background-color: var(--purple-600); }
.redirect-step__node--final { background-color: var(--color-brand); }

/* NỘI DUNG mỗi step */
.redirect-step__content {
    flex: 1;
    background: var(--color-surface);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-3);
    transition: box-shadow 0.2s ease;
}

.redirect-step__content:hover {
    box-shadow: var(--shadow-md);
}

.redirect-step__content--slowest {
    border-color: var(--orange-500);
    background: color-mix(in srgb, var(--orange-500) 10%, var(--color-surface));
}

.redirect-step__content--loop {
    border-color: var(--purple-500);
    background: color-mix(in srgb, var(--purple-500) 10%, var(--color-surface));
}

.redirect-step__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.redirect-step__url {
    font-family: var(--font-family-mono);
    color: var(--color-text-primary);
    word-break: break-all;
    flex: 1;
}

.redirect-step__meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

.redirect-step__timing {
    color: var(--color-text-muted);
    font-family: var(--font-family-mono);
}

.redirect-step__badge {
    font-weight: var(--font-weight-semibold);
    padding: 2px var(--space-2);
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.redirect-step__badge--location {
    color: var(--color-text-muted);
    margin-top: var(--space-1);
    font-family: var(--font-family-mono);
    display: block;
}

/* Penalty notice */
.redirect-penalty {
    color: var(--color-text-secondary);
    padding: var(--space-2) var(--space-3);
    background: var(--color-surface-muted);
    border-radius: var(--radius-md);
    border: var(--border-default);
    border-left: 4px solid var(--color-warning);
}

/* =========================================
   2. REDIRECT SCORE BADGE
========================================== */
.redirect-score {
    flex-wrap: wrap;
}

.redirect-score__badge {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-bold);
    flex-shrink: 0;
    border: 4px solid;
    color: var(--white);
}

.redirect-score__badge--great { border-color: var(--green-500);  background: var(--green-600); }
.redirect-score__badge--good  { border-color: var(--yellow-400); background: var(--yellow-500); color: var(--slate-900); }
.redirect-score__badge--warn  { border-color: var(--orange-400); background: var(--orange-500); }
.redirect-score__badge--bad   { border-color: var(--red-500);    background: var(--red-600); }

.redirect-score__badge small {
    font-weight: var(--font-normal);
    opacity: 0.8;
}

.redirect-score__breakdown {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.redirect-score__item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--color-text-secondary);
}

.redirect-score__item--deduct { color: var(--color-error); }
.redirect-score__item--ok     { color: var(--color-success); }

/* =========================================
   3. SECURITY AUDIT
========================================== */
.security-results {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.security-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-subtle);
    background: var(--color-surface);
}

.security-item--pass { border-left: 4px solid var(--color-success); }
.security-item--warn {
    border-left: 4px solid var(--color-warning);
    background: color-mix(in srgb, var(--color-warning) 10%, var(--color-surface));
}
.security-item--fail {
    border-left: 4px solid var(--color-error);
    background: color-mix(in srgb, var(--color-error) 10%, var(--color-surface));
}

.security-item__icon {
    flex-shrink: 0;
    margin-top: 2px;
}

.security-item--pass .security-item__icon { color: var(--color-success); }
.security-item--warn .security-item__icon { color: var(--color-warning); }
.security-item--fail .security-item__icon { color: var(--color-error); }

.security-item__title {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-1);
}

.security-item__desc {
    color: var(--color-text-muted);
    line-height: var(--line-height-relaxed);
}

/* =========================================
   4. SEO RESULTS GRID
========================================== */
.seo-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--space-3);
}

.seo-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-subtle);
    background: var(--color-surface);
}

.seo-item__label {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.seo-item__value {
    color: var(--color-text-primary);
    word-break: break-all;
    font-family: var(--font-family-mono);
}

.seo-item__value--missing {
    color: var(--color-error);
    font-style: italic;
    font-family: var(--font-family-base);
}

.seo-item__value--ok { color: var(--color-success); }

/* =========================================
   5. CURL OUTPUT
========================================== */
.redirect-curl-output {
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    overflow-x: auto;
    font-family: var(--font-family-mono);
    color: var(--code-text);
    line-height: var(--line-height-relaxed);
    white-space: pre;
    margin: 0;
}

/* =========================================
   6. PERFORMANCE TABLE
========================================== */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Hỗ trợ scroll mượt trên iOS */
}

.results-table th,
.results-table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border-subtle);
}

.results-table th {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    background-color: var(--color-surface-hover);
    white-space: nowrap;
}

/* ================== PERFORMANCE TABLE ================== */
/* 2 cột đầu (Bước, URL) căn trái */
#perfTable .results-table th:nth-child(1),
#perfTable .results-table td:nth-child(1),
#perfTable .results-table th:nth-child(2),
#perfTable .results-table td:nth-child(2) {
    text-align: left;
}

/* Cột 2 (URL) tự do mở rộng ngang */
#perfTable .results-table th:nth-child(2),
#perfTable .results-table td:nth-child(2) {
    min-width: 250px;
    white-space: nowrap !important;
}

/* Các cột thời gian (DNS, TCP, TLS, TTFB, Tổng) căn phải */
#perfTable .results-table th:nth-child(n+3),
#perfTable .results-table td:nth-child(n+3) {
    text-align: right;
}

/* ================== COMPARE TABLE ================== */
/* Cột 1,2,3,4 giãn trái/phải hợp lý */
#compareTable .results-table th,
#compareTable .results-table td {
    text-align: left;
}

#compareTable .results-table th:nth-child(4),
#compareTable .results-table td:nth-child(4) {
    text-align: center;
}

/* Cột 3 (URL Cuối) tự do mở rộng ngang */
#compareTable .results-table th:nth-child(3),
#compareTable .results-table td:nth-child(3) {
    min-width: 250px;
    white-space: nowrap !important;
}

.perf-cell--slow {
    color: var(--color-error);
    font-weight: var(--font-weight-bold);
}

/* =========================================
   7. RESPONSIVE
========================================== */
@media (max-width: 600px) {
    .redirect-step__header {
        flex-direction: column;
        align-items: flex-start;
    }

    .redirect-step__meta { flex-wrap: wrap; }

    .seo-results { grid-template-columns: 1fr; }

    .redirect-score {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
}
