/* ===== ConnectRX Design System =====
   Techniques: floating depth-2 decorations, staggered card entrance,
   gentle message animations, glassmorphism header/input, atmospheric
   background gradients (depth-0/1), bouncing-dot thinking indicator.
   ===== */

/* ===== Custom Properties ===== */
:root {
    --crx-primary: #0891b2;
    --crx-primary-dark: #0e7490;
    --crx-primary-light: #22d3ee;
    --crx-primary-50: #ecfeff;
    --crx-surface: #ffffff;
    --crx-text: #1e293b;
    --crx-text-secondary: #64748b;
    --crx-text-muted: #94a3b8;
    --crx-border: #e2e8f0;
    --crx-border-light: #f1f5f9;
    --crx-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --crx-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --crx-radius-md: 14px;
    --crx-radius-lg: 20px;
    --crx-radius-full: 9999px;
}

/* ===== Base ===== */
body {
    background: linear-gradient(160deg, #f0f9ff 0%, #ffffff 40%, #fefce8 100%);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--crx-text);
}

/* ===== App Container ===== */
.app-container {
    height: 100vh;
    height: 100dvh;
}

/* ===== Background Atmosphere (depth-0 / depth-1) ===== */
.app-atmosphere {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.app-atmosphere::before {
    content: '';
    position: absolute;
    width: 40vw;
    height: 40vw;
    max-width: 600px;
    max-height: 600px;
    top: -10%;
    left: -5%;
    background: radial-gradient(circle, rgba(8, 145, 178, 0.07) 0%, transparent 70%);
    border-radius: 50%;
}

.app-atmosphere::after {
    content: '';
    position: absolute;
    width: 35vw;
    height: 35vw;
    max-width: 500px;
    max-height: 500px;
    bottom: -5%;
    right: -5%;
    background: radial-gradient(circle, rgba(249, 115, 22, 0.05) 0%, transparent 70%);
    border-radius: 50%;
}

/* ===== Header (glassmorphism) ===== */
.crx-header {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: var(--crx-shadow-sm);
    z-index: 20;
}

.crx-logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #06b6d4, #0891b2);
    color: white;
    font-weight: 700;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ===== Chat Container ===== */
#chat-container {
    scroll-behavior: smooth;
}

#chat-container:has(> :last-child) {
    overflow-anchor: auto;
}

/* ===== Landing Screen ===== */
#landing {
    position: relative;
    animation: landing-fade 0.3s ease-out;
}

@keyframes landing-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Floating decorative shapes (depth-2) */
.landing-shapes {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.shape {
    position: absolute;
    border-radius: var(--crx-radius-full);
    opacity: 0;
}

.shape-1 {
    width: 36px;
    height: 36px;
    background: rgba(6, 182, 212, 0.12);
    top: 10%;
    left: 8%;
    animation: shape-enter 0.6s 0.3s ease-out forwards,
               float-a 10s 0.9s ease-in-out infinite;
}

.shape-2 {
    width: 24px;
    height: 42px;
    background: rgba(249, 115, 22, 0.10);
    top: 15%;
    right: 12%;
    border-radius: 12px;
    animation: shape-enter 0.6s 0.5s ease-out forwards,
               float-b 12s 1.1s ease-in-out infinite;
}

.shape-3 {
    width: 28px;
    height: 28px;
    background: rgba(139, 92, 246, 0.10);
    top: 55%;
    left: 5%;
    animation: shape-enter 0.6s 0.4s ease-out forwards,
               float-a 11s 1.0s ease-in-out infinite;
}

.shape-4 {
    width: 44px;
    height: 44px;
    background: rgba(16, 185, 129, 0.08);
    top: 45%;
    right: 6%;
    animation: shape-enter 0.6s 0.6s ease-out forwards,
               float-b 9s 1.2s ease-in-out infinite;
}

.shape-5 {
    width: 18px;
    height: 18px;
    background: rgba(6, 182, 212, 0.15);
    top: 25%;
    left: 35%;
    animation: shape-enter 0.6s 0.7s ease-out forwards,
               float-a 13s 1.3s ease-in-out infinite;
}

.shape-6 {
    width: 32px;
    height: 20px;
    background: rgba(249, 115, 22, 0.08);
    bottom: 20%;
    right: 25%;
    border-radius: 10px;
    animation: shape-enter 0.6s 0.55s ease-out forwards,
               float-b 11s 1.15s ease-in-out infinite;
}

@keyframes shape-enter {
    from { opacity: 0; transform: scale(0.3); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes float-a {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    33% { transform: translateY(-10px) rotate(2deg); }
    66% { transform: translateY(-5px) rotate(-1deg); }
}

@keyframes float-b {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-14px) rotate(-2deg); }
}

/* Landing welcome entrance */
.landing-entrance {
    opacity: 0;
    animation: entrance-up 0.6s ease-out 0.1s forwards;
}

.crx-welcome-icon {
    opacity: 0;
    animation: icon-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.05s forwards;
}

@keyframes icon-pop {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes entrance-up {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Quick Action Cards ===== */
.quick-card {
    display: flex;
    align-items: stretch;
    background: var(--crx-surface);
    border: 1px solid var(--crx-border-light);
    border-radius: var(--crx-radius-md);
    overflow: hidden;
    cursor: pointer;
    text-align: left;
    box-shadow: var(--crx-shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    opacity: 0;
    animation: card-enter 0.5s ease-out forwards;
}

.quick-card:nth-child(1) { animation-delay: 0.2s; }
.quick-card:nth-child(2) { animation-delay: 0.3s; }
.quick-card:nth-child(3) { animation-delay: 0.4s; }
.quick-card:nth-child(4) { animation-delay: 0.5s; }

.quick-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--crx-shadow-md);
}

.quick-card:active {
    transform: scale(0.98);
}

@keyframes card-enter {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.quick-card-accent {
    width: 4px;
    flex-shrink: 0;
}

.quick-card-content {
    padding: 14px 16px;
    flex: 1;
}

/* ===== Chat Messages ===== */
.chat {
    animation: msg-enter 0.3s ease-out;
}

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

/* User bubble (right side) */
.chat-end .chat-bubble {
    background: linear-gradient(135deg, #0891b2, #06b6d4) !important;
    color: white !important;
    border: none !important;
    border-radius: var(--crx-radius-lg) var(--crx-radius-lg) 6px var(--crx-radius-lg);
    box-shadow: 0 2px 8px rgba(8, 145, 178, 0.2);
}

/* AI bubble (left side) — excludes error bubbles */
.chat-start .chat-bubble:not([class*="error"]) {
    background: var(--crx-surface) !important;
    color: var(--crx-text) !important;
    border: 1px solid var(--crx-border) !important;
    border-radius: var(--crx-radius-lg) var(--crx-radius-lg) var(--crx-radius-lg) 6px;
    box-shadow: var(--crx-shadow-sm);
}

/* Error bubble — keep DaisyUI error colors, match radius */
.chat-start .chat-bubble[class*="error"] {
    border-radius: var(--crx-radius-lg) var(--crx-radius-lg) var(--crx-radius-lg) 6px;
}

/* Markdown rendering inside chat bubbles */
.chat-bubble p {
    margin-bottom: 0.75rem;
}

.chat-bubble p:last-child {
    margin-bottom: 0;
}

.chat-bubble ul,
.chat-bubble ol {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
}

.chat-bubble ul {
    list-style-type: disc;
}

.chat-bubble ol {
    list-style-type: decimal;
}

.chat-bubble li {
    margin-bottom: 0.25rem;
}

.chat-bubble strong {
    color: inherit;
    font-weight: 700;
}

.chat-bubble em {
    opacity: 0.8;
}

/* ===== DaisyUI Primary Button Override ===== */
.btn-primary {
    background-color: var(--crx-primary) !important;
    border-color: var(--crx-primary) !important;
    color: white !important;
}

.btn-primary:hover {
    background-color: var(--crx-primary-dark) !important;
    border-color: var(--crx-primary-dark) !important;
}

/* ===== Thinking Animation ===== */
.crx-thinking {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    animation: msg-enter 0.3s ease-out;
}

.thinking-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.thinking-dots span {
    width: 7px;
    height: 7px;
    background: var(--crx-primary);
    border-radius: 50%;
    animation: dot-bounce 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
    animation-delay: 0.16s;
}

.thinking-dots span:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes dot-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* ===== Tool Status ===== */
#tool-status.htmx-swapping {
    opacity: 0;
    transition: opacity 0.15s ease-out;
}

/* ===== Input Area (glassmorphism) ===== */
.crx-input-area {
    z-index: 20;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.crx-input {
    width: 100%;
    border-radius: 24px;
    border: 2px solid var(--crx-border);
    padding: 12px 20px;
    font-size: 15px;
    font-family: inherit;
    color: var(--crx-text);
    background: var(--crx-surface);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

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

.crx-input:focus {
    border-color: var(--crx-primary);
    box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.12);
}

.crx-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--crx-primary);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s, transform 0.15s;
}

.crx-send-btn:hover {
    background: var(--crx-primary-dark);
    transform: scale(1.05);
}

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

/* ===== Suggestion Chips ===== */
.suggestion-chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 16px;
    border-radius: var(--crx-radius-full);
    border: 1px solid var(--crx-primary);
    color: var(--crx-primary);
    font-size: 13px;
    font-weight: 500;
    background: transparent;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, transform 0.15s;
}

.suggestion-chip:hover {
    background: var(--crx-primary);
    color: white;
}

.suggestion-chip:active {
    transform: scale(0.97);
}

/* ===== Utility: Fade In ===== */
.animate-fade-in {
    animation: fade-in 0.2s ease-out;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(-0.5rem); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Focus Indicators (WCAG 2.4.7) ===== */
:focus-visible {
    outline: 3px solid var(--crx-primary);
    outline-offset: 2px;
    border-radius: 4px;
}

:focus:not(:focus-visible) {
    outline: none;
}

.crx-input:focus-visible {
    outline: none; /* uses box-shadow instead */
}

/* ===== Dark Mode (follows system preference) ===== */
[data-theme="dark"] {
    --crx-primary: #22d3ee;
    --crx-primary-dark: #06b6d4;
    --crx-primary-light: #67e8f9;
    --crx-primary-50: #083344;
    --crx-surface: #1e293b;
    --crx-text: #e2e8f0;
    --crx-text-secondary: #94a3b8;
    --crx-text-muted: #64748b;
    --crx-border: #334155;
    --crx-border-light: #1e293b;
    --crx-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --crx-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] body {
    background: linear-gradient(160deg, #0f172a 0%, #1e293b 40%, #1a1a2e 100%);
}

[data-theme="dark"] .crx-header {
    background: rgba(15, 23, 42, 0.85);
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .crx-input-area {
    background: rgba(15, 23, 42, 0.85);
    border-top-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .crx-input:focus {
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.15);
}

[data-theme="dark"] .chat-end .chat-bubble {
    box-shadow: 0 2px 8px rgba(6, 182, 212, 0.3);
}

[data-theme="dark"] .app-atmosphere::before {
    background: radial-gradient(circle, rgba(34, 211, 238, 0.04) 0%, transparent 70%);
}

[data-theme="dark"] .app-atmosphere::after {
    background: radial-gradient(circle, rgba(249, 115, 22, 0.03) 0%, transparent 70%);
}

[data-theme="dark"] .shape-1 { background: rgba(34, 211, 238, 0.08); }
[data-theme="dark"] .shape-2 { background: rgba(249, 115, 22, 0.06); }
[data-theme="dark"] .shape-3 { background: rgba(139, 92, 246, 0.06); }
[data-theme="dark"] .shape-4 { background: rgba(16, 185, 129, 0.05); }
[data-theme="dark"] .shape-5 { background: rgba(34, 211, 238, 0.10); }
[data-theme="dark"] .shape-6 { background: rgba(249, 115, 22, 0.05); }

[data-theme="dark"] .suggestion-chip {
    border-color: rgba(34, 211, 238, 0.4);
}

/* ===== Accessibility — Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .landing-shapes {
        display: none;
    }

    .quick-card,
    .landing-entrance,
    .crx-welcome-icon {
        opacity: 1 !important;
        transform: none !important;
    }
}

/* ===== Mobile: Hide floating shapes on touch ===== */
@media (pointer: coarse) {
    .landing-shapes {
        display: none;
    }
}

/* ===== Mobile: Layout & Touch Targets ===== */
@media (max-width: 640px) {
    .crx-header {
        padding-left: 12px;
        padding-right: 12px;
    }

    /* 16px prevents iOS zoom-on-focus */
    .crx-input {
        padding: 10px 16px;
        font-size: 16px;
    }

    .quick-card-content {
        padding: 12px 14px;
    }
}

/* ===== Safe Area for Notch Devices ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .crx-input-area {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
}
