/* ============================================
   KILA AI — Premium Chat Interface
   Design System & Styles
   ============================================ */

/* === CSS Variables === */
:root {
    /* Light Theme (Default) */
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --bg-card: rgba(255, 255, 255, 0.95);
    --bg-input: rgba(255, 255, 255, 0.98);
    --bg-hover: rgba(0, 123, 255, 0.06);

    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;

    --accent: #0069d9;
    --accent-light: #3d8bfd;
    --accent-dark: #0050a8;
    --accent-glow: rgba(0, 123, 255, 0.15);
    --accent-subtle: rgba(0, 123, 255, 0.08);

    --border: rgba(0, 0, 0, 0.08);
    --border-hover: rgba(0, 0, 0, 0.15);

    --user-bubble: linear-gradient(135deg, #3d8bfd, #0069d9);
    --user-bubble-solid: #0069d9;
    --bot-bubble: #f9fafb;

    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;

    --sidebar-width: 280px;
    --topbar-height: 56px;
    --input-area-height: auto;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 20px var(--accent-glow);

    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-primary: #0a0a12;
    --bg-secondary: #111118;
    --bg-tertiary: #1a1a28;
    --bg-card: rgba(22, 22, 35, 0.8);
    --bg-input: rgba(22, 22, 35, 0.9);
    --bg-hover: rgba(0, 123, 255, 0.1);

    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-muted: #55556a;

    --accent-glow: rgba(61, 139, 253, 0.2);
    --accent-subtle: rgba(61, 139, 253, 0.12);

    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);

    --bot-bubble: rgba(26, 26, 42, 0.9);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 24px var(--accent-glow);
}

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

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
    transition: background-color var(--transition-base), color var(--transition-base);
}

a {
    color: var(--accent-light);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* ============================================
   Background Canvas
   ============================================ */
#bg-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0.12;
}

[data-theme="dark"] #bg-canvas {
    opacity: 0.35;
}

/* ============================================
   App Layout
   ============================================ */
.app {
    display: flex;
    height: 100vh;
    position: relative;
    z-index: 1;
}

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform var(--transition-slow);
    z-index: 50;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.img-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.logo-icon svg {
    width: 20px;
    height: 20px;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-close {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.sidebar-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* New Chat Button */
.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 16px 8px;
    padding: 12px 16px;
    background: var(--accent-subtle);
    border: 1px dashed var(--accent);
    border-radius: var(--radius-md);
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
}

.new-chat-btn:hover {
    background: var(--bg-hover);
    border-style: solid;
    transform: translateY(-1px);
}

/* Chat History */
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.chat-history::-webkit-scrollbar {
    width: 4px;
}

.chat-history::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 4px;
}

.history-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: 8px 8px 4px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
}

.history-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.history-item.active {
    background: var(--accent-subtle);
    color: var(--accent);
}

.history-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.6;
}

.history-item .delete-btn {
    position: absolute;
    right: 8px;
    opacity: 0;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    transition: all var(--transition-fast);
}

.history-item:hover .delete-btn {
    opacity: 1;
}

.history-item .delete-btn:hover {
    color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

.history-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
    transition: color var(--transition-fast);
}

.sidebar-link:hover {
    color: var(--accent);
    text-decoration: none;
}

.theme-toggle-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.theme-toggle-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-hover);
    background: var(--bg-hover);
}

/* Theme icon visibility — Light mode is default (no data-theme) */
.moon-icon { display: block; }
.sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: block; }

/* ============================================
   Main Content
   ============================================ */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

/* Topbar */
.topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: var(--topbar-height);
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    backdrop-filter: blur(20px);
    flex-shrink: 0;
}

.menu-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.menu-btn:hover {
    background: var(--bg-hover);
}

.topbar-title {
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.topbar-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--success);
    font-weight: 500;
}

.status-dot {
    width: 6px;
    height: 6px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ============================================
   Chat Area
   ============================================ */
.chat-area {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar {
    width: 6px;
}

.chat-area::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 6px;
}

.chat-area::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================
   Welcome Screen
   ============================================ */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
    position: relative;
    animation: fadeIn 0.6s ease;
}

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

.welcome-glow {
    position: absolute;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, var(--accent-glow), transparent 70%);
    border-radius: 50%;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    filter: blur(60px);
    pointer-events: none;
    animation: glow-pulse 4s ease-in-out infinite alternate;
}

@keyframes glow-pulse {
    from { opacity: 0.5; transform: translateX(-50%) scale(1); }
    to { opacity: 0.8; transform: translateX(-50%) scale(1.15); }
}

.welcome-icon {
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    position: relative;
    animation: float 3s ease-in-out infinite;
}

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

.welcome-icon svg {
    width: 40px;
    height: 40px;
}

.welcome-title {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 12px;
    line-height: 1.2;
}

.welcome-title .highlight {
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    max-width: 500px;
    line-height: 1.6;
    margin-bottom: 40px;
}

/* Suggestion Grid */
.suggestion-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-width: 520px;
    width: 100%;
}

.suggestion-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: left;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
    display: flex;
    flex-direction: column;
    gap: 8px;
    backdrop-filter: blur(10px);
}

.suggestion-card:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.suggestion-icon {
    font-size: 1.3rem;
}

.suggestion-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.suggestion-card:hover .suggestion-text {
    color: var(--text-primary);
}

/* ============================================
   Messages
   ============================================ */
.messages-container {
    display: none;
    flex-direction: column;
    padding: 24px;
    gap: 8px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

.messages-container.active {
    display: flex;
}

.message {
    display: flex;
    gap: 12px;
    animation: msgIn 0.3s ease;
    max-width: 100%;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 4px;
}

.message.bot .message-avatar {
    background: var(--user-bubble);
    color: white;
    box-shadow: var(--shadow-glow);
}

.message.user .message-avatar {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.message-avatar svg {
    width: 16px;
    height: 16px;
}

.message-content {
    max-width: 75%;
    min-width: 0;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 0.9rem;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.bot .message-bubble {
    background: var(--bot-bubble);
    border: 1px solid var(--border);
    border-top-left-radius: 4px;
}

.message.user .message-bubble {
    background: var(--user-bubble);
    color: white;
    border-top-right-radius: 4px;
    box-shadow: var(--shadow-glow);
}

/* Message markdown styling */
.message-bubble p {
    margin-bottom: 8px;
}

.message-bubble p:last-child {
    margin-bottom: 0;
}

.message-bubble strong {
    font-weight: 600;
}

.message-bubble a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.message.user .message-bubble a {
    color: rgba(255, 255, 255, 0.9);
}

.message-bubble code {
    background: rgba(0, 0, 0, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
}

[data-theme="dark"] .message-bubble code {
    background: rgba(255, 255, 255, 0.1);
}

.message-bubble ul,
.message-bubble ol {
    padding-left: 20px;
    margin: 8px 0;
}

.message-bubble li {
    margin-bottom: 4px;
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.message.user .message-time {
    text-align: right;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 4px;
}

.typing-dot {
    width: 7px;
    height: 7px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ============================================
   Input Area
   ============================================ */
.input-area {
    padding: 16px 24px 20px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 8px 8px 8px 16px;
    transition: all var(--transition-fast);
    backdrop-filter: blur(20px);
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle), var(--shadow-md);
}

.message-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.5;
    resize: none;
    max-height: 150px;
    min-height: 24px;
    padding: 4px 0;
}

.message-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 40px;
    height: 40px;
    background: var(--user-bubble);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: var(--shadow-glow);
}

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

.send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 4px 0;
}

.char-count {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.powered-by {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.powered-by a {
    color: var(--text-muted);
    font-weight: 500;
    transition: color var(--transition-fast);
}

.powered-by a:hover {
    color: var(--accent);
    text-decoration: none;
}

/* ============================================
   Sidebar Overlay (Mobile)
   ============================================ */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 40;
    opacity: 0;
    transition: opacity var(--transition-base);
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ============================================
   Toast Notification
   ============================================ */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition-base);
    z-index: 100;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.error {
    border-color: var(--error);
    color: var(--error);
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        z-index: 50;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: flex;
    }

    .topbar {
        display: flex;
    }

    .welcome-title {
        font-size: 1.5rem;
    }

    .welcome-subtitle {
        font-size: 0.9rem;
    }

    .suggestion-grid {
        grid-template-columns: 1fr;
        max-width: 360px;
    }

    .messages-container {
        padding: 16px;
    }

    .message-content {
        max-width: 85%;
    }

    .input-area {
        padding: 12px 16px 16px;
    }

    .welcome-screen {
        padding: 24px 16px;
    }

    .welcome-icon {
        width: 64px;
        height: 64px;
    }

    .welcome-icon svg {
        width: 32px;
        height: 32px;
    }
}

@media (max-width: 480px) {
    .suggestion-card {
        padding: 12px;
    }

    .suggestion-text {
        font-size: 0.8rem;
    }

    .message-bubble {
        font-size: 0.85rem;
        padding: 10px 14px;
    }
}

/* ============================================
   Animations
   ============================================ */
@keyframes shimmer {
    0% { background-position: -200px 0; }
    100% { background-position: calc(200px + 100%) 0; }
}

.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--border-hover) 50%, var(--bg-tertiary) 75%);
    background-size: 200px 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
    height: 16px;
    margin-bottom: 8px;
}

.skeleton:last-child {
    width: 60%;
}

/* ============================================
   Scrollbar Global
   ============================================ */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================
   Selection Color
   ============================================ */
::selection {
    background: var(--accent);
    color: white;
}