/*
    TL.6.1 (#117) — styles for the tool-loop chat page.
    Loaded by App.razor alongside app.css. Lightweight + scoped to
    the .tl-* classes used by the new chat components; doesn't
    touch the legacy InstanceChat layout.
*/

.tl-page {
    display: flex;
    gap: 16px;
    height: calc(100vh - 100px);
}

.tl-sidebar {
    width: 280px;
    flex-shrink: 0;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tl-sidebar-header {
    padding: 12px;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tl-sidebar-new {
    flex-grow: 1;
}

.tl-sidebar-loading,
.tl-sidebar-empty {
    padding: 16px;
    color: #6c757d;
    text-align: center;
}

.tl-sidebar-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex-grow: 1;
}

.tl-sidebar-item {
    padding: 12px 14px;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
    transition: background-color 0.1s ease;
}

.tl-sidebar-item:hover {
    background: #e9ecef;
}

.tl-sidebar-item.active {
    background: #cfe2ff;
    border-left: 3px solid #0d6efd;
}

.tl-sidebar-item-title {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tl-sidebar-item-time {
    color: #6c757d;
}

.tl-main {
    flex-grow: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
}

.tl-empty-pane {
    padding: 48px;
    text-align: center;
    color: #6c757d;
}

.tl-header {
    padding: 12px 16px;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.tl-header-title {
    margin: 0;
    font-size: 1.25rem;
    cursor: pointer;
}

.tl-header-title:hover {
    color: #0d6efd;
}

.tl-header-title-edit {
    flex-grow: 1;
    font-size: 1.25rem;
    padding: 4px 8px;
    border: 1px solid #0d6efd;
    border-radius: 4px;
}

.tl-header-actions {
    display: flex;
    gap: 8px;
}

/* ---- Connection-status pill (issue #122) -------------------- */

.tl-conn-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    font-size: 0.72rem;
    font-weight: 500;
    border-radius: 12px;
    border: 1px solid transparent;
    white-space: nowrap;
    cursor: default;
    margin-right: 8px;
}

.tl-conn-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.tl-conn-live {
    color: #157347;
    background: #d1f0db;
    border-color: #a3dcb6;
}

.tl-conn-warn {
    color: #8a6d10;
    background: #fff3cd;
    border-color: #f5d97a;
}
.tl-conn-warn .tl-conn-dot {
    /* Subtle pulse so the user notices the reconnect attempt. */
    animation: tl-conn-pulse 1.2s ease-in-out infinite;
}

.tl-conn-danger {
    color: #842029;
    background: #f8d7da;
    border-color: #f1aeb5;
}

.tl-conn-muted {
    color: #6c757d;
    background: #f8f9fa;
    border-color: #dee2e6;
}

@keyframes tl-conn-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* ---- Usage badge (token / context indicator) -------------------- */

.tl-usage-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.75rem;
    color: #495057;
    padding: 2px 8px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    white-space: nowrap;
    cursor: default;
    margin-left: auto;
    margin-right: 8px;
}

.tl-usage-context {
    font-weight: 600;
}

.tl-usage-context.tl-usage-ok    { color: #198754; }
.tl-usage-context.tl-usage-warn  { color: #b88600; }
.tl-usage-context.tl-usage-danger{ color: #dc3545; }

.tl-usage-pct {
    font-weight: 400;
    margin-left: 2px;
    opacity: 0.85;
}

.tl-usage-sep {
    color: #adb5bd;
}

.tl-usage-cached {
    color: #6c757d;
}

.tl-usage-cost {
    color: #155724;
    background: #e9f7ef;
    padding: 1px 6px;
    border-radius: 8px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.tl-timeline {
    flex-grow: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tl-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    max-width: 80%;
    word-wrap: break-word;
}

/* Issue #124: Virtualize off-viewport placeholder. Same default
   height as <Virtualize>'s ItemSize hint so the scrollbar stays
   stable as items materialize. */
.tl-bubble-placeholder {
    height: 80px;
}

.tl-bubble-user {
    align-self: flex-end;
    background: #0d6efd;
    color: white;
}

.tl-bubble-assistant {
    align-self: flex-start;
    background: #f1f3f5;
    color: #212529;
}

.tl-bubble-tool-result {
    align-self: flex-start;
    background: #fff3cd;
    border: 1px solid #ffe69c;
    max-width: 90%;
}

.tl-bubble-tool-result.tl-tool-result-error {
    background: #f8d7da;
    border-color: #f5c2c7;
}

.tl-tool-result-header {
    color: #6c757d;
    margin-bottom: 4px;
}

.tl-tool-result-content {
    margin: 0;
    white-space: pre-wrap;
    font-size: 0.9rem;
}

.tl-bubble-unknown {
    align-self: stretch;
    background: #f8d7da;
    color: #842029;
}

.tl-tool-chip {
    align-self: flex-start;
    max-width: 90%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    background: white;
}

.tl-tool-chip-header {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

.tl-tool-chip-name {
    font-weight: 500;
    font-family: ui-monospace, monospace;
}

.tl-tool-chip-status {
    color: #6c757d;
    font-size: 0.8rem;
}

.tl-tool-chip-toggle {
    margin-left: auto;
    color: #6c757d;
}

.tl-tool-chip.tl-tool-running {
    border-color: #ffe69c;
    background: #fff8e1;
}

.tl-tool-chip.tl-tool-done {
    border-color: #badbcc;
    background: #d1e7dd;
}

.tl-tool-chip.tl-tool-error {
    border-color: #f5c2c7;
    background: #f8d7da;
}

.tl-tool-chip-result-label,
.tl-tool-chip-args-label {
    margin: 8px 0 2px 0;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6c757d;
    font-weight: 600;
}

.tl-tool-chip-result {
    margin: 0;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
    max-height: 300px;
    overflow-y: auto;
    font-size: 0.85rem;
    white-space: pre-wrap;
}

.tl-tool-chip-args {
    margin-top: 8px;
}

.tl-tool-chip-args-body {
    margin: 0;
    padding: 8px;
    background: #eef2f7;
    border-left: 3px solid #6f7780;
    border-radius: 4px;
    max-height: 220px;
    overflow: auto;
    font-size: 0.78rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    white-space: pre;
}

.tl-tool-chip-args-truncated {
    display: block;
    margin-top: 4px;
    color: #6c757d;
    font-style: italic;
}

.tl-tool-chip-progress {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tl-tool-chip-progress-bar {
    height: 4px;
    background: #e9ecef;
    border-radius: 2px;
    overflow: hidden;
}

.tl-tool-chip-progress-fill {
    height: 100%;
    background: #0d6efd;
    transition: width 0.2s ease-out;
}

.tl-tool-chip-progress-text {
    color: #6c757d;
    font-family: ui-monospace, monospace;
    font-size: 0.75rem;
}

.tl-typing-dots {
    display: inline-flex;
    gap: 4px;
}

.tl-typing-dots span {
    width: 6px;
    height: 6px;
    background: #6c757d;
    border-radius: 50%;
    animation: tl-typing 1.4s infinite ease-in-out;
}

.tl-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.tl-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes tl-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.tl-cursor {
    color: #0d6efd;
    animation: tl-blink 1s infinite step-end;
}

@keyframes tl-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.tl-busy-indicator {
    align-self: flex-start;
    color: #6c757d;
    font-style: italic;
    padding: 4px 12px;
}

/* Issue #121: sticky pill the Timeline shows when the user has
   scrolled up + new content streamed in. Anchored bottom-right of
   the .tl-timeline scroll viewport. */
.tl-new-below-pill {
    position: sticky;
    bottom: 16px;
    align-self: center;
    background: #0d6efd;
    color: white;
    border: none;
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 0.85rem;
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.35);
    cursor: pointer;
    z-index: 5;
    animation: tl-pill-fade-in 0.2s ease-out;
}

.tl-new-below-pill:hover {
    background: #0b5ed7;
}

@keyframes tl-pill-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.tl-banner {
    padding: 10px 14px;
    border-radius: 8px;
    margin: 0 4px;
}

.tl-banner-error {
    background: #f8d7da;
    color: #842029;
    border: 1px solid #f5c2c7;
}

.tl-composer {
    border-top: 1px solid #dee2e6;
    padding: 12px 16px;
    background: #f8f9fa;
}

.tl-composer-hint {
    color: #6c757d;
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.tl-composer-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.tl-composer-textarea {
    flex-grow: 1;
    resize: vertical;
    min-height: 48px;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #ced4da;
    font-family: inherit;
}

.tl-composer-textarea:focus {
    outline: none;
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.tl-composer-send {
    flex-shrink: 0;
    min-width: 80px;
}

.tl-form-host {
    align-self: stretch;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 16px;
    margin: 8px 0;
}

/* FormRenderer overrides (the component itself uses .form-renderer-*) */
.form-renderer .form-field {
    margin-bottom: 12px;
}

.form-renderer label {
    display: block;
    font-weight: 500;
    margin-bottom: 4px;
}

.form-renderer .required-marker {
    color: #dc3545;
}

.form-renderer .form-control {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
}

.form-renderer .form-field-help {
    display: block;
    color: #6c757d;
    margin-top: 4px;
}

.form-renderer .form-field-stub {
    color: #6c757d;
    font-style: italic;
    padding: 8px;
    background: #fff3cd;
    border-radius: 4px;
}

.form-renderer .form-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.form-renderer-error {
    color: #842029;
    background: #f8d7da;
    border: 1px solid #f5c2c7;
    padding: 12px;
    border-radius: 8px;
}

.form-renderer-empty {
    color: #6c757d;
    font-style: italic;
    padding: 12px;
}

/* ---- Diagnostic pane (right) -------------------------------------- */

.tl-main-with-logs {
    /* Shrink the main pane when the right-pane diagnostics is open
       so the chat doesn't overflow. */
    flex-grow: 1;
    min-width: 0;
}

.tl-diagnostics {
    width: 36%;
    min-width: 320px;
    max-width: 560px;
    flex-shrink: 0;
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tl-diagnostics-header {
    padding: 10px 12px;
    border-bottom: 1px solid #dee2e6;
    background: #f8f9fa;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.tl-diagnostics-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tl-diag-card {
    border: 1px solid #dee2e6;
    border-left-width: 3px;
    border-radius: 4px;
    padding: 6px 8px;
    background: #fff;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.78rem;
}

.tl-diag-card.tl-diag-info { border-left-color: #6c757d; }
.tl-diag-card.tl-diag-warn { border-left-color: #ffc107; background: #fff8e1; }
.tl-diag-card.tl-diag-error { border-left-color: #dc3545; background: #fdf1f2; }

.tl-diag-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    cursor: pointer;
}

.tl-diag-time {
    color: #6c757d;
    font-size: 0.72rem;
}

.tl-diag-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    color: #fff;
}

.tl-diag-badge-info { background: #6c757d; }
.tl-diag-badge-warn { background: #ffc107; color: #212529; }
.tl-diag-badge-error { background: #dc3545; }

.tl-diag-tool {
    color: #495057;
}

.tl-diag-toggle {
    margin-left: auto;
    color: #6c757d;
    font-size: 0.7rem;
}

.tl-diag-summary {
    margin-top: 2px;
    color: #495057;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tl-diag-summary.expanded {
    white-space: pre-wrap;
}

.tl-diag-payload {
    margin: 6px 0 0 0;
    padding: 6px 8px;
    background: #f1f3f5;
    border-radius: 4px;
    max-height: 320px;
    overflow: auto;
    font-size: 0.72rem;
    white-space: pre;
}
