/* ============================================
   MY KANHA PROJECT - COMPLETE STYLESHEET
   Clean, Mobile-First, PWA-Ready
   ============================================ */

/* CSS VARIABLES */
:root {
    --primary: #e09f3e;
    --primary-dark: #b6893e;
    --secondary: #b6e2d3;
    --surface: rgba(255, 251, 230, 0.98);
    --text-primary: #4a4a4a;
    --text-secondary: #7c6f57;
    --text-muted: #999;
    --border: rgba(200, 170, 100, 0.2);
    --shadow: rgba(200, 170, 100, 0.15);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --bottom-nav-height: 60px;
    --touch-target: 44px;
    --transition: 0.2s ease;
}

/* RESET */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, #fffbe6 0%, #ffe5b4 50%, #f5e6d3 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    overflow-x: hidden;
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
}

/* HEADER */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--surface);
    box-shadow: 0 2px 12px var(--shadow);
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.nav { display: flex; gap: 0.5rem; }

.nav a {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: var(--transition);
}

.nav a:hover, .nav a.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
}

@media (max-width: 768px) {
    .nav { display: none; }
    .header { justify-content: center; }
}

/* MAIN LAYOUT */
.main {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: calc(100vh - 56px);
    padding: 1.5rem 1rem;
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 2rem);
}

/* SECTIONS */
.container, .chat-section, .search-section, .history-section, .settings-section, .verse-section {
    background: var(--surface);
    border-radius: 20px;
    box-shadow: 0 4px 24px var(--shadow);
    padding: 1.5rem;
    width: 100%;
    max-width: 600px;
}

/* TYPOGRAPHY */
h1, h2, h3 { color: var(--primary-dark); font-weight: 700; margin-bottom: 0.5rem; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; color: var(--primary); }
p { color: var(--text-secondary); margin-bottom: 1rem; }

/* BUTTONS */
.btn, .start-btn, .send-btn, .search-btn, .save-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    min-height: var(--touch-target);
    transition: var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.btn:hover, .start-btn:hover, .send-btn:hover, .search-btn:hover, .save-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--shadow);
}

.btn:active, .start-btn:active, .send-btn:active { transform: translateY(0); }
.btn:disabled, .send-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.clear-btn {
    background: transparent;
    border: 1.5px solid var(--primary);
    color: var(--primary);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    min-height: var(--touch-target);
}

.clear-btn:hover { background: var(--primary); color: #fff; }

/* INPUTS */
input[type="text"], input[type="email"], input[type="password"], textarea, select, .chat-input, .search-input {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 16px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    background: #fff;
    color: var(--text-primary);
    transition: var(--transition);
    min-height: var(--touch-target);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(224, 159, 62, 0.15);
}

.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-weight: 600; color: var(--primary-dark); margin-bottom: 0.5rem; }

/* CHAT */
.chat-main { padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 1rem); }
.chat-header { text-align: center; margin-bottom: 1rem; }
.chat-subtitle { font-size: 0.9rem; color: var(--text-muted); margin: 0; }

.chat-window {
    position: relative;
    background: #fffdf5;
    border-radius: 16px;
    min-height: 350px;
    max-height: calc(100dvh - 320px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
}


.chat-window > *:not(.krishna-bg) { position: relative; z-index: 1; }

.chat-form { display: flex; gap: 0.75rem; background: var(--surface); padding: 0.5rem 0; }
.chat-input { flex: 1; }
.send-btn { flex-shrink: 0; padding: 0.875rem 1.25rem; }

.chat-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.chat-info { font-size: 0.75rem; color: var(--text-muted); }

/* MESSAGES */
.message { display: flex; gap: 0.75rem; margin-bottom: 1rem; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffe5b4, #f9d29d);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.message-content {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.message-text { color: var(--text-primary); line-height: 1.5; word-wrap: break-word;  }
.message-time { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.3rem; text-align: right; }

.user-message { flex-direction: row-reverse; }
.user-message .message-content { background: linear-gradient(135deg, var(--primary), #f9d29d); }
.user-message .message-text { color: #fff; }
.user-message .message-time { color: rgba(255, 255, 255, 0.8); }

.krishna-message .message-content { background: rgba(255, 251, 230, 0.98); border: 1px solid rgba(224, 159, 62, 0.2); }
.welcome-message .message-content { background: linear-gradient(135deg, rgba(182, 226, 211, 0.3), rgba(255, 251, 230, 0.98)); border: 1px solid rgba(182, 226, 211, 0.5); }

.system-message { justify-content: center; }
.system-message .message-content { max-width: 90%; text-align: center; font-size: 0.85rem; padding: 0.5rem 1rem; }
.system-message.error .message-content { background: #fff5f5; border: 1px solid #ff6b6b; color: #d63031; }

/* TYPING INDICATOR */
.typing-indicator .typing-dots { display: flex; gap: 4px; padding: 0.5rem 0; }
.typing-indicator .typing-dots span {
    width: 8px; height: 8px;
    background: var(--primary-dark);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-indicator .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

/* SOURCES */
.message-sources { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px dashed rgba(224, 159, 62, 0.3); }
.sources-header { font-size: 0.8rem; font-weight: 600; color: var(--primary-dark); margin-bottom: 0.5rem; }
.source-item { background: rgba(255, 229, 180, 0.3); border-radius: 8px; padding: 0.6rem; margin-bottom: 0.5rem; border-left: 3px solid var(--primary); }
.source-reference { font-weight: 600; color: var(--primary-dark); font-size: 0.85rem; }
.source-translation { color: var(--text-primary); font-size: 0.85rem; line-height: 1.4; margin-top: 0.25rem; }

/* SEARCH */
.search-form { display: flex; gap: 0.75rem; margin-bottom: 1.5rem; }
.search-results { min-height: 100px; }
.search-result-item {
    background: #fff;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    border-left: 3px solid var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    transition: var(--transition);
}
.search-result-item:hover { transform: translateY(-2px); box-shadow: 0 4px 12px var(--shadow); }

/* HISTORY */
.history-list { min-height: 100px; }
.history-item {
    background: #fff;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    cursor: pointer;
    transition: var(--transition);
}
.history-item:hover { transform: translateY(-2px); box-shadow: 0 4px 12px var(--shadow); }

/* SETTINGS */
.settings-form { display: flex; flex-direction: column; gap: 1.5rem; }
.setting-description { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.25rem; }

.toggle-switch { display: flex; align-items: center; gap: 1rem; }
.toggle-input { display: none; }
.toggle-label {
    position: relative;
    display: inline-block;
    width: 56px;
    height: 30px;
    background: #ddd;
    border-radius: 30px;
    cursor: pointer;
    transition: 0.3s ease;
}
.toggle-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    background: #fff;
    border-radius: 50%;
    transition: 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.toggle-input:checked + .toggle-label { background: linear-gradient(135deg, var(--primary), #ffa726); }
.toggle-input:checked + .toggle-label .toggle-slider { left: 29px; }
.status-text { font-size: 0.9rem; font-weight: 500; color: var(--text-secondary); }

.install-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 1rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    max-width: 280px;
    min-height: var(--touch-target);
    transition: var(--transition);
}
.install-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px var(--shadow); }
.pwa-status { display: flex; align-items: center; gap: 0.5rem; color: #00b894; font-weight: 500; }

.reset-btn {
    background: transparent;
    border: 1.5px solid var(--text-muted);
    color: var(--text-secondary);
    padding: 0.875rem 1.5rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    min-height: var(--touch-target);
    transition: var(--transition);
}

.reset-btn:hover { background: var(--text-muted); color: #fff; }

.button-group { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; }
.button-group .save-btn, .button-group .reset-btn { flex: 1; min-width: 140px; }

.theme-preview { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.preview-box { padding: 1rem; border-radius: 8px; color: #fff; font-size: 0.8rem; text-align: center; min-width: 80px; flex: 1; }

/* BOTTOM NAV */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
    padding-bottom: var(--safe-area-bottom);
    background: var(--surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.08);
    z-index: 1000;
    border-top: 1px solid var(--border);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-secondary);
    padding: 8px 16px;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    border-radius: 12px;
    transition: var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item:active { transform: scale(0.95); background: rgba(224, 159, 62, 0.1); }
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-icon { font-size: 1.3rem; margin-bottom: 2px; }
.bottom-nav-item.active .bottom-nav-icon { transform: scale(1.1); }
.bottom-nav-label { font-size: 0.7rem; font-weight: 600; }

@media (min-width: 769px) {
    .bottom-nav { display: none; }
    body { padding-bottom: 0; }
}

/* DARK MODE */
body.dark-mode, html.dark-mode {
    --surface: rgba(26, 26, 50, 0.95);
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-muted: #808080;
    --border: rgba(255, 183, 77, 0.2);
    --shadow: rgba(0, 0, 0, 0.3);
    background: linear-gradient(135deg, #0f0f1e 0%, #1a1a3e 50%, #0f0f1e 100%) !important;
}

body.dark-mode .header, html.dark-mode .header { background: rgba(15, 15, 30, 0.95) !important; border-bottom: 1px solid rgba(255, 183, 77, 0.2); }
body.dark-mode .logo, html.dark-mode .logo { color: #ffb74d !important; }
body.dark-mode .nav a, html.dark-mode .nav a { color: #b0b0b0 !important; }
body.dark-mode .nav a:hover, body.dark-mode .nav a.active, html.dark-mode .nav a:hover, html.dark-mode .nav a.active { background: rgba(255, 183, 77, 0.2) !important; color: #ffb74d !important; }

body.dark-mode .container, body.dark-mode .chat-section, body.dark-mode .search-section, body.dark-mode .history-section, body.dark-mode .settings-section,
html.dark-mode .container, html.dark-mode .chat-section, html.dark-mode .search-section, html.dark-mode .history-section, html.dark-mode .settings-section {
    background: rgba(26, 26, 50, 0.9) !important;
    border: 1px solid rgba(255, 183, 77, 0.1);
}

body.dark-mode h1, body.dark-mode h2, body.dark-mode h3, html.dark-mode h1, html.dark-mode h2, html.dark-mode h3 { color: #ffb74d !important; }
body.dark-mode p, body.dark-mode label, html.dark-mode p, html.dark-mode label { color: #b0b0b0 !important; }

body.dark-mode input, body.dark-mode textarea, body.dark-mode select, html.dark-mode input, html.dark-mode textarea, html.dark-mode select {
    background: rgba(30, 30, 60, 0.8) !important;
    color: #e0e0e0 !important;
    border-color: rgba(255, 183, 77, 0.2) !important;
}

body.dark-mode input:focus, html.dark-mode input:focus { border-color: #ffb74d !important; box-shadow: 0 0 0 3px rgba(255, 183, 77, 0.2) !important; }
body.dark-mode .chat-window, html.dark-mode .chat-window { background: rgba(20, 20, 40, 0.8) !important; }
body.dark-mode .message-content, html.dark-mode .message-content { background: rgba(40, 40, 70, 0.9) !important; }
body.dark-mode .message-text, html.dark-mode .message-text { color: #e0e0e0 !important; }

body.dark-mode .user-message .message-content, html.dark-mode .user-message .message-content { background: linear-gradient(135deg, #ffb74d, #ffa726) !important; }
body.dark-mode .user-message .message-text, html.dark-mode .user-message .message-text { color: #1a1a2e !important; }

body.dark-mode .bottom-nav, html.dark-mode .bottom-nav { background: rgba(15, 15, 30, 0.98) !important; border-top-color: rgba(255, 183, 77, 0.2) !important; }
body.dark-mode .bottom-nav-item, html.dark-mode .bottom-nav-item { color: #808080 !important; }
body.dark-mode .bottom-nav-item.active, html.dark-mode .bottom-nav-item.active { color: #ffb74d !important; }
body.dark-mode .status-text, html.dark-mode .status-text { color: #ffb74d !important; }

body.dark-mode .history-item, body.dark-mode .search-result-item, html.dark-mode .history-item, html.dark-mode .search-result-item {
    background: rgba(40, 40, 70, 0.8) !important;
    border-color: rgba(255, 183, 77, 0.1) !important;
}

body.dark-mode .clear-btn, html.dark-mode .clear-btn { border-color: #ffb74d !important; color: #ffb74d !important; }
body.dark-mode .clear-btn:hover, html.dark-mode .clear-btn:hover { background: #ffb74d !important; color: #1a1a2e !important; }

/* SCROLLBAR */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 4px; }
body.dark-mode ::-webkit-scrollbar-thumb { background: #ffb74d; }

/* RESPONSIVE */
@media (max-width: 480px) {
    .chat-window { max-height: calc(100dvh - 280px); min-height: 250px; }
    .message-content { max-width: 85%; }
    h2 { font-size: 1.2rem; }
}

@media (max-height: 500px) and (orientation: landscape) {
    .bottom-nav { height: calc(50px + var(--safe-area-bottom)); }
    .chat-window { min-height: 120px; max-height: calc(100dvh - 180px); }
}

@media print {
    .bottom-nav, .header { display: none !important; }
    body { padding: 0 !important; background: #fff !important; }
}

/* UTILITIES */
.text-center { text-align: center; }
.hidden { display: none !important; }
