/* ============================================================
   xCavate Web Assistant – Complete Stylesheet
   ============================================================ */

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

/* ---------- Design Tokens ---------- */
:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --muted: #9ca3af;
    --border: #e5e7eb;
    --border-light: #f0f0f3;
    --accent: #2d2b55;
    --accent-light: #4a4880;
    --user-bubble: #2d2b55;
    --user-bubble-text: #ffffff;
    --ai-bubble: #f7f7f9;
    --ai-bubble-border: #e8e8ed;
    --quick-pill-bg: #ffffff;
    --quick-pill-border: #e0e0e5;
    --danger: #ef4444;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-pill: 999px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
    --transition: 0.2s ease;
}

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

html, body {
    width: 100%; height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ---------- Layout ---------- */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100%;
    justify-content: center;
}

/* ---------- Sidebar ---------- */
.sidebar-controls {
    width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 12px;
    overflow: hidden;
    transition: width var(--transition), padding var(--transition);
}
.sidebar-controls.collapsed { width: 0; padding: 0; border-right: none; }

#history-sidebar { height: 100%; }
#chat-history-list {
    list-style: none;
    display: flex; flex-direction: column; gap: 6px;
    height: 100%; overflow-y: auto;
}
#chat-history-list li {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}
#chat-history-list li:hover { border-color: #ccc; background: #fafafa; }
#chat-history-list li.active { border-color: var(--accent); color: var(--text); }

.delete-btn { font-size: 18px; color: var(--muted); transition: color var(--transition); }
.delete-btn:hover { color: var(--danger); }
.chat-info { min-width: 0; display: flex; gap: 8px; align-items: center; }
.chat-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; }
.model-tag { display: none; }

/* ============================================================
   LANDING / HELP PAGE
   ============================================================ */
.landing-page {
    flex: 1;
    max-width: 480px;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

/* Scrollbar styling */
.landing-page::-webkit-scrollbar,
#chat-log::-webkit-scrollbar { width: 4px; }
.landing-page::-webkit-scrollbar-thumb,
#chat-log::-webkit-scrollbar-thumb { background: #d4d4d8; border-radius: 4px; }
.landing-page::-webkit-scrollbar-track,
#chat-log::-webkit-scrollbar-track { background: transparent; }

/* --- Landing Header --- */
.landing-header {
    position: sticky; top: 0; z-index: 20;
    background: var(--surface);
    padding: 24px 20px 16px;
    border-bottom: 1px solid var(--border-light);
}
.landing-header-row {
    display: flex; align-items: center; justify-content: space-between;
}
.landing-title {
    font-size: 22px; font-weight: 700; color: var(--text);
    letter-spacing: -0.3px;
}
.message-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 20px;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius-pill);
    font-size: 13px; font-weight: 600;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}
.message-btn:hover {
    background: var(--accent-light);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
.message-btn:active { transform: translateY(0); }

/* --- Search --- */
.landing-search-wrapper {
    padding: 12px 20px 20px;
}
.landing-search {
    width: 100%;
    padding: 14px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 14px;
    color: var(--text);
    background: #fafafa;
    outline: none;
    transition: all var(--transition);
}
.landing-search::placeholder { color: var(--muted); }
.landing-search:focus {
    border-color: var(--accent);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(45,43,85,0.08);
}

/* --- Sections --- */
.landing-section {
    padding: 8px 20px 20px;
}
.section-title {
    font-size: 14px; font-weight: 600; color: var(--text);
    margin-bottom: 14px;
    letter-spacing: -0.1px;
}

/* --- Self Service Grid --- */
.self-service-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.service-card {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    text-align: left;
    transition: all var(--transition);
    min-height: 72px;
}
.service-card:hover {
    border-color: #ccc;
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}
.service-card:active { transform: translateY(0); }
.service-card-icon {
    width: 36px; height: 36px; min-width: 36px;
    border-radius: 50%;
    background: #e8e8f0;
    display: flex; align-items: center; justify-content: center;
    color: var(--accent);
}
.service-card-label {
    font-size: 13px; line-height: 1.35;
    color: var(--text);
    font-weight: 500;
}

.view-all-btn {
    display: block;
    margin: 14px auto 0;
    padding: 10px 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 13px; font-weight: 500;
    color: var(--text);
    background: var(--surface);
    transition: all var(--transition);
}
.view-all-btn:hover {
    border-color: #bbb;
    background: #fafafa;
}

/* --- Category Columns --- */
.category-columns {
    display: flex; gap: 20px;
    overflow-x: auto;
    padding-bottom: 4px;
}
.category-column { flex: 1; min-width: 180px; }
.category-title {
    font-size: 13px; font-weight: 600; color: var(--text);
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}
.category-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.category-item {
    width: 100%;
    text-align: left;
    padding: 10px 0;
    font-size: 13px; color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
    transition: color var(--transition);
}
.category-item:hover { color: var(--text); }

/* --- FAQ --- */
.faq-list { list-style: none; display: flex; flex-direction: column; gap: 0; }
.faq-item {
    width: 100%;
    text-align: left;
    padding: 12px 0;
    font-size: 13px; color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
    transition: color var(--transition);
}
.faq-item:hover { color: var(--text); }
.faq-item:last-child { border-bottom: none; }

/* ============================================================
   CHAT VIEW
   ============================================================ */
.chat-container {
    flex: 1;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    background: var(--surface);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

/* --- Chat Header --- */
.app-header {
    position: sticky; top: 0; z-index: 20;
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    gap: 8px;
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    padding: 0 12px;
}
.app-header h1 {
    margin: 0; text-align: center;
    font-size: 16px; font-weight: 600;
    letter-spacing: -0.2px;
}

#toggle-sidebar-btn,
#new-chat-btn {
    width: 38px; height: 38px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    display: inline-flex; align-items: center; justify-content: center;
    transition: all var(--transition);
}
#toggle-sidebar-btn:hover,
#new-chat-btn:hover {
    border-color: #ccc;
    background: #f9f9fb;
}
#new-chat-btn { justify-self: end; }

/* --- Welcome State --- */
.welcome-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    flex: 1;
    gap: 16px;
    text-align: center;
    padding: 40px 20px 24px;
}
.welcome-text {
    max-width: 320px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}
.quick-start-grid,
.inline-quick-replies {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    width: 100%;
    max-width: 400px;
}

/* --- Quick Action Buttons (pills) --- */
.quick-action-btn {
    border: 1px solid var(--quick-pill-border);
    background: var(--quick-pill-bg);
    color: var(--text);
    border-radius: var(--radius-pill);
    padding: 9px 16px;
    font-size: 12.5px; font-weight: 500;
    line-height: 1.2;
    text-align: center;
    transition: all var(--transition);
}
.quick-action-btn:hover {
    border-color: #c0c0c8;
    background: #f5f5f8;
    transform: translateY(-1px);
}
.quick-action-btn:active { transform: translateY(0); }

/* --- Chat Log --- */
#chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* --- Messages --- */
.message {
    position: relative;
    max-width: 82%;
    padding: 11px 14px;
    border-radius: var(--radius-lg);
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 13.5px;
    animation: msgAppear 0.25s ease-out;
    margin: 0;
}
.message p:last-child {
    margin-bottom: 0;
}
.message p {
    margin: 0;
}
.ai-message li > p {
    display: inline;
    margin: 0;
}
.ai-message li {
    margin-bottom: 0;
}
@keyframes msgAppear {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* User message — right-aligned, dark bubble with tail */
.user-message {
    align-self: flex-end;
    background: var(--user-bubble);
    color: var(--user-bubble-text);
    border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
}
.user-message::after {
    content: "";
    position: absolute;
    right: -6px; top: 50%;
    transform: translateY(-50%);
    width: 0; height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 7px solid var(--user-bubble);
}

/* AI message — left-aligned, light bubble with tail */
.ai-message {
    align-self: flex-start;
    background: var(--ai-bubble);
    border: 1px solid var(--ai-bubble-border);
    color: var(--text);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
}
.ai-message::before {
    content: "";
    position: absolute;
    left: -6px; top: 50%;
    transform: translateY(-50%);
    width: 0; height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-right: 7px solid var(--ai-bubble-border);
}

/* Typing cursor */
.ai-message .cursor {
    display: inline-block;
    width: 6px; height: 1em;
    background: var(--muted);
    animation: blink 1s step-end infinite;
    vertical-align: text-bottom;
    border-radius: 1px;
}
@keyframes blink {
    from, to { background: transparent; }
    50% { background: var(--muted); }
}

/* Response time */
.response-time-info {
    margin-top: 6px;
    font-size: 11px;
    color: var(--muted);
}

/* --- Inline Quick Replies --- */
.inline-quick-replies {
    align-self: flex-start;
    margin-left: 2px;
    margin-top: 4px;
    margin-bottom: 8px;
    max-width: 360px;
    justify-content: flex-start;
}
.quick-reply-btn { background: #fff; }

/* --- Attachments --- */
.attachment-container {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 8px;
}
.attachment-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface);
    padding: 6px 12px;
    display: inline-flex; align-items: center; gap: 6px;
    max-width: 220px;
    font-size: 12px;
}
.file-icon { width: 14px; height: 14px; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.remove-attachment-btn {
    border: none; background: transparent;
    color: var(--muted); cursor: pointer;
}

/* --- Chat Input --- */
.chat-input-area {
    position: sticky; bottom: 0; z-index: 10;
    background: var(--surface);
    border-top: 1px solid var(--border-light);
    padding: 10px 16px 14px;
}
.metrics-container { display: none; }

#chat-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.prompt-input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

#prompt-input {
    width: 100%;
    min-height: 44px;
    max-height: 180px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: #fafafa;
    color: var(--text);
    font-size: 14px;
    line-height: 1.35;
    padding: 12px 18px;
    outline: none;
    transition: all var(--transition);
}
#prompt-input::placeholder { color: var(--muted); }
#prompt-input:focus {
    border-color: var(--accent);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(45,43,85,0.06);
}

#send-button,
#cancel-button {
    width: 44px; height: 44px; min-width: 44px;
    border-radius: 50%;
    border: 1px solid var(--border);
    display: inline-flex; align-items: center; justify-content: center;
    transition: all var(--transition);
}
#send-button {
    background: var(--surface);
    color: var(--text);
}
#send-button:hover {
    border-color: #ccc;
    background: #f5f5f8;
}
#send-button:disabled {
    background: #f0f0f5;
    cursor: not-allowed;
    color: var(--muted);
}
#send-button svg { pointer-events: none; }

#cancel-button {
    background: var(--surface);
    color: var(--danger);
    font-size: 11px; font-weight: 500;
    border-radius: 50%;
}

/* --- Drop Zone --- */
#drop-zone {
    position: absolute;
    inset: 60px 0 70px;
    border: 2px dashed #bac1d5;
    background: rgba(255,255,255,0.96);
    display: none;
    align-items: center; justify-content: center;
    pointer-events: none;
    border-radius: var(--radius-md);
}
.drop-zone-text {
    color: var(--text-secondary);
    font-size: 15px; text-align: center;
    padding: 0 20px;
}
.chat-container.drag-over #drop-zone {
    display: flex;
    pointer-events: all;
}

/* --- Code blocks in AI messages --- */
.ai-message pre {
    background: #f4f5f9;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    overflow-x: auto;
    font-size: 12.5px;
    margin: 6px 0;
}
.ai-message code {
    background: #f4f5f9;
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 12.5px;
}
.ai-message ul, .ai-message ol {
    padding-left: 18px;
    margin: 6px 0;
}
.ai-message li {
    margin-bottom: 4px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (min-width: 900px) {
    .app-layout { justify-content: center; }
}

@media (max-width: 899px) {
    .sidebar-controls { display: none; }
    .landing-page, .chat-container {
        max-width: 100%;
        border-left: none;
        border-right: none;
    }
}

/* ============================================================
   MCP STATUS INDICATOR
   ============================================================ */
.mcp-status-indicator {
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
    transition: background-color var(--transition);
}
.mcp-status-indicator.mcp-connected {
    background: var(--color-green, #22c55e);
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}
.mcp-status-indicator.mcp-disconnected {
    background: var(--color-gray, #9ca3af);
}

@media (max-width: 480px) {
    .self-service-grid { grid-template-columns: 1fr; }
    .category-columns { flex-direction: column; }
    .landing-header { padding: 20px 16px 12px; }
    .landing-search-wrapper { padding: 8px 16px 16px; }
    .landing-section { padding: 8px 16px 16px; }
}
