:root {
    --primary: #0078d4;
    --primary-dark: #006bbd;
    --success: #107c10;
    --warning: #ffc107;
    --danger: #d13438;
    --info: #0078d4;
    --gray-light: #f3f2f1;
    --gray-medium: #e1dfdd;
    --gray-dark: #605e5c;
    --text-dark: #323130;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    color: var(--text-dark);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
    background: #f5f5f5;
    min-height: 100vh;
}

/* ========== LANDING PAGE ========== */

.landing-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

.landing-container {
    width: 100%;
    max-width: 600px;
    padding: 2rem;
}

.landing-content {
    text-align: center;
}

.landing-title {
    font-size: 2.8rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
    color: var(--text-dark);
}

.landing-title i {
    color: var(--primary);
    margin-right: 0.5rem;
}

.landing-subtitle {
    font-size: 1rem;
    color: #666;
    margin: 0 0 2rem 0;
}

.landing-form {
    margin: 2rem 0;
}

.landing-form .input-group {
    border: 1px solid var(--gray-medium);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.landing-form .form-control {
    border: none;
    padding: 12px 16px;
    font-size: 1rem;
}

.landing-form .form-control:focus {
    border: none;
    box-shadow: none;
    outline: none;
}

.landing-form .btn {
    border-radius: 0;
    border: none;
    padding: 12px 24px;
    font-weight: 600;
    background-color: var(--primary);
    color: white;
    cursor: pointer;
}

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

.form-message {
    margin-top: 1rem;
    font-size: 0.9rem;
    min-height: 1.2rem;
}

.landing-divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 3rem 0 2rem 0;
    color: #999;
    font-size: 0.9rem;
}

.landing-divider::before,
.landing-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--gray-medium);
}

.runs-list-landing {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.run-card {
    background: white;
    border: 1px solid var(--gray-medium);
    border-radius: 8px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.run-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.run-card-url {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary);
    word-break: break-all;
    margin-bottom: 0.75rem;
}

.run-card-status-time {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 0.75rem;
}

.run-card-status {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.run-card-status.completed {
    background: #d4edda;
    color: var(--success);
}

.run-card-status.running {
    background: #d1ecf1;
    color: #0c5460;
}

.run-card-status.queued {
    background: #fff3cd;
    color: #856404;
}

.run-card-status.failed {
    background: #f8d7da;
    color: #721c24;
}

/* ========== DETAIL PAGE ========== */

.detail-page {
    min-height: 100vh;
    background: white;
}

.audit-header {
    background: white;
    border-bottom: 1px solid var(--gray-medium);
    padding: 1.2rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
}

.site-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.site-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: #999;
    letter-spacing: 1px;
}

.site-url {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-dark);
}

.last-update {
    font-size: 0.85rem;
    color: #999;
}

.btn-back {
    background: none;
    border: 1px solid var(--gray-medium);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    color: var(--primary);
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-back:hover {
    background: var(--gray-light);
    border-color: var(--gray-dark);
}

/* Tabs Navigation */
.tabs-container {
    background: white;
    border-bottom: 2px solid var(--gray-medium);
    padding: 0;
    margin: 0;
    position: sticky;
    top: 70px;
}

.tabs-nav {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 0;
}

.tabs-nav li {
    border-bottom: 3px solid transparent;
}

.tab-button {
    background: none;
    border: none;
    padding: 1rem 2rem;
    cursor: pointer;
    color: #666;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 3px solid transparent;
    margin-bottom: -3px;
}

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

.tab-button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Tab Content */
.audit-content {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* ========== CARDS & METRICS ========== */

.metric-card {
    background: white;
    border: 1px solid var(--gray-medium);
    border-radius: 8px;
    padding: 1.5rem;
    transition: all 0.2s ease;
}

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

.metric-title {
    font-size: 0.9rem;
    color: #999;
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.metric-value-large {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.metric-value-small {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-dark);
}

.metric-label {
    font-size: 0.8rem;
    color: #999;
    margin-top: 0.3rem;
}

.progress-bar-custom {
    height: 8px;
    background: var(--gray-light);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 1rem;
}

.progress-fill {
    height: 100%;
    background: var(--success);
    border-radius: 4px;
}

/* ========== TABLES ========== */

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border: 1px solid var(--gray-medium);
    border-radius: 8px;
    overflow: hidden;
}

.data-table thead {
    background: var(--gray-light);
    border-bottom: 2px solid var(--gray-medium);
}

.data-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-dark);
}

.data-table td {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--gray-medium);
    font-size: 0.9rem;
}

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

.data-table tbody tr:hover {
    background: #fafafa;
}

/* ========== PAGE DRAWER ========== */

.page-drawer-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

.page-drawer-backdrop.open {
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
}

.page-drawer {
    background: white;
    width: 100%;
    max-width: 480px;
    height: 100%;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    border-left: 1px solid var(--gray-medium);
}

.page-drawer-backdrop.open .page-drawer {
    transform: translateX(0);
}

.page-drawer-header {
    background: var(--gray-light);
    padding: 1.5rem;
    border-bottom: 1px solid var(--gray-medium);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-drawer-header h5 {
    margin: 0;
    font-weight: 600;
    color: var(--text-dark);
}

.page-drawer-close {
    background: white;
    border: 1px solid var(--gray-medium);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    transition: all 0.2s;
}

.page-drawer-close:hover {
    background: var(--gray-light);
}

.page-drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

body.drawer-open {
    overflow: hidden;
}

/* ========== STATUS BADGES ========== */

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
}

.status-chip.status-pass {
    background-color: #d4edda;
    color: var(--success);
}

.status-chip.status-fail {
    background-color: #f8d7da;
    color: var(--danger);
}

.audit-check-row-zero {
    color: #9b9b9b;
    background: #f7f7f7;
}

.audit-check-row-zero td {
    color: inherit;
}

.audit-check-row-zero .status-chip {
    background: #ececec !important;
    color: #8a8886 !important;
}

/* Section loading feedback */
.section-loading {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.section-loading-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--gray-medium);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: section-spin 0.8s linear infinite;
    flex-shrink: 0;
}

.section-loading-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-dark);
}

.section-loading-subtitle {
    font-size: 0.85rem;
    color: #777;
}

.keyword-textarea,
.keyword-select {
    width: 100%;
    border: 1px solid var(--gray-medium);
    border-radius: 8px;
    padding: 0.85rem 0.9rem;
    font: inherit;
    color: var(--text-dark);
    background: #fff;
}

.keyword-textarea {
    min-height: 220px;
    resize: vertical;
}

.keyword-pill-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    max-width: 100%;
}

.keyword-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: #eef6ff;
    color: #1b1a19;
    border: 1px solid #d2e8ff;
    border-radius: 999px;
    padding: 0.2rem 0.5rem;
    font-size: 0.78rem;
    line-height: 1.3;
}

.keyword-pill strong {
    font-weight: 600;
}

.keyword-pill em {
    font-style: normal;
    color: #005a9e;
    font-weight: 700;
}

.sitemap-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.6rem 1rem;
    font-size: 0.92rem;
    color: #3b3a39;
}

.sitemap-help-text {
    margin-top: 0.75rem;
    font-size: 0.86rem;
    color: #605e5c;
}

.sitemap-board {
    border: 1px solid var(--gray-medium);
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}

.sitemap-board-toolbar {
    border-bottom: 1px solid var(--gray-medium);
    background: #fbfbfb;
    padding: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    flex-wrap: wrap;
}

.sitemap-legend {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.9rem;
    flex-wrap: wrap;
    font-size: 0.82rem;
    color: #605e5c;
}

.sitemap-legend span {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

#sitemapCanvas {
    display: block;
    width: 100%;
    height: min(75vh, 760px);
    background: linear-gradient(180deg, #fdfefe 0%, #f8fbff 100%);
    touch-action: none;
}

.btn-back:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

@keyframes section-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========== RESPONSIVE ========== */

@media (max-width: 768px) {
    .landing-container {
        padding: 1.5rem;
    }

    .landing-title {
        font-size: 2rem;
    }

    .runs-list-landing {
        grid-template-columns: 1fr;
    }

    .header-content {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }

    .tabs-nav {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .tab-button {
        padding: 0.8rem 1rem;
        font-size: 0.85rem;
    }

    .audit-content {
        padding: 1rem;
    }

    .page-drawer {
        max-width: 100%;
    }

    .sitemap-legend {
        margin-left: 0;
        width: 100%;
    }

    #sitemapCanvas {
        height: min(68vh, 620px);
    }
}

/* Charts Container */
.chart-container {
    position: relative;
    height: 300px;
    margin: 1rem 0;
}

.compact-table {
    font-size: 0.9rem;
}

.compact-table th {
    background: #f8f9fa;
    font-weight: 600;
    font-size: 0.85rem;
}

.compact-table td {
    padding: 0.6rem;
}

/* Utility Classes */
.hidden {
    display: none;
}

/* Responsive */
@media (max-width: 768px) {
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
    }
    
    .page-drawer {
        max-width: 100%;
    }
}

button {
    border: none;
    background: linear-gradient(135deg, var(--accent), #ee9b00);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    padding: 0.72rem 1rem;
}

button:hover {
    filter: brightness(0.95);
}

.scroll {
    max-height: 68vh;
    overflow: auto;
}

.muted {
    color: var(--ink-soft);
}

.run-item {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem;
    margin-bottom: 0.6rem;
    background: #fff;
}

.run-item button {
    margin-top: 0.5rem;
    width: 100%;
    background: var(--accent-2);
}

.badge {
    display: inline-block;
    border-radius: 999px;
    font-size: 0.78rem;
    padding: 0.2rem 0.52rem;
    font-weight: 700;
    color: #fff;
}

.badge.running,
.badge.queued {
    background: var(--warn);
}

.badge.completed {
    background: var(--ok);
}

.badge.failed {
    background: var(--critical);
}

.metrics {
    display: grid;
    gap: 0.6rem;
    grid-template-columns: repeat(4, minmax(130px, 1fr));
}

.metric {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.55rem;
    background: #fffdf9;
}

.metric strong {
    display: block;
    font-size: 1.1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.8rem;
    font-size: 0.92rem;
}

pre {
    margin: 0;
    padding: 0.7rem;
    background: #f8f4ea;
    border: 1px solid var(--border);
    border-radius: 10px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 320px;
    overflow: auto;
}

th,
td {
    border-bottom: 1px solid var(--border);
    text-align: left;
    padding: 0.42rem 0.5rem;
    vertical-align: top;
}

@media (min-width: 1400px) {
    .layout {
        width: calc(100vw - 1.4rem);
    }

    .panel {
        padding: 0.85rem 0.9rem 1rem;
    }

    table {
        font-size: 0.88rem;
    }
}

.severity-critical {
    color: var(--critical);
    font-weight: 700;
}

.severity-warning {
    color: var(--warn);
    font-weight: 700;
}

.severity-info {
    color: var(--accent-2);
    font-weight: 700;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    border-radius: 999px;
    padding: 0.15rem 0.5rem;
    font-size: 0.78rem;
    font-weight: 700;
    border: 1px solid transparent;
    white-space: nowrap;
}

.status-pass {
    color: #0f6f46;
    background: #e7f7ee;
    border-color: #b9e8ce;
}

.status-fail {
    color: #8f1e1e;
    background: #ffecec;
    border-color: #f6c0c0;
}

.page-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(30, 36, 50, 0.42);
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
    z-index: 80;
}

.page-drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.page-drawer {
    position: absolute;
    top: 0;
    right: 0;
    width: min(1180px, 94vw);
    height: 100%;
    background: #fffefb;
    border-left: 1px solid var(--border);
    box-shadow: -16px 0 38px rgba(30, 36, 50, 0.24);
    transform: translateX(100%);
    transition: transform 260ms ease;
    display: grid;
    grid-template-rows: auto 1fr;
}

.page-drawer-backdrop.open .page-drawer {
    transform: translateX(0);
}

.page-drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #fff6e7 0%, #fffdf8 100%);
}

.page-drawer-header h2 {
    margin: 0;
    font-size: 1.25rem;
}

.page-drawer-close {
    background: var(--accent-2);
    color: #fff;
    padding: 0.5rem 0.8rem;
}

.page-drawer-content {
    overflow: auto;
    padding: 1rem;
}

.page-seo-screen {
    display: grid;
    gap: 0.7rem;
}

@media (max-width: 980px) {
    .grid {
        grid-template-columns: 1fr;
    }

    .run-form {
        grid-template-columns: 1fr;
    }

    .metrics {
        grid-template-columns: repeat(2, minmax(120px, 1fr));
    }

    .page-drawer {
        width: 100vw;
    }
}
