/* ========================================
   BallBrain Chat - CSS
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Space+Grotesk:wght@600;700;800&display=swap');

:root {
    --bg: hsl(222, 30%, 6%);
    --bg-surface: hsl(222, 25%, 10%);
    --bg-card: hsl(222, 25%, 13%);
    --bg-input: hsl(222, 25%, 11%);
    --accent: hsl(142, 72%, 50%);
    --accent-dim: hsla(142, 72%, 50%, 0.12);
    --accent-border: hsla(142, 72%, 50%, 0.3);
    --blue: hsl(210, 90%, 62%);
    --text: hsl(210, 30%, 96%);
    --text-secondary: hsl(210, 15%, 65%);
    --text-muted: hsl(210, 10%, 45%);
    --border: hsla(210, 30%, 70%, 0.08);
    --border-strong: hsla(210, 30%, 70%, 0.14);
    --user-bubble: hsl(142, 60%, 16%);
    --user-bubble-border: hsla(142, 72%, 50%, 0.2);
    --ai-bubble: hsl(222, 25%, 14%);
    --error: hsl(0, 70%, 60%);
    --error-dim: hsla(0, 70%, 60%, 0.1);
    --yellow: hsl(45, 90%, 58%);
    --font: 'Inter', sans-serif;
    --font-display: 'Space Grotesk', sans-serif;
    --radius: 8px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
}

/* ---- Header ---- */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-strong);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
    height: 64px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    transform: translateZ(0);
}

.back-btn {
    font-size: 1.6rem;
    color: var(--text-secondary);
    text-decoration: none;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 8px;
    transition: var(--transition);
    font-weight: 300;
}

.back-btn:hover {
    color: var(--text);
    background: var(--bg-card);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chat-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.chat-logo-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-header-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
}

.chat-header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    color: var(--accent);
}

.status-dot {
    width: 7px;
    height: 7px;
    background: var(--accent);
    border-radius: 50%;
    animation: dotPulse 2s ease-in-out infinite;
}

@keyframes dotPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.header-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    padding: 6px 10px;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
}

.header-btn:hover {
    border-color: var(--border-strong);
    color: var(--text);
}

.header-btn.settings-btn {
    font-size: 0.9rem;
}

/* ---- Main Chat Area ---- */
.chat-main {
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    bottom: 100px;
    overflow-y: auto;
    padding: 16px;
    scroll-behavior: smooth;
}

.chat-main::-webkit-scrollbar {
    width: 4px;
}

.chat-main::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 2px;
}

/* ---- Welcome Screen ---- */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 16px;
    max-width: 560px;
    margin: 0 auto;
}

.welcome-logo {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--accent), hsl(160, 70%, 40%));
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 38px;
    margin-bottom: 20px;
    box-shadow: 0 0 40px hsla(142, 72%, 50%, 0.25);
}

.welcome-title {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.welcome-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 36px;
}

.welcome-tips {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    padding: 20px;
}

.tip-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 14px;
}

.tip-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 0.88rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 6px;
    border: 1px solid transparent;
}

.tip-item:last-child {
    margin-bottom: 0;
}

.tip-item:hover {
    background: var(--accent-dim);
    border-color: var(--accent-border);
    color: var(--text);
}

.tip-icon {
    font-size: 1.1rem;
}

/* ---- Messages ---- */
.messages-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 760px;
    margin: 0 auto;
    padding-bottom: 8px;
}

/* Message Row */
.msg-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    animation: msgIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    opacity: 0;
    transform: translateY(16px);
}

@keyframes msgIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.msg-row.user-row {
    justify-content: flex-end;
}

.msg-row.ai-row {
    justify-content: flex-start;
}

.msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 16px;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--accent), hsl(160, 70%, 40%));
}

.msg-avatar.user-avatar {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    font-size: 14px;
}

/* Bubbles */
.bubble {
    max-width: min(460px, 75vw);
    padding: 12px 16px;
    font-size: 0.9rem;
    line-height: 1.6;
    border-radius: 18px;
    transform: translateZ(0);
}

.user-bubble {
    background: var(--user-bubble);
    border: 1px solid var(--user-bubble-border);
    border-radius: 18px 18px 4px 18px;
    color: var(--text);
}

.ai-bubble {
    background: var(--ai-bubble);
    border: 1px solid var(--border-strong);
    border-radius: 18px 18px 18px 4px;
    color: var(--text);
}

.ai-bubble.error-bubble {
    background: var(--error-dim);
    border-color: hsla(0, 70%, 60%, 0.2);
    color: var(--error);
}

/* Prediction Cards Group */
.predictions-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(520px, 85vw);
}

.prediction-card {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    padding: 16px;
    transition: var(--transition);
}

.prediction-card:hover {
    border-color: var(--accent-border);
}

.pred-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.pred-type-badge {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--accent);
    background: var(--accent-dim);
    border: 1px solid var(--accent-border);
    padding: 3px 10px;
    border-radius: 20px;
}

.pred-outcome {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
}

.pred-reason {
    font-size: 0.83rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 12px;
}

.pred-confidence-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pred-conf-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.pred-conf-track {
    flex: 1;
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
}

.pred-conf-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--accent), hsl(160, 80%, 45%));
    transition: width 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.pred-conf-pct {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent);
    width: 34px;
    text-align: right;
}

/* Confidence color shifts */
.pred-conf-fill.medium {
    background: linear-gradient(90deg, var(--yellow), hsl(35, 90%, 55%));
}

.pred-conf-fill.low {
    background: linear-gradient(90deg, var(--error), hsl(15, 80%, 55%));
}

/* Match Title in AI row */
.match-title-tag {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ---- Typing Indicator ---- */
.typing-row {
    position: fixed;
    bottom: 100px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 10;
}

.typing-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 16px;
    background: linear-gradient(135deg, var(--accent), hsl(160, 70%, 40%));
}

.typing-bubble {
    background: var(--ai-bubble);
    border: 1px solid var(--border-strong);
    border-radius: 18px 18px 18px 4px;
    padding: 12px 16px;
    display: flex;
    gap: 5px;
    align-items: center;
}

.typing-dot {
    width: 7px;
    height: 7px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: translateY(0);
        background: var(--text-muted);
    }

    40% {
        transform: translateY(-8px);
        background: var(--accent);
    }
}

.typing-text {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ---- Footer Input ---- */
.chat-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-strong);
    padding: 10px 16px 12px;
    z-index: 50;
}

.input-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: 24px;
    padding: 8px 8px 8px 16px;
    transition: var(--transition);
}

.input-bar:focus-within {
    border-color: var(--accent-border);
    box-shadow: 0 0 0 3px hsla(142, 72%, 50%, 0.08);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.92rem;
    line-height: 1.5;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    overflow-y: auto;
    padding: 4px 0;
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.chat-input::-webkit-scrollbar {
    width: 3px;
}

.chat-input::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 2px;
}

.send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: hsl(222, 30%, 6%);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.send-btn:disabled {
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    transform: scale(1.1);
    box-shadow: 0 0 16px hsla(142, 72%, 50%, 0.4);
}

.send-btn:not(:disabled):active {
    transform: scale(0.95);
}

.input-hints {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 4px 0;
}

.char-count {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.api-note {
    font-size: 0.7rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.api-note:hover {
    color: var(--accent);
}

.api-note span {
    color: var(--accent);
}

/* ---- Config Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    padding: 28px;
    max-width: 400px;
    width: 100%;
}

.modal-title {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.modal-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.modal-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    padding: 12px 14px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.88rem;
    outline: none;
    transition: var(--transition);
    margin-bottom: 20px;
}

.modal-input:focus {
    border-color: var(--accent-border);
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.modal-btn-secondary {
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    color: var(--text-secondary);
    padding: 10px 18px;
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.88rem;
    transition: var(--transition);
}

.modal-btn-secondary:hover {
    border-color: var(--border-strong);
    color: var(--text);
}

.modal-btn-primary {
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: hsl(222, 30%, 6%);
    padding: 10px 18px;
    font-weight: 700;
    font-family: var(--font);
    font-size: 0.88rem;
    cursor: pointer;
    transition: var(--transition);
}

.modal-btn-primary:hover {
    opacity: 0.9;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
    .chat-main {
        padding: 12px 10px;
    }

    .bubble {
        max-width: 82vw;
    }

    .predictions-group {
        max-width: 88vw;
    }

    .welcome-logo {
        width: 64px;
        height: 64px;
        font-size: 30px;
    }

    .welcome-title {
        font-size: 1.6rem;
    }
}

/* --- Auth UI (Chat Page) --- */
.chat-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--accent-border);
    flex-shrink: 0;
}

.chat-user-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-signin-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 6px 12px;
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font);
    white-space: nowrap;
}

.chat-signin-btn:hover {
    border-color: var(--accent-border);
    background: var(--accent-dim);
}

.chat-signout-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.72rem;
    cursor: pointer;
    padding: 3px 8px;
    transition: var(--transition);
    font-family: var(--font);
    white-space: nowrap;
}

.chat-signout-btn:hover {
    color: hsl(0, 70%, 60%);
    border-color: hsla(0, 70%, 60%, 0.2);
}

/* ====================================
   Auth Modal (chat.css copy)
   ==================================== */
.bb-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 16, 0.92);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.bb-modal-card {
    background: hsl(222, 28%, 10%);
    border: 1px solid hsla(210, 30%, 70%, 0.12);
    border-radius: 24px;
    padding: 36px 32px 32px;
    width: 100%;
    max-width: 420px;
    position: relative;
    box-shadow: 0 40px 80px rgba(0, 0, 0, 0.6);
    transform: translateY(24px) scale(0.96);
    opacity: 0;
    transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.18s ease;
}

.bb-modal-card.open {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.bb-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: hsl(222, 25%, 14%);
    border: 1px solid hsla(210, 30%, 70%, 0.1);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    font-size: 0.75rem;
    color: hsl(210, 15%, 60%);
    cursor: pointer;
    transition: all 0.2s;
}

.bb-modal-close:hover {
    color: #fff;
}

.bb-modal-logo {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--accent), hsl(160, 70%, 40%));
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 26px;
    margin: 0 auto 12px;
    box-shadow: 0 0 32px hsla(142, 72%, 50%, 0.22);
}

.bb-modal-brand {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 800;
    text-align: center;
    margin-bottom: 24px;
    color: var(--text);
}

.bb-tabs {
    display: flex;
    background: hsl(222, 28%, 14%);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 24px;
}

.bb-tab {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.bb-tab.active {
    background: hsl(222, 28%, 19%);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.bb-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.bb-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.bb-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.bb-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.bb-input {
    width: 100%;
    background: hsl(222, 28%, 14%);
    border: 1px solid hsla(210, 30%, 70%, 0.1);
    border-radius: 10px;
    padding: 11px 14px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.2s;
}

.bb-input:focus {
    border-color: var(--accent-border);
}

.bb-input::placeholder {
    color: var(--text-muted);
}

.bb-eye-btn {
    position: absolute;
    right: 10px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-muted);
    padding: 4px;
}

.bb-error {
    font-size: 0.78rem;
    color: hsl(0, 70%, 62%);
    min-height: 18px;
    font-weight: 500;
}

.bb-submit-btn {
    background: linear-gradient(135deg, hsl(142, 72%, 44%), hsl(160, 70%, 38%));
    border: none;
    border-radius: 12px;
    color: hsl(222, 30%, 6%);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 700;
    padding: 13px;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 2px;
}

.bb-submit-btn:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
}

.bb-submit-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.bb-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0 16px;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.bb-divider::before,
.bb-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: hsla(210, 30%, 70%, 0.08);
}

.bb-google-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.bb-google-btn:hover {
    background: var(--bg-input);
    transform: translateY(-1px);
}

@media (max-width: 480px) {
    .bb-modal-card {
        padding: 28px 20px 24px;
    }
}

/* Legal links */
.bb-legal {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.bb-legal-link {
    font-size: 0.72rem;
    color: hsl(210, 90%, 62%);
    text-decoration: none;
    transition: color 0.2s;
}

.bb-legal-link:hover {
    color: hsl(210, 90%, 75%);
    text-decoration: underline;
}

.bb-legal-sep {
    color: var(--text-muted);
    font-size: 0.72rem;
}