:root {
    --bg: #1a1a1a;
    --bg2: #222222;
    --box: #2c2c2c;
    --border: #383838;
    --text: #e5e5e5;
    --muted: #888;
    --blue: #4a90d9;
    --userbubble: #2b5c8a;
    --botbubble: #2c2c2c;
    --red: #e05555;
    --r: 10px;
    --sidebar: 210px;
}

[data-theme="light"] {
    --bg: #f4f4f4;
    --bg2: #eaeaea;
    --box: #ffffff;
    --border: #cccccc;
    --text: #1a1a1a;
    --muted: #777;
    --blue: #2a6db5;
    --userbubble: #2a6db5;
    --botbubble: #ffffff;
}

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

body, html {
    height: 100%;
    font-family: 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

.blue { color: var(--blue); }

.glass {
    background: var(--box);
    border: 1px solid var(--border);
}

.hidden {
    display: none !important;
}

.screen {
    position: fixed;
    inset: 0;
    display: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.screen.active {
    display: flex;
    opacity: 1;
}

#login-screen {
    justify-content: center;
    align-items: center;
    background: var(--bg);
}

.login-box {
    width: 360px;
    padding: 2rem;
    border-radius: var(--r);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    animation: popIn 0.4s ease;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.sub {
    color: var(--muted);
    font-size: 0.83rem;
    margin-bottom: 1.5rem;
}

.field {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.field label {
    font-size: 0.8rem;
    color: var(--muted);
}

.field input {
    padding: 10px 12px;
    border-radius: var(--r);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
}

.field input:focus {
    border-color: var(--blue);
}

.field input::placeholder {
    color: var(--muted);
}

.login-box button[type="submit"] {
    width: 100%;
    padding: 10px;
    background: var(--blue);
    color: white;
    border: none;
    border-radius: var(--r);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 5px;
}

.login-box button[type="submit"]:hover {
    opacity: 0.85;
}

#chat-screen {
    flex-direction: row;
}

#sidebar {
    width: var(--sidebar);
    min-width: var(--sidebar);
    height: 100%;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1rem 0.8rem;
    z-index: 50;
    transition: transform 0.2s;
}

.side-top {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
    font-weight: 700;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.side-title { font-size: 1rem; }

#user-info {
    margin-bottom: 1rem;
}

#user-info span {
    font-size: 0.78rem;
    padding: 4px 10px;
    border-radius: 6px;
    background: var(--box);
    border: 1px solid var(--border);
    color: var(--blue);
    display: inline-block;
}

.side-btns {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.side-btns button {
    background: none;
    border: none;
    color: var(--muted);
    text-align: left;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.87rem;
}

.side-btns button:hover {
    background: var(--box);
    color: var(--text);
}

.contact-me {
    padding: 10px 0;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.contact-title {
    font-size: 0.72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: block;
    margin-bottom: 8px;
    padding: 0 2px;
}

.contact-links {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.contact-links a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.83rem;
    color: var(--muted);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.contact-links a:hover { background: var(--box); color: var(--text); }

.contact-links a svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.contact-links a[title="Instagram"]:hover { color: #e1306c; }
.contact-links a[title="GitHub"]:hover { color: #f0f0f0; }
.contact-links a[title="LinkedIn"]:hover { color: #0a66c2; }

.side-bottom {
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.toggle-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--muted);
    -webkit-user-select: none;
}

.toggle-wrap input { display: none; }

.toggle-track {
    width: 36px;
    height: 20px;
    background: var(--border);
    border-radius: 999px;
    position: relative;
}

.toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--muted);
    transition: transform 0.2s, background 0.2s;
}

.toggle-wrap input:checked ~ .toggle-track {
    background: var(--blue);
}

.toggle-wrap input:checked ~ .toggle-track .toggle-thumb {
    transform: translateX(16px);
    background: white;
}

#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

#topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#status {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4caf50;
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

#menu-btn, #clear-btn2 {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 6px;
}

#menu-btn:hover, #clear-btn2:hover {
    background: var(--box);
    color: var(--text);
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.msg-row {
    display: flex;
    gap: 8px;
    animation: fadeUp 0.2s ease;
}

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

.msg-row.user { flex-direction: row-reverse; }

.av {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    flex-shrink: 0;
    background: var(--box);
    border: 1px solid var(--border);
    color: var(--muted);
}

.msg-row.user .av {
    background: var(--blue);
    color: white;
    border-color: var(--blue);
}

.msg-body {
    max-width: 70%;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.msg-row.user .msg-body { align-items: flex-end; }

.bubble {
    padding: 8px 12px;
    border-radius: var(--r);
    font-size: 0.91rem;
    line-height: 1.6;
    word-break: break-word;
}

.msg-row.user .bubble {
    background: var(--userbubble);
    color: white;
    border-bottom-right-radius: 3px;
}

.msg-row.bot .bubble {
    background: var(--botbubble);
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: 3px;
}

.bubble p { margin-bottom: 6px; }
.bubble p:last-child { margin-bottom: 0; }

.bubble code {
    background: rgba(0,0,0,0.25);
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 0.83em;
    font-family: monospace;
}

[data-theme="light"] .bubble code {
    background: rgba(0,0,0,0.06);
}

.bubble pre {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    overflow-x: auto;
    margin: 6px 0;
}

[data-theme="light"] .bubble pre { background: #efefef; }
.bubble pre code { background: none; padding: 0; }
.bubble a { color: var(--blue); }
.bubble ul, .bubble ol { padding-left: 18px; }

.ts {
    font-size: 0.68rem;
    color: var(--muted);
    padding: 0 3px;
}

.sys-msg {
    text-align: center;
    font-size: 0.77rem;
    color: var(--muted);
    background: var(--box);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 14px;
    align-self: center;
}

.img-grid {
    display: grid;
    grid-template-columns: repeat(2, 90px);
    gap: 5px;
    margin-top: 8px;
}

.img-card {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    width: 90px;
    height: 90px;
    background: var(--box);
    border: 1px solid var(--border);
}

.img-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.2s;
}

.img-card:hover img { transform: scale(1.05); }

.img-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.2s;
}

.img-card:hover .img-overlay { opacity: 1; }

.img-overlay button, .img-overlay a {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    border-radius: 6px;
    padding: 4px 7px;
    font-size: 0.72rem;
    cursor: pointer;
    text-decoration: none;
}

.img-overlay button:hover, .img-overlay a:hover {
    background: rgba(255,255,255,0.3);
}

.skeleton {
    width: 90px;
    height: 90px;
    border-radius: 8px;
    background: linear-gradient(90deg, var(--box) 25%, var(--border) 50%, var(--box) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.3s infinite;
}

@keyframes shimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}

#typing {
    padding: 0 15px 8px;
    flex-shrink: 0;
}

.typing-box {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 12px;
    background: var(--botbubble);
    border: 1px solid var(--border);
    border-radius: var(--r);
    border-bottom-left-radius: 3px;
    font-size: 0.78rem;
    color: var(--muted);
}

.b {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--blue);
    animation: jump 1.2s infinite;
}

.b:nth-child(2) { animation-delay: 0.2s; }
.b:nth-child(3) { animation-delay: 0.4s; }

@keyframes jump {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-5px); opacity: 1; }
}

#input-area {
    padding: 10px 15px;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#msg-box {
    flex: 1;
    background: var(--box);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 9px 12px;
    color: var(--text);
    font-size: 0.91rem;
    resize: none;
    outline: none;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.5;
    font-family: inherit;
    transition: border-color 0.2s;
}

#msg-box:focus { border-color: var(--blue); }
#msg-box::placeholder { color: var(--muted); }

#send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--blue);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#send-btn:hover { opacity: 0.85; }
#send-btn svg { width: 15px; height: 15px; }

#input-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 5px;
    font-size: 0.71rem;
    color: var(--muted);
}

#input-footer code {
    background: var(--box);
    border: 1px solid var(--border);
    padding: 1px 5px;
    border-radius: 4px;
}

#img-modal {
    position: fixed;
    inset: 0;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
}

#modal-bg {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.8);
}

#modal-box {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    max-width: 90vw;
    max-height: 90vh;
    animation: popIn 0.25s ease;
}

#modal-img {
    max-width: 100%;
    max-height: 75vh;
    border-radius: var(--r);
    object-fit: contain;
}

#modal-btns {
    display: flex;
    gap: 10px;
}

#modal-dl {
    padding: 8px 16px;
    background: var(--blue);
    color: white;
    border-radius: var(--r);
    text-decoration: none;
    font-size: 0.9rem;
}

#modal-close {
    padding: 8px 16px;
    background: var(--box);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--r);
    cursor: pointer;
    font-size: 0.9rem;
}

@media (max-width: 640px) {
    #sidebar {
        position: fixed;
        transform: translateX(-100%);
        height: 100%;
    }
    #sidebar.open {
        transform: translateX(0);
    }
    #menu-btn { display: block; }
    .msg-body { max-width: 85%; }
    .img-grid { grid-template-columns: repeat(2, 80px); }
}

@media (min-width: 641px) {
    #menu-btn { display: none; }
}
