/* =====================================================
   THEME: Light with Dynamic Brand Colors
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    /* These defaults will be overridden by EJS injection */
    --green-900: #0f3d2e;
    --green-800: #14532d;
    --green-700: #166534;
    --green-600: #15803d;
    --green-100: #dcfce7;
    --green-50:  #f0fdf4;

    --yellow-500: #facc15;
    --yellow-400: #fbbf24;
    --yellow-600: #eab308;
    --yellow-100: #fef9c3;
    --yellow-50:  #fefce8;

    --bg:        #fefef7;
    --surface:   #ffffff;
    --border:    #e8efe5;
    --text:      #0f2419;
    --text-soft: #52665a;
    --text-mute: #8a9a90;

    --shadow-sm: 0 1px 2px rgba(20, 83, 45, 0.04);
    --shadow-md: 0 4px 16px rgba(20, 83, 45, 0.08);
    --shadow-lg: 0 12px 40px rgba(20, 83, 45, 0.12);

    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 999px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    background-image:
        radial-gradient(circle at 0% 0%, rgba(250, 204, 21, 0.10) 0%, transparent 40%),
        radial-gradient(circle at 100% 100%, rgba(20, 83, 45, 0.08) 0%, transparent 45%);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

/* =====================================================
   CHAT PAGE
   ===================================================== */

.chat-container {
    width: 100%;
    max-width: 720px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 48px);
    max-height: 800px;
    border: 1px solid var(--border);
    animation: fadeUp 0.5s ease both;
}

.chat-header {
    background: linear-gradient(135deg, var(--green-800) 0%, var(--green-900) 100%);
    color: #fff;
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.chat-header::after {
    content: '';
    position: absolute;
    right: -30px;
    top: -30px;
    width: 120px;
    height: 120px;
    background: radial-gradient(circle, rgba(250, 204, 21, 0.35) 0%, transparent 70%);
    pointer-events: none;
}

.chat-header-left { display: flex; align-items: center; gap: 14px; z-index: 1; }
.brand-logo {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--yellow-500), var(--yellow-600));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 4px 12px rgba(234, 179, 8, 0.4);
    color: var(--green-900);
}

.chat-header h2 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.01em; }
.chat-header .status-line {
    font-size: 0.78rem;
    color: var(--yellow-400);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.status-dot {
    width: 7px;
    height: 7px;
    background: var(--yellow-500);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(250, 204, 21, 0.7);
    animation: pulse 2s infinite;
}

.chat-box {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: var(--surface);
    scroll-behavior: smooth;
}

.chat-box::-webkit-scrollbar { width: 6px; }
.chat-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.message-row {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    animation: fadeUp 0.3s ease both;
}
.message-row.user { flex-direction: row-reverse; }

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
}

.avatar.bot { background: linear-gradient(135deg, var(--green-800), var(--green-700)); color: var(--yellow-500); }
.avatar.user { background: linear-gradient(135deg, var(--yellow-500), var(--yellow-600)); color: var(--green-900); }

.message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.55;
    font-size: 0.94rem;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.user-message {
    background: var(--green-800);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.bot-message {
    background: var(--green-50);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 14px 18px;
    background: var(--green-50);
    border: 1px solid var(--border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}
.typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green-700);
    animation: bounce 1.4s infinite ease-in-out;
    opacity: 0.6;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

/* Input area */
.input-area {
    display: flex;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    gap: 10px;
    align-items: center;
}

.input-area input {
    flex: 1;
    padding: 14px 20px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 0.94rem;
    font-family: inherit;
    outline: none;
    background: var(--bg);
    color: var(--text);
    transition: all 0.2s ease;
}
.input-area input::placeholder { color: var(--text-mute); }
.input-area input:focus { border-color: var(--green-700); background: #fff; box-shadow: 0 0 0 4px rgba(22, 101, 52, 0.08); }

.input-area button {
    padding: 14px 22px;
    background: linear-gradient(135deg, var(--green-800), var(--green-700));
    color: var(--yellow-500);
    border: none;
    border-radius: var(--radius-full);
    font-family: inherit;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(20, 83, 45, 0.25);
}
.input-area button:hover:not(:disabled) { background: linear-gradient(135deg, var(--green-700), var(--green-600)); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(20, 83, 45, 0.35); }
.input-area button:disabled { opacity: 0.55; cursor: not-allowed; }

/* Markdown Formatting */
.bot-message ul { margin: 8px 0 8px 20px; padding-left: 0; }
.bot-message li { margin-bottom: 6px; line-height: 1.5; }
.bot-message strong { font-weight: 700; color: var(--green-900); }
.bot-message em { font-style: italic; color: var(--green-800); }
.bot-message > *:first-child { margin-top: 0; }
.bot-message > *:last-child { margin-bottom: 0; }

/* =====================================================
   ADMIN / TRAINING DASHBOARD
   ===================================================== */

.admin-container { width: 100%; max-width: 860px; padding: 0; animation: fadeUp 0.5s ease both; }

.admin-header {
    background: linear-gradient(135deg, var(--green-800) 0%, var(--green-900) 100%);
    border-radius: var(--radius-lg);
    padding: 28px 32px;
    margin-bottom: 24px;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}
.admin-header::after {
    content: '';
    position: absolute;
    right: -40px;
    bottom: -40px;
    width: 180px;
    height: 180px;
    background: radial-gradient(circle, rgba(250, 204, 21, 0.3) 0%, transparent 70%);
    pointer-events: none;
}

.admin-header h1 { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; display: flex; align-items: center; gap: 12px; z-index: 1; }
.admin-header h1 .emoji { display: inline-flex; width: 40px; height: 40px; background: var(--yellow-500); border-radius: 12px; align-items: center; justify-content: center; font-size: 20px; color: var(--green-900); }
.admin-header p { font-size: 0.85rem; color: var(--yellow-400); margin-top: 6px; font-weight: 500; z-index: 1; }

.header-actions { display: flex; gap: 10px; align-items: center; z-index: 1; }

.back-link {
    color: #fff;
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.15);
    transition: all 0.2s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}
.back-link:hover { background: var(--yellow-500); color: var(--green-900); border-color: var(--yellow-500); }

.btn-outline {
    background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, 0.25); padding: 10px 16px; font-size: 0.82rem; box-shadow: none; display: flex; align-items: center; gap: 6px; border-radius: var(--radius-full); cursor: pointer; font-family: inherit; font-weight: 600; transition: all 0.2s ease;
}
.btn-outline:hover:not(:disabled) { background: rgba(255, 255, 255, 0.15); transform: translateY(-1px); box-shadow: none; }

.card {
    background: var(--surface);
    padding: 28px;
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}
.card::before {
    content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: linear-gradient(180deg, var(--yellow-500), var(--green-700));
}

.card h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; color: var(--green-900); display: flex; align-items: center; gap: 8px; }
.card h2 .badge { font-size: 0.7rem; background: var(--yellow-100); color: var(--green-800); padding: 3px 10px; border-radius: var(--radius-full); font-weight: 700; letter-spacing: 0.02em; }
.card h3 { font-size: 0.92rem; font-weight: 700; color: var(--green-900); margin: 20px 0 10px; }
.card-desc { font-size: 0.85rem; color: var(--text-soft); margin-bottom: 16px; line-height: 1.6; }

textarea, input[type="text"], input[type="password"], input[type="number"] {
    width: 100%; padding: 14px 16px; border: 1.5px solid var(--border); border-radius: var(--radius-md); font-family: inherit; font-size: 0.92rem; color: var(--text); background: var(--bg); outline: none; transition: all 0.2s ease; resize: vertical; line-height: 1.5;
}
textarea:focus, input[type="text"]:focus, input[type="password"]:focus, input[type="number"]:focus { border-color: var(--green-700); background: #fff; box-shadow: 0 0 0 4px rgba(22, 101, 52, 0.08); }
textarea::placeholder, input::placeholder { color: var(--text-mute); }

.field-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.field-label { font-size: 0.8rem; font-weight: 600; color: var(--green-900); text-transform: uppercase; letter-spacing: 0.04em; }

button {
    padding: 12px 22px; background: linear-gradient(135deg, var(--green-800), var(--green-700)); color: var(--yellow-500); border: none; border-radius: var(--radius-full); font-family: inherit; font-weight: 700; font-size: 0.88rem; cursor: pointer; transition: all 0.2s ease; display: inline-flex; align-items: center; gap: 6px; box-shadow: 0 4px 12px rgba(20, 83, 45, 0.2);
}
button:hover:not(:disabled) { background: linear-gradient(135deg, var(--green-700), var(--green-600)); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(20, 83, 45, 0.3); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-row { display: flex; align-items: center; gap: 12px; margin-top: 4px; flex-wrap: wrap; }
.status { font-size: 0.82rem; font-weight: 600; color: var(--green-700); display: inline-flex; align-items: center; gap: 5px; opacity: 0; transform: translateY(-4px); transition: all 0.3s ease; }
.status.show { opacity: 1; transform: translateY(0); }

/* Knowledge list */
.knowledge-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.knowledge-item {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; background: var(--bg); padding: 16px 18px; border-radius: var(--radius-md); border: 1.5px solid var(--border); transition: all 0.2s ease; animation: fadeUp 0.3s ease both;
}
.knowledge-item:hover { border-color: var(--yellow-500); background: var(--yellow-50); transform: translateX(2px); }
.knowledge-item-content { flex: 1; min-width: 0; }
.knowledge-item-content .q { font-size: 0.92rem; font-weight: 700; color: var(--green-900); margin-bottom: 6px; display: flex; align-items: flex-start; gap: 8px; line-height: 1.4; }
.knowledge-item-content .q::before { content: 'Q'; flex-shrink: 0; width: 20px; height: 20px; background: var(--green-800); color: var(--yellow-500); border-radius: 6px; font-size: 0.68rem; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; margin-top: 1px; }
.knowledge-item-content .a { font-size: 0.88rem; color: var(--text-soft); line-height: 1.55; display: flex; align-items: flex-start; gap: 8px; word-break: break-word; }
.knowledge-item-content .a::before { content: 'A'; flex-shrink: 0; width: 20px; height: 20px; background: var(--yellow-500); color: var(--green-900); border-radius: 6px; font-size: 0.68rem; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; margin-top: 1px; }

.delete-btn { background: transparent; color: var(--text-mute); padding: 8px; border-radius: var(--radius-sm); box-shadow: none; flex-shrink: 0; font-size: 1rem; transition: all 0.2s ease; }
.delete-btn:hover:not(:disabled) { background: #fee2e2; color: #dc2626; transform: none; box-shadow: none; }

.empty-state { text-align: center; padding: 32px 20px; color: var(--text-mute); font-size: 0.88rem; background: var(--bg); border: 1.5px dashed var(--border); border-radius: var(--radius-md); }
.empty-state .icon { font-size: 2rem; display: block; margin-bottom: 8px; opacity: 0.5; }
.add-entry-section { border-top: 1px solid var(--border); padding-top: 20px; margin-top: 8px; }

/* Toast notifications */
.toast-container { position: fixed; top: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 9999; }
.toast { background: var(--green-800); color: #fff; padding: 14px 20px; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); font-size: 0.88rem; font-weight: 600; display: flex; align-items: center; gap: 10px; animation: slideIn 0.3s ease both; border-left: 4px solid var(--yellow-500); min-width: 240px; }
.toast.success { border-left-color: var(--yellow-500); }
.toast.error { border-left-color: #ef4444; }

/* =====================================================
   LOGIN PAGE & PASSWORD TOGGLE
   ===================================================== */

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); background-image: radial-gradient(circle at 0% 0%, rgba(250, 204, 21, 0.15) 0%, transparent 40%), radial-gradient(circle at 100% 100%, rgba(20, 83, 45, 0.10) 0%, transparent 45%); }
.login-container { width: 100%; max-width: 420px; padding: 20px; }
.login-card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); border: 1px solid var(--border); padding: 40px 32px; animation: fadeUp 0.5s ease both; }
.login-header { text-align: center; margin-bottom: 28px; }
.login-header .brand-logo { margin: 0 auto 16px; width: 56px; height: 56px; border-radius: 16px; background: linear-gradient(135deg, var(--green-800), var(--green-700)); color: var(--yellow-500); display: flex; align-items: center; justify-content: center; }
.login-header h1 { font-size: 1.4rem; font-weight: 800; color: var(--green-900); margin-bottom: 6px; }
.login-header p { font-size: 0.88rem; color: var(--text-soft); }
.login-footer { text-align: center; margin-top: 20px; }
.login-footer a { font-size: 0.85rem; color: var(--text-soft); text-decoration: none; font-weight: 600; }
.login-footer a:hover { color: var(--green-700); }
.login-error { color: #dc2626; font-size: 0.85rem; font-weight: 600; text-align: center; margin-top: 12px; min-height: 20px; }
.btn-full { width: 100%; justify-content: center; padding: 14px; }

.password-wrapper { position: relative; display: flex; align-items: center; }
.password-wrapper input { padding-right: 48px; }
.toggle-password { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: transparent; border: none; color: var(--text-mute); padding: 6px; cursor: pointer; box-shadow: none; display: flex; align-items: center; justify-content: center; border-radius: 8px; transition: color 0.2s ease; }
.toggle-password:hover:not(:disabled) { background: transparent; color: var(--green-700); transform: translateY(-50%); box-shadow: none; }

/* =====================================================
   ANIMATIONS & RESPONSIVE
   ===================================================== */

@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(250, 204, 21, 0.7); } 70% { box-shadow: 0 0 0 8px rgba(250, 204, 21, 0); } 100% { box-shadow: 0 0 0 0 rgba(250, 204, 21, 0); } }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }

@media (max-width: 640px) {
    body { padding: 12px; }
    .chat-container { height: calc(100vh - 24px); border-radius: var(--radius-md); }
    .chat-header { padding: 16px; }
    .chat-header h2 { font-size: 1rem; }
    .message { max-width: 85%; font-size: 0.9rem; }
    .admin-header { padding: 20px; flex-direction: column; align-items: flex-start; gap: 14px; }
    .card { padding: 20px; }
    .knowledge-item { flex-direction: column; }
    .delete-btn { align-self: flex-end; }
}

button svg, .admin-link svg, .back-link svg, .card h2 svg, .toast svg { flex-shrink: 0; }
.brand-logo svg, .emoji svg { color: var(--green-900); }
.toast svg { color: var(--yellow-500); }
.toast.error svg { color: #ef4444; }
#usageBar { border-radius: 5px; }