/* ==========================================================================
   Test Environment Log Viewer — component styles
   Terminal log viewer, service pills, search, toolbar, log history,
   connection status, and error auto-display alert.
   ========================================================================== */

/* ---------------------------------------------------------------------------
   LOG VIEWER TERMINAL
   --------------------------------------------------------------------------- */

.testenv-log-viewer-wrapper {
    position: relative;
}

.testenv-log-viewer {
    background: #1e1e2e;
    color: #cdd6f4;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: var(--text-xs);
    line-height: 1.6;
    padding: 0;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    overflow: auto;
    max-height: 500px;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
}

/* Log line */
.log-line {
    display: flex;
    padding: 0 1rem;
    min-height: 1.6em;
}

.log-line:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Line numbers */
.log-line-number {
    display: none;
    color: #585b70;
    min-width: 3.5em;
    text-align: right;
    padding-right: 1em;
    user-select: none;
    flex-shrink: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    margin-right: 0.75em;
}

.testenv-log-viewer.show-line-numbers .log-line-number {
    display: inline-block;
}

.log-line-content {
    flex: 1;
    min-width: 0;
}

/* Timestamp */
.log-timestamp {
    color: #7f849c;
    margin-right: 0.5em;
}

/* ---------------------------------------------------------------------------
   SERVICE NAME COLORS
   --------------------------------------------------------------------------- */

.log-service {
    font-weight: 600;
    margin-right: 0.5em;
}
.log-service-web       { color: #89b4fa; }
.log-service-postgres,
.log-service-db        { color: #a6e3a1; }
.log-service-redis     { color: #fab387; }
.log-service-nginx     { color: #cba6f7; }
.log-service-default   { color: #94e2d5; }

/* ---------------------------------------------------------------------------
   SEVERITY COLORS
   --------------------------------------------------------------------------- */

.log-line-error               { color: #f38ba8; }
.log-line-error .log-line-content { color: #f38ba8; }

.log-line-warn                { color: #f9e2af; }
.log-line-warn  .log-line-content { color: #f9e2af; }

.log-line-debug               { color: #585b70; }
.log-line-debug .log-line-content { color: #585b70; }

/* ---------------------------------------------------------------------------
   SEARCH HIGHLIGHT & DIMMING
   --------------------------------------------------------------------------- */

.log-line.log-line-dimmed {
    opacity: 0.25;
}

.log-line .log-search-highlight {
    background: rgba(249, 226, 175, 0.3);
    color: #f9e2af;
    border-radius: 2px;
    padding: 0 1px;
}

/* ---------------------------------------------------------------------------
   CONNECTION STATUS INDICATOR
   --------------------------------------------------------------------------- */

.testenv-connection-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-xs);
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
}

.testenv-connection-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.testenv-connection-status.connected .testenv-connection-dot {
    background: #a6e3a1;
    box-shadow: 0 0 4px rgba(166, 227, 161, 0.5);
}
.testenv-connection-status.connected { color: #a6e3a1; }

.testenv-connection-status.reconnecting .testenv-connection-dot {
    background: #f9e2af;
    animation: connectionPulse 1s infinite;
}
.testenv-connection-status.reconnecting { color: #f9e2af; }

.testenv-connection-status.disconnected .testenv-connection-dot {
    background: #f38ba8;
}
.testenv-connection-status.disconnected { color: #f38ba8; }

@keyframes connectionPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ---------------------------------------------------------------------------
   SERVICE FILTER PILLS
   --------------------------------------------------------------------------- */

.testenv-service-pills {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    align-items: center;
}

.testenv-service-pill {
    padding: 3px 10px;
    border-radius: 12px;
    border: 1px solid var(--color-border);
    background: transparent;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.testenv-service-pill:hover {
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--color-text);
}

/* Generic active (accent teal) */
.testenv-service-pill.active {
    background: rgba(78, 205, 196, 0.15);
    border-color: rgba(78, 205, 196, 0.3);
    color: #4ecdc4;
}

/* Per-service colored pill variants — match log-service-* palette */
.testenv-service-pill.active[data-service="web"] {
    background: rgba(137, 180, 250, 0.15);
    border-color: rgba(137, 180, 250, 0.35);
    color: #89b4fa;
}

.testenv-service-pill.active[data-service="postgres"],
.testenv-service-pill.active[data-service="db"] {
    background: rgba(166, 227, 161, 0.15);
    border-color: rgba(166, 227, 161, 0.35);
    color: #a6e3a1;
}

.testenv-service-pill.active[data-service="redis"] {
    background: rgba(250, 179, 135, 0.15);
    border-color: rgba(250, 179, 135, 0.35);
    color: #fab387;
}

.testenv-service-pill.active[data-service="nginx"] {
    background: rgba(203, 166, 247, 0.15);
    border-color: rgba(203, 166, 247, 0.35);
    color: #cba6f7;
}

/* ---------------------------------------------------------------------------
   SEARCH BAR
   --------------------------------------------------------------------------- */

.testenv-log-search {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    max-width: 280px;
    position: relative;
}

.testenv-log-search input {
    width: 100%;
    padding: 4px 8px;
    padding-right: 60px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    color: var(--color-text);
    font-size: var(--text-xs);
    height: 28px;
}

.testenv-log-search input:focus {
    outline: none;
    border-color: rgba(78, 205, 196, 0.5);
}

.testenv-log-search-info {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
}

.testenv-log-search-count {
    font-size: var(--text-2xs);
    color: var(--color-text-muted);
    white-space: nowrap;
}

.testenv-log-search-clear {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0;
    font-size: var(--text-xs);
    line-height: 1;
    display: flex;
    align-items: center;
}

.testenv-log-search-clear:hover {
    color: var(--color-text);
}

/* ---------------------------------------------------------------------------
   JUMP TO BOTTOM
   --------------------------------------------------------------------------- */

.testenv-jump-bottom {
    position: absolute;
    bottom: 12px;
    right: 20px;
    padding: 4px 12px;
    background: rgba(78, 205, 196, 0.9);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: var(--text-xs);
    font-weight: 500;
    cursor: pointer;
    display: none;
    z-index: 5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: background 0.15s;
}

.testenv-jump-bottom:hover {
    background: rgba(78, 205, 196, 1);
}

.testenv-jump-bottom.visible {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ---------------------------------------------------------------------------
   TOOLBAR LAYOUT
   --------------------------------------------------------------------------- */

.testenv-log-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: var(--space-3);
}

.testenv-log-toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}

.testenv-log-toolbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
   LOG HISTORY SPLIT LAYOUT
   --------------------------------------------------------------------------- */

.testenv-log-history-layout {
    display: flex;
    gap: 0;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    overflow: hidden;
    min-height: 400px;
    max-height: 550px;
}

.testenv-log-history-sidebar {
    width: 280px;
    flex-shrink: 0;
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    background: var(--color-surface-elevated);
}

.testenv-log-history-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.testenv-log-history-sidebar-title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--color-text);
}

.testenv-log-history-run-list {
    flex: 1;
    overflow-y: auto;
}

.testenv-log-history-run-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
    transition: background 0.15s ease;
}

.testenv-log-history-run-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.testenv-log-history-run-item--selected {
    background: rgba(78, 205, 196, 0.08);
    border-left: 3px solid #4ecdc4;
    padding-left: calc(1rem - 3px);
}

.testenv-log-history-run-item--selected:hover {
    background: rgba(78, 205, 196, 0.12);
}

.testenv-log-history-run-time {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-text);
}

.testenv-log-history-run-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

.testenv-log-history-run-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: var(--text-2xs);
    font-weight: 500;
}

.testenv-log-history-run-status.status-up {
    background: rgba(46, 204, 113, 0.15);
    color: #2ecc71;
}
.testenv-log-history-run-status.status-down {
    background: rgba(148, 163, 184, 0.15);
    color: var(--color-text-muted);
}
.testenv-log-history-run-status.status-error {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
}

.testenv-log-history-viewer-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.testenv-log-history-viewer-panel > .testenv-tab-empty,
.testenv-log-history-viewer-panel > .testenv-tab-loading {
    flex: 1;
}

.testenv-log-history-viewer-panel > .testenv-tab-error {
    margin: 1rem;
}

#testenv-log-history-viewer-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 0.75rem;
}

#testenv-log-history-viewer-content .testenv-log-toolbar {
    margin-bottom: 0.5rem;
}

#testenv-log-history-viewer-content .testenv-log-viewer-wrapper {
    flex: 1;
    min-height: 0;
}

#testenv-log-history-viewer-content .testenv-log-viewer {
    max-height: none;
    height: 100%;
}

/* ---------------------------------------------------------------------------
   ERROR AUTO-DISPLAY ALERT
   --------------------------------------------------------------------------- */

.testenv-error-alert {
    margin-bottom: var(--space-3);
    background: rgba(231, 76, 60, 0.08);
    border: 1px solid rgba(231, 76, 60, 0.35);
    border-left: 4px solid #e74c3c;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    animation: agentStatsSlideIn 0.25s ease-out;
}

.testenv-error-alert-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.testenv-error-alert-icon {
    flex-shrink: 0;
    color: #e74c3c;
    font-size: var(--text-base);
    margin-top: 1px;
}

.testenv-error-alert-content {
    flex: 1;
    min-width: 0;
}

.testenv-error-alert-summary {
    font-size: var(--text-sm);
    font-weight: 600;
    color: #f38ba8;
    word-break: break-word;
}

.testenv-error-alert-suggestion {
    margin-top: 4px;
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    line-height: 1.5;
}

.testenv-error-alert-dismiss {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: var(--text-sm);
    line-height: 1;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.testenv-error-alert-dismiss:hover {
    color: var(--color-text);
    background: rgba(255, 255, 255, 0.06);
}

.testenv-error-alert-actions {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(231, 76, 60, 0.15);
}

.testenv-error-alert-link {
    background: none;
    border: none;
    color: #f38ba8;
    cursor: pointer;
    font-size: var(--text-xs);
    font-weight: 500;
    padding: 2px 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color 0.15s ease;
}

.testenv-error-alert-link:hover {
    color: #e74c3c;
    text-decoration: underline;
}

/* Error flash highlight for scrollToFirstError */
.log-line.testenv-error-flash {
    background: rgba(231, 76, 60, 0.2) !important;
    transition: background 2s ease-out;
}

/* ---------------------------------------------------------------------------
   RESPONSIVE — LOG VIEWER COMPONENTS
   --------------------------------------------------------------------------- */

@media (max-width: 768px) {
    /* Log history stacks vertically */
    .testenv-log-history-layout {
        flex-direction: column;
        max-height: none;
    }

    .testenv-log-history-sidebar {
        width: 100%;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }

    .testenv-log-history-viewer-panel {
        min-height: 300px;
    }

    /* Log viewer full-width */
    .testenv-log-viewer {
        border-radius: 0;
        max-height: 350px;
    }

    /* Toolbar stacks */
    .testenv-log-toolbar {
        gap: 6px;
    }

    .testenv-log-toolbar-left {
        flex-basis: 100%;
    }

    .testenv-log-search {
        max-width: 100%;
        flex-basis: 100%;
    }

    /* Pills wrap naturally (flex-wrap already set) */
    .testenv-service-pills {
        gap: 3px;
    }
}
