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

:root {
    --bg: #0a0a12;
    --surface: #12121e;
    --surface2: #1a1a2e;
    --surface3: #222240;
    --border: rgba(139, 92, 246, 0.12);
    --border-hover: rgba(139, 92, 246, 0.3);
    --text: #f0eef8;
    --text-muted: #8a86a8;
    --accent: #a78bfa;
    --accent-bright: #c4b5fd;
    --accent-deep: #7c3aed;
    --accent-glow: rgba(139, 92, 246, 0.1);
    --accent-glow-strong: rgba(139, 92, 246, 0.2);
    --warm: #f59e0b;
    --warm-glow: rgba(245, 158, 11, 0.1);
    --rose: #f472b6;
    --teal: #2dd4bf;
    --user-bg: linear-gradient(135deg, #2d1b69 0%, #1e1145 100%);
    --assistant-bg: linear-gradient(135deg, #15152a 0%, #1a1a2e 100%);
    --radius: 16px;
    --radius-lg: 20px;
    --radius-pill: 99px;
    --shadow-glow: 0 0 40px rgba(139, 92, 246, 0.06);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
}

/* Ambient background glow */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at 30% 20%, rgba(139, 92, 246, 0.04) 0%, transparent 50%),
                radial-gradient(ellipse at 70% 80%, rgba(244, 114, 182, 0.03) 0%, transparent 50%),
                radial-gradient(ellipse at 50% 50%, rgba(45, 212, 191, 0.02) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 780px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: rgba(18, 18, 30, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.2);
}

.chat-header h1 {
    font-size: 17px;
    font-weight: 800;
    line-height: 1.2;
    background: linear-gradient(135deg, var(--accent-bright), var(--rose));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.header-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.header-link:hover {
    opacity: 1;
}

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

.message {
    max-width: 88%;
    animation: messageIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.message.user {
    align-self: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.message-content {
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    line-height: 1.7;
    font-size: 14.5px;
    font-weight: 400;
}

.message.user .message-content {
    background: var(--user-bg);
    border: 1px solid rgba(139, 92, 246, 0.25);
    border-radius: var(--radius-lg) var(--radius-lg) 6px var(--radius-lg);
    box-shadow: 0 4px 24px rgba(139, 92, 246, 0.08);
}

.message.assistant .message-content {
    background: var(--assistant-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 6px;
    box-shadow: var(--shadow-glow);
}

.message-content p {
    margin-bottom: 10px;
}

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

.message-content strong {
    color: var(--accent-bright);
    font-weight: 700;
}

.message-content em {
    color: var(--rose);
    font-style: italic;
}

.message-content a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.15s;
}

.message-content a:hover {
    color: var(--accent-bright);
}

.message-content h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--accent-bright);
    margin: 16px 0 6px;
}

.message-content h3:first-child {
    margin-top: 0;
}

/* Pattern images */
.pattern-img {
    margin: 10px 0;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    max-width: 320px;
}

.pattern-img img {
    width: 100%;
    height: auto;
    max-height: 240px;
    object-fit: cover;
    display: block;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.pattern-img:hover img {
    transform: scale(1.03);
}

.message-content img:not(.pattern-img img) {
    max-width: 320px;
    max-height: 240px;
    object-fit: cover;
    border-radius: var(--radius);
    margin: 10px 0;
    border: 1px solid var(--border);
    display: block;
}

.link-sep {
    color: var(--text-muted);
    margin: 0 2px;
}

.message-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

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

/* Open in Stash2Go button */
.open-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--bg);
    background: linear-gradient(135deg, var(--accent), var(--accent-deep));
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    text-decoration: none;
    letter-spacing: 0.02em;
    transition: all 0.2s;
    box-shadow: 0 2px 12px rgba(139, 92, 246, 0.3);
}

.open-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
    color: var(--bg);
    text-decoration: none;
}

/* Welcome suggestions */
.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.suggestion {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 18px;
    border-radius: var(--radius-pill);
    font-size: 13px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

.suggestion::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--accent-glow), var(--warm-glow));
    opacity: 0;
    transition: opacity 0.2s;
}

.suggestion:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(139, 92, 246, 0.15);
}

.suggestion:hover::before {
    opacity: 1;
}

/* Input area */
.input-area {
    padding: 16px 24px 20px;
    background: rgba(18, 18, 30, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 6px 6px 20px;
    transition: all 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow), 0 4px 24px rgba(139, 92, 246, 0.08);
}

#messageInput {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    font-weight: 600;
    outline: none;
    padding: 10px 0;
}

#messageInput::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

#sendBtn {
    background: linear-gradient(135deg, var(--accent), var(--accent-deep));
    border: none;
    color: white;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    box-shadow: 0 2px 12px rgba(139, 92, 246, 0.25);
}

#sendBtn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.35);
}

#sendBtn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.disclaimer {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 10px;
    opacity: 0.5;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 6px 0;
    align-items: center;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.6;
    animation: pulse 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.4;
    }
    40% {
        transform: scale(1.2);
        opacity: 0.9;
    }
}

/* Scrollbar */
.messages::-webkit-scrollbar {
    width: 5px;
}

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

.messages::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.2);
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.35);
}

/* Ravelry link styling */
.rav-link {
    color: var(--teal);
    font-weight: 600;
}

/* Mobile */
@media (max-width: 640px) {
    .message {
        max-width: 94%;
    }

    .messages {
        padding: 16px;
        gap: 16px;
    }

    .chat-header {
        padding: 12px 16px;
    }

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

    .suggestions {
        flex-direction: column;
    }

    .suggestion {
        text-align: left;
    }

    .message-content img {
        max-height: 200px;
    }
}

/* Tablet and up — give it room to breathe */
@media (min-width: 641px) {
    .chat-container {
        margin-top: 12px;
        margin-bottom: 12px;
        height: calc(100dvh - 24px);
        border: 1px solid var(--border);
        border-radius: 24px;
        overflow: hidden;
        box-shadow: 0 0 80px rgba(139, 92, 246, 0.05),
                    0 0 1px rgba(139, 92, 246, 0.2);
    }

    .chat-header {
        border-radius: 24px 24px 0 0;
    }
}
