@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    color-scheme: light;
    font-family: 'Inter', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background-color: #edf1f7;
    --surface: rgba(255, 255, 255, 0.76);
    --surface-strong: rgba(255, 255, 255, 0.92);
    --outline: rgba(34, 78, 139, 0.12);
    --accent: #2151a4;
    --accent-soft: rgba(33, 81, 164, 0.1);
    --text-strong: #0f2142;
    --text-soft: #4a5b7c;
    --radius-xl: 32px;
    --radius-lg: 20px;
    --radius-md: 14px;
    --shadow-lg: 0 35px 60px -25px rgba(21, 52, 96, 0.35);
    --shadow-md: 0 20px 45px rgba(26, 61, 117, 0.15);
}

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

body {
    margin: 0;
    min-height: 100vh;
    padding: 36px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 10% 20%, #ffffff 0%, #eef3fb 45%, #dce4f4 100%);
    color: var(--text-strong);
}

.app-shell {
    width: min(1080px, 95vw);
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 32px;
    border-radius: var(--radius-xl);
    background: var(--surface);
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(33, 81, 164, 0.08);
}

.app-header {
    display: flex;
    gap: 16px;
    align-items: center;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(33, 81, 164, 0.08);
}

.avatar {
    width: 72px;
    height: 72px;
    min-width: 72px;
    border-radius: 50%;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 18px 36px rgba(47, 111, 211, 0.32);
    background: rgba(255, 255, 255, 0.35);
    border: 1px solid rgba(122, 173, 255, 0.4);
}

.avatar svg {
    width: 100%;
    height: 100%;
}

.header-copy h1 {
    margin: 0;
    font-size: 1.75rem;
    letter-spacing: -0.015em;
    font-weight: 700;
}

.header-copy p {
    margin: 6px 0 0;
    font-size: 0.95rem;
    color: var(--text-soft);
}

.app-body {
    display: grid;
    grid-template-columns: minmax(0, 2.6fr) minmax(260px, 1fr);
    gap: 24px;
    align-items: stretch;
}

.chat-column {
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-height: 0;
}

.chat-window-wrapper {
    flex: 1;
    min-height: 360px;
    background: var(--surface-strong);
    border-radius: var(--radius-lg);
    border: 1px solid var(--outline);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45), var(--shadow-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-thread {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 24px 22px;
    overflow-y: auto;
}

.chat-window {
    display: none;
}

.message-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 88%;
}

.message-row.user {
    align-self: flex-start;
}

.message-row.assistant {
    align-self: flex-end;
}

.message-author {
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-soft);
}

.message-bubble {
    padding: 14px 16px;
    border-radius: 18px;
    box-shadow: 0 12px 28px rgba(31, 65, 120, 0.12);
    line-height: 1.55;
    white-space: pre-wrap;
    font-size: 0.96rem;
}

.message-row.user .message-bubble {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(33, 81, 164, 0.12);
    color: var(--text-strong);
}

.message-row.assistant .message-bubble {
    background: linear-gradient(135deg, rgba(33, 81, 164, 0.16), rgba(72, 163, 255, 0.28));
    border: 1px solid rgba(33, 81, 164, 0.18);
    color: var(--text-strong);
}

.message-metadata {
    font-size: 0.72rem;
    color: var(--text-soft);
}

.header-actions {
    margin-left: auto;
    display: flex;
    gap: 10px;
    align-items: center;
}

.header-button {
    padding: 10px 16px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(33, 81, 164, 0.18);
    background: rgba(255, 255, 255, 0.92);
    color: var(--text-strong);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.header-button:focus {
    outline: none;
    border-color: rgba(33, 81, 164, 0.45);
    box-shadow: 0 0 0 4px rgba(33, 81, 164, 0.1);
}

.header-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(52, 132, 233, 0.18);
}

.status-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--accent-soft);
    color: var(--text-strong);
    border-radius: 999px;
    font-size: 0.85rem;
    border: 1px solid rgba(33, 81, 164, 0.15);
}

.composer {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.composer textarea {
    padding: 14px 16px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(33, 81, 164, 0.18);
    background: rgba(255, 255, 255, 0.92);
    font-size: 1rem;
    color: var(--text-strong);
    resize: vertical;
    min-height: 60px;
    max-height: 220px;
    transition: border 0.2s ease, box-shadow 0.2s ease;
}

.composer textarea:focus {
    outline: none;
    border-color: rgba(33, 81, 164, 0.45);
    box-shadow: 0 0 0 4px rgba(33, 81, 164, 0.1);
}

.composer-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

.chat-more-btn {
    align-self: flex-start;
    margin-left: 22px;
    margin-bottom: 8px;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(33, 81, 164, 0.24);
    background: rgba(255, 255, 255, 0.92);
    color: var(--text-strong);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.chat-more-btn:focus {
    outline: none;
    border-color: rgba(33, 81, 164, 0.45);
    box-shadow: 0 0 0 4px rgba(33, 81, 164, 0.1);
}

.chat-more-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(52, 132, 233, 0.23);
}

.icon-button {
    border: 1px solid rgba(33, 81, 164, 0.18);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.92);
    color: var(--text-strong);
    font-size: 1.1rem;
    padding: 10px 14px;
    cursor: pointer;
    transition: border 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease, opacity 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-button:focus {
    outline: none;
    border-color: rgba(33, 81, 164, 0.45);
    box-shadow: 0 0 0 4px rgba(33, 81, 164, 0.1);
}

.icon-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.icon-button:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(52, 132, 233, 0.18);
}

.icon-button.active {
    border-color: rgba(33, 81, 164, 0.6);
    box-shadow: 0 0 0 4px rgba(33, 81, 164, 0.18);
    background: linear-gradient(135deg, rgba(74, 165, 255, 0.22), rgba(48, 102, 214, 0.28));
}

.action-selector,
.helper-selector {
    appearance: none;
    border: 1px solid rgba(33, 81, 164, 0.18);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.92);
    font-size: 0.92rem;
    color: var(--text-strong);
    cursor: pointer;
    transition: border 0.2s ease, box-shadow 0.2s ease;
}

.action-selector:focus,
.helper-selector:focus {
    outline: none;
    border-color: rgba(33, 81, 164, 0.45);
    box-shadow: 0 0 0 4px rgba(33, 81, 164, 0.1);
}

#send-button {
    border: none;
    border-radius: var(--radius-md);
    padding: 11px 20px;
    font-weight: 600;
    font-size: 0.95rem;
    background: linear-gradient(135deg, #2151a4, #48a0f8);
    color: #ffffff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 14px 30px rgba(52, 132, 233, 0.28);
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

#send-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

#send-button:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: 0 18px 36px rgba(52, 132, 233, 0.35);
}

.insight-column {
    display: flex;
    flex-direction: column;
}

.insight-grid {
    display: grid;
    gap: 16px;
}

.insight-card {
    background: var(--surface-strong);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    border: 1px solid var(--outline);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.card-badge {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.01em;
}

.card-icon {
    font-size: 1.2rem;
}

.card-content {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.45;
    color: var(--text-soft);
    white-space: pre-wrap;
}

.self-heal-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    white-space: normal;
    max-height: 240px;
    overflow-y: auto;
}

.self-heal-empty {
    text-align: center;
    font-size: 0.84rem;
    color: var(--text-soft);
    padding: 8px 0;
}

.self-heal-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.self-heal-item {
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--outline);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    box-shadow: var(--shadow-md);
}

.self-heal-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.self-heal-title {
    font-weight: 600;
    color: var(--text-strong);
    font-size: 0.95rem;
}

.self-heal-status-tag {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 999px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    background: var(--accent-soft);
    color: var(--accent);
}

.self-heal-progress-track {
    position: relative;
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: rgba(33, 81, 164, 0.12);
    overflow: hidden;
    margin-bottom: 8px;
}

.self-heal-progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, #4aa8ff, #2151a4);
    transition: width 0.3s ease;
}

.self-heal-meta {
    font-size: 0.82rem;
    color: var(--text-soft);
    margin-bottom: 6px;
}

.self-heal-message {
    font-size: 0.82rem;
    color: var(--text-strong);
    white-space: pre-wrap;
}

.self-heal-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 10px;
}

.self-heal-spinner {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 3px solid rgba(33, 81, 164, 0.22);
    border-top-color: rgba(33, 81, 164, 0.75);
    animation: spin 0.75s linear infinite;
}

.self-heal-accept-btn {
    border: 1px solid rgba(33, 81, 164, 0.28);
    border-radius: var(--radius-md);
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--text-strong);
    font-size: 0.85rem;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border 0.2s ease, opacity 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.self-heal-accept-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.self-heal-accept-btn:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(52, 132, 233, 0.18);
}

.self-heal-accept-btn.loading {
    position: relative;
    color: transparent;
}

.self-heal-accept-btn.loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(33, 81, 164, 0.25);
    border-top-color: rgba(33, 81, 164, 0.75);
    animation: spin 0.6s linear infinite;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.self-heal-accept-btn.success {
    background: linear-gradient(135deg, #2bb673, #1f8f55);
    border-color: rgba(31, 143, 85, 0.9);
    color: #ffffff;
}

.status-success {

.status-success {
    background: rgba(82, 170, 111, 0.18);
    color: #2d7c4b;
}

.status-danger {
    background: rgba(220, 82, 82, 0.18);
    color: #b13e3e;
}

.status-info {
    background: rgba(66, 133, 244, 0.16);
    color: #2151a4;
}

.status-warning {
    background: rgba(239, 180, 47, 0.22);
    color: #8a5b0b;
}

.status-muted {
    background: rgba(87, 100, 126, 0.12);
    color: #4a5b7c;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.auth-gate {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, rgba(20, 33, 61, 0.8), rgba(20, 33, 61, 0.55));
    backdrop-filter: blur(8px);
    transition: opacity 0.3s ease;
    padding: 24px;
    z-index: 100;
}

.auth-gate.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.auth-card {
    max-width: 360px;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: 0 25px 60px rgba(17, 31, 61, 0.35);
    text-align: center;
    color: var(--text-strong);
}

.auth-card h2 {
    margin: 0 0 12px;
    font-size: 1.45rem;
}

.auth-card p {
    margin: 0 0 20px;
    color: var(--text-soft);
    line-height: 1.45;
}

#auth-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

#auth-password {
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(33, 81, 164, 0.25);
    background: rgba(255, 255, 255, 0.9);
    font-size: 1rem;
    color: var(--text-strong);
}

#auth-password:focus {
    outline: none;
    border-color: rgba(33, 81, 164, 0.55);
    box-shadow: 0 0 0 4px rgba(33, 81, 164, 0.12);
}

#auth-form button {
    padding: 12px;
    border: none;
    border-radius: var(--radius-md);
    background: linear-gradient(125deg, #2151a4, #4fa3ff);
    color: #ffffff;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#auth-form button:hover {
    transform: translateY(-1px);
    box-shadow: 0 18px 32px rgba(33, 81, 164, 0.3);
}

.auth-error {
    min-height: 18px;
    margin: 0;
    color: #d74242;
    font-size: 0.85rem;
}

@media (max-width: 980px) {
    body {
        padding: 18px 12px;
    }
    .app-shell {
        padding: 22px;
        gap: 20px;
    }
    .app-body {
        grid-template-columns: 1fr;
        gap: 18px;
    }
    .insight-column {
        order: -1;
    }
    .chat-window-wrapper {
        min-height: 320px;
    }
    .header-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 8px;
    }
}

@media (max-width: 640px) {
    .composer-controls {
        flex-wrap: wrap;
    }
    #send-button {
        width: 100%;
        justify-content: center;
    }
    .status-chip {
        flex: 1 1 auto;
        justify-content: center;
    }
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

#toast-container {
    position: fixed;
    bottom: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1200;
    pointer-events: none;
}

.toast {
    min-width: 220px;
    background: rgba(32, 35, 45, 0.95);
    color: #ffffff;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: auto;
    font-size: 0.9rem;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    border-left: 4px solid #2ecc71;
}

.toast-error {
    border-left: 4px solid #e74c3c;
}

.process-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.process-item {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid rgba(33, 81, 164, 0.14);
    border-left: 4px solid rgba(33, 81, 164, 0.2);
    border-radius: var(--radius-md);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(240, 246, 255, 0.8));
    padding: 10px 12px;
}

.process-item.is-ok {
    border-left-color: #2ecc71;
}

.process-item.is-fail {
    border-left-color: #e74c3c;
}

.process-indicator {
    font-size: 1.1rem;
    line-height: 1;
}

.process-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.process-name {
    font-weight: 600;
    color: var(--text-strong);
}

.process-meta {
    font-size: 0.78rem;
    color: var(--text-soft);
}

.process-action {
    border: 1px solid rgba(33, 81, 164, 0.22);
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, rgba(33, 81, 164, 0.08), rgba(33, 81, 164, 0.18));
    color: var(--text-strong);
    font-size: 0.78rem;
    padding: 6px 12px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.process-action:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(33, 81, 164, 0.18);
}

.process-action:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
