* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --pink: #ff1a75;
    --pink-dark: #cc0052;
    --pink-light: #ff4081;
    --red: #ff0040;
    --bg: #0a0005;
    --bg2: #12000a;
    --bg3: #1a0010;
    --text: #ffe0ec;
    --text2: #ffb3cc;
    --border: #ff1a7540;
    --shadow: #ff1a7530;
}

body {
    background: var(--bg);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    overflow: hidden;
    color: var(--text);
    position: relative;
}

/* === BACKGROUND LOGO === */
.bg-logo {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: min(50vw, 50vh, 400px);
    opacity: 0.03;
    pointer-events: none;
    z-index: 0;
    user-select: none;
    animation: bgPulse 4s ease-in-out infinite;
}

@keyframes bgPulse {
    0%, 100% { opacity: 0.03; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 0.05; transform: translate(-50%, -50%) scale(1.05); }
}

/* === API OVERLAY === */
.api-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5,0,2,0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.api-box {
    background: linear-gradient(180deg, var(--bg3) 0%, var(--bg2) 100%);
    border: 2px solid var(--pink);
    border-radius: 24px;
    padding: 35px 25px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 40px var(--shadow), 0 0 80px rgba(255,26,117,0.1);
}

.api-logo {
    font-size: 60px;
    margin-bottom: 10px;
    animation: bgPulse 3s ease-in-out infinite;
}

.api-box h2 {
    color: var(--pink);
    margin-bottom: 12px;
    font-size: 1.6em;
    text-shadow: 0 0 20px var(--pink);
}

.api-box p {
    color: var(--text2);
    margin-bottom: 8px;
    font-size: 0.9em;
}

.api-hint {
    font-size: 0.75em !important;
}

.api-hint a {
    color: var(--pink-light);
    text-decoration: underline;
}

.api-box input {
    width: 100%;
    padding: 14px 18px;
    background: var(--bg);
    border: 1.5px solid var(--pink);
    border-radius: 30px;
    color: #fff;
    font-size: 0.85em;
    margin: 15px 0;
    outline: none;
    text-align: center;
    transition: all 0.3s;
}

.api-box input:focus {
    box-shadow: 0 0 20px var(--shadow);
    border-color: var(--pink-light);
}

.api-box button {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--pink), var(--pink-dark));
    border: none;
    border-radius: 30px;
    color: #fff;
    font-weight: bold;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.api-box button:hover {
    transform: scale(1.03);
    box-shadow: 0 0 25px var(--shadow);
}

.api-box button:active {
    transform: scale(0.97);
}

.api-error {
    color: #ff4444 !important;
    margin-top: 10px;
    font-size: 0.85em !important;
    min-height: 20px;
}

.api-info {
    color: #996677 !important;
    font-size: 0.7em !important;
    margin-top: 15px;
}

/* === APP CONTAINER === */
.app-container {
    display: flex;
    width: 100%;
    max-width: 1300px;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

/* === SIDEBAR === */
.sidebar {
    width: 270px;
    min-width: 270px;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: all 0.3s ease;
    z-index: 10;
}

.sidebar-header {
    padding: 18px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    font-size: 1.8em;
}

.sidebar-title {
    flex: 1;
    font-weight: bold;
    color: var(--pink);
    font-size: 1em;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text2);
    font-size: 1.3em;
    cursor: pointer;
    display: none;
}

.new-chat-btn, .img-gen-btn {
    margin: 8px 10px;
    padding: 12px;
    border: none;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 0.85em;
    text-align: center;
}

.new-chat-btn {
    background: linear-gradient(135deg, var(--pink), var(--pink-dark));
    color: #fff;
}

.img-gen-btn {
    background: linear-gradient(135deg, #ff0080, #ff4081);
    color: #fff;
    margin-top: 0;
}

.new-chat-btn:hover, .img-gen-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 0 15px var(--shadow);
}

.chat-tabs {
    flex: 1;
    overflow-y: auto;
    padding: 5px 8px;
}

.chat-tabs::-webkit-scrollbar {
    width: 3px;
}

.chat-tabs::-webkit-scrollbar-thumb {
    background: var(--pink);
    border-radius: 3px;
}

.chat-tab {
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 10px;
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    font-size: 0.82em;
    color: var(--text2);
}

.chat-tab:hover {
    background: rgba(255,255,255,0.04);
}

.chat-tab.active {
    background: rgba(255,26,117,0.15);
    border-left: 3px solid var(--pink);
    color: #fff;
}

.chat-tab .tab-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-tab .tab-delete {
    opacity: 0;
    cursor: pointer;
    color: #ff4444;
    font-size: 0.75em;
    padding: 3px 6px;
    border-radius: 50%;
    transition: all 0.2s;
    background: none;
    border: none;
}

.chat-tab:hover .tab-delete {
    opacity: 1;
}

.chat-tab .tab-delete:hover {
    background: rgba(255,68,68,0.2);
}

.sidebar-footer {
    padding: 10px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#settings-btn-sidebar, #clear-all-btn {
    width: 100%;
    padding: 10px;
    border: 1px solid #333;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 0.78em;
    text-align: center;
}

#settings-btn-sidebar {
    background: rgba(255,255,255,0.03);
    color: var(--text2);
}

#clear-all-btn {
    background: rgba(255,0,0,0.1);
    color: #ff6666;
    border-color: #ff444440;
}

#settings-btn-sidebar:hover {
    background: rgba(255,255,255,0.08);
}

#clear-all-btn:hover {
    background: rgba(255,0,0,0.2);
}

/* === CHAT CONTAINER === */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--bg3) 0%, var(--bg) 100%);
    min-width: 0;
    position: relative;
}

.chat-header {
    background: linear-gradient(90deg, var(--pink-dark), var(--pink), #cc0066);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: bold;
    font-size: 1em;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
    flex-shrink: 0;
}

.menu-btn {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.3em;
    cursor: pointer;
}

#chat-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-dot {
    width: 9px;
    height: 9px;
    background: #00ff88;
    border-radius: 50%;
    animation: pulse 2s infinite;
    box-shadow: 0 0 8px #00ff88;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.4); }
}

.rename-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 50%;
    font-size: 0.85em;
    transition: all 0.3s;
}

.rename-btn:hover {
    background: rgba(255,255,255,0.3);
}

/* === CHAT BOX === */
.chat-box {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-box::-webkit-scrollbar {
    width: 4px;
}

.chat-box::-webkit-scrollbar-track {
    background: transparent;
}

.chat-box::-webkit-scrollbar-thumb {
    background: var(--pink);
    border-radius: 3px;
}

/* === MESSAGE BUBBLES === */
.message {
    max-width: 78%;
    padding: 12px 16px;
    border-radius: 20px;
    line-height: 1.55;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease;
    position: relative;
    font-size: 0.93em;
}

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

@keyframes fadeOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-8px); }
}

.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--pink), var(--pink-dark));
    color: #fff;
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 12px rgba(255,26,117,0.35);
}

.message.ai {
    align-self: flex-start;
    background: linear-gradient(135deg, #1a0a15, #200a18);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

/* === MESSAGE ACTIONS === */
.msg-actions {
    position: absolute;
    top: -12px;
    right: 12px;
    display: flex;
    gap: 3px;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .msg-actions {
    opacity: 1;
}

.msg-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.75);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    transition: all 0.2s;
}

.edit-btn:hover {
    background: #4CAF50;
    transform: scale(1.2);
}

.del-btn:hover {
    background: #f44336;
    transform: scale(1.2);
}

/* === IMAGE PANEL === */
.image-panel {
    border-top: 2px solid var(--pink);
    background: var(--bg2);
    padding: 15px;
    max-height: 320px;
    overflow-y: auto;
    flex-shrink: 0;
}

.image-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    color: var(--pink);
    font-weight: bold;
}

#close-image-panel {
    background: none;
    border: none;
    color: #ff4444;
    cursor: pointer;
    font-size: 1.2em;
}

.image-prompt-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#image-prompt {
    width: 100%;
    padding: 10px;
    background: var(--bg);
    border: 1px solid #333;
    border-radius: 10px;
    color: #fff;
    resize: none;
    font-family: inherit;
    font-size: 0.85em;
    outline: none;
}

#image-prompt:focus {
    border-color: var(--pink);
}

.image-options {
    display: flex;
    gap: 8px;
}

.image-options select {
    flex: 1;
    padding: 8px;
    background: var(--bg);
    border: 1px solid #333;
    border-radius: 8px;
    color: #fff;
    outline: none;
    font-size: 0.8em;
}

#generate-image-submit {
    padding: 10px;
    background: linear-gradient(135deg, #ff0080, #ff4081);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

#generate-image-submit:hover {
    box-shadow: 0 0 15px rgba(255,0,128,0.4);
}

#generate-image-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.image-result {
    margin-top: 10px;
    text-align: center;
}

.image-result img {
    max-width: 100%;
    max-height: 220px;
    border-radius: 12px;
    border: 2px solid var(--pink);
    box-shadow: 0 0 20px var(--shadow);
}

/* === INPUT AREA === */
.input-area {
    display: flex;
    padding: 12px 15px;
    background: var(--bg2);
    border-top: 2px solid var(--pink);
    gap: 10px;
    flex-shrink: 0;
}

.input-area input {
    flex: 1;
    padding: 13px 18px;
    background: var(--bg);
    border: 1.5px solid #333;
    border-radius: 30px;
    color: #fff;
    outline: none;
    font-size: 0.92em;
    transition: all 0.3s;
    min-width: 0;
}

.input-area input:focus {
    border-color: var(--pink);
    box-shadow: 0 0 15px var(--shadow);
}

.input-area input::placeholder {
    color: #664455;
    font-style: italic;
}

.input-area button {
    background: linear-gradient(135deg, var(--pink), var(--pink-dark));
    border: none;
    padding: 13px 22px;
    border-radius: 30px;
    font-weight: bold;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 0.92em;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.input-area button:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 0 20px var(--shadow);
}

.input-area button:active:not(:disabled) {
    transform: scale(0.95);
}

.input-area button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.footer-info {
    text-align: center;
    padding: 6px;
    font-size: 0.65em;
    color: #553344;
    background: var(--bg);
    border-top: 1px solid #1a0a15;
    flex-shrink: 0;
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100%;
        z-index: 100;
        box-shadow: 5px 0 30px rgba(0,0,0,0.5);
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .sidebar-toggle {
        display: block;
    }
    
    .menu-btn {
        display: block;
    }
    
    .message {
        max-width: 88%;
    }
    
    .input-area {
        padding: 10px 12px;
    }
    
    .input-area input {
        padding: 11px 15px;
        font-size: 0.88em;
    }
    
    .input-area button {
        padding: 11px 18px;
        font-size: 0.88em;
    }
}

@media (max-width: 400px) {
    .chat-header {
        padding: 10px 12px;
        font-size: 0.9em;
    }
    
    .message {
        max-width: 92%;
        font-size: 0.85em;
    }
    
    .input-area {
        padding: 8px 10px;
        gap: 6px;
    }
    
    .input-area input {
        padding: 10px 12px;
        font-size: 0.82em;
    }
    
    .input-area button {
        padding: 10px 14px;
        font-size: 0.82em;
    }
}
