/* =============================================
   Gemini-Style Chat Interface (RTL / Arabic)
   ============================================= */

/* Reset body for full-page chat */
body {
    margin: 0;
    padding: 0;
    background-color: #131314 !important;
    color: #e3e3e3;
    overflow: hidden;
    min-height: 100vh;
    font-family: 'Cairo', sans-serif;
}

/* Full-page chat app */
.chat-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    background-color: #131314;
}

/* =============================================
   Top Bar (New Chat button)
   ============================================= */
.chat-topbar {
    flex-shrink: 0;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    border-bottom: 1px solid #2a2a2d;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: transparent;
    border: 1px solid #3c3c43;
    border-radius: 20px;
    padding: 0.4rem 0.85rem;
    color: #adb5bd;
    font-family: 'Cairo', sans-serif;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.new-chat-btn:hover {
    background: #1e1f20;
    border-color: #5f6368;
}

.new-chat-btn i {
    font-size: 0.9rem;
}

/* =============================================
   Messages Area
   ============================================= */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding-bottom: 1rem;
}

/* =============================================
   Welcome State (centered, Gemini-style)
   ============================================= */
.welcome-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 2rem;
    text-align: center;
}

.welcome-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4285f4, #8ab4f8);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.25rem;
    font-size: 2rem;
    color: white;
}

.welcome-state h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(90deg, #8ab4f8, #c084fc, #f472b6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.welcome-subtitle {
    color: #9aa0a6;
    font-size: 0.95rem;
    margin-bottom: 2rem;
}

.suggestions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    max-width: 600px;
    width: 100%;
}

@media (max-width: 600px) {
    .suggestions {
        grid-template-columns: 1fr;
    }
}

.suggestion-btn {
    background: #1e1f20;
    border: 1px solid #3c3c43;
    border-radius: 16px;
    padding: 0.875rem 1rem;
    color: #c4c7c5;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-family: 'Cairo', sans-serif;
    font-size: 0.875rem;
    transition: background 0.2s, border-color 0.2s;
    text-align: right;
}

.suggestion-btn:hover {
    background: #28292a;
    border-color: #5f6368;
}

.suggestion-btn i {
    font-size: 1.1rem;
    color: #8ab4f8;
    flex-shrink: 0;
}

/* =============================================
   Message Rows (Gemini-style)
   ============================================= */
.message-row {
    width: 100%;
    padding: 1.25rem 0;
}

.message-row.user-row {
    background-color: transparent;
}

.message-row.assistant-row {
    background-color: transparent;
}

.message-content {
    max-width: 768px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

/* User: avatar on right (natural RTL) */
.user-row .message-content {
    flex-direction: row;
}

/* Assistant: avatar on left (reversed RTL) */
.assistant-row .message-content {
    flex-direction: row-reverse;
}

/* Avatar */
.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.85rem;
}

.user-row .msg-avatar {
    background: #3c4043;
    color: #e8eaed;
}

.assistant-row .msg-avatar {
    background: linear-gradient(135deg, #4285f4, #8ab4f8);
    color: white;
    font-size: 0.75rem;
}

/* Message text */
.msg-text {
    flex: 1;
    line-height: 1.75;
    font-size: 0.95rem;
    color: #e3e3e3;
    min-width: 0;
    overflow-wrap: break-word;
}

/* User message bubble */
.user-row .msg-text {
    background: #1e1f20;
    border-radius: 20px 20px 4px 20px;
    padding: 0.75rem 1.15rem;
    color: #e3e3e3;
}

/* Assistant message — no bubble, clean text */
.assistant-row .msg-text {
    padding: 0.25rem 0;
}

.msg-text p {
    margin-bottom: 0.75rem;
}

.msg-text p:last-child {
    margin-bottom: 0;
}

.msg-text ul, .msg-text ol {
    margin-bottom: 0.75rem;
    padding-right: 1.5rem;
}

.msg-text li {
    margin-bottom: 0.25rem;
}

.msg-text strong {
    color: #fff;
}

.msg-text code {
    background: #1e1f20;
    color: #8ab4f8;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85rem;
    direction: ltr;
    display: inline;
    border: 1px solid #2a2a2d;
}

.msg-text pre {
    background: #1e1f20;
    border: 1px solid #2a2a2d;
    border-radius: 8px;
    padding: 1rem;
    overflow-x: auto;
    direction: ltr;
    text-align: left;
    margin: 0.75rem 0;
}

.msg-text pre code {
    background: none;
    color: #d4d4d4;
    padding: 0;
}

/* =============================================
   Thinking Indicator
   ============================================= */
.typing-row {
    width: 100%;
    padding: 1.5rem 0;
}

.typing-content {
    max-width: 768px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    gap: 1rem;
    align-items: center;
}

.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: #9aa0a6;
    font-size: 0.9rem;
    font-family: 'Cairo', sans-serif;
}

.thinking-indicator .thinking-text {
    animation: thinkingPulse 1.8s infinite ease-in-out;
}

.thinking-indicator .thinking-dots {
    display: inline-flex;
    gap: 3px;
}

.thinking-indicator .thinking-dots .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #8ab4f8;
    animation: thinkingBounce 1.4s infinite ease-in-out;
}

.thinking-indicator .thinking-dots .dot:nth-child(2) {
    animation-delay: 0.15s;
}

.thinking-indicator .thinking-dots .dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes thinkingPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

@keyframes thinkingBounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    40% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* =============================================
   Input Area (bottom, ChatGPT-style)
   ============================================= */
.chat-input-wrapper {
    flex-shrink: 0;
    padding: 0 1rem 1rem;
    background: #131314;
}

.chat-input-container {
    max-width: 768px;
    margin: 0 auto;
}

.input-box {
    display: flex;
    align-items: flex-end;
    background: #1e1f20;
    border: 1px solid #3c3c43;
    border-radius: 26px;
    padding: 0.5rem 0.75rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-box:focus-within {
    border-color: #8ab4f8;
    box-shadow: 0 0 0 1px rgba(138, 180, 248, 0.15);
}

.input-box textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #e3e3e3;
    font-family: 'Cairo', sans-serif;
    font-size: 0.95rem;
    resize: none;
    padding: 0.5rem 0.5rem;
    max-height: 200px;
    line-height: 1.5;
}

.input-box textarea::placeholder {
    color: #9aa0a6;
}

.send-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: #8ab4f8;
    color: #131314;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s, opacity 0.2s;
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.send-btn:hover {
    background: #aecbfa;
}

.send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: #3c4043;
}

.input-disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: #9aa0a6;
    margin-top: 0.5rem;
    margin-bottom: 0;
}

/* =============================================
   Scrollbar (dark theme)
   ============================================= */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #3c3c43;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #5f6368;
}

/* =============================================
   Animations
   ============================================= */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-row {
    animation: fadeIn 0.3s ease-out;
}

/* =============================================
   Error message
   ============================================= */
.msg-text.error-text {
    color: #ef4444;
}

/* Blinking cursor while AI is still streaming */
.msg-text.streaming::after {
    content: '\25CF';
    display: inline;
    color: #8ab4f8;
    animation: cursorBlink 1s infinite;
    margin-right: 2px;
    font-size: 0.7em;
}

@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* =============================================
   Responsive
   ============================================= */
@media (max-width: 768px) {
    .message-content, .typing-content, .chat-input-container {
        padding: 0 1rem;
    }

    .welcome-state h1 {
        font-size: 1.35rem;
    }

    .suggestions {
        grid-template-columns: 1fr;
    }
}

/* =============================================
   Kinship Path (Visual Timeline)
   ============================================= */

/* Result wrapper */
.kinship-result {
    margin: 0.5rem 0;
}

.kinship-label {
    font-size: 1.1rem;
    font-weight: 700;
    color: #e3e3e3;
    background: linear-gradient(135deg, #1a3a5c, #2d1b4e);
    border: 1px solid #4285f444;
    border-radius: 12px;
    padding: 0.75rem 1.2rem;
    text-align: center;
    margin-bottom: 1rem;
    font-family: 'Cairo', sans-serif;
}

.kinship-section-title {
    font-size: 0.85rem;
    color: #9aa0a6;
    margin-bottom: 0.5rem;
    font-family: 'Cairo', sans-serif;
}

/* ============================================
   Hierarchy Tree (fork at common ancestor)
   ============================================ */
.kt-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 1rem 0;
    padding: 0.5rem 0;
}

/* Person node (generic) */
.kt-person {
    background: #1e1f20;
    border: 1.5px solid #3c3c43;
    border-radius: 8px;
    padding: 0.35rem 0.75rem;
    font-size: 0.78rem;
    color: #c4c7c5;
    font-weight: 600;
    white-space: nowrap;
    text-align: center;
    font-family: 'Cairo', sans-serif;
}

/* Common ancestor (amber) */
.kt-person.kt-ancestor {
    background: linear-gradient(135deg, #78350f, #a16207);
    border-color: #ca8a04;
    color: #fef3c7;
    font-size: 0.82rem;
    padding: 0.45rem 1rem;
    box-shadow: 0 2px 10px rgba(202, 138, 4, 0.25);
}

/* Person A highlight (Gemini blue) */
.kt-person.kt-highlight-a {
    background: linear-gradient(135deg, #1a56db, #4285f4);
    border-color: #8ab4f8;
    color: #fff;
    box-shadow: 0 2px 10px rgba(66, 133, 244, 0.3);
}

/* Person B highlight (Gemini purple) */
.kt-person.kt-highlight-b {
    background: linear-gradient(135deg, #7c3aed, #a78bfa);
    border-color: #c084fc;
    color: #fff;
    box-shadow: 0 2px 10px rgba(124, 58, 237, 0.3);
}

/* Vertical line from ancestor to horizontal bar */
.kt-fork {
    width: 2px;
    height: 20px;
    background: #3c3c43;
}

/* Container for the two branches — uses border-top as the horizontal bar */
.kt-branches {
    display: flex;
    justify-content: center;
    border-top: 2px solid #3c3c43;
    gap: 0;
}

/* Each branch column */
.kt-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 1.5rem;
    min-width: 100px;
}

/* Vertical drop from horizontal bar to first node */
.kt-drop {
    width: 2px;
    height: 16px;
    background: #3c3c43;
}

/* Vertical connector between nodes in a branch */
.kt-stem {
    width: 2px;
    height: 16px;
    background: #3c3c43;
}

/* ============================================
   Linear Chain (fallback for simple paths)
   ============================================ */
.kinship-chain {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0;
    margin: 1rem 0;
    direction: rtl;
    overflow-x: auto;
    padding: 0.75rem 0.5rem;
    -webkit-overflow-scrolling: touch;
}

.kinship-chain::-webkit-scrollbar {
    height: 4px;
}

.kinship-chain::-webkit-scrollbar-thumb {
    background: #424242;
    border-radius: 2px;
}

.kc-node {
    background: #1e1f20;
    border: 1.5px solid #3c3c43;
    border-radius: 8px;
    padding: 0.35rem 0.75rem;
    font-size: 0.78rem;
    color: #c4c7c5;
    font-weight: 600;
    white-space: nowrap;
    text-align: center;
    font-family: 'Cairo', sans-serif;
    flex-shrink: 0;
}

.kc-node.kc-start {
    background: linear-gradient(135deg, #1a56db, #4285f4);
    border-color: #8ab4f8;
    color: #fff;
    box-shadow: 0 2px 10px rgba(66, 133, 244, 0.3);
}

.kc-node.kc-end {
    background: linear-gradient(135deg, #7c3aed, #a78bfa);
    border-color: #c084fc;
    color: #fff;
    box-shadow: 0 2px 10px rgba(124, 58, 237, 0.3);
}

.kc-arrow {
    width: 40px;
    height: 2px;
    background: #3c3c43;
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kc-arrow span {
    position: absolute;
    top: -20px;
    background: #131314;
    padding: 0.1rem 0.35rem;
    font-size: 0.6rem;
    color: #9aa0a6;
    white-space: nowrap;
    font-family: 'Cairo', sans-serif;
    border-radius: 5px;
    border: 1px solid #2a2a2d;
}

/* Mobile adjustments */
@media (max-width: 600px) {
    .kt-branch {
        padding: 0 0.7rem;
        min-width: 80px;
    }

    .kt-person {
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
    }

    .kc-node {
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
    }

    .kc-arrow {
        width: 28px;
    }
}
