:root {
    --primary: #7209B7;
    --primary-dark: #560bad;
    --secondary: #4CC9F0;
    --bg-dark: #0a0a0f;
    --bg-sidebar: #12121a;
    --glass: rgba(255, 255, 255, 0.05);
    --text: #e0e0e0;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.app-wrapper {
    display: flex;
    height: 100%;
}

/* SIDEBAR */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, transform 0.3s ease;
    z-index: 10;
    overflow: hidden; /* Hide content when closed */
    white-space: nowrap; /* Prevent text wrap during transition */
}

.sidebar.closed {
    width: 0;
    border: none;
}

/* Mobile: Sidebar behavior overrides */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        height: 100%;
        transform: translateX(-100%);
        width: 260px;
    }

    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar.closed {
        width: 260px; /* On mobile, closed means off-screen, handled by transform */
    }
}

.brand {
    padding: 20px;
    font-family: 'Cinzel', serif;
    font-size: 1.5rem;
    color: var(--secondary);
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-new-chat {
    margin: 15px;
    padding: 12px;
    background: linear-gradient(45deg, var(--primary), var(--primary-dark));
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
    transition: 0.2s;
}

.btn-new-chat:hover {
    opacity: 0.9;
}

/* SESSION LIST STYLES (Manus Inspired) */
.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    margin-top: 10px;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    margin-bottom: 5px;
    border-radius: 8px;
    cursor: pointer;
    color: #a0a0a0;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.session-item:hover {
    background: rgba(255, 255, 255, 0.03);
    color: #e0e0e0;
}

.session-item.active {
    background: rgba(76, 201, 240, 0.1);
    border-color: rgba(76, 201, 240, 0.2);
    color: #fff;
}

.session-icon {
    font-size: 1rem;
    opacity: 0.7;
}

.session-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.session-title {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-date {
    font-size: 0.7rem;
    opacity: 0.5;
}

.btn-delete-session {
    background: none;
    border: none;
    color: #666;
    padding: 6px;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: 0.2s;
}

.session-item:hover .btn-delete-session {
    opacity: 1;
}

.btn-delete-session:hover {
    background: rgba(247, 37, 133, 0.1);
    color: #F72585;
}

/* Scrollbar for sidebar */
.session-list::-webkit-scrollbar {
    width: 4px;
}
.session-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

/* USER PROFILE (Redesigned for Organization) */
.user-profile {
    padding: 15px;
    background: #0d0d12;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: auto;
    position: relative;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.3);
}

.profile-compact {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
    padding: 8px;
    border-radius: 10px;
}

.profile-compact:hover {
    background: rgba(255, 255, 255, 0.05);
}

.avatar-container {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--primary);
    background: #000;
    flex-shrink: 0;
}

.profile-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.profile-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.credits-display {
    font-size: 0.75rem;
    color: #ffd700;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Premium Feature - Hidden by Default */
/* #btn-attach removed */

/* Helper Class */
.hidden {
    display: none !important;
}

/* Tooltip (Custom) */
.profile-tooltip {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: 110%;
    left: 10px;
    width: 240px;
    background: #1a1a2e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 5px 20px rgba(0,0,0,0.5);
    z-index: 100;
    transition: all 0.3s ease;
    transform: translateY(10px);
}

.user-profile:hover .profile-tooltip {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

.tooltip-header {
    padding: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px 12px 0 0;
}

.tooltip-header span {
    font-weight: 600;
    color: white;
}

.plan-badge {
    font-size: 0.7rem;
    padding: 4px 8px;
    border-radius: 20px;
    background: rgba(76, 201, 240, 0.1);
    color: var(--secondary) !important;
    border: 1px solid rgba(76, 201, 240, 0.3);
}

.tooltip-body {
    padding: 15px;
}

.tooltip-body p {
    margin: 0;
    font-size: 0.85rem;
    color: #aaa;
}

.tooltip-footer {
    padding: 10px 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* Custom Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: none; /* Allows clicking through container */
}

.toast {
    background: rgba(20, 20, 25, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 16px 24px;
    border-radius: 12px;
    min-width: 300px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    gap: 15px;
    transform: translateX(120%);
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    pointer-events: auto;
    position: relative;
    overflow: hidden;
}

.toast::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: currentColor;
    opacity: 0.8;
}

.toast.show {
    transform: translateX(0);
}

.toast.success { color: #4CC9F0; border-color: rgba(76, 201, 240, 0.3); }
.toast.error { color: #F72585; border-color: rgba(247, 37, 133, 0.3); }
.toast.info { color: #e0e0e0; border-color: rgba(255, 255, 255, 0.2); }

/* Override left border with pseudo element color */
.toast.success::before { background: #4CC9F0; }
.toast.error::before { background: #F72585; }
.toast.info::before { background: #e0e0e0; }

.toast-icon {
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 4px;
    color: #fff;
    font-family: 'Cinzel', serif;
    letter-spacing: 0.5px;
}

.toast-message {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.4;
}

/* Logout Button Enhanced */
#btn-logout {
    width: 100%;
    background: rgba(247, 37, 133, 0.05);
    color: #F72585;
    border: 1px solid rgba(247, 37, 133, 0.3);
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#btn-logout:hover {
    background: rgba(247, 37, 133, 0.15);
    border-color: #F72585;
    box-shadow: 0 0 20px rgba(247, 37, 133, 0.3);
    transform: translateY(-2px);
    color: #fff;
}

#btn-logout i {
    transition: transform 0.3s ease;
}

#btn-logout:hover i {
    transform: translateX(4px);
}

/* Fix mobile toggle visibility/position */
.mobile-only {
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20; /* Ensure above logo */
}

/* CHAT AREA */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-image: radial-gradient(circle at top right, #1a1a2e 0%, #0a0a0f 60%);
    position: relative;
}

.chat-header {
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    height: 60px;
    position: relative; /* Enable absolute positioning for children */
    justify-content: space-between;
}

.header-logo {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Cinzel', serif;
    font-size: 1.2rem;
    color: var(--secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none; /* Let clicks pass through if needed, though unlikely */
}

.chat-header h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 400;
    color: #fff;
    display: none; /* Hide old h2 if present */
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Bubbles */
.message {
    display: flex;
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message.system {
    justify-content: center;
    opacity: 0.7;
    font-size: 0.85rem;
}

.bubble {
    max-width: 70%;
    padding: 12px 18px;
    border-radius: 12px;
    line-height: 1.5;
    word-wrap: break-word;
    /* Importante para não quebrar layout */
    white-space: pre-wrap;
    /* Mantém quebras de linha */
}

/* ONBOARDING MODAL */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.modal-container {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    width: 90%;
    max-width: 500px;
    max-height: 90vh; /* Limit modal height */
    display: flex; /* Flexbox for sticky header/footer */
    flex-direction: column;
    padding: 40px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 30px rgba(114, 9, 183, 0.2);
    text-align: center;
    animation: fadeIn 0.5s ease;
}

.onboarding-step {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden; /* Prevent spill */
}

.onboarding-step h2 {
    font-family: 'Cinzel', serif;
    color: var(--secondary);
    margin-bottom: 10px;
    font-size: 2rem;
}

.onboarding-step p {
    color: #ccc;
    margin-bottom: 30px;
}

.onboarding-step input {
    width: 100%;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: #fff;
    font-size: 1.1rem;
    margin-bottom: 30px;
    outline: none;
    transition: 0.3s;
    text-align: center;
}

.onboarding-step input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(76, 201, 240, 0.2);
}

.btn-primary {
    background: var(--primary);
    color: #000;
    border: none;
    padding: 15px 40px;
    border-radius: 50px;
    font-weight: bold;
    font-size: 1rem;
    cursor: pointer;
    transition: 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary:hover:not(:disabled) {
    background: #fff;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 255, 255, 0.2);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #555;
}

/* Avatar Gallery */
.avatar-gallery {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8%; /* Increased gap */
    padding: 5%; /* Percentage padding */
    
    /* Scroll Logic */
    flex: 1; 
    min-height: 0; 
    overflow-y: auto;
    
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.05);

    /* Custom Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--secondary) rgba(0,0,0,0.1);
}

.avatar-gallery::-webkit-scrollbar {
    width: 8px;
}

.avatar-gallery::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
}

.avatar-gallery::-webkit-scrollbar-thumb {
    background: var(--secondary);
    border-radius: 4px;
}

.avatar-option {
    aspect-ratio: 1;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    overflow: hidden;
    transition: 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    
    /* Responsive width */
    width: 100%; 
    max-width: none; 
}

.avatar-option img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-option:hover {
    transform: scale(1.05);
    border-color: rgba(255, 255, 255, 0.5);
}

.avatar-option.selected {
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(76, 201, 240, 0.4);
    transform: scale(1.05);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user .bubble {
    background-color: var(--primary);
    color: white;
    border-bottom-right-radius: 2px;
}

.message.assistant .bubble {
    background-color: #1e1e24;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
    border-bottom-left-radius: 2px;
}

/* Input Area */
.input-area {
    padding: 20px;
    background: rgba(10, 10, 15, 0.8);
    backdrop-filter: blur(10px);
}

#chat-form {
    display: flex;
    gap: 10px;
    background: #1e1e24;
    padding: 8px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    align-items: center;
}

#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    padding: 10px;
    font-size: 1rem;
}

#chat-input:focus {
    outline: none;
}

.btn-attach,
.btn-send {
    background: none;
    border: none;
    color: #aaa;
    padding: 10px;
    cursor: pointer;
    transition: 0.2s;
    border-radius: 50%;
}

.btn-attach:hover {
    color: var(--secondary);
    background: rgba(255, 255, 255, 0.05);
}

.btn-send {
    background: var(--primary);
    color: white;
}

.btn-send:hover {
    opacity: 0.9;
}

.file-preview {
    background: #1e1e24;
    padding: 5px 10px;
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    border: 1px solid var(--secondary);
    color: var(--secondary);
    font-size: 0.85rem;
}

.hidden {
    display: none !important;
}

/* CARD SYSTEM STYLES */
.game-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    margin-top: 15px;
    overflow: hidden;
    max-width: 100%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}

.game-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.card-header {
    padding: 15px;
    display: flex;
    align-items: center;
    gap: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.card-npc .card-header { background: linear-gradient(135deg, rgba(114, 9, 183, 0.2), rgba(86, 11, 173, 0.2)); border-left: 4px solid #7209B7; }
.card-item .card-header { background: linear-gradient(135deg, rgba(76, 201, 240, 0.2), rgba(72, 149, 239, 0.2)); border-left: 4px solid #4CC9F0; }
.card-monster .card-header { background: linear-gradient(135deg, rgba(247, 37, 133, 0.2), rgba(181, 23, 158, 0.2)); border-left: 4px solid #F72585; }
.card-location .card-header { background: linear-gradient(135deg, rgba(58, 12, 163, 0.2), rgba(67, 97, 238, 0.2)); border-left: 4px solid #3A0CA3; }

.card-type-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: white;
}

.card-title h4 {
    margin: 0;
    font-size: 1.1rem;
    color: white;
    font-family: 'Cinzel', serif;
}

.card-title span {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 1px;
}

.card-body {
    padding: 15px;
}

.card-description {
    font-size: 0.9rem;
    color: #e0e0e0;
    margin-bottom: 15px;
    line-height: 1.5;
    font-style: italic;
    background: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-radius: 6px;
}

.card-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.stat-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 8px;
    border-radius: 6px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.7rem;
    color: #aaa;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.stat-value {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--secondary);
}

.card-traits {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.trait-tag {
    background: rgba(76, 201, 240, 0.1);
    border: 1px solid rgba(76, 201, 240, 0.3);
    color: var(--secondary);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.mobile-only {
    display: block; /* Visible on Desktop too now */
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    margin-right: 10px;
}

.mobile-only:hover {
    color: var(--secondary);
}

/* Sidebar behavior */
@media (min-width: 769px) {
    .sidebar.closed {
        width: 0;
        border: none;
        overflow: hidden;
    }
    
    .chat-header h2 {
        margin-left: 0;
    }
}

/* Overlay para mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9;
    backdrop-filter: blur(5px);
}

.sidebar-overlay.active {
    display: block;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }

    .sidebar {
        position: fixed;
        height: 100%;
        transform: translateX(-100%);
        box-shadow: 2px 0 20px rgba(0, 0, 0, 0.5);
    }

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

    .chat-header h2 {
        font-size: 1rem;
    }

    .bubble {
        max-width: 85%;
    }

    .input-area {
        padding: 15px;
    }

    #chat-input {
        font-size: 16px;
        /* Previne zoom no iOS */
    }
}

@media (max-width: 480px) {
    .brand {
        font-size: 1.2rem;
        padding: 15px;
    }

    .btn-new-chat {
        margin: 10px;
        padding: 10px;
        font-size: 0.9rem;
    }

    .bubble {
        max-width: 90%;
        padding: 10px 14px;
        font-size: 0.95rem;
    }

    .input-area {
        padding: 10px;
    }

    #chat-form {
        padding: 6px;
    }

    .modal-container {
        padding: 20px;
        width: 95%;
        max-height: 95vh;
    }
}