/* ============================================
   SAP B1 Integration Test Runner — Dark Theme
   ============================================ */

:root {
    --bg-base: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #253349;
    --bg-input: #0f172a;
    --text-primary: #e2e8f0;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --border: #334155;
    --border-light: #475569;
    --color-passed: #22c55e;
    --color-passed-bg: rgba(34, 197, 94, 0.1);
    --color-failed: #ef4444;
    --color-failed-bg: rgba(239, 68, 68, 0.1);
    --color-running: #3b82f6;
    --color-running-bg: rgba(59, 130, 246, 0.1);
    --color-pending: #64748b;
    --color-pending-bg: rgba(100, 116, 139, 0.1);
    --color-skipped: #eab308;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* ---- Reset & Base ---- */

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-base);
}

/* ---- Layout ---- */

.test-runner-layout {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.test-runner-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.test-runner-header h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.test-runner-subtitle {
    font-size: 13px;
    color: var(--text-muted);
}

.test-runner-main {
    flex: 1;
    padding: 20px 24px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* ---- Summary Bar ---- */

.summary-bar {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.summary-stat {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 90px;
    box-shadow: var(--shadow);
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-top: 2px;
}

.stat-passed .stat-value { color: var(--color-passed); }
.stat-failed .stat-value { color: var(--color-failed); }
.stat-running .stat-value { color: var(--color-running); }

/* ---- Controls Bar ---- */

.controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.filter-select,
.filter-input {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.filter-select:focus,
.filter-input:focus {
    border-color: var(--color-running);
}

.filter-input {
    width: 220px;
}

.filter-input::placeholder {
    color: var(--text-dim);
}

.actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.delay-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--text-muted);
}

.delay-input {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 6px;
    width: 70px;
    font-size: 13px;
    text-align: center;
    outline: none;
}

.delay-input:focus {
    border-color: var(--color-running);
}

/* ---- Buttons ---- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, opacity 0.2s, box-shadow 0.2s;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--color-running);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #2563eb;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.btn-secondary {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.btn-success {
    background: var(--color-passed);
    color: #fff;
}

.btn-success:hover:not(:disabled) {
    background: #16a34a;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}

.btn-danger {
    background: var(--color-failed);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.25);
}

.btn-sm {
    padding: 3px 8px;
    font-size: 12px;
}

/* ---- Save Toast ---- */

.save-toast {
    background: var(--color-passed-bg);
    border: 1px solid var(--color-passed);
    color: var(--color-passed);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    margin-bottom: 12px;
    font-size: 13px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---- Progress Bar ---- */

.progress-bar-container {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    margin-bottom: 16px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-running), var(--color-passed));
    border-radius: 3px;
    transition: width 0.4s ease;
}

/* ---- Test Cards ---- */

.test-cards {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.test-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.test-card:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow);
}

.test-card.status-passed { border-left: 3px solid var(--color-passed); }
.test-card.status-failed { border-left: 3px solid var(--color-failed); }
.test-card.status-running { border-left: 3px solid var(--color-running); }
.test-card.status-pending { border-left: 3px solid var(--color-pending); }
.test-card.status-skipped { border-left: 3px solid var(--color-skipped); }

/* ---- Test Card Header ---- */

.test-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s;
}

.test-card-header:hover {
    background: var(--bg-card-hover);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 42px;
    text-align: center;
}

.status-badge.status-passed {
    background: var(--color-passed-bg);
    color: var(--color-passed);
}

.status-badge.status-failed {
    background: var(--color-failed-bg);
    color: var(--color-failed);
}

.status-badge.status-running {
    background: var(--color-running-bg);
    color: var(--color-running);
    animation: pulse 1.2s infinite;
}

.status-badge.status-pending {
    background: var(--color-pending-bg);
    color: var(--color-pending);
}

.status-badge.status-skipped {
    background: rgba(234, 179, 8, 0.1);
    color: var(--color-skipped);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.test-id {
    font-size: 12px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
    min-width: 30px;
}

.test-name {
    flex: 1;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.test-category {
    font-size: 11px;
    color: var(--text-dim);
    background: var(--bg-input);
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.test-duration {
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    min-width: 60px;
    text-align: right;
}

.test-card-actions {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

/* ---- Test Card Details ---- */

.test-card-details {
    border-top: 1px solid var(--border);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(15, 23, 42, 0.5);
}

.detail-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.detail-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 130px;
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.detail-value {
    font-size: 13px;
    color: var(--text-primary);
    word-break: break-word;
}

.detail-code {
    font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
    font-size: 12px;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin: 0;
    overflow-x: auto;
    white-space: pre-wrap;
    color: #93c5fd;
    max-height: 300px;
}

.response-text {
    max-height: 200px;
    overflow-y: auto;
    padding: 8px 10px;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1.6;
}

.error-row .detail-value {
    color: var(--color-failed);
    font-weight: 500;
    background: var(--color-failed-bg);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
}

/* ---- Validation Section ---- */

.validation-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.validation-section > .detail-label {
    margin-bottom: 4px;
}

.validation-rule {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.rule-passed {
    background: var(--color-passed-bg);
}

.rule-failed {
    background: var(--color-failed-bg);
}

.rule-icon {
    font-weight: 700;
    font-size: 14px;
    width: 18px;
    text-align: center;
}

.rule-passed .rule-icon { color: var(--color-passed); }
.rule-failed .rule-icon { color: var(--color-failed); }

.rule-name {
    font-weight: 500;
    color: var(--text-primary);
    min-width: 160px;
}

.rule-message {
    color: var(--text-muted);
    font-size: 12px;
}

/* ---- Event Trace ---- */

.event-trace {
    margin-top: 6px;
}

.event-trace > summary {
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 0;
    user-select: none;
    transition: color 0.15s;
}

.event-trace > summary:hover {
    color: var(--text-primary);
}

.event-list {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 400px;
    overflow-y: auto;
}

.event-item {
    display: flex;
    gap: 8px;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    background: var(--bg-base);
}

.event-type {
    color: var(--color-running);
    font-weight: 600;
    min-width: 180px;
    font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
    font-size: 11px;
}

.event-summary {
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Scrollbars ---- */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* ---- Responsive ---- */

@media (max-width: 900px) {
    .test-runner-main {
        padding: 12px;
    }

    .controls-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filters,
    .actions {
        flex-wrap: wrap;
    }

    .filter-input {
        width: 100%;
    }

    .test-card-header {
        flex-wrap: wrap;
    }

    .test-name {
        min-width: 100%;
        order: 10;
    }

    .detail-row {
        flex-direction: column;
        gap: 4px;
    }

    .detail-label {
        min-width: unset;
    }
}
