/* 
 * Frog AI | Premium Chat Design System
 * Features: Dark/Light Mode, Glassmorphism, Animations, Markdown Support
 */

:root {
    /* Color Palette - Dark Theme (Default) — pure black base */
    --bg-base: #000000;
    --bg-gradient-1: #000000;
    --bg-gradient-2: #0a0a0a;

    --glass-bg: rgba(15, 15, 15, 0.85);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.6);

    --primary: #8b5cf6;
    --primary-hover: #7c3aed;
    --secondary: #10b981;
    /* For mic button */
    --accent: #ef4444;
    /* For delete button */

    --text-main: #f8fafc;
    --text-muted: #94a3b8;

    --user-msg-bg: rgba(139, 92, 246, 0.18);
    --user-msg-border: rgba(139, 92, 246, 0.35);

    --ai-msg-bg: rgba(20, 20, 20, 0.9);
    --ai-msg-border: rgba(255, 255, 255, 0.06);

    --code-bg: #111111;

    --layout-radius: 20px;
    --element-radius: 12px;
}

[data-theme="light"] {
    --bg-base: #f8fafc;
    --bg-gradient-1: #e2e8f0;
    --bg-gradient-2: #f1f5f9;

    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 255, 255, 1);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);

    --primary: #6366f1;
    --primary-hover: #4f46e5;

    --text-main: #0f172a;
    --text-muted: #64748b;

    --user-msg-bg: #e0e7ff;
    --user-msg-border: #6366f1;

    --ai-msg-bg: #ffffff;
    --ai-msg-border: #e2e8f0;

    --code-bg: #f1f5f9;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
    background-color: var(--bg-base);
    background: var(--bg-base);
    color: var(--text-main);
    line-height: 1.6;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: background 0.5s ease;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Background Shapes — hidden on black theme */
.bg-shapes {
    display: none;
}

/* Layout Containers */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    gap: 1rem;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: var(--layout-radius);
    transition: all 0.3s ease;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    flex-shrink: 0;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-wrapper {
    position: relative;
}

.logo {
    height: 50px;
    width: 50px;
    border-radius: 12px;
    object-fit: cover;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.logo-container h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: -4px;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, var(--text-main), var(--primary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.status-badge {
    font-size: 0.75rem;
    color: var(--secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.pulse {
    width: 8px;
    height: 8px;
    background-color: var(--secondary);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulsing 2s infinite cubic-bezier(0.66, 0, 0, 1);
}

@keyframes pulsing {
    to {
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

.btn-icon {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--glass-border);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--glass-border);
    color: var(--text-main);
    transform: translateY(-2px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    padding: 0 1rem;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.btn-ghost:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--accent);
}

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    min-width: 0;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
    min-width: 0;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    margin: auto 0;
    padding: 2rem 1rem;
    animation: fadeInUp 0.6s ease-out forwards;
}

.welcome-icon {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 1rem;
    filter: drop-shadow(0 0 10px rgba(139, 92, 246, 0.5));
}

.welcome-message h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.welcome-message p {
    color: var(--text-muted);
    font-size: 1.1rem;
    max-width: 500px;
    margin: 0 auto 2rem auto;
}

.suggestions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    max-width: 800px;
    margin: 0 auto;
}

.suggestion-btn {
    background: var(--ai-msg-bg);
    border: 1px solid var(--glass-border);
    padding: 1rem;
    border-radius: var(--element-radius);
    color: var(--text-main);
    cursor: pointer;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: all 0.3s ease;
    font-size: 0.95rem;
}

.suggestion-btn i {
    color: var(--primary);
    font-size: 1.25rem;
}

.suggestion-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    border-color: var(--primary);
}

/* Chat Messages */
.message-wrapper {
    display: flex;
    flex-direction: column;
    min-width: 0;
    animation: slideInUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* FIX 1: user bubble — unchanged, already correct */
.message-wrapper.user {
    align-self: flex-end;
    align-items: flex-end;
    width: auto;
    max-width: 85%;
    min-width: 0;
}

/* FIX 1: assistant bubble — fit-content so short replies don't stretch full width */
.message-wrapper.assistant {
    align-self: flex-start;
    align-items: flex-start;
    width: fit-content;
    max-width: 85%;
    min-width: 0;
}

.message {
    padding: 1rem 1.25rem;
    line-height: 1.7;
    font-size: 1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.user .message {
    background: var(--user-msg-bg);
    border: 1px solid var(--user-msg-border);
    border-radius: 18px 18px 4px 18px;
    color: var(--text-main);
    width: auto;
    min-width: 0;
}

.assistant .message {
    background: var(--ai-msg-bg);
    border: 1px solid var(--ai-msg-border);
    border-radius: 18px 18px 18px 4px;
    color: var(--text-main);
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
    margin-bottom: -0.5rem;
}

/* Markdown Styling within Assistant Messages */
.message h1,
.message h2,
.message h3,
.message h4 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.message h1:first-child,
.message h2:first-child,
.message h3:first-child {
    margin-top: 0;
}

.message p {
    margin-bottom: 0.75rem;
}

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

.message ul,
.message ol {
    margin-left: 1.5rem;
    margin-bottom: 0.75rem;
}

.message li {
    margin-bottom: 0.25rem;
}

.message a {
    color: var(--primary);
    text-decoration: none;
}

.message a:hover {
    text-decoration: underline;
}

/* Inline Code */
.message code {
    background: var(--code-bg);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.9em;
    color: #e2e8f0;
}

[data-theme="light"] .message code {
    color: #0f172a;
    border: 1px solid #e2e8f0;
}

/* Code Blocks — horizontal scroll enabled for long lines */
.message pre {
    background: var(--code-bg);
    border-radius: 8px;
    padding: 1rem;
    overflow-x: auto;
    margin: 1rem 0;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
    max-width: 100%;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.message pre code {
    background: transparent;
    padding: 0;
    border: none;
    color: inherit;
    font-size: 0.9em;
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
    display: block;
    max-width: max-content;
}

/* Tables — horizontal scroll if too wide */
.message table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    display: block;
    overflow-x: auto;
    white-space: nowrap;
}

.message th,
.message td {
    padding: 0.5rem 1rem;
    border: 1px solid var(--glass-border);
    text-align: left;
}

.message th {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
}

/* Input Area */
.input-wrapper {
    padding: 1rem 1.5rem 1.5rem 1.5rem;
    background: linear-gradient(to top, var(--glass-bg), transparent);
    border-top: 1px solid var(--glass-border);
}

.glass-input-container {
    display: flex;
    background: var(--ai-msg-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 0.5rem;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

.glass-input-container:focus-within {
    border-color: var(--primary);
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.2);
}

#user-input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0.5rem 1rem;
    color: var(--text-main);
    font-size: 1rem;
    outline: none;
}

#user-input::placeholder {
    color: var(--text-muted);
}

.input-actions {
    display: flex;
    gap: 0.5rem;
    padding-right: 0.25rem;
}

#mic-btn.recording {
    background-color: rgba(239, 68, 68, 0.2);
    color: var(--accent);
    animation: micPulse 1.5s infinite;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-primary:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.btn-primary:active:not(:disabled) {
    transform: scale(0.95);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--text-muted);
}

.disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
}

/* Typing Indicator Overlay */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0 1rem 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    animation: fadeIn 0.3s ease-out;
}

.dots-container {
    display: flex;
    gap: 4px;
    background: var(--ai-msg-bg);
    padding: 6px 10px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.dots-container span {
    width: 5px;
    height: 5px;
    background: var(--primary);
    border-radius: 50%;
    animation: jump 1.4s infinite ease-in-out both;
}

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

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

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

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes jump {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1.5);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes micPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    70% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* Footer Bar */
.app-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1.5rem;
    flex-shrink: 0;
    font-size: 0.78rem;
    color: var(--text-muted);
    gap: 1rem;
}

.footer-dev {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 500;
}

.footer-dev i {
    color: var(--primary);
}

.footer-dev a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

.footer-dev a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.footer-version {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.version-badge,
.model-badge {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--glass-border);
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    border: 1px solid var(--glass-border);
    font-weight: 500;
    letter-spacing: 0.02em;
    transition: background 0.2s ease;
}

.version-badge i {
    color: var(--secondary);
    font-size: 0.7rem;
}

.model-badge i {
    color: var(--primary);
    font-size: 0.7rem;
}

.footer-clock {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--text-main);
    background: var(--glass-border);
    padding: 0.2rem 0.75rem;
    border-radius: 20px;
    border: 1px solid var(--glass-border);
}

.footer-clock i {
    color: var(--primary);
    font-size: 0.75rem;
    animation: tickTock 1s step-start infinite;
}

@keyframes tickTock {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }

    100% {
        opacity: 1;
    }
}

/* ==============================
   RESPONSIVE SYSTEM
   ============================== */

#user-input {
    font-size: 16px;
}

/* ── Medium / Tablet ── */
@media (max-width: 768px) {
    .app-container {
        padding: 0;
        gap: 0;
        height: 100dvh;
    }

    .glass-panel {
        border-radius: 0;
        border: none;
        border-bottom: 1px solid var(--glass-border);
    }

    .app-header {
        padding: 0.75rem 1rem;
    }

    .logo {
        height: 40px;
        width: 40px;
    }

    .logo-container h1 {
        font-size: 1.15rem;
    }

    .suggestions {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    /* FIX 3 (tablet): assistant bubble fit-content */
    .message-wrapper {
        max-width: 92%;
        min-width: 0;
    }

    .message-wrapper.user {
        width: auto;
        max-width: 92%;
    }

    .message-wrapper.assistant {
        width: fit-content;
        max-width: 92%;
        min-width: 0;
    }

    .input-wrapper {
        padding: 0.75rem 1rem;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }

    .app-footer {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.4rem;
        padding: 0.5rem 1rem;
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    }

    .footer-version {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* ── Small Mobile ── */
@media (max-width: 480px) {
    .app-header {
        padding: 0.6rem 0.875rem;
    }

    .logo {
        height: 34px;
        width: 34px;
        border-radius: 8px;
    }

    .logo-container {
        gap: 0.6rem;
    }

    .logo-container h1 {
        font-size: 1rem;
        letter-spacing: -0.3px;
    }

    .status-badge {
        font-size: 0.68rem;
    }

    .btn-ghost {
        padding: 0 0.6rem;
        font-size: 0.8rem;
        height: 36px;
    }

    .btn-icon {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }

    .welcome-message {
        padding: 1.25rem 0.75rem;
    }

    .welcome-icon {
        font-size: 2.25rem;
        margin-bottom: 0.75rem;
    }

    .welcome-message h2 {
        font-size: 1.35rem;
    }

    .welcome-message p {
        font-size: 0.9rem;
    }

    .suggestions {
        grid-template-columns: 1fr;
        gap: 0.6rem;
    }

    .suggestion-btn {
        flex-direction: row;
        align-items: center;
        gap: 0.75rem;
        padding: 0.75rem 1rem;
    }

    .suggestion-btn i {
        font-size: 1.1rem;
        flex-shrink: 0;
    }

    /* FIX 4 (mobile): assistant bubble fit-content */
    .message-wrapper {
        max-width: 95%;
        min-width: 0;
    }

    .message-wrapper.user {
        width: auto;
        max-width: 95%;
    }

    .message-wrapper.assistant {
        width: fit-content;
        max-width: 95%;
        min-width: 0;
    }

    .message {
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
    }

    .chat-history {
        padding: 1rem 0.75rem;
        gap: 1rem;
    }

    .input-wrapper {
        padding: 0.6rem 0.75rem;
        padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
    }

    .glass-input-container {
        border-radius: 14px;
    }

    #user-input {
        padding: 0.4rem 0.75rem;
    }

    .btn-primary {
        width: 40px;
        height: 40px;
        border-radius: 10px;
    }

    .disclaimer {
        font-size: 0.68rem;
        margin-top: 0.5rem;
    }

    .app-footer {
        flex-direction: column;
        align-items: center;
        gap: 0.35rem;
        padding: 0.5rem 0.75rem;
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
        font-size: 0.72rem;
    }

    .footer-clock {
        padding: 0.15rem 0.6rem;
    }

    .footer-version {
        gap: 0.4rem;
    }

    .version-badge,
    .model-badge {
        padding: 0.15rem 0.5rem;
        font-size: 0.7rem;
    }
}

/* ── Extra-small ── */
@media (max-width: 360px) {
    .logo-container h1 {
        display: none;
    }

    .suggestions {
        grid-template-columns: 1fr;
    }

    .footer-version .model-badge {
        display: none;
    }
}

/* ── Large desktop ── */
@media (min-width: 1400px) {
    .app-container {
        max-width: 1400px;
    }
}

/* ── Touch device hover removal ── */
@media (hover: none) {
    .suggestion-btn:hover {
        transform: none;
        box-shadow: none;
    }

    .btn-ghost:hover {
        background: transparent;
        border-color: var(--glass-border);
        color: var(--text-main);
    }

    .btn-icon:hover {
        background: transparent;
        transform: none;
    }
}