/* ═══════════════════════════════════════════════════
   Cô Út Pháp Luật — Bright Feminine Modern UI v3.1
   ═══════════════════════════════════════════════════ */

:root {
    --sidebar-w: 240px;
    --rose-50:   #fff1f5;
    --rose-100:  #ffe2ea;
    --rose-200:  #ffc8d8;
    --rose-300:  #ffa0bb;
    --rose-400:  #f96c98;
    --rose-500:  #f0417a;
    --rose-600:  #d4215f;
    --peach-50:  #fff8f3;
    --peach-100: #feeee4;
    --peach-200: #fdd5bb;
    --mauve:     #c97eb0;
    --mauve-dim: #9b5a88;
    --text:      #3d1a2e;
    --text-mid:  #7a4060;
    --text-muted:#a67088;
    --text-dim:  #c4a0b5;
    --bg-page:   #fff5f8;
    --bg-sidebar:#fff0f4;
    --bg-header: #ffffff;
    --bg-input:  #ffffff;
    
    /* Tokens for KM page */
    --pink-50:   #fff7f8;
    --pink-100:  #fdecee;
    --pink-200:  #f8dfe3;
    --pink-300:  #f4c4cd;
    --pink-400:  #e4a1b3;
    --pink-500:  #c08497;
    --accent:    #d46a8a;
    
    --border:        rgba(240, 65, 122, 0.12);
    --border-mid:    rgba(240, 65, 122, 0.22);
    --border-strong: rgba(240, 65, 122, 0.4);
    --shadow-sm: 0 2px 8px rgba(212, 33, 95, 0.08);
    --shadow-md: 0 6px 24px rgba(212, 33, 95, 0.12);
    --shadow-lg: 0 16px 48px rgba(212, 33, 95, 0.15);
    --shadow-card: 0 2px 12px rgba(212, 33, 95, 0.1), 0 1px 3px rgba(212,33,95,0.06);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Be Vietnam Pro', sans-serif;
    background: var(--bg-page);
    color: var(--text);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

body::before {
    content: '';
    position: fixed; inset: 0;
    background:
        radial-gradient(ellipse 70% 50% at 90% 10%, rgba(249,108,152,0.07) 0%, transparent 60%),
        radial-gradient(ellipse 50% 60% at 10% 90%, rgba(201,126,176,0.07) 0%, transparent 60%);
    pointer-events: none; z-index: 0;
}

#particles-js {
    position: fixed; inset: 0; z-index: 0;
    pointer-events: none; opacity: 0.5;
}

/* SIDEBAR */
#sidebar {
    position: relative; z-index: 10;
    width: var(--sidebar-w); min-width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    box-shadow: 2px 0 16px rgba(212,33,95,0.05);
}

#sidebar h2 {
    font-size: 12px; font-weight: 600;
    letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--text-muted);
    padding: 22px 16px 12px;
    border-bottom: 1px solid var(--border);
}

#btn-new-chat {
    margin: 12px 12px 8px; padding: 10px 14px; border-radius: 12px;
    background: linear-gradient(135deg, var(--rose-400), var(--rose-500));
    border: none; color: #fff;
    font-family: inherit; font-size: 12.5px; font-weight: 600;
    cursor: pointer; transition: all .2s ease; text-align: left;
    box-shadow: 0 4px 14px rgba(240,65,122,0.3);
}

#btn-new-chat:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(240,65,122,0.4); }

#history {
    flex: 1; overflow-y: auto; padding: 8px;
    scrollbar-width: thin; scrollbar-color: var(--rose-200) transparent;
}

.hist-item {
    display: flex; align-items: center; gap: 4px;
    padding: 2px 6px; border-radius: 10px;
    transition: background .15s; margin-bottom: 2px;
}
.hist-item:hover { background: var(--rose-100); }
.hist-item.active { background: var(--rose-100); border: 1px solid var(--border-mid); }

.hist-title {
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    cursor: pointer; font-size: 12px; color: var(--text-mid);
    padding: 7px 4px; transition: color .15s;
}
.hist-item:hover .hist-title, .hist-item.active .hist-title { color: var(--text); }

.hist-del {
    flex-shrink: 0; background: none; border: none; color: var(--text-dim);
    font-size: 11px; padding: 3px 5px; border-radius: 4px;
    cursor: pointer; opacity: 0; transition: opacity .15s, color .15s; line-height: 1;
}
.hist-item:hover .hist-del { opacity: 1; }
.hist-del:hover { color: var(--rose-500); }

.hist-empty { padding: 20px 10px; font-size: 12px; color: var(--text-dim); text-align: center; }

.hist-clear-all {
    display: block; width: calc(100% - 20px); margin: 6px 10px 12px; padding: 7px;
    background: none; border: 1px dashed var(--rose-200); border-radius: 10px;
    color: var(--text-muted); font-size: 11.5px; font-family: inherit; cursor: pointer; transition: all .2s;
}
.hist-clear-all:hover { background: var(--rose-50); border-color: var(--rose-300); color: var(--rose-500); }

/* CHAT WRAP */
#chat-wrap {
    position: relative; z-index: 5; flex: 1;
    display: flex; flex-direction: column; overflow: hidden; min-width: 0;
}

/* HEADER */
#chat-header {
    position: relative; display: flex; align-items: center; justify-content: space-between;
    padding: 14px 22px; background: var(--bg-header);
    border-bottom: 1px solid var(--border); flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}
#chat-header::after {
    content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, var(--rose-300), var(--mauve), var(--rose-400));
    opacity: 0.6;
}
#chat-header > span { display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 600; color: var(--text); }
#chat-header small { font-size: 11px; color: var(--text-muted); }

/* MESSAGES */
#messages {
    flex: 1; overflow-y: auto; padding: 22px 26px;
    display: flex; flex-direction: column; gap: 14px;
    scrollbar-width: thin; scrollbar-color: var(--rose-200) transparent;
}

/* BUBBLES */
.msg {
    max-width: 80%; padding: 12px 16px; border-radius: 18px;
    font-size: 13.5px; line-height: 1.75;
    animation: msgIn .3s cubic-bezier(.4,0,.2,1) both;
    position: relative; transition: transform .2s ease, box-shadow .2s ease;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--rose-400) 0%, var(--rose-500) 100%);
    color: #fff; border-bottom-right-radius: 4px;
    box-shadow: 0 4px 16px rgba(240,65,122,0.25), 0 1px 3px rgba(240,65,122,0.15);
}
.msg-bot {
    align-self: flex-start; background: #ffffff; color: var(--text);
    border: 1px solid var(--border); border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-card);
}
.msg:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.msg-user:hover { box-shadow: 0 8px 28px rgba(240,65,122,0.32); }

.thinking {
    color: var(--text-muted);
    background: linear-gradient(90deg, #ffffff 0%, var(--rose-50) 50%, #ffffff 100%);
    background-size: 200% 100%;
    animation: shimmer 1.6s ease-in-out infinite, msgIn .3s both;
    border: 1px solid var(--border);
}
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* WELCOME */
#welcome {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 32px 24px; text-align: center; gap: 18px; overflow-y: auto;
}
.avatar {
    width: 80px; height: 80px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 38px;
    background: linear-gradient(135deg, var(--rose-100), var(--peach-100));
    border: 2.5px solid var(--rose-300);
    box-shadow: 0 0 0 8px rgba(249,108,152,0.08), var(--shadow-md);
    animation: avatarFloat 4s ease-in-out infinite; flex-shrink: 0;
}
@keyframes avatarFloat {
    0%,100% { transform: translateY(0); box-shadow: 0 0 0 8px rgba(249,108,152,0.08), var(--shadow-md); }
    50%     { transform: translateY(-5px); box-shadow: 0 0 0 12px rgba(249,108,152,0.12), var(--shadow-lg); }
}
#welcome h3 {
    font-size: 22px; font-weight: 700;
    background: linear-gradient(135deg, var(--rose-500), var(--mauve));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
    letter-spacing: -0.02em; margin-bottom: 2px;
}
#welcome > p { font-size: 13px; color: var(--text-muted); line-height: 1.75; max-width: 360px; }

.topic-group { width: 100%; max-width: 560px; text-align: left; }
.topic-label {
    font-size: 10.5px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.09em; color: var(--rose-400); margin-bottom: 10px; padding-left: 2px;
}
.sample-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sample-btn {
    padding: 11px 14px; border-radius: 14px; background: #ffffff;
    border: 1px solid var(--border); color: var(--text-mid);
    font-family: inherit; font-size: 12px; line-height: 1.5;
    cursor: pointer; text-align: left; transition: all .2s ease; box-shadow: var(--shadow-sm);
}
.sample-btn:hover {
    border-color: var(--rose-300); color: var(--rose-600); background: var(--rose-50);
    transform: translateY(-2px); box-shadow: var(--shadow-md);
}

/* SOURCES */
.sources-wrap { align-self: flex-start; max-width: 80%; }
.sources-toggle {
    font-size: 12px; color: var(--mauve-dim); background: var(--peach-100);
    border: 1px solid var(--peach-200); border-radius: 20px; padding: 5px 14px;
    cursor: pointer; font-family: inherit; transition: all .2s;
}
.sources-toggle:hover { background: var(--rose-100); border-color: var(--rose-300); color: var(--rose-600); }
.sources-body {
    margin-top: 8px; background: #fff; border: 1px solid var(--border);
    border-radius: 14px; padding: 12px 14px; line-height: 1.7;
    font-size: 12.5px; color: var(--text-mid); box-shadow: var(--shadow-sm);
}

/* SUGGEST CHIPS */
.suggest-wrap { align-self: flex-start; display: flex; flex-wrap: wrap; gap: 7px; max-width: 85%; }
.suggest-btn {
    font-size: 11.5px; padding: 6px 14px; border-radius: 20px;
    background: var(--rose-50); border: 1px solid var(--rose-200);
    color: var(--rose-600); cursor: pointer; font-family: inherit;
    transition: all .2s; font-weight: 500;
}
.suggest-btn:hover {
    background: var(--rose-100); border-color: var(--rose-400);
    transform: translateY(-1px); box-shadow: 0 3px 10px rgba(240,65,122,0.15);
}

/* INPUT AREA */
#input-area {
    padding: 14px 20px; background: var(--bg-input);
    border-top: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 8px;
    box-shadow: 0 -2px 12px rgba(212,33,95,0.05);
}
#input-row { display: flex; gap: 10px; align-items: center; width: 100%; }

#user-input {
    flex: 1; padding: 11px 18px; border-radius: 24px;
    border: 1.5px solid var(--border-mid); font-family: inherit;
    font-size: 13.5px; color: var(--text); outline: none;
    background: var(--rose-50); transition: all .2s ease;
}
#user-input::placeholder { color: var(--text-dim); }
#user-input:focus { border-color: var(--rose-400); background: #fff; box-shadow: 0 0 0 3px rgba(249,108,152,0.12); }

#btn-send {
    width: 44px; height: 44px; border-radius: 50%;
    background: linear-gradient(135deg, var(--rose-400), var(--rose-500));
    border: none; font-size: 16px; cursor: pointer; transition: all .2s ease;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 14px rgba(240,65,122,0.35); flex-shrink: 0; color: #fff;
}
#btn-send:hover { transform: scale(1.08) translateY(-1px); box-shadow: 0 6px 22px rgba(240,65,122,0.45); }
#btn-send:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

#btn-attach {
    flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%;
    background: var(--rose-50); border: 1.5px solid var(--border-mid);
    font-size: 17px; cursor: pointer; transition: all .2s;
    display: flex; align-items: center; justify-content: center; color: var(--text-muted);
}
#btn-attach:hover { background: var(--rose-100); border-color: var(--rose-300); transform: rotate(12deg) scale(1.05); color: var(--rose-500); }

#file-badge {
    display: flex; align-items: center; gap: 8px;
    background: var(--peach-100); border: 1px solid var(--peach-200);
    border-radius: 12px; padding: 5px 12px; font-size: 12px;
    color: var(--mauve-dim); width: fit-content; max-width: 100%;
}
#file-badge-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
#btn-remove-file {
    flex-shrink: 0; background: none; border: none; color: var(--text-muted);
    font-size: 12px; cursor: pointer; padding: 0 2px; line-height: 1; transition: color .15s;
}
#btn-remove-file:hover { color: var(--rose-500); }

#file-banner {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--peach-100); border-bottom: 1px solid var(--peach-200);
    padding: 7px 18px; font-size: 12.5px; color: var(--mauve-dim); gap: 8px;
}
#btn-banner-remove {
    background: none; border: none; color: var(--text-muted);
    font-size: 12px; cursor: pointer; padding: 0 2px; transition: color .15s;
}
#btn-banner-remove:hover { color: var(--rose-500); }

#embed-progress {
    width: 100%; border-radius: 8px; overflow: hidden; font-size: 11px;
    background: var(--rose-100); border: 1px solid var(--rose-200);
}
.bg-pink {
    background: linear-gradient(90deg, var(--rose-400), var(--mauve)) !important;
    color: #fff; font-size: 11px; line-height: 18px;
}

.mode-switch { display: none; }

#btn-toggle-sidebar {
    display: none; background: none; border: none; font-size: 18px;
    cursor: pointer; padding: 0 10px 0 0; color: var(--text-muted); transition: color .15s;
}
#btn-toggle-sidebar:hover { color: var(--rose-500); }

.glass {
    background: rgba(255,255,255,0.85); backdrop-filter: blur(12px);
    border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}

body.rich-mode .msg-bot { box-shadow: var(--shadow-md); }
body.rich-mode .msg-user { box-shadow: 0 8px 28px rgba(240,65,122,0.3); }
body.rich-mode .msg:hover { transform: translateY(-4px) scale(1.015); }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rose-200); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--rose-300); }

@media (max-width: 640px) {
    #btn-toggle-sidebar { display: inline-block; }
    #sidebar { position: fixed; top: 0; left: 0; height: 100%; z-index: 200; transform: translateX(-100%); }
    #sidebar.open { transform: translateX(0); }
    .sample-grid { grid-template-columns: 1fr; }
    .msg { max-width: 92%; }
    #messages { padding: 14px 16px; }
}

.text-muted { color: var(--text-muted) !important; }
::selection { background: var(--rose-200); color: var(--text); }
