/*
 * Design system based on docs/style_guide.md
 * IBM color-blind safe palette, Inter font, glassmorphism auth
 */

/* CSS Reset & Variables */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* IBM color-blind safe palette */
    --color-primary: #785ef0;
    --color-primary-dark: #5a3fd8;
    --color-primary-light: rgba(120, 94, 240, 0.08);

    --color-success: #059669;
    --color-warning: #ffb000;
    --color-error: #DC2626;

    --color-bg: #f9fafb;
    --color-bg-card: #FFFFFF;
    --color-bg-dark: #0A2540;
    --color-bg-sidebar: #1e2433;

    --color-text: #425466;
    --color-text-dark: #0A2540;
    --color-text-light: #9CA3AF;
    --color-text-inverse: #FFFFFF;

    --color-border: #e5e7eb;
    --color-border-focus: #785ef0;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.04), 0 2px 4px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.04), 0 4px 6px rgba(0, 0, 0, 0.02);
    --shadow-focus: 0 0 0 3px rgba(120, 94, 240, 0.1);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SF Mono', Monaco, Consolas, monospace;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

[x-cloak] {
    display: none !important;
}

/* ================================
   AUTH PAGES (Login)
   ================================ */

.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-lg);
    position: relative;
    overflow: hidden;
    background: #0f1117;
}

.auth-background {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
}

.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.5;
}

.orb-1 {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, #785ef0, transparent 70%);
    top: -250px;
    right: -150px;
    animation: float 20s ease-in-out infinite;
}

.orb-2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, #648fff, transparent 70%);
    bottom: -200px;
    left: -150px;
    animation: float 25s ease-in-out infinite reverse;
}

.orb-3 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, #dc267f, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: pulse 15s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(30px, -30px); }
}

@keyframes pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.5; }
    50% { transform: translate(-50%, -50%) scale(1.15); opacity: 0.3; }
}

.auth-card {
    position: relative;
    z-index: 1;
    background: #FFFFFF;
    border-radius: var(--radius-xl);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    padding: var(--space-2xl);
    width: 100%;
    max-width: 420px;
}

.auth-header {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.logo {
    margin-bottom: var(--space-lg);
}

.auth-header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--color-text-dark);
    margin-bottom: var(--space-sm);
}

.subtitle {
    color: var(--color-text-light);
    font-size: 0.95rem;
}

.form-group {
    margin-bottom: var(--space-lg);
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-dark);
    margin-bottom: var(--space-sm);
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    font-size: 15px;
    font-family: var(--font-sans);
    color: var(--color-text-dark);
    background: var(--color-bg-card);
    transition: var(--transition-fast);
}

.form-group input:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: var(--shadow-focus);
}

.form-group input::placeholder {
    color: var(--color-text-light);
}

.btn-primary {
    width: 100%;
    padding: 12px 20px;
    background: var(--color-primary);
    color: var(--color-text-inverse);
    border: none;
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.error-message {
    background: #FEF2F2;
    border: 1px solid #FECACA;
    color: var(--color-error);
    padding: var(--space-md);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-lg);
    font-size: 0.875rem;
    text-align: center;
}

.auth-footer {
    margin-top: var(--space-xl);
    text-align: center;
}

.demo-credentials {
    font-size: 0.8rem;
    color: var(--color-text-light);
}

.demo-credentials code {
    background: var(--color-bg);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

/* Loading spinner */
.loading-spinner {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.spinner {
    width: 20px;
    height: 20px;
    animation: rotate 1.5s linear infinite;
}

@keyframes rotate {
    100% { transform: rotate(360deg); }
}

/* ================================
   MAIN APP LAYOUT
   ================================ */

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--color-bg-sidebar);
    color: var(--color-text-inverse);
    display: flex;
    flex-direction: column;
    transition: var(--transition-normal);
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar.collapsed {
    width: 72px;
}

.sidebar-header {
    padding: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.app-name {
    font-weight: 600;
    font-size: 1.125rem;
    white-space: nowrap;
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-md);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: var(--transition-fast);
    margin-bottom: var(--space-sm);
    background: transparent;
    border: none;
    width: 100%;
    cursor: pointer;
    font-size: 0.875rem;
    font-family: var(--font-sans);
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--color-text-inverse);
}

.nav-item.active {
    background: var(--color-primary);
    color: var(--color-text-inverse);
}

.sidebar-footer {
    padding: var(--space-lg);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--color-text-inverse);
    flex-shrink: 0;
}

.username {
    font-size: 0.875rem;
    opacity: 0.9;
}

.logout-btn {
    color: rgba(255, 255, 255, 0.5);
    background: transparent;
    border: none;
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.logout-btn:hover {
    color: var(--color-text-inverse);
    background: rgba(255, 255, 255, 0.08);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    transition: var(--transition-normal);
}

.sidebar.collapsed + .main-content,
.sidebar.collapsed ~ .main-content {
    margin-left: 72px;
}

.main-header {
    padding: var(--space-md) var(--space-xl);
    background: var(--color-bg-card);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.toggle-sidebar {
    background: transparent;
    border: none;
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--color-text);
    transition: var(--transition-fast);
}

.toggle-sidebar:hover {
    background: var(--color-bg);
}

.main-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text-dark);
}

/* Query Interface */
.query-interface {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: var(--space-xl);
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.query-form-container {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--color-bg);
    padding-bottom: var(--space-lg);
}

.query-input-wrapper {
    display: flex;
    gap: var(--space-md);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: var(--space-md);
    box-shadow: var(--shadow-sm);
    transition: var(--transition-fast);
}

.query-input-wrapper:focus-within {
    border-color: var(--color-border-focus);
    box-shadow: var(--shadow-focus);
}

.query-input-wrapper textarea {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    resize: none;
    min-height: 24px;
    max-height: 200px;
    font-family: var(--font-sans);
    color: var(--color-text-dark);
    background: transparent;
    line-height: 1.5;
}

.query-input-wrapper textarea::placeholder {
    color: var(--color-text-light);
}

.send-btn {
    background: var(--color-primary);
    color: var(--color-text-inverse);
    border: none;
    border-radius: var(--radius-lg);
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover:not(:disabled) {
    background: var(--color-primary-dark);
}

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

/* Responses */
.responses-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
}

.response-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.response-card.animate-in {
    animation: slideIn 0.3s ease;
}

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

.query-bubble,
.response-bubble {
    display: flex;
    gap: var(--space-md);
}

.avatar.user {
    background: var(--color-text-dark);
}

.avatar.ai {
    background: var(--color-primary);
    font-size: 0.75rem;
}

.query-bubble .message,
.response-bubble .message {
    flex: 1;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-xl);
    line-height: 1.6;
    font-size: 0.9375rem;
}

.query-bubble .message {
    background: var(--color-primary-light);
    color: var(--color-text-dark);
}

.response-bubble .message {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    color: var(--color-text);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: var(--space-2xl) var(--space-xl);
    color: var(--color-text-light);
}

.empty-state svg {
    margin-bottom: var(--space-lg);
    opacity: 0.4;
    color: var(--color-primary);
}

.empty-state h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-sm);
}

.empty-state p {
    font-size: 0.875rem;
}

/* History Panel */
.history-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 400px;
    height: 100vh;
    background: var(--color-bg-card);
    border-left: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    padding: var(--space-xl);
    overflow-y: auto;
    z-index: 200;
    transform: translateX(100%);
    transition: var(--transition-normal);
}

.history-panel:not(:empty) {
    transform: translateX(0);
}

.history-list h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-dark);
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-border);
}

.history-item {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-md);
    overflow: hidden;
}

.history-header {
    padding: var(--space-md);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition-fast);
}

.history-header:hover {
    background: var(--color-border);
}

.history-query {
    font-size: 0.875rem;
    color: var(--color-text-dark);
    font-weight: 500;
}

.history-date {
    font-size: 0.75rem;
    color: var(--color-text-light);
}

.history-content {
    padding: var(--space-md);
    border-top: 1px solid var(--color-border);
    font-size: 0.875rem;
}

.history-full-query,
.history-response {
    margin-bottom: var(--space-md);
}

.delete-btn {
    background: transparent;
    border: 1px solid var(--color-error);
    color: var(--color-error);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: var(--transition-fast);
}

.delete-btn:hover {
    background: var(--color-error);
    color: var(--color-text-inverse);
}

.no-history {
    text-align: center;
    color: var(--color-text-light);
    padding: var(--space-xl);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar:not(.collapsed) {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .history-panel {
        width: 100%;
    }
}
