/* ==========================================================================
   SourNex Engine - Custom Stylesheet
   ========================================================================== */

:root {
    --bg-dark: #070709;
    --bg-surface: #0f0f12;
    --bg-surface-elevated: #16161a;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(212, 175, 55, 0.3);
    --accent-gold: #d4af37;
    --accent-gold-hover: #f1c40f;
    --text-primary: #f4f4f6;
    --text-secondary: #8e8e93;
    --text-muted: #545458;
    --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --glass-bg: rgba(15, 15, 18, 0.78);
    --shadow-gold: 0 0 25px -5px rgba(212, 175, 55, 0.15);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    background-image:
        radial-gradient(circle at 50% 0%, rgba(212, 175, 55, 0.04) 0%, transparent 70%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.015) 0%, transparent 50%);
    background-attachment: fixed;
    margin: 0;
}

.font-mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

.hidden {
    display: none !important;
}

svg {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

/* --- Focus Accessibility --- */
:focus-visible {
    outline: 2px solid rgba(212, 175, 55, 0.65);
    outline-offset: 2px;
}

/* --- Glassmorphism Header & Floating Composer --- */
header, .snx-floating-composer {
    background: var(--glass-bg) !important;
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-color: var(--border-color) !important;
}

/* --- Auth Modal Overlay --- */
#auth-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(7, 7, 9, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.875rem;
}

.auth-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 1.25rem;
    border-radius: 1rem;
    max-width: 28rem;
    width: 100%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65), var(--shadow-gold);
    max-height: 90dvh;
    overflow-y: auto;
}

@media (min-width: 640px) {
    .auth-card {
        padding: 1.5rem;
    }
}

/* --- Form Inputs --- */
.auth-card input[type="text"],
.auth-card input[type="email"],
.auth-card input[type="password"],
.auth-card input[type="date"] {
    width: 100%;
    background-color: rgba(7, 7, 9, 0.72);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    color: var(--text-primary);
    font-size: 1rem;
    padding: 0.65rem 0.95rem;
    transition: border-color 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 640px) {
    .auth-card input[type="text"],
    .auth-card input[type="email"],
    .auth-card input[type="password"],
    .auth-card input[type="date"] {
        font-size: 0.875rem;
    }
}

.auth-card input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.8);
    cursor: pointer;
}

.auth-card input[type="text"]:focus,
.auth-card input[type="email"]:focus,
.auth-card input[type="password"]:focus,
.auth-card input[type="date"]:focus {
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.15);
    outline: none;
}

/* --- Accent Buttons --- */
#btn-submit {
    background: linear-gradient(135deg, #d4af37 0%, #aa820a 100%);
    color: #000000;
    font-weight: 700;
    letter-spacing: 0.1em;
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.2);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease, filter 0.2s ease;
}

#btn-submit:hover:not(:disabled) {
    filter: brightness(1.08);
    box-shadow: 0 6px 20px rgba(212, 175, 55, 0.35);
    transform: translateY(-1px);
}

#btn-google, #btn-github {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

#btn-google:hover, #btn-github:hover {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.05);
    color: #ffffff;
}

/* --- Chat Thread Scroll, Pinch-Zoom Message Scaling & Selection --- */
#chat-thread {
    --snx-msg-scale: 1;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

#chat-thread, #chat-thread * {
    user-select: text;
    -webkit-user-select: text;
}

.snx-msg-text {
    font-size: calc(0.875rem * var(--snx-msg-scale, 1));
    line-height: 1.58;
}

/* --- Safe Markdown & Code Blocks --- */
.snx-markdown {
    font-size: calc(0.875rem * var(--snx-msg-scale, 1));
    line-height: 1.58;
    color: #e4e4e7;
    overflow-wrap: anywhere;
    word-break: break-word;
    min-width: 0;
}

.snx-markdown > * + * {
    margin-top: 0.55rem;
}

.snx-markdown h1,
.snx-markdown h2,
.snx-markdown h3 {
    color: #ffffff;
    font-weight: 600;
    line-height: 1.35;
    margin-top: 0.75rem;
}

.snx-markdown h1 { font-size: calc(1.08rem * var(--snx-msg-scale, 1)); }
.snx-markdown h2 { font-size: calc(0.98rem * var(--snx-msg-scale, 1)); }
.snx-markdown h3 { font-size: calc(0.9rem * var(--snx-msg-scale, 1)); color: #f4e3a3; }

.snx-markdown ul,
.snx-markdown ol {
    padding-left: 1.25rem;
}

.snx-markdown ul { list-style-type: disc; }
.snx-markdown ol { list-style-type: decimal; }

.snx-markdown li + li {
    margin-top: 0.25rem;
}

.snx-markdown blockquote {
    border-left: 2px solid rgba(212, 175, 55, 0.5);
    padding-left: 0.75rem;
    color: #a1a1aa;
    font-style: italic;
}

.snx-markdown a {
    color: var(--accent-gold);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.snx-markdown code.snx-inline-code {
    font-family: var(--font-mono);
    font-size: 0.8em;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #f5d77f;
    padding: 0.1rem 0.35rem;
    border-radius: 0.35rem;
}

.snx-code-block {
    background: #070709;
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 0.75rem;
    overflow: hidden;
    margin-top: 0.75rem;
    width: 100%;
    max-width: 100%;
}

.snx-code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #8e8e93;
}

.snx-copy-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #d4d4d8;
    border-radius: 0.4rem;
    padding: 0.25rem 0.6rem;
    font-size: 0.7rem;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.snx-copy-btn:hover {
    border-color: var(--accent-gold);
    color: var(--accent-gold);
}

.snx-code-block pre {
    margin: 0;
    padding: 0.75rem;
    max-width: 100%;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: calc(0.78rem * var(--snx-msg-scale, 1));
    line-height: 1.5;
    color: #e4e4e7;
}

/* --- Toast Stack --- */
#snx-toast-container {
    position: fixed;
    top: 4rem;
    left: 1rem;
    right: 1rem;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 24rem;
    margin-left: auto;
    pointer-events: none;
}

.snx-toast {
    pointer-events: auto;
    background: #121216;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.75rem;
    padding: 0.8rem 0.95rem;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
    color: #e4e4e7;
    font-size: 0.8125rem;
    line-height: 1.45;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.snx-toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.snx-toast--success { border-color: rgba(16, 185, 129, 0.4); }
.snx-toast--warning { border-color: rgba(212, 175, 55, 0.45); }
.snx-toast--error { border-color: rgba(239, 68, 68, 0.45); }

/* --- AI Thinking & Chain-of-Thought Loading Animation --- */
.snx-thinking-box {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    width: 100%;
    text-align: left;
}

.snx-thinking-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: calc(0.8125rem * var(--snx-msg-scale, 1));
    color: #e4e4e7;
    font-weight: 500;
}

.snx-thinking-dots {
    display: inline-flex;
    align-items: center;
    gap: 0.24rem;
    flex-shrink: 0;
}

.snx-thinking-dots span {
    width: 5px;
    height: 5px;
    border-radius: 9999px;
    background-color: var(--accent-gold);
    animation: snx-dot-bounce 1.3s infinite ease-in-out both;
}

.snx-thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.snx-thinking-dots span:nth-child(2) { animation-delay: -0.16s; }
.snx-thinking-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes snx-dot-bounce {
    0%, 80%, 100% {
        transform: scale(0.55);
        opacity: 0.35;
    }
    40% {
        transform: scale(1.1);
        opacity: 1;
    }
}

.snx-thinking-steps {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding-left: 0.15rem;
}

.snx-thinking-step {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: calc(0.75rem * var(--snx-msg-scale, 1));
    color: #71717a;
    animation: snx-step-in 0.24s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transition: color 0.2s ease, opacity 0.2s ease;
}

@keyframes snx-step-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.snx-thinking-step.is-active {
    color: #f4e3a3;
}

.snx-thinking-step.is-done {
    color: #a1a1aa;
}

/* --- Message Zoom Badge --- */
#snx-zoom-indicator {
    position: fixed;
    top: 3.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(-4px);
    z-index: 45;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.65rem;
    border-radius: 9999px;
    background: rgba(18, 18, 22, 0.94);
    border: 1px solid rgba(212, 175, 55, 0.35);
    color: #e4e4e7;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

#snx-zoom-indicator.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.snx-shimmer-stack {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding-top: 0.15rem;
}

.snx-shimmer-line {
    height: 0.6rem;
    border-radius: 9999px;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.05) 0%,
        rgba(212, 175, 55, 0.18) 50%,
        rgba(255, 255, 255, 0.05) 100%
    );
    background-size: 200% 100%;
    animation: snx-shimmer 1.6s infinite linear;
}

@keyframes snx-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* --- Custom Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-gold);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
