/* ================================================
   STORETRACK AI CHATBOT - MOBILE-FIRST DESIGN
   ================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ========================
   BASE RESET & VARIABLES
   ======================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    /* Core Colors */
    --primary: #00284E;
    --primary-light: #003d6b;
    --accent: #0066CC;
    --success: #00A651;
    --error: #DC3545;
    --warning: #FFC107;

    /* Greys */
    --grey-50: #FAFBFC;
    --grey-100: #F5F6F7;
    --grey-200: #EBEEF0;
    --grey-300: #D1D5DB;
    --grey-400: #9CA3AF;
    --grey-500: #6B7280;
    --grey-600: #4B5563;
    --grey-700: #374151;
    --grey-800: #1F2937;
    --grey-900: #111827;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Transitions */
    --transition: 0.2s ease;
}

/* ========================
   BODY & LAYOUT
   ======================== */
html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-family);
    background: var(--grey-50);
    color: var(--grey-900);
    position: relative;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    background: white;
}

/* ========================
   HEADER
   ======================== */
.app-header {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* Logo */
.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.logo-mark {
    width: 32px;
    height: 32px;
    background: white;
    color: var(--primary);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
}

.logo-text {
    font-weight: 600;
    font-size: 16px;
    letter-spacing: 0.5px;
}

/* Filter Bar */
.filter-bar {
    display: flex;
    gap: var(--spacing-sm);
}

.filter-input {
    flex: 1;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    font-family: var(--font-family);
    font-size: 14px;
    transition: var(--transition);
}

.filter-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.filter-input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
}

.btn-filter {
    padding: 10px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-filter:active {
    transform: scale(0.98);
}

/* ========================
   CHAT AREA
   ======================== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--grey-50);
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    -webkit-overflow-scrolling: touch;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--grey-300);
    border-radius: 3px;
}

/* Messages */
.message {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message.system {
    justify-content: center;
}

.message-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
}

.message.user .message-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: white;
    color: var(--grey-800);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--grey-200);
    border-bottom-left-radius: 4px;
}

.message.system .message-bubble {
    background: var(--grey-200);
    color: var(--grey-600);
    font-size: 13px;
    padding: 8px 16px;
    border-radius: 20px;
    max-width: fit-content;
}

/* Markdown Styling */
.message.assistant .message-bubble h1,
.message.assistant .message-bubble h2,
.message.assistant .message-bubble h3 {
    margin-top: 16px;
    margin-bottom: 8px;
    color: var(--primary);
    font-weight: 600;
}

.message.assistant .message-bubble p {
    margin: 8px 0;
}

.message.assistant .message-bubble ul,
.message.assistant .message-bubble ol {
    margin: 8px 0;
    padding-left: 20px;
    list-style-position: outside;
}

.message.assistant .message-bubble li {
    margin: 6px 0;
    word-break: break-word;
    overflow-wrap: break-word;
    line-height: 1.4;
}

/* Better handling of long text in messages */
.message.assistant .message-bubble {
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.message.assistant .message-bubble code {
    background: var(--grey-100);
    color: var(--accent);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.message.assistant .message-bubble pre {
    background: var(--grey-100);
    border: 1px solid var(--grey-200);
    border-radius: 8px;
    padding: 12px;
    margin: 12px 0;
    overflow-x: auto;
}

.message.assistant .message-bubble pre code {
    background: none;
    padding: 0;
    color: var(--grey-700);
}

/* Typing Indicator */
.typing-indicator {
    display: none;
    padding: 12px 16px;
    background: white;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    border: 1px solid var(--grey-200);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.typing-indicator.active {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--grey-400);
    animation: typingPulse 1.4s infinite;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
    0%, 80%, 100% {
        opacity: 0.4;
    }
    40% {
        opacity: 1;
    }
}

/* ========================
   CHAT INPUT
   ======================== */
.chat-input-container {
    background: white;
    border-top: 1px solid var(--grey-200);
    padding: var(--spacing-md);
    display: flex;
    gap: var(--spacing-sm);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--grey-50);
    border: 1px solid var(--grey-300);
    border-radius: 24px;
    font-family: var(--font-family);
    font-size: 14px;
    transition: var(--transition);
    -webkit-appearance: none;
}

.chat-input::placeholder {
    color: var(--grey-400);
}

.chat-input:focus {
    outline: none;
    border-color: var(--accent);
    background: white;
}

.btn-send {
    width: 44px;
    height: 44px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-send:active {
    transform: scale(0.95);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========================
   CONNECTION STATUS
   ======================== */
.connection-status {
    position: fixed;
    bottom: 76px;
    right: 16px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 100;
}

.connection-status .status-dot {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: block;
}

.connection-status.connected .status-dot {
    background: var(--success);
}

.connection-status.disconnected .status-dot {
    background: var(--error);
}

.connection-status.connecting .status-dot {
    background: var(--warning);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ========================
   RESPONSIVE DESIGN
   ======================== */
@media (min-width: 768px) {
    .header-content {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: var(--spacing-md) var(--spacing-xl);
    }

    .filter-bar {
        max-width: 500px;
        flex: 1;
    }

    .chat-messages {
        padding: var(--spacing-xl);
    }

    .message-bubble {
        max-width: 70%;
    }

    .chat-input-container {
        padding: var(--spacing-lg) var(--spacing-xl);
    }

    .chat-input {
        font-size: 15px;
    }

    .btn-send {
        width: 48px;
        height: 48px;
    }
}

@media (min-width: 1024px) {
    .app-container {
        max-width: 1200px;
        margin: 0 auto;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
    }

    .message-bubble {
        max-width: 60%;
    }
}

/* Safe area support for modern iPhones */
@supports (padding: max(0px)) {
    .chat-input-container {
        padding-bottom: max(var(--spacing-md), env(safe-area-inset-bottom));
    }
}

/* Prevent iOS zoom on input focus */
@media screen and (max-width: 768px) {
    input, textarea, select {
        font-size: 16px !important;
    }
}