:root {
    /* Default Dark Theme */
    --primary: #3b82f6;
    --bg: #0f172a;
    --card: #1e293b;
    --text: #f8fafc;
    --text-light: #94a3b8;
    --border: #334155;
    --incoming-bg: #1e293b;
    --outgoing-bg: #1e3a8a;
    --input-bg: #020617;
    --danger: #ef4444;
    --success: #10b981;
    --safe-bottom: env(safe-area-inset-bottom, 20px);
}

/* Light Theme Overrides */
[data-theme="light"] {
    --primary: #2563eb;
    --bg: #f3f4f6;
    --card: #ffffff;
    --text: #111827;
    --text-light: #6b7280;
    --border: #e5e7eb;
    --incoming-bg: #ffffff;
    --outgoing-bg: #eff6ff;
    --input-bg: #f9fafb;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); height: 100vh; width: 100vw; overflow: hidden; transition: background 0.3s, color 0.3s; }

/* --- Layout --- */
.screen { position: absolute; width: 100%; height: 100%; background: var(--bg); display: flex; flex-direction: column; z-index: 10; transition: transform 0.3s ease; }
.slide-screen { transform: translateX(100%); z-index: 20; }
.slide-screen.open { transform: translateX(0); }

/* --- Login --- */
#screen-login { z-index: 50; background: var(--bg); align-items: center; justify-content: center; }
.login-content { text-align: center; width: 80%; max-width: 350px; }
.logo-circle { width: 70px; height: 70px; background: var(--primary); color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 32px; margin: 0 auto 20px; box-shadow: 0 10px 25px rgba(59,130,246,0.5); }
.pincode-wrapper input { width: 100%; padding: 15px; font-size: 24px; text-align: center; letter-spacing: 8px; border: 2px solid var(--border); border-radius: 12px; margin: 20px 0; outline: none; background: var(--card); color: var(--text); }
.pincode-wrapper input:focus { border-color: var(--primary); }
.btn-primary-large { width: 100%; padding: 15px; background: var(--primary); color: white; border: none; border-radius: 12px; font-size: 16px; font-weight: 600; cursor: pointer; }

/* --- Header --- */
.app-header { height: 60px; background: var(--card); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; border-bottom: 1px solid var(--border); }
.badge { background: var(--input-bg); color: var(--primary); padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; border: 1px solid var(--border); }
.badge.pulse { animation: pulse 2s infinite; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }
.icon-btn { background: none; border: none; font-size: 22px; color: var(--text); cursor: pointer; padding: 5px; }

/* --- Bottom Nav --- */
.bottom-nav { height: 65px; background: var(--card); border-top: 1px solid var(--border); display: flex; justify-content: space-around; align-items: center; padding-bottom: var(--safe-bottom); }
.nav-item { background: none; border: none; display: flex; flex-direction: column; align-items: center; color: var(--text-light); font-size: 10px; gap: 4px; cursor: pointer; }
.nav-item i { font-size: 22px; }
.nav-item.active { color: var(--primary); }

/* --- Main Content --- */
.tab-view { flex: 1; display: none; flex-direction: column; overflow: hidden; }
.tab-view.active { display: flex; }
.scroll-content { flex: 1; overflow-y: auto; padding-bottom: 80px; }
.padding-20 { padding: 20px; }

/* Search Bar */
.search-container { padding: 10px 15px; background: var(--card); border-bottom: 1px solid var(--border); }
.search-box { position: relative; }
.search-box input { width: 100%; background: var(--input-bg); border: 1px solid var(--border); color: var(--text); padding: 12px 12px 12px 40px; border-radius: 10px; font-size: 15px; outline: none; }
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-light); }

/* Device List Item */
.device-item { background: var(--card); padding: 15px; margin: 8px 15px; border-radius: 12px; display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--border); position: relative; transition: transform 0.1s; }
.device-item:active { transform: scale(0.98); }
.device-left { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.device-top { display: flex; align-items: center; gap: 8px; }
.device-model { font-size: 15px; font-weight: 600; }
.device-meta { font-size: 12px; color: var(--text-light); display: flex; gap: 10px; align-items: center;}
.device-right { text-align: right; display: flex; align-items: center; gap: 10px; }

/* Pin Button */
.pin-btn { background: none; border: none; color: var(--text-light); font-size: 20px; cursor: pointer; padding: 5px; transition: 0.2s; }
.pin-btn.active { color: var(--primary); transform: rotate(45deg); }

/* Status Dot & Last Seen */
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.status-dot.online { background: var(--success); box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.15); }
.last-seen { font-size: 11px; color: var(--text-light); background: var(--input-bg); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--border); }
.last-seen.active { color: var(--success); border-color: var(--success); background: rgba(16, 185, 129, 0.1); }

/* Settings Cards */
.settings-card { background: var(--card); border-radius: 12px; border: 1px solid var(--border); margin-bottom: 15px; overflow: hidden; }
.sc-header { padding: 15px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; font-weight: 600; background: rgba(0,0,0,0.02); }
.sc-icon { width: 30px; height: 30px; border-radius: 6px; display: flex; align-items: center; justify-content: center; color: white; }
.sc-icon.orange { background: #f97316; }
.sc-icon.blue { background: #3b82f6; }
.sc-icon.red { background: #ef4444; }
.sc-body { padding: 15px; }
.sc-row { display: flex; justify-content: space-between; align-items: center; }

.input-group label { display: block; font-size: 12px; color: var(--text-light); margin-bottom: 5px; }
.input-box { width: 100%; padding: 10px; background: var(--input-bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); margin-bottom: 10px; }
.btn-secondary { width: 100%; padding: 12px; background: var(--primary); color: white; border: none; border-radius: 8px; font-weight: 600; cursor: pointer; }
.btn-danger-outline { width: 100%; padding: 12px; border: 1px solid var(--danger); color: var(--danger); background: transparent; border-radius: 8px; font-weight: 600; cursor: pointer; }
.full { width: 100%; }
.version-info { text-align: center; font-size: 12px; color: var(--text-light); margin-top: 20px; }

/* Toggle Switch */
.switch { position: relative; display: inline-block; width: 50px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border); transition: .4s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(24px); }

/* Chat View */
.chat-header { height: 60px; background: var(--card); display: flex; align-items: center; padding: 0 10px; border-bottom: 1px solid var(--border); }
.header-info { flex: 1; text-align: center; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 12px; background: var(--bg); border: 1px solid var(--border); }
.status-dot-small { width: 6px; height: 6px; border-radius: 50%; background: var(--text-light); }
.status-pill.online .status-dot-small { background: var(--success); }
.status-pill.online { border-color: var(--success); color: var(--success); }

.chat-filters { padding: 10px; display: flex; gap: 8px; overflow-x: auto; background: var(--bg); border-bottom: 1px solid var(--border); }
.chip { padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--card); font-size: 12px; font-weight: 500; color: var(--text); cursor: pointer; }
.chip.active { background: var(--primary); color: white; border-color: var(--primary); }
.chat-area { flex: 1; overflow-y: auto; padding: 15px; display: flex; flex-direction: column; gap: 12px; }
.msg-bubble { max-width: 85%; padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.4; position: relative; word-wrap: break-word; }
.msg-in { align-self: flex-start; background: var(--incoming-bg); border: 1px solid var(--border); border-bottom-left-radius: 2px; color: var(--text); }
.msg-out { align-self: flex-end; background: var(--outgoing-bg); border: 1px solid rgba(59,130,246,0.3); border-bottom-right-radius: 2px; color: var(--text); }
.msg-sender { font-size: 11px; font-weight: 700; color: var(--primary); display: block; margin-bottom: 2px; }
.msg-time { font-size: 10px; color: var(--text-light); float: right; margin-top: 4px; margin-left: 8px; }
.otp-code { background: #fef3c7; color: #92400e; padding: 1px 4px; font-weight: 600; border-radius: 4px; }

/* Chat Footer */
.chat-footer { background: var(--card); padding: 10px; border-top: 1px solid var(--border); padding-bottom: max(10px, var(--safe-bottom)); }
.input-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.chat-footer input, textarea { width: 100%; background: var(--input-bg); border: 1px solid var(--border); padding: 12px; border-radius: 12px; font-family: inherit; outline: none; color: var(--text); }
.send-fab { width: 44px; height: 44px; border-radius: 50%; background: var(--primary); color: white; border: none; display: flex; align-items: center; justify-content: center; font-size: 20px; cursor: pointer; }

/* Modal & Stats */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 100; display: none; align-items: flex-end; backdrop-filter: blur(2px); }
.modal-card { background: var(--card); width: 100%; border-radius: 20px 20px 0 0; padding: 25px; animation: slideUp 0.3s ease; max-height: 85vh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; margin-bottom: 20px; font-weight: 700; font-size: 18px; }
.info-row { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.btn-danger { background: var(--danger); color: white; padding: 15px; width: 100%; border: none; border-radius: 12px; margin-top: 20px; font-weight: 600; font-size: 16px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.stat-card { background: var(--card); padding: 15px; border-radius: 10px; border: 1px solid var(--border); text-align: center; }
.stat-card span { font-size: 24px; font-weight: 700; display: block; }
.stat-card span.green { color: var(--success); }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* Toast */
#toast-container { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 200; width: 90%; max-width: 350px; pointer-events: none; }
.toast { background: var(--card); color: var(--text); padding: 12px 16px; border-radius: 50px; text-align: center; font-size: 14px; margin-bottom: 10px; box-shadow: 0 8px 20px rgba(0,0,0,0.2); animation: fadeIn 0.3s; border: 1px solid var(--border); display: inline-block; pointer-events: auto; }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }