/* ==========================================================================
   Krishi Sahayak — Glassmorphism UI
   ========================================================================== */

:root {
    --primary: #22c55e;
    --primary-dk: #16a34a;
    --primary-lt: #4ade80;
    --accent: #facc15;
    --bg: #0a1628;
    --glass: rgba(255,255,255,.06);
    --glass-border: rgba(255,255,255,.1);
    --glass-strong: rgba(255,255,255,.1);
    --glass-strong-border: rgba(255,255,255,.18);
    --user-bg: linear-gradient(135deg, #16a34a, #059669);
    --bot-bg: rgba(255,255,255,.07);
    --text: #f0fdf4;
    --text-dim: rgba(255,255,255,.5);
    --text-secondary: rgba(255,255,255,.4);
    --radius: 18px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="light"] {
    --bg: #e8f5e9;
    --glass: rgba(255,255,255,.55);
    --glass-border: rgba(255,255,255,.7);
    --glass-strong: rgba(255,255,255,.7);
    --glass-strong-border: rgba(255,255,255,.85);
    --bot-bg: rgba(255,255,255,.6);
    --text: #0f2419;
    --text-dim: rgba(0,40,15,.5);
    --text-secondary: rgba(0,40,15,.4);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    color: var(--text);
    min-height: 100vh;
    /* Gradient mesh background */
    background: var(--bg);
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(22,163,74,.25) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(250,204,21,.15) 0%, transparent 40%),
        radial-gradient(ellipse at 50% 80%, rgba(5,150,105,.2) 0%, transparent 50%),
        radial-gradient(ellipse at 10% 90%, rgba(22,163,74,.12) 0%, transparent 40%);
    background-attachment: fixed;
    transition: background .4s, color .4s;
}

[data-theme="light"] body {
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(22,163,74,.18) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(250,204,21,.12) 0%, transparent 40%),
        radial-gradient(ellipse at 50% 80%, rgba(5,150,105,.15) 0%, transparent 50%),
        radial-gradient(ellipse at 10% 90%, rgba(22,163,74,.1) 0%, transparent 40%);
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

/* ── NAVBAR (Glass) ── */
.navbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    background: rgba(10,22,40,.6);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.nav-inner {
    max-width: 800px; margin: 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    padding: 13px 22px;
}

.brand {
    display: flex; align-items: center; gap: 10px;
    font-weight: 800; font-size: 1.18rem; color: #fff; text-decoration: none;
    letter-spacing: -.3px;
}

.brand-icon {
    width: 34px; height: 34px; border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; color: #fff;
    box-shadow: 0 0 16px rgba(34,197,94,.3);
}

.nav-actions { display: flex; gap: 6px; }

.nav-btn {
    border: 1px solid rgba(255,255,255,.12);
    background: rgba(255,255,255,.06);
    color: rgba(255,255,255,.8);
    border-radius: 50px; padding: 6px 14px;
    font-size: .76rem; font-weight: 500; cursor: pointer;
    transition: all .25s;
    display: flex; align-items: center; gap: 5px;
    font-family: var(--font);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

.nav-btn:hover {
    background: rgba(255,255,255,.12);
    border-color: rgba(255,255,255,.25);
    color: #fff;
    box-shadow: 0 0 12px rgba(34,197,94,.15);
}

@media (max-width: 480px) { .btn-label { display: none; } }

/* ── MAIN ── */
.main {
    max-width: 780px; margin: 0 auto;
    padding: 82px 12px 70px;
}

/* ── CHAT CARD (Glass) ── */
.chat-card {
    background: var(--glass);
    -webkit-backdrop-filter: blur(24px) saturate(150%);
    backdrop-filter: blur(24px) saturate(150%);
    border: 1px solid var(--glass-border);
    border-radius: 22px;
    overflow: hidden;
    display: flex; flex-direction: column;
    min-height: calc(100vh - 162px);
    box-shadow:
        0 8px 32px rgba(0,0,0,.15),
        inset 0 1px 0 rgba(255,255,255,.08);
}

/* ── HEADER (Glass) ── */
.card-header {
    padding: 16px 22px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,.06);
    background: rgba(255,255,255,.03);
}

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

.avatar {
    width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
    background: linear-gradient(135deg, #16a34a, #facc15);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 1rem;
    box-shadow: 0 0 14px rgba(34,197,94,.35);
}

.card-header h5 { font-size: .92rem; font-weight: 700; margin: 0; }
.status { font-size: .72rem; color: var(--text-dim); }
.status i { color: #4ade80; font-size: 5px; vertical-align: middle; margin-right: 3px; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
.date { font-size: .72rem; color: var(--text-secondary); white-space: nowrap; }

/* ── MESSAGES ── */
.messages {
    flex: 1; overflow-y: auto; padding: 20px;
    display: flex; flex-direction: column; gap: 10px;
    background: rgba(0,0,0,.05);
    min-height: 300px;
    max-height: calc(100vh - 330px);
}

.msg { display: flex; gap: 10px; max-width: 82%; animation: slideIn .3s cubic-bezier(.22,1,.36,1); }
@keyframes slideIn { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.bot { align-self: flex-start; }

.msg-av {
    width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0; margin-top: 2px;
    display: flex; align-items: center; justify-content: center; font-size: .72rem;
}
.msg.user .msg-av { background: var(--user-bg); color: #fff; }
.msg.bot .msg-av { background: linear-gradient(135deg, #16a34a, #facc15); color: #fff; }

.bubble {
    padding: 12px 16px; border-radius: 14px; font-size: .9rem;
    line-height: 1.7; word-wrap: break-word;
}

.msg.user .bubble {
    background: var(--user-bg); color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 16px rgba(22,163,74,.25);
}

.msg.bot .bubble {
    background: var(--bot-bg);
    color: var(--text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--glass-border);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.bubble p { margin-bottom: 5px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble img { max-width: 100%; border-radius: 8px; margin: 6px 0; }

.msg-meta {
    font-size: .62rem; color: var(--text-secondary); margin-top: 3px;
    display: flex; align-items: center; gap: 6px;
}
.msg.user .msg-meta { color: rgba(255,255,255,.45); justify-content: flex-end; }

.cache-tag {
    display: inline-flex; align-items: center; gap: 3px;
    background: rgba(34,197,94,.12); color: var(--primary);
    padding: 1px 6px; border-radius: 4px; font-size: .58rem; font-weight: 600;
}

.msg-img {
    max-width: 200px; max-height: 150px; border-radius: 10px;
    margin-bottom: 6px; object-fit: cover; display: block;
}

/* ── WELCOME ── */
.welcome { text-align: center; padding: 48px 20px; margin: auto; }

.welcome-icon {
    width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 18px;
    background: linear-gradient(135deg, #16a34a, #facc15);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.8rem; color: #fff;
    box-shadow: 0 0 30px rgba(34,197,94,.35), 0 8px 24px rgba(0,0,0,.2);
}

.welcome h3 { font-size: 1.25rem; font-weight: 800; margin-bottom: 6px; }
.welcome p { color: var(--text-dim); font-size: .88rem; max-width: 400px; margin: 0 auto 22px; line-height: 1.5; }

.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-width: 420px; margin: 0 auto; }

.chip {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-radius: 12px; padding: 11px 13px;
    font-size: .8rem; cursor: pointer; transition: all .25s;
    color: var(--text); text-align: left;
    display: flex; align-items: center; gap: 8px;
}

.chip i { color: var(--primary); font-size: .9rem; flex-shrink: 0; }

.chip:hover {
    border-color: var(--primary);
    background: rgba(34,197,94,.1);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(34,197,94,.15);
}

/* ── TYPING ── */
.typing { display: none; align-items: center; gap: 8px; padding: 4px 20px 6px; }
.typing.visible { display: flex; }

.dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--primary-lt);
    animation: bounce 1.4s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%,60%,100%{transform:translateY(0);opacity:.3} 30%{transform:translateY(-5px);opacity:1} }
.typing-label { font-size: .72rem; color: var(--text-secondary); }

/* ── IMAGE PREVIEW ── */
.image-preview {
    display: none; padding: 8px 20px;
    border-top: 1px solid rgba(255,255,255,.06);
    background: rgba(0,0,0,.05);
}
.image-preview.active { display: flex; align-items: center; gap: 10px; }
.image-preview img {
    height: 60px; width: 60px; object-fit: cover; border-radius: 10px;
    border: 2px solid var(--primary);
    box-shadow: 0 0 10px rgba(34,197,94,.3);
}
.remove-image {
    width: 24px; height: 24px; border-radius: 50%; border: none;
    background: rgba(239,68,68,.8); color: #fff; font-size: .6rem;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: .2s;
}
.remove-image:hover { background: #ef4444; transform: scale(1.1); }

/* ── INPUT BAR (Glass) ── */
.input-bar {
    padding: 10px 14px 14px;
    border-top: 1px solid rgba(255,255,255,.06);
    display: flex; align-items: center; gap: 6px;
    background: rgba(255,255,255,.03);
}

.icon-btn {
    width: 38px; height: 38px; border-radius: 50%; border: none;
    background: rgba(255,255,255,.06); color: var(--primary); font-size: 1.1rem;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all .25s; flex-shrink: 0;
    border: 1px solid rgba(255,255,255,.08);
}
.icon-btn:hover {
    background: rgba(34,197,94,.15);
    border-color: rgba(34,197,94,.3);
    box-shadow: 0 0 12px rgba(34,197,94,.15);
}
.icon-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.icon-btn.mic.recording {
    background: rgba(239,68,68,.8); color: #fff; border-color: transparent;
    animation: micPulse 1.5s infinite;
}
@keyframes micPulse { 0%,100%{box-shadow:0 0 0 0 rgba(239,68,68,.4)} 50%{box-shadow:0 0 0 8px rgba(239,68,68,0)} }

.input-row { display: flex; align-items: center; gap: 6px; flex: 1; }

.chat-input {
    flex: 1; border: 1px solid rgba(255,255,255,.1);
    border-radius: 50px; padding: 9px 16px; font-size: .88rem;
    background: rgba(255,255,255,.05);
    color: var(--text); outline: none; transition: all .25s; font-family: var(--font);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}
.chat-input:focus {
    border-color: rgba(34,197,94,.5);
    box-shadow: 0 0 0 3px rgba(34,197,94,.1), 0 0 20px rgba(34,197,94,.08);
}
.chat-input::placeholder { color: var(--text-secondary); }

.send-btn {
    width: 38px; height: 38px; border-radius: 50%; border: none;
    background: linear-gradient(135deg, #16a34a, #059669); color: #fff;
    font-size: .9rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 16px rgba(34,197,94,.3); transition: all .25s; flex-shrink: 0;
}
.send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 24px rgba(34,197,94,.4);
}
.send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }

/* ── FOOTER (Glass) ── */
.footer {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    background: rgba(10,22,40,.5);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border-top: 1px solid rgba(255,255,255,.06);
    padding: 10px 0; text-align: center;
}
.footer p { font-size: .72rem; color: var(--text-secondary); margin: 0; }
.footer a { color: var(--primary); text-decoration: none; }
.footer a:hover { text-decoration: underline; }
.footer-heart { color: #ef4444; }
.d-none { display: none !important; }

/* ── TOAST ── */
.toast-msg {
    position: fixed; bottom: 60px; right: 14px; z-index: 999;
    background: rgba(255,255,255,.08);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 12px; padding: 10px 16px; font-size: .8rem;
    color: var(--text);
    box-shadow: 0 4px 20px rgba(0,0,0,.2);
    display: none;
    animation: toastIn .3s ease;
}
@keyframes toastIn { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }

/* ── RESPONSIVE ── */
@media (max-width: 576px) {
    .main { padding: 74px 6px 64px; }
    .chat-card { border-radius: 14px; min-height: calc(100vh - 148px); }
    .card-header { padding: 12px 14px; }
    .messages { padding: 14px; max-height: calc(100vh - 300px); min-height: 200px; }
    .msg { max-width: 90%; }
    .bubble { font-size: .86rem; padding: 10px 13px; }
    .chips { grid-template-columns: 1fr; }
    .welcome { padding: 28px 10px; }
    .welcome-icon { width: 52px; height: 52px; font-size: 1.4rem; border-radius: 14px; }
    .input-bar { gap: 4px; padding: 8px 10px 10px; }
}