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

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-chat: #0d0d14;
    --surface: #1a1a2e;
    --surface-hover: #222240;
    --accent: #f59e0b;
    --accent-glow: rgba(245, 158, 11, 0.3);
    --accent-dark: #d97706;
    --text-primary: #f1f1f4;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --bubble-user: linear-gradient(135deg, #f59e0b, #d97706);
    --bubble-bot: #1e1e32;
    --border: rgba(255, 255, 255, 0.06);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --radius: 16px;
    --radius-sm: 10px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --viewport-height: 100vh;
}

html,
body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* ─── App Container ─────────────────────────────────────── */
.app {
    display: flex;
    flex-direction: column;
    height: var(--viewport-height);
    max-width: 520px;
    margin: 0 auto;
    background: var(--bg-chat);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    min-height: 0;
}

/* ─── Header ─────────────────────────────────────────────── */
.chat-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(20px);
    position: sticky;
    top: 0;
    z-index: 10;
    flex-shrink: 0;
}

.header-avatar {
    width: 44px;
    height: 44px;
    background: var(--surface);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 0 20px var(--accent-glow);
    border: 2px solid var(--accent);
}

.header-info h1 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.header-status {
    font-size: 0.78rem;
    font-weight: 500;
}

.header-status.status-open {
    color: #34d399;
}

.header-status.status-soon {
    color: #fbbf24;
}

.header-status.status-closed {
    color: #f87171;
}

.header-status.status-unknown {
    color: #9ca3af;
}

/* ─── Messages Area ──────────────────────────────────────── */
.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

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

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

/* ─── Welcome Message ────────────────────────────────────── */
.welcome-message {
    text-align: center;
    padding: 40px 20px 20px;
    animation: fadeIn 0.5s ease;
}

.welcome-icon {
    font-size: 56px;
    margin-bottom: 16px;
    animation: bounce 2s ease infinite;
}

.welcome-message h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--accent), #fbbf24);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-message p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.quick-btn {
    padding: 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text-primary);
    font-size: 0.82rem;
    font-family: var(--font);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-btn:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.15);
}

/* ─── Message Bubbles ────────────────────────────────────── */
.message {
    display: flex;
    flex-direction: column;
    max-width: 82%;
    animation: slideIn 0.3s ease;
}

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

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

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.user .message-bubble {
    background: var(--bubble-user);
    color: #1a1a2e;
    font-weight: 500;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: var(--bubble-bot);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.order-qr {
    width: 140px;
    height: 140px;
    margin-top: 10px;
    padding: 8px;
    background: #fff;
    border-radius: 14px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.share-order-btn {
    margin-top: 10px;
    padding: 10px 14px;
    border: 1px solid var(--accent);
    border-radius: 999px;
    background: transparent;
    color: var(--accent);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.share-order-btn:hover {
    background: rgba(245, 158, 11, 0.12);
}

.share-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    z-index: 100;
}

.share-sheet {
    width: min(520px, 100%);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 22px 22px 14px 14px;
    box-shadow: var(--shadow);
    padding: 18px;
}

.share-sheet-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.share-sheet-subtitle {
    color: var(--text-secondary);
    font-size: 0.84rem;
    margin-bottom: 14px;
}

.share-sheet-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.share-sheet-btn,
.share-sheet-close {
    width: 100%;
    padding: 12px 14px;
    border-radius: 14px;
    font: inherit;
    font-size: 0.86rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
}

.share-sheet-btn {
    background: var(--surface);
    color: var(--text-primary);
}

.share-sheet-close {
    margin-top: 12px;
    background: transparent;
    color: var(--text-secondary);
}

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

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

/* ─── Typing Indicator ───────────────────────────────────── */
.typing-indicator {
    padding: 4px 16px 8px;
}

.typing-bubble {
    display: inline-flex;
    gap: 5px;
    padding: 12px 18px;
    background: var(--bubble-bot);
    border-radius: var(--radius);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

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

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* ─── Input Area ─────────────────────────────────────────── */
.chat-input-area {
    padding: 12px 16px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    position: sticky;
    bottom: 0;
    z-index: 10;
    flex-shrink: 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

.chat-form {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border-radius: 28px;
    padding: 4px 4px 4px 18px;
    border: 1px solid var(--border);
    transition: border-color 0.2s ease;
}

.chat-form:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 0.92rem;
    font-family: var(--font);
    padding: 10px 0;
}

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

.send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--bubble-user);
    border: none;
    color: #1a1a2e;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 16px var(--accent-glow);
}

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

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

/* ─── Animations ─────────────────────────────────────────── */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

@keyframes typingPulse {

    0%,
    100% {
        opacity: 0.3;
        transform: scale(0.85);
    }

    50% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 560px) {
    .app {
        max-width: 100%;
        border: none;
    }
}

@supports (height: 100dvh) {
    :root {
        --viewport-height: 100dvh;
    }
}

/* ─── Markdown-like styling in messages ──────────────────── */
.message-bubble strong,
.message-bubble b {
    font-weight: 700;
    color: var(--accent);
}

.message.user .message-bubble strong,
.message.user .message-bubble b {
    color: #1a1a2e;
}

/* ─── Reply Buttons ──────────────────────────────────────── */
.reply-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.reply-btn {
    padding: 8px 16px;
    background: transparent;
    border: 1.5px solid var(--accent);
    border-radius: 20px;
    color: var(--accent);
    font-size: 0.82rem;
    font-family: var(--font);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.reply-btn:hover:not(:disabled) {
    background: var(--accent);
    color: #1a1a2e;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.reply-btn:active:not(:disabled) {
    transform: scale(0.96);
}

.reply-btn.selected {
    background: var(--accent);
    color: #1a1a2e;
    border-color: var(--accent);
}

.reply-btn.used:not(.selected) {
    opacity: 0.3;
    border-color: var(--text-muted);
    color: var(--text-muted);
    cursor: default;
}

.reply-btn:disabled {
    cursor: default;
    pointer-events: none;
}
