/* === Design Tokens === */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-tertiary: #1a1a24;
    --bg-surface: #1e1e2a;
    --bg-surface-hover: #252535;

    --border-subtle: #2a2a3a;
    --border-medium: #3a3a4a;

    --purple-dark: #2d1b3d;
    --purple-medium: #4a2c5a;
    --purple-light: #6b3d7a;
    --purple-glow: rgba(107, 61, 122, 0.3);

    --gold: #d4af37;
    --gold-light: #f5e6d3;
    --gold-glow: rgba(212, 175, 55, 0.3);

    --text-primary: #e8e6e3;
    --text-secondary: #b8b6b3;
    --text-muted: #777;
    --text-dim: #555;

    --accent-green: #7bd88f;
    --accent-red: #ff6b6b;
    --accent-blue: #6ba3ff;

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

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

    --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 20px var(--gold-glow);

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;
}

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

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    position: relative;
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

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

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

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

.sidebar-logo-icon {
    font-size: 24px;
}

.sidebar-logo-text {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 20px;
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-close-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.sidebar-close-btn:hover {
    color: var(--text-primary);
    background: var(--bg-surface-hover);
}

.new-reading-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--purple-dark) 0%, var(--purple-medium) 100%);
    border: 1px solid var(--purple-light);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-normal);
}
.new-reading-btn:hover {
    background: linear-gradient(135deg, var(--purple-medium) 0%, var(--purple-light) 100%);
    box-shadow: 0 4px 16px var(--purple-glow);
    transform: translateY(-1px);
}
.new-reading-btn:active {
    transform: translateY(0);
}

.new-reading-icon {
    font-size: 18px;
}

.sidebar-sessions {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.sidebar-section-title {
    padding: 8px 16px 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
}

.session-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 8px;
}

.session-list-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
    line-height: 1.5;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}
.session-item:hover {
    background: var(--bg-surface-hover);
}
.session-item.active {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
}
.session-item-icon {
    font-size: 16px;
    flex-shrink: 0;
}
.session-item-text {
    flex: 1;
    min-width: 0;
}
.session-item-question {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.session-item-date {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}
.session-item-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all var(--transition-fast);
}
.session-item:hover .session-item-delete {
    opacity: 1;
}
.session-item-delete:hover {
    color: var(--accent-red);
    background: rgba(255, 107, 107, 0.1);
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border-subtle);
}

.sidebar-promo {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.08) 0%, rgba(107, 61, 122, 0.08) 100%);
    border: 1px solid rgba(212, 175, 55, 0.15);
    border-radius: var(--radius-sm);
}
.promo-icon { font-size: 16px; }
.promo-text {
    font-size: 12px;
    color: var(--gold-light);
    font-weight: 500;
}

/* Sidebar Overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 99;
}
.sidebar-overlay.active {
    display: block;
}

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

/* === Topbar === */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-height);
    padding: 0 16px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    flex-shrink: 0;
    z-index: 10;
}

.topbar-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 22px;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}
.topbar-menu-btn:hover {
    background: var(--bg-surface-hover);
}

.topbar-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 18px;
}
.topbar-logo-icon { font-size: 20px; }

.topbar-new-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}
.topbar-new-btn:hover {
    background: var(--bg-surface-hover);
    border-color: var(--purple-medium);
}

/* === Chat Area === */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    position: relative;
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 24px;
}
.welcome-content {
    text-align: center;
    max-width: 600px;
}
.welcome-icon {
    font-size: 64px;
    margin-bottom: 20px;
    animation: float 3s ease-in-out infinite;
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}
.welcome-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 40px;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-light) 50%, var(--gold) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    background-size: 200% auto;
    animation: shimmer 4s ease-in-out infinite;
}
@keyframes shimmer {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}
.welcome-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 16px;
}
.welcome-promo {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.1) 0%, rgba(107, 61, 122, 0.1) 100%);
    border: 1px solid rgba(212, 175, 55, 0.2);
    border-radius: var(--radius-full);
    font-size: 13px;
    color: var(--gold-light);
    font-weight: 500;
    margin-bottom: 28px;
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-width: 500px;
    margin: 0 auto;
}
.suggestion-chip {
    padding: 10px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-normal);
    font-family: inherit;
}
.suggestion-chip:hover {
    background: var(--bg-surface-hover);
    border-color: var(--purple-medium);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--purple-glow);
}

/* Chat Messages */
.chat-messages {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 100%;
    max-width: 900px;
    margin: 0 auto;
}
.chat-messages.hidden { display: none; }

/* Message Bubble */
.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    width: fit-content;
    animation: messageIn 0.3s ease-out;
}

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

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

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 4px;
}
.message.user .message-avatar {
    background: linear-gradient(135deg, var(--purple-dark), var(--purple-medium));
    border: 1px solid var(--purple-light);
}
.message.assistant .message-avatar {
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.2), rgba(107, 61, 122, 0.2));
    border: 1px solid rgba(212, 175, 55, 0.3);
}

.message-body {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 85%;
}

.message.user .message-body {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.message.assistant .message-body {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.message-content {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary);
}

.message.user .message-content {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    padding: 12px 16px;
    border-radius: var(--radius-lg) var(--radius-sm) var(--radius-lg) var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.message.assistant .message-content {
    background: transparent;
    padding: 4px 0;
}

/* Card spread in chat */
.spread-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 8px 0;
}

.card-reading {
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--purple-dark) 100%);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px;
    position: relative;
    overflow: hidden;
    animation: cardReveal 0.5s ease-out;
}
@keyframes cardReveal {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
.card-reading::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(212, 175, 55, 0.03) 0%, transparent 70%);
    animation: rotateslow 20s linear infinite;
    pointer-events: none;
}
@keyframes rotateslow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.card-reading-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.card-position-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--gold);
    padding: 4px 10px;
    background: rgba(212, 175, 55, 0.1);
    border: 1px solid rgba(212, 175, 55, 0.2);
    border-radius: var(--radius-full);
}
.card-name {
    font-family: 'Playfair Display', serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--gold-light);
}
.card-reversed-badge {
    font-size: 11px;
    color: var(--accent-red);
    padding: 2px 8px;
    background: rgba(255, 107, 107, 0.1);
    border-radius: var(--radius-full);
}

.card-reading-body {
    display: flex;
    gap: 16px;
}
.card-image-wrapper {
    flex-shrink: 0;
}
.card-image {
    width: 140px;
    height: auto;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    transition: transform var(--transition-normal);
}
.card-image:hover {
    transform: scale(1.05);
}
.card-reading-text {
    flex: 1;
    min-width: 0;
}
.card-narrative {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
    margin-bottom: 10px;
}
.card-advice {
    font-size: 13px;
    line-height: 1.6;
    color: var(--gold-light);
    padding: 8px 12px;
    background: rgba(212, 175, 55, 0.06);
    border-left: 3px solid var(--gold);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.card-advice::before {
    content: '💡 ';
}

.reading-summary {
    margin-top: 8px;
    padding: 16px;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.06) 0%, rgba(107, 61, 122, 0.06) 100%);
    border: 1px solid rgba(212, 175, 55, 0.15);
    border-radius: var(--radius-md);
}
.reading-summary-title {
    font-family: 'Playfair Display', serif;
    font-size: 16px;
    color: var(--gold-light);
    margin-bottom: 8px;
}
.reading-summary-text {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}
.typing-indicator.hidden { display: none; }

.typing-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.2), rgba(107, 61, 122, 0.2));
    border: 1px solid rgba(212, 175, 55, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}
.typing-dots {
    display: flex;
    gap: 4px;
}
.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-dim);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-6px); opacity: 1; }
}
.typing-text {
    font-size: 13px;
    color: var(--text-dim);
    font-style: italic;
}

/* === Input Area === */
.input-area {
    padding: 12px 20px 20px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
}

.topic-selector-wrapper {
    margin-bottom: 8px;
}
.topic-select {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23777' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}
.topic-select:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 2px var(--gold-glow);
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 8px 8px 8px 16px;
    transition: all var(--transition-fast);
}
.input-row:focus-within {
    border-color: var(--gold);
    box-shadow: 0 0 0 2px var(--gold-glow);
}

.question-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    padding: 4px 0;
}
.question-input:focus {
    outline: none;
}
.question-input::placeholder {
    color: var(--text-dim);
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--gold);
    color: var(--bg-primary);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}
.send-btn:disabled {
    background: var(--border-medium);
    color: var(--text-dim);
    cursor: not-allowed;
}
.send-btn:not(:disabled):hover {
    background: var(--gold-light);
    transform: scale(1.05);
    box-shadow: var(--shadow-glow);
}

.input-hint {
    padding: 4px 4px 0;
    min-height: 16px;
}
.follow-up-counter {
    font-size: 11px;
    color: var(--text-dim);
}
.follow-up-counter.hidden { display: none; }

/* New reading button in chat */
.new-reading-inline-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: linear-gradient(135deg, var(--purple-dark) 0%, var(--purple-medium) 100%);
    border: 1px solid var(--purple-light);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 12px;
    transition: all var(--transition-normal);
    font-family: inherit;
}
.new-reading-inline-btn:hover {
    background: linear-gradient(135deg, var(--purple-medium) 0%, var(--purple-light) 100%);
    box-shadow: 0 4px 16px var(--purple-glow);
}

/* === Mobile Responsive === */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        transform: translateX(-100%);
        z-index: 200;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-close-btn {
        display: block;
    }
    .topbar-menu-btn {
        display: flex;
    }

    .welcome-title {
        font-size: 32px;
    }
    .welcome-subtitle {
        font-size: 14px;
    }
    .suggestion-chips {
        gap: 6px;
    }
    .suggestion-chip {
        font-size: 12px;
        padding: 8px 14px;
    }

    .card-reading-body {
        flex-direction: column;
    }
    .card-image-wrapper {
        align-self: center;
        margin-bottom: 8px;
    }
    .card-image {
        width: 140px;
    }

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

@media (max-width: 480px) {
    .welcome-title { font-size: 28px; }
    .card-name { font-size: 16px; }
    .card-reading { padding: 14px; }
}

/* === Dark smoke background effect === */
.main-content::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(circle at 20% 50%, rgba(74, 44, 90, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(107, 61, 122, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(45, 27, 61, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}
.chat-area, .topbar, .input-area {
    position: relative;
    z-index: 1;
}
