/* ==========================================
   TestFlow Dashboard pages — overview, active tests, failures,
   history, validators, modals, toasts.
   ========================================== */

:root {
    --tf-primary: #5c8cff;
    --tf-primary-dark: #3b1f9f;
    --tf-accent: #00BFA6;
    --tf-success: #4CAF50;
    --tf-warning: #FF9800;
    --tf-danger: #F44336;
    --tf-text-primary: #e6e6e9;
    --tf-text-secondary: #8b8d97;
    --tf-bg-surface: #111114;
    --tf-bg-surface-2: #16161b;
    --tf-border-color: #22232a;
}

.page-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.live-status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.live-status.is-live {
    background: rgba(63, 185, 80, 0.12);
    color: var(--tf-success);
    border: 1px solid rgba(63, 185, 80, 0.35);
}

.live-status.is-offline {
    background: rgba(140, 142, 152, 0.1);
    color: var(--tf-text-secondary);
    border: 1px solid rgba(140, 142, 152, 0.35);
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

/* Dashboard Grid & Cards */

.dashboard-grid {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.metrics-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.metric-card {
    background: var(--tf-bg-surface);
    border-radius: 8px;
    padding: 1.25rem;
    text-align: center;
    border: 1px solid var(--tf-border-color);
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--tf-primary);
}

.metric-value.active { color: var(--tf-accent); }
.metric-value.good { color: var(--tf-success); }
.metric-value.warning { color: var(--tf-warning); }
.metric-value.bad { color: var(--tf-danger); }

.metric-label {
    color: var(--tf-text-secondary);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* Sections */

.section {
    background: var(--tf-bg-surface);
    border-radius: 8px;
    padding: 1.25rem;
    border: 1px solid var(--tf-border-color);
}

/* Runner Cards */

.runners-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.runner-card {
    background: var(--tf-bg-surface-2);
    border-radius: 6px;
    padding: 1rem;
    border-left: 4px solid var(--tf-success);
}

.runner-card.degraded { border-left-color: var(--tf-warning); }
.runner-card.unhealthy, .runner-card.offline { border-left-color: var(--tf-danger); }

.runner-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.runner-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--tf-success);
}

.runner-status-dot.offline { background-color: var(--tf-danger); }

.runner-details {
    font-size: 0.85rem;
    color: var(--tf-text-secondary);
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.runner-heartbeat {
    font-size: 0.75rem;
    color: var(--tf-text-secondary);
    margin-top: 0.5rem;
}

/* Validation Cards */

.validations-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.validation-card {
    background: var(--tf-bg-surface-2);
    border-radius: 6px;
    padding: 0.75rem 1rem;
}

.validation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.validation-details {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--tf-text-secondary);
}

.elapsed { font-family: monospace; }

/* Failure Cards */

.failures-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.failure-card {
    background: rgba(248, 81, 73, 0.05);
    border-radius: 6px;
    padding: 0.75rem 1rem;
    border-left: 3px solid var(--tf-danger);
}

.failure-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.failure-message {
    font-size: 0.85rem;
    color: var(--tf-danger);
    margin-bottom: 0.25rem;
}

.failure-validator {
    font-size: 0.75rem;
    color: var(--tf-text-secondary);
}

.time-ago {
    font-size: 0.75rem;
    color: var(--tf-text-secondary);
}

/* Quick Stats */

.quick-stats {
    display: flex;
    gap: 2rem;
}

.stat { text-align: center; }

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--tf-primary);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--tf-text-secondary);
}

/* Summary Cards */

.summary-row, .summary-cards {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.summary-card {
    background: var(--tf-bg-surface);
    border-radius: 8px;
    padding: 1.5rem;
    min-width: 150px;
    text-align: center;
    border: 1px solid var(--tf-border-color);
}

.summary-card.highlight {
    border-color: var(--tf-primary);
    border-width: 2px;
}

.summary-card.has-failures { border-color: var(--tf-danger); }

.summary-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.summary-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--tf-primary);
}

.summary-label {
    font-size: 0.85rem;
    color: var(--tf-text-secondary);
}

/* Badges */

.category-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--tf-bg-surface-2);
}

.category-dm { background: rgba(33, 150, 243, 0.18); color: #64b5f6; }
.category-svc { background: rgba(156, 39, 176, 0.18); color: #ce93d8; }
.category-productv2 { background: rgba(76, 175, 80, 0.18); color: #81c784; }
.category-ecomm { background: rgba(255, 152, 0, 0.18); color: #ffb74d; }
.category-ngbat { background: rgba(233, 30, 99, 0.18); color: #f48fb1; }

.result-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

.badge-passed { background: rgba(76, 175, 80, 0.18); color: var(--tf-success); }
.badge-failed { background: rgba(244, 67, 54, 0.18); color: var(--tf-danger); }
.badge-error { background: rgba(255, 152, 0, 0.18); color: var(--tf-warning); }
.badge-timeout { background: rgba(255, 152, 0, 0.18); color: var(--tf-warning); }
.badge-skipped { background: var(--tf-bg-surface-2); color: var(--tf-text-secondary); }

/* Validators Grid */

.validators-filter {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.validators-filter .form-control,
.validators-filter .form-select {
    max-width: 300px;
}

.validators-count {
    font-size: 0.85rem;
    color: var(--tf-text-secondary);
    margin-bottom: 1rem;
}

.validators-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

.validator-card {
    background: var(--tf-bg-surface);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid var(--tf-border-color);
}

.validator-card.disabled { opacity: 0.6; }

.validator-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.validator-name {
    font-weight: 600;
    color: var(--tf-text-primary);
}

.validator-id {
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--tf-text-secondary);
    margin-bottom: 0.5rem;
}

.validator-description {
    font-size: 0.85rem;
    color: var(--tf-text-secondary);
    margin-bottom: 0.75rem;
}

.validator-details { margin-bottom: 0.75rem; }

.detail-row {
    display: flex;
    gap: 0.5rem;
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
}

.detail-label { color: var(--tf-text-secondary); }
.detail-value { color: var(--tf-text-primary); }

.issue-types, .required-fields {
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

.issue-types-label, .fields-label {
    color: var(--tf-text-secondary);
    margin-right: 0.25rem;
}

.issue-type-badge {
    display: inline-block;
    background: var(--tf-bg-surface-2);
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    margin: 0.1rem;
    font-size: 0.7rem;
}

.disabled-badge {
    display: inline-block;
    background: var(--tf-bg-surface-2);
    color: var(--tf-text-secondary);
    padding: 0.1rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    text-transform: uppercase;
}

/* History Table */

.history-filter { margin-bottom: 1rem; }
.history-filter .form-select { max-width: 200px; }

.result-passed { background: rgba(76, 175, 80, 0.05); }
.result-failed { background: rgba(244, 67, 54, 0.05); }
.result-error { background: rgba(255, 152, 0, 0.05); }

.message-row td {
    padding-top: 0 !important;
    border-top: none !important;
}

.time-saved {
    color: var(--tf-success);
    font-weight: 500;
}

/* Failures detail */

.failure-summary { margin-bottom: 1.5rem; }

.no-failures-message {
    text-align: center;
    padding: 3rem;
}

.success-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.category-breakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.category-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--tf-bg-surface-2);
    padding: 0.5rem 1rem;
    border-radius: 4px;
}

.category-count { font-weight: 600; }

.top-errors {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.error-item {
    background: var(--tf-bg-surface-2);
    padding: 0.75rem;
    border-radius: 4px;
}

.error-message {
    font-weight: 500;
    color: var(--tf-danger);
    margin-bottom: 0.25rem;
}

.error-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--tf-text-secondary);
}

.failure-detail-card {
    background: var(--tf-bg-surface);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--tf-border-color);
    border-left: 4px solid var(--tf-danger);
}

.ticket-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.ticket-key { font-size: 1.1rem; }
.jira-link { font-size: 0.8rem; }

.failure-summary-text {
    color: var(--tf-text-secondary);
    margin: 0.5rem 0;
}

.failure-error {
    display: flex;
    gap: 0.5rem;
    background: rgba(244, 67, 54, 0.08);
    padding: 0.75rem;
    border-radius: 4px;
    margin: 0.75rem 0;
}

.error-text {
    color: var(--tf-danger);
    font-size: 0.9rem;
}

.failure-footer {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--tf-text-secondary);
}

/* Last Updated */

.last-updated {
    margin-top: 1.5rem;
    font-size: 0.85rem;
    color: var(--tf-text-secondary);
    text-align: center;
}

/* Loading */

.loading-spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    color: var(--tf-text-secondary);
}

/* No results */

.no-results, .no-tests {
    text-align: center;
    padding: 2rem;
    color: var(--tf-text-secondary);
}

/* Auto-refresh toggle */

.auto-refresh-toggle {
    display: inline-flex;
    align-items: center;
    margin-left: 1rem;
}

.auto-refresh-toggle label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--tf-text-secondary);
    cursor: pointer;
}

.auto-refresh-toggle .form-check-input { margin: 0; }

.quick-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Action bar (active tests) */

.action-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.active-row.long-running { background: rgba(255, 152, 0, 0.06); }

.runners-detailed {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.runner-detail-card {
    background: var(--tf-bg-surface);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid var(--tf-border-color);
}

.runner-detail-card.online { border-left: 4px solid var(--tf-success); }
.runner-detail-card.offline { border-left: 4px solid var(--tf-danger); opacity: 0.7; }

.runner-info .info-row {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    font-size: 0.85rem;
}

.runner-info .label { color: var(--tf-text-secondary); }
.runner-info .value { color: var(--tf-text-primary); }
.runner-info .value.healthy { color: var(--tf-success); }
.runner-info .value.degraded { color: var(--tf-warning); }
.runner-info .value.unhealthy, .runner-info .value.offline { color: var(--tf-danger); }

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--tf-success);
}

.status-indicator.offline { background: var(--tf-danger); }

/* Time range selector */

.time-range-selector { margin-bottom: 1rem; }
.time-range-selector .form-select { max-width: 200px; }

/* Toasts */

.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 400px;
}

.toast-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    border-radius: 8px;
    background: var(--tf-bg-surface);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    animation: tf-slideIn 0.3s ease;
    border-left: 4px solid;
    color: var(--tf-text-primary);
}

.toast-item.leaving {
    animation: tf-slideOut 0.3s ease forwards;
}

@keyframes tf-slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes tf-slideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

.toast-success { border-left-color: var(--tf-success); }
.toast-error { border-left-color: var(--tf-danger); }
.toast-warning { border-left-color: var(--tf-warning); }
.toast-info { border-left-color: var(--tf-primary); }

.toast-icon {
    font-size: 1.25rem;
    font-weight: bold;
}

.toast-success .toast-icon { color: var(--tf-success); }
.toast-error .toast-icon { color: var(--tf-danger); }
.toast-warning .toast-icon { color: var(--tf-warning); }
.toast-info .toast-icon { color: var(--tf-primary); }

.toast-content { flex: 1; }

.toast-title {
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.toast-message {
    font-size: 0.9rem;
}

.toast-close {
    background: none;
    border: none;
    color: var(--tf-text-secondary);
    cursor: pointer;
    font-size: 1rem;
}

/* Global Search */

.global-search { position: relative; }

.search-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.8rem;
    background: var(--tf-bg-surface-2);
    border: 1px solid var(--tf-border-color);
    border-radius: 6px;
    color: var(--tf-text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
}

.search-trigger:hover {
    color: var(--tf-text-primary);
    border-color: var(--tf-primary);
}

.search-shortcut {
    margin-left: 0.5rem;
    font-size: 0.7rem;
    background: var(--tf-bg-surface);
    border: 1px solid var(--tf-border-color);
    padding: 0.05rem 0.4rem;
    border-radius: 3px;
}

.search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
}

.search-modal {
    position: fixed;
    top: 5rem;
    left: 50%;
    transform: translateX(-50%);
    width: min(640px, 92vw);
    background: var(--tf-bg-surface);
    border: 1px solid var(--tf-border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 1050;
    padding: 1rem;
}

.search-input-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.search-input {
    flex: 1;
    background: var(--tf-bg-surface-2);
    border: 1px solid var(--tf-border-color);
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    color: var(--tf-text-primary);
}

.search-close {
    background: none;
    border: 1px solid var(--tf-border-color);
    padding: 0.4rem 0.7rem;
    color: var(--tf-text-secondary);
    border-radius: 4px;
    font-size: 0.7rem;
    cursor: pointer;
}

.search-results { display: flex; flex-direction: column; gap: 0.5rem; }

.search-section-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--tf-text-secondary);
    margin-bottom: 0.25rem;
    letter-spacing: 0.08em;
}

.search-result {
    display: flex;
    gap: 0.6rem;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    color: var(--tf-text-primary);
}

.search-result:hover { background: var(--tf-bg-surface-2); }

.search-hint-text {
    text-align: center;
    color: var(--tf-text-secondary);
    font-size: 0.85rem;
    padding: 0.5rem 0;
}

/* ===========================================================================
   Responsive — tablet (≤ 900px) and phone (≤ 640px)
   =========================================================================== */

/* Tablet — gentler stacks, smaller padding */
@media (max-width: 900px) {
    .metrics-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
    .runners-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
    .runners-detailed { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
    .validators-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

    .summary-card { padding: 1rem; min-width: 130px; }
    .summary-value { font-size: 1.6rem; }
    .metric-value { font-size: 1.6rem; }

    .toast-container { max-width: min(360px, calc(100vw - 1rem)); }
}

/* Phone — stack flex rows, tighten cards, allow tables to scroll */
@media (max-width: 640px) {
    /* Header rows with title + status pill — let the pill drop below */
    .page-header-row {
        flex-wrap: wrap;
        gap: 0.5rem;
        align-items: flex-start;
    }

    /* Metric/summary/runner grids — one or two columns */
    .metrics-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
    .runners-grid { grid-template-columns: 1fr; }
    .runners-detailed { grid-template-columns: 1fr; }
    .validators-grid { grid-template-columns: 1fr; }

    .metric-card { padding: 0.85rem; }
    .metric-value { font-size: 1.4rem; }
    .metric-label { font-size: 0.78rem; }

    .summary-row, .summary-cards {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.6rem;
        margin-bottom: 1rem;
    }
    .summary-card { min-width: 0; padding: 0.85rem; }
    .summary-value { font-size: 1.5rem; }

    .section { padding: 0.85rem; }

    /* Quick stats — flex with gap 2rem will overflow; stack them */
    .quick-stats {
        gap: 1rem;
        flex-wrap: wrap;
        justify-content: space-around;
    }
    .stat-value { font-size: 1.25rem; }

    /* Quick action buttons — full-width on phones */
    .quick-actions { flex-direction: column; align-items: stretch; }
    .quick-actions > .btn { width: 100%; }

    /* Filters — stack inputs vertically */
    .validators-filter {
        flex-direction: column;
        gap: 0.5rem;
    }
    .validators-filter .form-control,
    .validators-filter .form-select { max-width: none; width: 100%; }

    .history-filter .form-select { max-width: none; width: 100%; }
    .time-range-selector .form-select { max-width: none; width: 100%; }

    /* Action bar (active tests) — stack title and controls */
    .action-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .auto-refresh-toggle { margin-left: 0; }

    /* Validation / failure / error cards — let header wrap */
    .validation-header,
    .failure-header,
    .failure-footer,
    .validation-details {
        flex-wrap: wrap;
        gap: 0.25rem 0.5rem;
    }

    /* Failure summary — let category breakdown / error stats wrap */
    .category-breakdown { gap: 0.4rem; }
    .category-item { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
    .error-stats { flex-wrap: wrap; gap: 0.5rem; }

    /* Tables — horizontal scroll instead of overflowing */
    .section table,
    .dashboard-grid table {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* Last updated bar — stack refresh + auto-refresh */
    .last-updated {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        align-items: center;
    }

    /* Toasts — full-width minus a little margin */
    .toast-container {
        left: 0.5rem;
        right: 0.5rem;
        top: 0.5rem;
        max-width: none;
    }
    .toast-item { padding: 0.75rem; }

    /* Global search — hide the keyboard shortcut hint chip on mobile */
    .search-shortcut { display: none; }
    .search-trigger { padding: 0.35rem 0.55rem; }
    .search-modal {
        top: 1rem;
        width: calc(100vw - 1rem);
    }

    /* Ticket info — wrap link below key on small screens */
    .ticket-info { flex-wrap: wrap; gap: 0.5rem; }
}
