@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap');

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

body {
    margin: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
    background: #f5f5fa;
    color: #1f2937;
}


/* =========================================
   NAVBAR MODERN
========================================= */

.navbar {

    position: sticky;
    top: 0;

    z-index: 1000;

    margin: 18px;

    padding: 18px 34px;

    background: rgba(255,255,255,0.92);

    backdrop-filter: blur(12px);

    border: 1px solid #ececf5;

    border-radius: 24px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    box-shadow:
        0 8px 30px rgba(0,0,0,0.04);
}

/* LEFT */
.navbar-left {

    display: flex;
    align-items: center;
}

/* LOGO */
.logo {

    display: flex;
    align-items: center;

    gap: 14px;

    margin-left: 0;

    color: #1f2a63;

    font-size: 15px;
    font-weight: 700;
}

.logo img {

    width: 42px;
    height: 42px;

    object-fit: contain;
}

/* =========================================
   MENU
========================================= */

.menu {

    display: flex;
    align-items: center;

    gap: 42px;

    padding: 0;

    margin-left: auto;
    margin-right: 30px; /* tambah jarak ke tombol chatbot */
}

/* LINK */
.menu a,
.dropdown-toggle {

    text-decoration: none;

    color: #1f2a63;

    font-size: 15px;
    font-weight: 500;

    transition: 0.25s ease;

    cursor: pointer;
}

/* HOVER */
.menu a:hover,
.dropdown-toggle:hover {

    color: #5f67ff;
}

/* ACTIVE */
.menu a.active {

    color: #5f67ff;

    font-weight: 700;
}

/* =========================================
   DROPDOWN
========================================= */

.menu-dropdown {

    position: relative;
}

.dropdown-toggle {

    display: flex;
    align-items: center;

    gap: 6px;
}

/* MENU DROPDOWN */
.dropdown-menu {

    position: absolute;

    top: 42px;
    left: 0;

    min-width: 220px;

    background: white;

    border-radius: 18px;

    padding: 10px;

    display: none;

    border: 1px solid #ececf5;

    box-shadow:
        0 12px 35px rgba(0,0,0,0.08);
}

/* SHOW */
.menu-dropdown.open .dropdown-menu {

    display: flex;
    flex-direction: column;
}

/* ITEM */
.dropdown-menu a {

    padding: 12px 16px;

    border-radius: 12px;

    font-size: 14px;
}

.dropdown-menu a:hover {

    background: #f4f5ff;
}

/* =========================================
   CHATBOT BUTTON MENU
========================================= */

.menu a:last-child {

    padding: 12px 22px;

    border-radius: 14px;

    background: linear-gradient(
        135deg,
        #6f73ff,
        #8b63ff
    );

    color: white;

    font-weight: 600;

    box-shadow:
        0 10px 24px rgba(111,115,255,0.25);
}

.menu a:last-child:hover {

    transform: translateY(-2px);

    color: white;
}

/* =========================================
   HAMBURGER
========================================= */

.menu-toggle {

    display: none;

    font-size: 28px;

    color: #1f2a63;

    cursor: pointer;
}

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

@media (max-width: 768px) {

    .navbar {

        padding: 16px 20px;

        border-radius: 18px;

        margin: 10px;
    }

    .menu-toggle {

        display: block;
    }

    .navbar-left {

        width: 100%;

        justify-content: space-between;
    }

    .menu {

        display: none;

        flex-direction: column;

        align-items: flex-start;

        width: 100%;

        margin-top: 20px;

        gap: 18px;

        padding-top: 18px;

        border-top: 1px solid #ececf5;
    }

    .menu.show {

        display: flex;
    }

    .menu a:last-child {

        width: 100%;

        text-align: center;
    }

    .dropdown-menu {

        position: static;

        width: 100%;

        margin-top: 10px;
    }
}

/* CHATBOT NAVBAR RIGHT BUTTONS */
.navbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.nav-btn-ghost {
    text-decoration: none;
    color: #4b5563;
    font-size: 14px;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 8px;
    transition: all 0.2s;
}

.nav-btn-ghost:hover {
    background: #f3f4f6;
    color: #1f2937;
}

.nav-btn-primary {
    text-decoration: none;
    background: #3b4bdf;
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    padding: 9px 20px;
    border-radius: 10px;
    transition: all 0.2s;
}

.nav-btn-primary:hover {
    background: #2d3ac0;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(59, 75, 223, 0.35);
}

/* HAMBURGER */
.menu-toggle {
    display: none;
    font-size: 26px;
    cursor: pointer;
    color: #3b4bdf;
}

/* =============================================
   PAGE WRAPPER
============================================= */
.page-wrapper {
    display: flex;
    height: calc(100vh - 64px);
    overflow: hidden;
    background: #f5f5fa;
}

/* =============================================
   SIDEBAR
============================================= */
.chat-sidebar {
    width: 300px;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-right: 1px solid #e8e8f0;
    transition: width 0.28s cubic-bezier(.4,0,.2,1),
                min-width 0.28s cubic-bezier(.4,0,.2,1),
                opacity 0.22s ease;
    overflow: hidden;
    flex-shrink: 0;
}

.chat-sidebar.collapsed {
    width: 0;
    min-width: 0;
    opacity: 0;
}

.sidebar-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid #f0f0f8;
    flex-shrink: 0;
}

/* Tombol Mulai Chat Baru */
.btn-new-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 11px 16px;
    background: #3b4bdf;
    border: none;
    border-radius: 10px;
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s, transform 0.15s, box-shadow 0.18s;
    box-sizing: border-box;
    font-family: inherit;
    text-align: center;
    letter-spacing: 0.01em;
}

.btn-new-chat:hover {
    background: #2d3ac0;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(59, 75, 223, 0.3);
}

/* Label Riwayat */
.sidebar-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #9ca3af;
    margin-top: 20px;
    margin-bottom: 8px;
    padding: 0 4px;
    display: block;
}

/* Daftar riwayat */
.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 75, 223, 0.15) transparent;
}

.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-thumb {
    background: rgba(59, 75, 223, 0.15);
    border-radius: 4px;
}

.group-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #9ca3af;
    padding: 12px 8px 5px;
    white-space: nowrap;
}

.hist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.16s;
    border: 1.5px solid transparent;
    margin-bottom: 2px;
}

.hist-item:hover { background: #f5f5fa; }

.hist-item.active {
    background: #eef0ff;
    border-color: #d0d4f8;
}

.hist-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #eef0ff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    color: #3b4bdf;
}

.hist-item.active .hist-icon {
    background: #3b4bdf;
    color: #ffffff;
}

.hist-text { flex: 1; min-width: 0; }

.hist-title {
    font-size: 13px;
    color: #1f2937;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.hist-item.active .hist-title {
    color: #3b4bdf;
    font-weight: 600;
}

.hist-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 2px;
    white-space: nowrap;
}

.hist-del {
    opacity: 0;
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 12px;
    transition: opacity 0.14s, background 0.14s, color 0.14s;
    flex-shrink: 0;
    font-family: inherit;
}

.hist-item:hover .hist-del { opacity: 1; }
.hist-del:hover { background: #fee2e2; color: #dc2626; }

.sidebar-empty {
    text-align: center;
    padding: 40px 16px;
    color: #9ca3af;
    font-size: 13px;
    line-height: 1.8;
}

.sidebar-empty-ic { font-size: 32px; margin-bottom: 8px; }

/* Skeleton */
.skel {
    height: 50px;
    border-radius: 10px;
    background: #f0f0f8;
    margin-bottom: 6px;
    animation: sk 1.6s ease-in-out infinite;
}

@keyframes sk { 0%,100%{opacity:.4} 50%{opacity:.9} }

/* =============================================
   TOGGLE STRIP
============================================= */
.sidebar-toggle {
    width: 14px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.toggle-btn {
    position: absolute;
    background: #ffffff;
    border: 1px solid #e8e8f0;
    border-left: none;
    border-radius: 0 8px 8px 0;
    color: #9ca3af;
    width: 14px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    transition: background 0.18s, color 0.18s;
    font-family: inherit;
}

.toggle-btn:hover { background: #f0f1ff; color: #3b4bdf; }

/* =============================================
   CHAT MAIN
============================================= */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    background: #f8f8fc;
}

/* ── PIPELINE BAR ── */
.pipeline-steps {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    padding: 10px 20px;
    background: #ffffff;
    border-bottom: 1px solid #e8e8f0;
    font-size: 11px;
    flex-shrink: 0;
}

.pipeline-steps .step {
    display: flex;
    align-items: center;
    gap: 5px;
    color: #9ca3af;
    transition: color .25s, transform .25s;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    font-size: 10.5px;
}

.pipeline-steps .step.active { color: #3b4bdf; transform: scale(1.05); }

.pipeline-steps .step .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #d1d5db;
    transition: background .25s;
}

.pipeline-steps .step.active .dot { background: #3b4bdf; }

.pipeline-steps .arrow {
    color: #d1d5db;
    font-size: 10px;
    margin: 0 1px;
}

/* ── CHAT BOX ── */
.chat-box {
    flex: 1;
    overflow-y: auto;
    padding: 28px 40px;
    scroll-behavior: smooth;
}

.chat-box::-webkit-scrollbar { width: 5px; }
.chat-box::-webkit-scrollbar-thumb {
    background: rgba(59, 75, 223, 0.15);
    border-radius: 4px;
}

/* ── WELCOME BUBBLE ── */
.welcome-bubble {
    background: #ffffff;
    border: 1px solid #e8e8f0;
    border-radius: 16px;
    padding: 18px 22px;
    margin-bottom: 20px;
    font-size: 14px;
    color: #374151;
    line-height: 1.7;
    max-width: 780px;
}

/* ── CHAT BUBBLES ── */
.chat { margin-bottom: 20px; }

.chat > span {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.6;
    display: block;
    margin-bottom: 4px;
}

.chat.user > span {
    text-align: right;
    color: #3b4bdf;
}

.chat.bot > span {
    text-align: left;
    color: #374151;
}

/* User bubble */
.chat.user p {
    display: inline-block;
    padding: 12px 18px;
    border-radius: 16px 16px 4px 16px;
    font-size: 14px;
    line-height: 1.6;
    max-width: 70%;
    margin: 0;
    word-wrap: break-word;
    background: #3b4bdf;
    color: #ffffff;
    float: right;
    clear: both;
    font-weight: 500;
}

/* Bot card */
.chat.bot {
    clear: both;
}

.chat.bot .bot-card {
    background: #ffffff;
    border: 1px solid #e8e8f0;
    border-radius: 16px;
    padding: 18px 22px;
    max-width: 780px;
    font-size: 14px;
    line-height: 1.7;
    color: #1f2937;
    clear: both;
}

/* fallback: p inside bot (for old addBotMsg) */
.chat.bot p {
    display: block;
    padding: 18px 22px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.7;
    max-width: 780px;
    margin: 0;
    word-wrap: break-word;
    background: #ffffff;
    border: 1px solid #e8e8f0;
    color: #1f2937;
    float: left;
    clear: both;
}

.chat::after { content:''; display:block; clear:both; }

/* Sender label e.g. "BOT RUANG AMAN" */
.chat.bot > span {
    color: #6b7280;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* Timestamp inline with sender */
.chat-sender-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.chat-sender-row .sender-name {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #6b7280;
}

.chat-sender-row .sender-time {
    font-size: 10.5px;
    color: #9ca3af;
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
}

.chat.user .chat-sender-row {
    justify-content: flex-end;
}

/* Meta (time + badge) */
.chat .meta {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 6px;
    clear: both;
}

.chat.user .meta { text-align: right; }
.chat.bot  .meta { text-align: left; }

/* Badge confidence */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
    margin-left: 5px;
}

.badge-tinggi  { background: #d1fae5; color: #065f46; }
.badge-relevan { background: #dbeafe; color: #1e40af; }
.badge-cukup   { background: #fef9c3; color: #854d0e; }
.badge-rendah  { background: #fee2e2; color: #991b1b; }

/* Session bar */
.session-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 20px 4px;
    font-size: 12px;
    color: #9ca3af;
    flex-shrink: 0;
    background: #f8f8fc;
}

.session-bar strong { color: #374151; font-weight: 600; }

/* ── TYPING INDICATOR ── */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 12px 18px;
    background: #ffffff;
    border: 1px solid #e8e8f0;
    border-radius: 16px;
    float: left;
    clear: both;
}

.typing-indicator span {
    width: 7px; height: 7px; border-radius: 50%;
    background: #3b4bdf;
    animation: bounce 1.2s infinite; display: block;
    opacity: 0.5;
}

.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* ── CHATBOT HEADER (watermark) ── */
.chatbot-header {
    position: relative;
    pointer-events: none;
    user-select: none;
    text-align: center;
    padding: 16px 0 0;
    flex-shrink: 0;
}

.chatbot-header .bot-watermark-icon {
    font-size: 36px;
    opacity: 0.07;
    color: #3b4bdf;
    line-height: 1;
    margin-bottom: 2px;
}

.chatbot-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: #3b4bdf;
    opacity: 0.08;
    margin: 0;
    letter-spacing: -0.3px;
}

.chatbot-header .sparkles {
    font-size: 12px;
    letter-spacing: 8px;
    color: #3b4bdf;
    opacity: 0.08;
    margin-bottom: 2px;
}

/* ── INPUT AREA ── */
.chat-input-area {
    flex-shrink: 0;
    padding: 12px 40px 16px;
    background: #ffffff;
    border-top: 1px solid #e8e8f0;
}

.input-wrap {
    display: flex;
    gap: 8px;
    align-items: center;
    background: #ffffff;
    border: 1.5px solid #e8e8f0;
    border-radius: 14px;
    padding: 10px 14px;
    transition: border-color .2s, box-shadow .2s;
}

.input-wrap:focus-within {
    border-color: #3b4bdf;
    box-shadow: 0 0 0 3px rgba(59, 75, 223, 0.08);
}

/* Attachment icon */
.input-wrap .attach-icon {
    font-size: 18px;
    color: #9ca3af;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.2s;
}

.input-wrap .attach-icon:hover {
    color: #3b4bdf;
}

.input-wrap input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 14px;
    color: #1f2937;
    font-family: inherit;
    padding: 2px 0;
}

.input-wrap input::placeholder { color: #9ca3af; }

/* Send icon button */
.input-wrap button {
    background: none;
    border: none;
    color: #9ca3af;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s, transform 0.15s;
    font-family: inherit;
    border-radius: 8px;
    padding: 0;
}

.input-wrap button:hover {
    color: #3b4bdf;
    transform: scale(1.1);
}

.input-wrap button:disabled {
    opacity: .4;
    cursor: not-allowed;
    transform: none;
}

/* Input footer note */
.input-note {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 11.5px;
    color: #9ca3af;
}

.input-note .note-left {
    display: flex;
    align-items: center;
    gap: 5px;
}

.input-note .note-link {
    color: #3b4bdf;
    text-decoration: none;
    font-weight: 500;
    font-size: 11.5px;
    transition: opacity 0.2s;
}

.input-note .note-link:hover { opacity: 0.7; }

/* =============================================
   MOBILE
============================================= */
.mob-menu-btn { display: none; }

@media (max-width: 992px) {
    .navbar-right { display: none; }
}

@media (max-width: 768px) {
    .navbar {
        flex-wrap: wrap;
        padding: 12px 20px;
        height: auto;
    }

    .menu {
        display: none;
        flex-direction: column;
        width: 100%;
        background: #f5f5fa;
        margin-top: 10px;
        border-radius: 12px;
        padding: 8px;
        gap: 2px;
        align-items: flex-start;
        flex: unset;
    }

    .menu a { width: 100%; }
    .menu.show { display: flex; }
    .menu-toggle { display: block; }

    .menu-dropdown { width: 100%; }
    .dropdown-menu {
        position: static;
        box-shadow: none;
        border: none;
        background: transparent;
        padding: 4px 0 0 16px;
    }

    .chat-box { padding: 16px 20px; }
    .chat-input-area { padding: 10px 16px 14px; }
}

@media (max-width: 640px) {
    .chat-sidebar {
        position: fixed;
        top: 64px; left: 0;
        height: calc(100vh - 64px);
        transform: translateX(-100%);
        width: 280px !important;
        min-width: 280px !important;
        opacity: 1 !important;
        box-shadow: 4px 0 24px rgba(0,0,0,0.12);
        z-index: 20;
    }

    .chat-sidebar.mobile-open { transform: translateX(0); }
    .sidebar-toggle { display: none; }

    .mob-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.25);
        z-index: 19;
    }

    .mob-overlay.show { display: block; }

    .mob-menu-btn {
        display: inline-flex !important;
        align-items: center;
        gap: 5px;
        background: #f0f1ff;
        border: 1px solid #d0d4f8;
        border-radius: 8px;
        color: #3b4bdf;
        padding: 5px 10px;
        font-size: 12px;
        cursor: pointer;
        font-family: inherit;
        font-weight: 500;
    }
}

/* iframe mode */
body.iframe-mode .navbar { display: none; }
body.iframe-mode .page-wrapper { height: 100vh; }