/* ============================================================
   Dhamma AI — Full-page chat layout
   Uses the same CSS variables and fonts as the main app
   ============================================================ */

/* Prevent page/body bounce and scroll on mobile */
body {
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    position: fixed;
}

/* Full-viewport layout */
.dai-layout {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg-primary);
}

/* ── Sidebar ───────────────────────────────────────────────── */
.dai-sidebar {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    transition: transform 0.3s ease;
    z-index: 200;
}

.dai-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.dai-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.95rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.dai-sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.3rem;
    border-radius: 0.5rem;
}

.dai-new-chat-btn {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 1rem;
    padding: 0.7rem 1rem;
    background: var(--gradient-primary);
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 3px 12px rgba(228, 178, 61, 0.3);
}

@media (hover: hover) {
    .dai-new-chat-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 18px rgba(228, 178, 61, 0.45);
    }
}

/* Sessions list */
.dai-sessions-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.5rem 0.75rem;
}

.dai-sessions-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.7;
}

.dai-session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 0.75rem;
    border-radius: 0.65rem;
    cursor: pointer;
    transition: background 0.2s ease;
    gap: 0.5rem;
    margin-bottom: 0.2rem;
}

@media (hover: hover) {
    .dai-session-item:hover {
        background: rgba(228, 178, 61, 0.08);
    }
}

.dai-session-item.active {
    background: rgba(228, 178, 61, 0.14);
}

.dai-session-title {
    font-size: 0.875rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.dai-session-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.dai-session-delete {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.2rem;
    border-radius: 0.4rem;
    opacity: 0;
    transition: all 0.2s;
    flex-shrink: 0;
    font-size: 1rem;
    line-height: 1;
}

@media (hover: hover) {
    .dai-session-item:hover .dai-session-delete {
        opacity: 1;
    }
}

@media (hover: hover) {
    .dai-session-delete:hover {
        color: #e53e3e;
        background: rgba(229, 62, 62, 0.1);
    }
}

/* Sidebar footer */
.dai-sidebar-footer {
    padding: 0.85rem 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: center;
}

.dai-footer-link {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s;
}

@media (hover: hover) {
    .dai-footer-link:hover {
        color: var(--saffron-500);
    }
}

.dai-footer-note {
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.5;
    width: 100%;
}

/* ── Main Chat Area ────────────────────────────────────────── */
.dai-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Top bar */
.dai-topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.dai-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 0.5rem;
    transition: color 0.2s;
}

@media (hover: hover) {
    .dai-menu-btn:hover {
        color: var(--saffron-500);
    }
}

.dai-topbar-title {
    font-size: 1rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    flex: 1;
}

.dai-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Messages scrollable area */
.dai-messages-area {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
}

/* ── Welcome Screen ───────────────────────────────────────── */
.dai-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex: 1;
    padding: 2rem 1rem;
    animation: fadeInUp 0.6s ease-out;
}

.dai-welcome-icon {
    font-size: 3.5rem;
    margin-bottom: 1.25rem;
    filter: drop-shadow(0 4px 12px rgba(228, 178, 61, 0.4));
    animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

.dai-welcome-title {
    font-family: 'Playfair Display', serif;
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    margin-bottom: 0.75rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.dai-welcome-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    max-width: 500px;
    line-height: 1.7;
    margin-bottom: 2rem;
}

.dai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    justify-content: center;
    max-width: 600px;
}

.dai-suggestion {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 2rem;
    padding: 0.55rem 1.1rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.25s ease;
}

@media (hover: hover) {
    .dai-suggestion:hover {
        border-color: var(--saffron-400);
        background: rgba(228, 178, 61, 0.08);
        transform: translateY(-2px);
        box-shadow: var(--shadow-md);
    }
}

/* ── Chat Messages ────────────────────────────────────────── */
.dai-messages {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
    padding-bottom: 1rem;
}

.dai-msg {
    display: flex;
    gap: 0.75rem;
    animation: fadeInUp 0.3s ease-out;
}

.dai-msg-user {
    flex-direction: row-reverse;
}

.dai-msg-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.dai-msg-user .dai-msg-avatar {
    background: var(--gradient-primary);
    color: white;
}

.dai-msg-assistant .dai-msg-avatar {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--saffron-500);
    font-size: 1rem;
}

.dai-msg-body {
    max-width: 75%;
}

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

.dai-msg-bubble {
    padding: 0.85rem 1.1rem;
    border-radius: 1rem;
    line-height: 1.65;
    font-size: 0.94rem;
}

.dai-msg-user .dai-msg-bubble {
    background: rgba(228, 178, 61, 0.15);
    border: 1px solid rgba(228, 178, 61, 0.25);
    border-radius: 1rem 1rem 0.25rem 1rem;
    color: var(--text-primary);
}

.dai-msg-assistant .dai-msg-bubble {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 1rem 1rem 1rem 0.25rem;
    color: var(--text-primary);
}

.dai-msg-bubble p {
    margin-bottom: 0.65rem;
}
.dai-msg-bubble p:last-child {
    margin-bottom: 0;
}

/* Citations */
.dai-citations {
    margin-top: 0.85rem;
    display: grid;
    gap: 0.45rem;
}

.dai-citation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.6rem;
    text-decoration: none;
    background: rgba(228, 178, 61, 0.07);
    border: 1px solid rgba(228, 178, 61, 0.18);
    color: var(--text-primary);
    transition: all 0.2s ease;
    font-size: 0.85rem;
}

@media (hover: hover) {
    .dai-citation:hover {
        background: rgba(228, 178, 61, 0.14);
        border-color: var(--saffron-400);
        transform: translateX(3px);
    }
}

.dai-citation span {
    font-weight: 600;
}

.dai-citation small {
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Loading dots */
.dai-loading {
    display: flex;
    gap: 0.3rem;
    align-items: center;
    padding: 0.5rem 0;
}

.dai-loading span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--saffron-400);
    animation: dotBounce 1.2s ease-in-out infinite;
}

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

@keyframes dotBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40% { transform: translateY(-8px); opacity: 1; }
}

/* ── Input Area ───────────────────────────────────────────── */
.dai-input-area {
    padding: 0.85rem 1rem calc(0.65rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.dai-input-form {
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
    max-width: 780px;
    margin: 0 auto;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 0.65rem 0.65rem 0.65rem 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.dai-input-form:focus-within {
    border-color: var(--saffron-400);
    box-shadow: 0 0 0 3px rgba(228, 178, 61, 0.12);
}

.dai-textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    resize: none;
    font: inherit;
    font-size: 0.94rem;
    color: var(--text-primary);
    line-height: 1.55;
    max-height: 140px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.dai-textarea::placeholder {
    color: var(--text-secondary);
}

.dai-send-btn {
    flex-shrink: 0;
    width: 2.2rem;
    height: 2.2rem;
    border: none;
    border-radius: 0.65rem;
    background: var(--gradient-primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
    box-shadow: 0 2px 8px rgba(228, 178, 61, 0.35);
}

@media (hover: hover) {
    .dai-send-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 5px 14px rgba(228, 178, 61, 0.5);
    }
}

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

.dai-disclaimer {
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 0.45rem;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .dai-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
        box-shadow: var(--shadow-2xl);
    }

    .dai-sidebar.open {
        transform: translateX(0);
    }

    .dai-sidebar-close {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .dai-menu-btn {
        display: flex;
    }

    .dai-msg-body {
        max-width: 90%;
    }

    /* Sidebar overlay */
    .dai-sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 199;
    }

    .dai-sidebar-overlay.visible {
        display: block;
    }
}

/* ============================================================
   Cross-Device Compatibility Fixes
   ============================================================ */

/* GAP-01: Prevent iOS auto-zoom on inputs (font-size must be >= 16px) */
@media (max-width: 1024px) {
    .dai-textarea {
        font-size: 16px;
    }
}
