/* ==========================================================
   OAP AI — modern UI  (works with index.html + script.js v20)
   ========================================================== */
:root {
    --bg: #07090d;
    --panel: #0e131a;
    --panel-2: #151b25;
    --panel-3: #1b2330;
    --line: rgba(255, 255, 255, 0.08);
    --line-2: rgba(255, 255, 255, 0.14);
    --text: #e8ecf2;
    --muted: #8b95a5;
    --lime: #84cc16;
    --lime-2: #a3e635;
    --lime-d: #65a30d;
    --danger: #ef4444;
    --radius: 18px;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    --col: 860px; /* width of the centred chat column */
}

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

html, body { height: 100%; overflow: hidden; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, Tahoma, sans-serif;
    color: var(--text);
    background:
        radial-gradient(900px 480px at 78% -8%, rgba(132, 204, 22, 0.10), transparent 60%),
        radial-gradient(700px 480px at -5% 105%, rgba(34, 197, 94, 0.07), transparent 60%),
        var(--bg);
    -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

.app { display: flex; height: 100vh; height: 100dvh; }

/* ==========================================================
   SIDEBAR
   ========================================================== */
.sidebar {
    width: 276px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 14px 14px;
    background: rgba(14, 19, 26, 0.78);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-right: 1px solid var(--line);
}

.sidebar-header { display: flex; align-items: center; gap: 12px; padding: 2px 6px; }

.brand-mark {
    width: 38px; height: 38px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 14px; letter-spacing: 0.3px;
    color: #0a1204;
    background: linear-gradient(135deg, var(--lime-2), var(--lime-d));
    box-shadow: 0 6px 22px rgba(132, 204, 22, 0.35);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.sidebar-title { font-size: 17px; font-weight: 700; color: #fff; letter-spacing: -0.2px; }
.sidebar-sub { font-size: 11.5px; color: var(--muted); }

.new-chat-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%;
    padding: 12px 14px;
    border: none; border-radius: 12px;
    font-size: 14px; font-weight: 700;
    color: #0a1204;
    background: linear-gradient(135deg, var(--lime-2), var(--lime));
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s;
}
.new-chat-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 26px rgba(132, 204, 22, 0.35); }
.new-chat-btn:active { transform: translateY(0); }

.sidebar-label {
    font-size: 11px; color: var(--muted);
    text-transform: uppercase; letter-spacing: 1.2px;
    padding: 6px 8px 0;
}

.chat-list {
    flex: 1; min-height: 0;
    overflow-y: auto;
    display: flex; flex-direction: column; gap: 2px;
}

.chat-item {
    position: relative;
    display: flex; align-items: center; gap: 10px;
    padding: 10px 34px 10px 12px;
    border-radius: 10px;
    font-size: 13.5px; color: #cbd2dc;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.chat-item:hover { background: rgba(255, 255, 255, 0.05); }
.chat-item.active {
    background: rgba(132, 204, 22, 0.10);
    color: #fff;
    box-shadow: inset 2px 0 0 var(--lime);
}
.chat-item .chat-icon { flex-shrink: 0; opacity: 0.55; }
.chat-item .chat-title-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .delete-btn {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    width: 26px; height: 26px; padding: 0;
    display: flex; align-items: center; justify-content: center;
    border: none; border-radius: 7px;
    background: transparent; color: var(--muted);
    cursor: pointer; opacity: 0; transition: all 0.15s;
}
.chat-item:hover .delete-btn { opacity: 1; }
.chat-item .delete-btn:hover { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.chat-item .delete-btn svg { pointer-events: none; }

.sidebar-footer { border-top: 1px solid var(--line); padding-top: 12px; margin-top: auto; }

.user-pill {
    width: 100%;
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: 12px;
    border: 1px solid transparent; background: transparent;
    color: inherit; font: inherit; text-align: left; cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.user-pill.is-admin { border-color: rgba(132, 204, 22, 0.35); background: rgba(132, 204, 22, 0.07); }
.user-action {
    margin-left: auto; flex-shrink: 0;
    padding: 5px 10px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600;
    color: var(--lime-2); border: 1px solid rgba(132, 204, 22, 0.45);
}
.user-pill.is-admin .user-action { color: var(--muted); border-color: var(--line-2); }
.user-pill:hover { background: rgba(255, 255, 255, 0.05); }
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; color: #0a1204;
    background: linear-gradient(135deg, var(--lime-2), var(--lime-d));
}
.user-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.user-name { font-size: 14px; color: var(--text); }
.user-hint { font-size: 11px; color: var(--muted); }

.scrim { display: none; }

/* ==========================================================
   MAIN + TOP BAR
   ========================================================== */
.main { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; }

.topbar {
    display: flex; align-items: center; gap: 14px;
    height: 62px; flex-shrink: 0;
    padding: 0 clamp(14px, 3vw, 28px);
    border-bottom: 1px solid var(--line);
    background: rgba(7, 9, 13, 0.92); /* no blur here: it would stop the logo's black background from blending away */
}



.icon-btn {
    width: 38px; height: 38px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--line-2); border-radius: 10px;
    background: rgba(255, 255, 255, 0.04); color: var(--text);
    cursor: pointer;
}

.icon-btn.menu-btn { display: none; }

.topbar-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-logo {
    height: 38px; width: auto; flex-shrink: 0;
    mix-blend-mode: screen; /* a black logo background disappears on the dark bar */
}
.topbar-text { padding-left: 12px; border-left: 1px solid var(--line-2); }
.topbar-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.topbar-text strong { font-size: 15px; color: #fff; font-weight: 700; }
.topbar-text small { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.brand-slot { margin-left: auto; }

/* Styalica | OneApple switch (built by script.js) */
.brand-switch {
    display: inline-flex; align-items: center; gap: 2px;
    padding: 3px;
    background: var(--panel); border: 1px solid var(--line-2); border-radius: 999px;
}
.brand-btn {
    border: none; background: transparent; color: var(--muted);
    padding: 7px 16px; border-radius: 999px;
    font-size: 12.5px; font-weight: 600; cursor: pointer;
    transition: all 0.18s;
}
.brand-btn:hover { color: var(--text); }
.brand-btn.active {
    color: #0a1204;
    background: linear-gradient(135deg, var(--lime-2), var(--lime));
    box-shadow: 0 4px 14px rgba(132, 204, 22, 0.3);
}

/* ==========================================================
   MESSAGES
   ========================================================== */
.messages {
    flex: 1; min-height: 0;
    overflow-y: auto;
    display: flex; flex-direction: column; gap: 14px;
    padding: 26px max(16px, calc((100% - var(--col)) / 2)) 14px;
    scroll-behavior: smooth;
}

.message {
    align-self: flex-start;
    max-width: min(82%, 720px);
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 15px; line-height: 1.6;
    word-wrap: break-word; overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.ai-message {
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-top-left-radius: 6px;
}

.user-message {
    align-self: flex-end;
    color: #0a1204; font-weight: 500;
    background: linear-gradient(135deg, var(--lime-2), var(--lime));
    border-top-right-radius: 6px;
    box-shadow: 0 8px 24px rgba(132, 204, 22, 0.16);
}
.user-message img { max-width: 220px; border-radius: 12px; display: block; }

.typing { color: var(--muted); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

/* Poster card inside the chat */
.message.poster-message {
    max-width: min(100%, 480px);
    padding: 12px;
    white-space: normal;
}
.poster-message img { border-radius: 14px; }

/* ---------- welcome screen ---------- */
.welcome {
    margin: auto; align-self: center;
    max-width: 640px;
    display: flex; flex-direction: column; align-items: center;
    text-align: center; gap: 10px;
    padding: 12px 0 30px;
}
.welcome-logo {
    width: min(280px, 64%); height: auto;
    filter: drop-shadow(0 0 38px rgba(132, 204, 22, 0.35));
    mix-blend-mode: screen; /* a black logo background disappears on the dark page */
    margin-bottom: 6px;
}
.welcome h1 { font-size: clamp(22px, 3.2vw, 30px); font-weight: 700; color: #fff; letter-spacing: -0.4px; }
.welcome p { color: var(--muted); font-size: 14.5px; line-height: 1.55; max-width: 460px; }

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 16px; }
.chip {
    padding: 10px 16px;
    font-size: 13.5px; color: var(--text);
    background: var(--panel-2);
    border: 1px solid var(--line-2); border-radius: 999px;
    cursor: pointer;
    transition: all 0.18s;
}
.chip:hover {
    border-color: rgba(132, 204, 22, 0.7);
    background: rgba(132, 204, 22, 0.08);
    transform: translateY(-1px);
}

/* ---------- voice reply ---------- */
.voice-reply-marker {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 12px; border-radius: 12px;
    font-size: 13px; color: var(--muted);
    background: var(--panel-2); border: 1px solid var(--line);
    max-width: min(82%, 720px);
    white-space: normal;
}
.voice-reply-text { color: #d1d5db; margin-left: 4px; font-style: normal; }
.voice-btn {
    width: 28px; height: 28px; padding: 0; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border: none; border-radius: 8px;
    background: var(--panel-3); color: var(--text);
    font-size: 11px; cursor: pointer; transition: background 0.15s;
}
.voice-btn:hover { background: #28323f; color: var(--lime-2); }
.voice-btn.voice-play { color: var(--lime-2); }

/* ==========================================================
   COMPOSER
   ========================================================== */
.composer {
    flex-shrink: 0;
    padding: 6px max(14px, calc((100% - var(--col)) / 2)) max(14px, env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--bg) 62%, transparent);
}
.composer-inner { width: 100%; }

.status-line {
    min-height: 20px; padding-bottom: 6px;
    text-align: center; font-size: 12.5px; letter-spacing: 0.2px;
    color: var(--lime-2);
}

.image-preview {
    margin-bottom: 10px; padding: 10px 12px;
    display: none; align-items: center; gap: 12px;
    background: var(--panel-2);
    border: 1px solid var(--line-2); border-radius: 16px;
}
.image-preview[style*="block"] { display: flex !important; }
.preview-thumb {
    width: 56px; height: 56px; object-fit: cover; flex-shrink: 0;
    border-radius: 10px; border: 1px solid var(--line-2); background: #000;
}
.preview-info { flex: 1; min-width: 0; }
.preview-name { font-size: 13px; color: #d1d5db; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-hint { font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.preview-remove {
    padding: 7px 12px; flex-shrink: 0;
    font-size: 12px; color: var(--text); cursor: pointer;
    background: transparent; border: 1px solid var(--line-2); border-radius: 8px;
}
.preview-remove:hover { border-color: var(--danger); color: var(--danger); }

.input-bar {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 7px 7px 7px 20px;
    background: var(--panel);
    border: 1px solid var(--line-2); border-radius: 28px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input-bar:focus-within {
    border-color: rgba(132, 204, 22, 0.65);
    box-shadow: 0 0 0 4px rgba(132, 204, 22, 0.12), 0 10px 40px rgba(0, 0, 0, 0.35);
}
.input-bar textarea {
    flex: 1; min-width: 0;
    height: 42px; max-height: 160px;
    padding: 10px 0; resize: none; overflow-y: auto;
    font-size: 15px; line-height: 22px; font-family: inherit; color: var(--text);
    background: transparent; border: none; outline: none;
}
.input-bar textarea::placeholder { color: #6b7686; }

.mic-btn, .send-btn, .attach-btn {
    width: 42px; height: 42px; padding: 0; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border: none; border-radius: 50%;
    cursor: pointer; transition: all 0.18s ease;
}
.mic-btn svg, .send-btn svg, .attach-btn svg { pointer-events: none; }

.attach-btn, .mic-btn { background: transparent; color: #aab3c0; }
.attach-btn:hover, .mic-btn:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.attach-btn.has-image { background: rgba(132, 204, 22, 0.16); color: var(--lime-2); }

.mic-btn.recording {
    color: #0a1204;
    background: linear-gradient(135deg, var(--lime-2), var(--lime));
    animation: pulse-ring 1.5s infinite;
}
.mic-btn.processing { background: #2a3340; color: var(--muted); cursor: wait; }
@keyframes pulse-ring {
    0%   { box-shadow: 0 0 0 0 rgba(132, 204, 22, 0.55); }
    70%  { box-shadow: 0 0 0 16px rgba(132, 204, 22, 0); }
    100% { box-shadow: 0 0 0 0 rgba(132, 204, 22, 0); }
}

.send-btn { color: #0a1204; background: linear-gradient(135deg, var(--lime-2), var(--lime)); }
.send-btn:hover { transform: scale(1.06); box-shadow: 0 0 22px rgba(132, 204, 22, 0.45); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

.quickbar {
    display: none;
    gap: 8px; padding: 0 2px 10px;
    overflow-x: auto; white-space: nowrap;
    scrollbar-width: none;
}
.quickbar::-webkit-scrollbar { display: none; }
body.chat-active .quickbar { display: flex; }
.chip-sm { padding: 7px 13px; font-size: 12.5px; flex-shrink: 0; }

.composer-note { text-align: center; font-size: 11px; color: #5f6978; padding-top: 8px; }

/* ==========================================================
   MODAL
   ========================================================== */
.modal-overlay {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal {
    width: 90%; max-width: 400px; padding: 24px 26px;
    background: var(--panel-2);
    border: 1px solid var(--line-2); border-radius: 18px;
    box-shadow: var(--shadow);
}
.modal h3 { font-size: 18px; color: #fff; margin-bottom: 10px; font-weight: 700; }
.modal p { font-size: 14px; color: var(--muted); margin-bottom: 22px; line-height: 1.55; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-btn {
    padding: 10px 18px; border: none; border-radius: 10px;
    font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.modal-input {
    width: 100%; padding: 12px 14px; margin-bottom: 8px;
    font-size: 15px; font-family: inherit; color: var(--text);
    background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; outline: none;
}
.modal-input:focus { border-color: rgba(132, 204, 22, 0.7); box-shadow: 0 0 0 3px rgba(132, 204, 22, 0.14); }
.modal-error { min-height: 20px; margin-bottom: 14px; font-size: 13px; color: #fca5a5; }
.modal-btn.primary { color: #0a1204; background: linear-gradient(135deg, var(--lime-2), var(--lime)); }
.modal-btn.primary:hover { box-shadow: 0 0 18px rgba(132, 204, 22, 0.4); }
.modal-btn:disabled { opacity: 0.6; cursor: wait; }
.modal-btn.cancel { background: transparent; color: var(--text); border: 1px solid var(--line-2); }
.modal-btn.cancel:hover { background: rgba(255, 255, 255, 0.06); }
.modal-btn.danger { background: #dc2626; color: #fff; }
.modal-btn.danger:hover { background: var(--danger); box-shadow: 0 0 16px rgba(239, 68, 68, 0.4); }

/* ==========================================================
   SCROLLBARS
   ========================================================== */
.messages::-webkit-scrollbar, .chat-list::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb, .chat-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.10); border-radius: 4px;
}
.messages::-webkit-scrollbar-thumb:hover, .chat-list::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); }

/* ==========================================================
   MOBILE / TABLET  (sidebar becomes a slide-in drawer)
   ========================================================== */
@media (max-width: 860px) {
    .icon-btn.menu-btn { display: inline-flex; }

    .sidebar {
        position: fixed; top: 0; bottom: 0; left: 0; z-index: 60;
        width: 84vw; max-width: 320px;
        transform: translateX(-102%);
        transition: transform 0.25s ease;
        background: rgba(12, 16, 22, 0.97);
    }
    body.sidebar-open .sidebar { transform: translateX(0); box-shadow: 20px 0 60px rgba(0, 0, 0, 0.6); }

    .scrim {
        position: fixed; inset: 0; z-index: 50;
        background: rgba(0, 0, 0, 0.55);
        opacity: 0; pointer-events: none; transition: opacity 0.25s;
    }
    body.sidebar-open .scrim { display: block; opacity: 1; pointer-events: auto; }

    .chat-item .delete-btn { opacity: 0.7; }

    .topbar { height: 56px; gap: 10px; }
    .topbar-text small { display: none; }
    .topbar-text { display: none; }
    .topbar-logo { height: 34px; }
    .brand-btn { padding: 6px 12px; font-size: 12px; }

    .messages { padding: 16px 12px 10px; gap: 12px; }
    .message { max-width: 92%; font-size: 14.5px; padding: 10px 14px; }
    .voice-reply-marker { max-width: 92%; }

    .welcome-logo { width: min(200px, 56%); }
    .chip { padding: 9px 14px; font-size: 13px; }

    .composer { padding-left: 10px; padding-right: 10px; }
    .composer-note { display: none; }
    .input-bar { padding-left: 16px; }
    .input-bar textarea { height: 40px; }
    .mic-btn, .send-btn, .attach-btn { width: 40px; height: 40px; }
}

@media (max-width: 400px) {
    .brand-btn { padding: 6px 10px; font-size: 11.5px; }
    .topbar-text strong { font-size: 14px; }
    .message { font-size: 14px; }
}

/* ==========================================================
   ACCOUNT + USERS DIALOGS
   ========================================================== */
.modal.modal-wide { max-width: 600px; max-height: 88vh; overflow-y: auto; }
.modal-actions.spread { flex-wrap: wrap; justify-content: flex-end; }

.account-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.user-avatar.big { width: 52px; height: 52px; font-size: 20px; flex-shrink: 0; }
.account-id { min-width: 0; flex: 1; }
.account-name { font-size: 17px; font-weight: 700; color: #fff; }
.account-email { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-note { font-size: 13px !important; margin-bottom: 16px !important; }
.role-badge {
    padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
    color: var(--lime-2); border: 1px solid rgba(132, 204, 22, 0.45); background: rgba(132, 204, 22, 0.08);
}
.role-badge.user { color: var(--muted); border-color: var(--line-2); background: transparent; }

.acc-box { margin-bottom: 16px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }

.users-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; max-height: 300px; overflow-y: auto; }
.user-row {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.user-row.off { opacity: 0.55; }
.user-row .u-main { flex: 1; min-width: 160px; }
.user-row .u-name { font-size: 14px; color: #fff; font-weight: 600; }
.user-row .u-email { font-size: 12px; color: var(--muted); }
.user-row .u-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.mini-btn {
    padding: 5px 10px; font-size: 11.5px; font-weight: 600; cursor: pointer;
    color: var(--text); background: transparent; border: 1px solid var(--line-2); border-radius: 8px;
}
.mini-btn:hover { border-color: rgba(132, 204, 22, 0.7); color: var(--lime-2); }
.mini-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.add-user-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 1px; }
.add-user-form { display: grid; grid-template-columns: 1.4fr 1fr 100px auto; gap: 8px; align-items: start; }
.add-user-form .modal-input { margin-bottom: 0; }
.users-msg { margin: 12px 0 16px; font-size: 13.5px; line-height: 1.5; color: var(--text); }
.users-msg.error { color: #fca5a5; }
.users-msg .temp-pass {
    display: inline-block; margin: 4px 0; padding: 6px 12px; border-radius: 10px;
    font-family: Consolas, 'Courier New', monospace; font-size: 15px; letter-spacing: 1px;
    color: #0a1204; background: linear-gradient(135deg, var(--lime-2), var(--lime));
}

@media (max-width: 640px) {
    .add-user-form { grid-template-columns: 1fr 1fr; }
    .add-user-form .modal-btn { grid-column: span 2; }
}
