/* =========================================================
   RAG Chat UI — app.css
   Argha - 2026-03-03 - #11 - Redesigned for modern SaaS aesthetic
   All token values come from design-system.css
   ========================================================= */

/* ─── Layout shell ──────────────────────────────────────────────────── */
html, body {
    height: 100%;
    overflow: hidden;
}

.page-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.page-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.page-body-scroll {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-6) var(--space-8);
    background: var(--bg-base);
}

/* ─── Navbar overrides ──────────────────────────────────────────────── */
/* Argha - 2026-02-21 - Commented: old Bootstrap dark navbar styles */
/* .navbar { background-color: #212529; } */
.navbar.navbar-modern {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
    height: var(--navbar-height);
    padding: 0 var(--space-6);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    text-decoration: none;
    font-size: var(--text-lg);
    font-weight: var(--weight-bold);
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.01em;
}

.nav-brand-icon {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-link-modern {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-secondary) !important;
    text-decoration: none;
    transition: all var(--transition-fast);
}
.nav-link-modern:hover {
    background: var(--bg-subtle);
    color: var(--text-primary) !important;
}
.nav-link-modern.active {
    background: var(--primary-light);
    color: var(--primary) !important;
    font-weight: var(--weight-semibold);
}
.nav-link-modern svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* ─── Footer ────────────────────────────────────────────────────────── */
.app-footer {
    padding: var(--space-3) var(--space-6);
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-align: center;
    flex-shrink: 0;
}

/* ─── Chat layout ─────────────────────────────────────────────────── */
.chat-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Sidebar */
.chat-sidebar {
    width: 272px;
    min-width: 272px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
    overflow-y: auto;
    background: var(--bg-subtle);
}

.conv-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

/* Conversation item */
.conv-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    cursor: pointer;
    border: 1px solid transparent;
    background: var(--bg-surface);
    transition: all var(--transition-base);
    position: relative;
}
.conv-item:hover {
    border-color: var(--border);
    box-shadow: var(--shadow-xs);
}
.conv-item.active {
    border-color: var(--primary-mid);
    background: var(--primary-light);
    border-left: 3px solid var(--primary);
}
.conv-info {
    flex: 1;
    min-width: 0;
}
.conv-title {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}
.conv-date {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 1px;
}
.conv-delete {
    opacity: 0;
    transition: opacity var(--transition-fast);
    flex-shrink: 0;
}
.conv-item:hover .conv-delete {
    opacity: 1;
}

/* Chat panel */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-base);
}

/* Empty state */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-12) var(--space-8);
}

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}
.message.user {
    align-self: flex-end;
    align-items: flex-end;
}
.message.assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.bubble {
    padding: var(--space-3) var(--space-4);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.6;
    font-size: var(--text-md);
}
.message.user .bubble {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: var(--text-inverse);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-xs) var(--radius-lg);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}
.message.assistant .bubble {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-xs);
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
}

/* Typing indicator */
.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: var(--space-3) var(--space-4);
}
.typing-dots span {
    width: 7px;
    height: 7px;
    background: var(--primary-mid);
    border-radius: 50%;
    animation: dot-bounce 1.2s ease-in-out infinite;
    display: inline-block;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-6px); }
}

/* Argha - 2026-02-21 - Commented: old blink cursor; replaced by dot-bounce */
/* .typing-cursor { animation: blink 0.8s step-end infinite; } */

/* Sources panel */
.sources-panel {
    margin-top: var(--space-2);
    font-size: var(--text-sm);
    max-width: 520px;
    width: 100%;
}
.sources-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) 0;
    color: var(--primary);
    cursor: pointer;
    user-select: none;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    list-style: none;
    background: none;
    border: none;
}
.sources-toggle:hover {
    color: var(--primary-hover);
}
.source-item {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary-mid);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: var(--space-3);
    margin-top: var(--space-2);
    transition: border-left-color var(--transition-fast);
}
.source-item:hover {
    border-left-color: var(--primary);
}
.source-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-1);
}
.source-filename {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.source-score {
    font-size: var(--text-xs);
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}
.source-text {
    color: var(--text-secondary);
    font-size: var(--text-xs);
    margin: 0;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Input area */
.input-area {
    padding: var(--space-4) var(--space-5);
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
}
.input-area-inner {
    display: flex;
    align-items: flex-end;
    gap: var(--space-3);
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.input-area-inner:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
    background: var(--bg-surface);
}
.input-area-inner textarea {
    flex: 1;
    resize: none;
    border: none;
    background: transparent;
    font-family: var(--font-sans);
    font-size: var(--text-md);
    color: var(--text-primary);
    line-height: 1.5;
    outline: none;
    padding: 0;
    max-height: 160px;
    overflow-y: auto;
}
.input-area-inner textarea::placeholder {
    color: var(--text-muted);
}
.send-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: var(--text-inverse);
    border: none;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}
.send-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--primary-hover), var(--primary-active));
    transform: scale(1.08);
}
.send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}
.input-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: var(--space-1);
    padding: 0 var(--space-4);
}

/* ─── Documents page ─────────────────────────────────────────────── */

/* Upload zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-10) var(--space-8);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-base);
    background: var(--bg-surface);
    position: relative;
}
.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}
.upload-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}
.upload-zone-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-3);
    color: var(--primary);
}
.upload-zone-title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    margin: 0 0 var(--space-1);
}
.upload-zone-sub {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin: 0 0 var(--space-4);
}

/* Document card grid */
.docs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-4);
    margin-top: var(--space-5);
}

.doc-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: box-shadow var(--transition-base), transform var(--transition-base);
}
.doc-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.doc-card-status-bar {
    height: 3px;
    flex-shrink: 0;
}
.doc-card-status-bar.completed { background: var(--success); }
.doc-card-status-bar.processing { background: var(--warning); }
.doc-card-status-bar.failed    { background: var(--danger); }

.doc-card-body {
    padding: var(--space-4);
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}
.doc-card-header {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
}
.doc-card-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--bg-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-secondary);
}
.doc-card-name {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    line-height: 1.4;
    word-break: break-all;
    flex: 1;
}
.doc-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--text-xs);
    color: var(--text-muted);
}
.doc-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
}
.doc-card-footer {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-subtle);
}
.doc-card-date {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* Tag filter bar */
.filter-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

/* ─── Health page ─────────────────────────────────────────────────── */

/* Status banner (glassmorphism effect) */
.health-banner {
    border-radius: var(--radius-lg);
    padding: var(--space-6) var(--space-8);
    margin-bottom: var(--space-6);
    display: flex;
    align-items: center;
    gap: var(--space-5);
    position: relative;
    overflow: hidden;
}
.health-banner.healthy {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    border: 1px solid #6ee7b7;
}
.health-banner.degraded {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 1px solid #fcd34d;
}
.health-banner.unhealthy {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border: 1px solid #fca5a5;
}
.health-banner-icon {
    font-size: 2.5rem;
    line-height: 1;
    flex-shrink: 0;
}
.health-banner-content {}
.health-banner-status {
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    margin: 0 0 var(--space-1);
}
.health-banner-meta {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin: 0;
}
.health-banner-actions {
    margin-left: auto;
    flex-shrink: 0;
}

/* Health dependency card */
.health-dep-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow var(--transition-base);
}
.health-dep-card:hover {
    box-shadow: var(--shadow-md);
}
.health-dep-card-accent {
    height: 100%;
    display: flex;
    flex-direction: column;
    border-left: 4px solid transparent;
}
.health-dep-card-accent.healthy  { border-left-color: var(--success); }
.health-dep-card-accent.degraded { border-left-color: var(--warning); }
.health-dep-card-accent.unhealthy{ border-left-color: var(--danger); }

.health-dep-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-4) var(--space-3);
}
.health-dep-name {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-size: 0.7rem;
}
.health-dep-body {
    padding: 0 var(--space-4) var(--space-4);
    flex: 1;
}
.health-dep-desc {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin: 0 0 var(--space-2);
}
.health-dep-latency {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin: 0;
}
.health-dep-error {
    font-size: var(--text-xs);
    color: var(--danger-text);
    background: var(--danger-light);
    border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-3);
    margin-top: var(--space-2);
    word-break: break-word;
}

/* ─── Blazor error UI ─────────────────────────────────────────────── */
#blazor-error-ui {
    background: var(--warning-light);
    border-top: 2px solid var(--warning);
    bottom: 0;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
    display: none;
    left: 0;
    padding: var(--space-3) var(--space-6);
    position: fixed;
    width: 100%;
    z-index: 9999;
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--warning-text);
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 1rem;
    top: 0.6rem;
}
