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

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: #0f0f0f;
    color: #e8e8e8;
    font-size: 15px;
    line-height: 1.6;
}

a { color: inherit; text-decoration: none; }

/* App layout */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: #1a1a1a;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #2a2a2a;
    overflow: hidden;
}

.sidebar-header {
    padding: 24px 20px 16px;
    border-bottom: 1px solid #2a2a2a;
}

.sidebar-logo {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: #7c6af7;
}

.sidebar-actions {
    padding: 12px 12px 8px;
}

.btn-new-conv {
    display: block;
    width: 100%;
    padding: 9px 14px;
    background: rgba(124, 106, 247, 0.12);
    border: 1px solid rgba(124, 106, 247, 0.25);
    border-radius: 8px;
    color: #a78bfa;
    font-size: 0.85rem;
    text-align: center;
    transition: all 0.2s;
    cursor: pointer;
}

.btn-new-conv:hover {
    background: rgba(124, 106, 247, 0.2);
    border-color: rgba(124, 106, 247, 0.4);
}

.conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 8px;
}

.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-track { background: transparent; }
.conv-list::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 2px; }

/* Conversation item wrapper (enables relative positioning for delete btn) */
.conv-item-wrap {
    position: relative;
    margin-bottom: 2px;
    border-radius: 8px;
    overflow: hidden;
    transition: background 0.15s;
}

.conv-item-wrap:hover { background: #242424; }
.conv-item-wrap.active { background: rgba(124, 106, 247, 0.1); }

/* The actual link inside the wrapper */
.conv-item-link {
    display: block;
    padding: 10px 36px 10px 12px; /* right padding reserves space for delete btn */
    cursor: pointer;
    text-decoration: none;
}

.conv-title {
    display: block;
    font-size: 0.85rem;
    color: #ccc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item-wrap.active .conv-title { color: #e8e8e8; }

.conv-date {
    display: block;
    font-size: 0.72rem;
    color: #555;
    margin-top: 2px;
}

/* Delete button — hidden until hover / swipe */
.btn-delete-conv {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: #555;
    padding: 6px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.conv-item-wrap:hover .btn-delete-conv { opacity: 1; }
.btn-delete-conv:hover { color: #ff6b6b; background: rgba(220, 53, 69, 0.12); }

/* Mobile swipe: reveal delete zone */
.conv-item-wrap.swiped { background: rgba(220, 53, 69, 0.08); }
.conv-item-wrap.swiped .btn-delete-conv { opacity: 1; color: #ff6b6b; }
.conv-item-wrap.swiped .conv-item-link { transform: translateX(-44px); transition: transform 0.2s; }
.conv-item-link { transition: transform 0.2s; }

/* ===== MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-overlay.open { display: flex; }

.modal-box {
    background: #1e1e2e;
    border: 1px solid #2a2a2a;
    border-radius: 14px;
    padding: 28px 28px 24px;
    max-width: 420px;
    width: 100%;
    animation: modal-in 0.18s ease;
}

@keyframes modal-in {
    from { opacity: 0; transform: scale(0.95) translateY(8px); }
    to   { opacity: 1; transform: scale(1)    translateY(0);   }
}

.modal-title {
    font-size: 1rem;
    font-weight: 600;
    color: #e8e8e8;
    margin-bottom: 12px;
}

.modal-body {
    font-size: 0.88rem;
    color: #999;
    line-height: 1.65;
    margin-bottom: 24px;
}

.modal-note {
    display: block;
    margin-top: 8px;
    font-size: 0.8rem;
    color: #666;
    font-style: italic;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.btn-modal-cancel {
    padding: 9px 18px;
    background: none;
    border: 1px solid #333;
    border-radius: 8px;
    color: #888;
    cursor: pointer;
    font-size: 0.88rem;
    font-family: inherit;
    transition: border-color 0.15s, color 0.15s;
}

.btn-modal-cancel:hover { border-color: #555; color: #ccc; }

.btn-modal-confirm {
    padding: 9px 18px;
    background: rgba(220, 53, 69, 0.15);
    border: 1px solid rgba(220, 53, 69, 0.35);
    border-radius: 8px;
    color: #ff6b6b;
    cursor: pointer;
    font-size: 0.88rem;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
}

.btn-modal-confirm:hover { background: rgba(220, 53, 69, 0.28); border-color: rgba(220, 53, 69, 0.55); }
.btn-modal-confirm:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: #1e1e2e;
    border: 1px solid #2a2a2a;
    border-radius: 10px;
    padding: 12px 20px;
    font-size: 0.88rem;
    color: #ccc;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 300;
    max-width: calc(100vw - 48px);
    text-align: center;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid #2a2a2a;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-name { font-size: 0.85rem; color: #888; }

.btn-logout {
    font-size: 0.8rem;
    color: #555;
    transition: color 0.2s;
}

.btn-logout:hover { color: #ff6b6b; }

/* Chat main */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    padding: 16px 28px;
    border-bottom: 1px solid #1e1e1e;
    display: flex;
    align-items: center;
}

.chat-header-title { display: flex; align-items: center; gap: 12px; }

.ikonia-name {
    font-size: 1rem;
    font-weight: 600;
    color: #e8e8e8;
}

.ikonia-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: #555;
}

.status-dot {
    width: 7px;
    height: 7px;
    background: #4ade80;
    border-radius: 50%;
}

/* Messages area */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 2px; }

/* Message bubbles */
.message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 72%;
}

.message-host {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-ikonia {
    align-self: flex-start;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    background: #7c6af7;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.msg-bubble { max-width: 100%; }

.msg-content {
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.6;
    font-size: 0.93rem;
    word-wrap: break-word;
}

.message-host .msg-content {
    background: #2d2d5e;
    border-bottom-right-radius: 4px;
}

.message-ikonia .msg-content {
    background: #1e1e2e;
    border-bottom-left-radius: 4px;
}

.msg-content p { margin-bottom: 8px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content ul, .msg-content ol { padding-left: 20px; margin-bottom: 8px; }
.msg-content li { margin-bottom: 4px; }
.msg-content code {
    background: rgba(124, 106, 247, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.88em;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
}
.msg-content pre {
    background: #0f0f0f;
    padding: 14px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}
.msg-content pre code { background: none; padding: 0; }
.msg-content h1, .msg-content h2, .msg-content h3 {
    color: #e8e8e8;
    margin-top: 12px;
    margin-bottom: 6px;
}
.msg-content strong { color: #fff; }
.msg-content blockquote {
    border-left: 3px solid #7c6af7;
    padding-left: 12px;
    color: #aaa;
    margin: 8px 0;
}

.msg-time {
    font-size: 0.7rem;
    color: #444;
    margin-top: 4px;
    text-align: right;
}

.message-ikonia .msg-time { text-align: left; }

/* Input area */
.input-area {
    padding: 16px 28px 24px;
    border-top: 1px solid #1e1e1e;
}

.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: #7c6af7;
    margin-bottom: 10px;
    padding-left: 4px;
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots span {
    width: 5px;
    height: 5px;
    background: #7c6af7;
    border-radius: 50%;
    animation: dot-bounce 1.2s infinite ease-in-out;
}

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

@keyframes dot-bounce {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

.input-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
    padding: 10px 10px 10px 16px;
    transition: border-color 0.2s;
}

.input-form:focus-within { border-color: rgba(124, 106, 247, 0.4); }

.msg-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #e8e8e8;
    font-size: 0.93rem;
    font-family: inherit;
    line-height: 1.6;
    resize: none;
    max-height: 160px;
    overflow-y: auto;
}

.msg-input::placeholder { color: #444; }

.btn-send {
    width: 36px;
    height: 36px;
    background: #7c6af7;
    border: none;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.btn-send:hover { background: #6a58e0; }
.btn-send:disabled { background: #333; cursor: not-allowed; }

/* ===== RESPONSIVE MOBILE ===== */

/* Hamburger button — hidden on desktop */
.btn-hamburger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    color: #888;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    border-radius: 6px;
    transition: background 0.15s;
}
.btn-hamburger:hover { background: #242424; }
.btn-hamburger svg { display: block; }

/* Sidebar overlay backdrop */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 99;
}
.sidebar-overlay.visible { display: block; }

@media (max-width: 767px) {
    /* Show hamburger */
    .btn-hamburger { display: flex; }

    /* Sidebar: off-canvas, slides in from left */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.6);
    }
    .sidebar.open { transform: translateX(0); }

    /* Header: fixed so it never scrolls away
       padding-top absorbs the Dynamic Island / notch safe area */
    .chat-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        padding: 0 16px;
        padding-top: env(safe-area-inset-top);
        height: calc(52px + env(safe-area-inset-top));
        display: flex;
        align-items: flex-end;
        padding-bottom: 10px;
        background: #0f0f0f;
        border-bottom: 1px solid #1e1e1e;
    }

    /* Push messages below the fixed header */
    .messages-area {
        padding: 14px 12px 8px;
        padding-top: calc(60px + env(safe-area-inset-top));
        gap: 12px;
    }

    /* Message bubbles: wider on small screens */
    .message { max-width: 90%; }

    /* Input: prevent iOS zoom (font-size must be >= 16px) */
    .msg-input { font-size: 16px; }

    /* Input area: respect home indicator safe zone */
    .input-area {
        padding: 10px 12px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}
