:root {
    --bg-color: #f4f6f9;
    --card-bg: rgba(255, 255, 255, 0.75);
    --card-border: rgba(255, 255, 255, 0.5);
    --primary-gradient: linear-gradient(135deg, #0088cc 0%, #007aff 100%);
    --primary-color: #007aff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --accent-success: #34c759;
    --accent-danger: #ff3b30;
    --accent-warning: #ff9500;
    --input-bg: #f1f5f9;
    --input-focus-border: #007aff;
    --sidebar-width: 260px;
    --border-radius: 16px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.03);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Background Glow Circles */
.glow-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.glow-circle {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.35;
    animation: float 20s infinite ease-in-out alternate;
}

.glow-circle-1 {
    width: 500px;
    height: 500px;
    background: #dbeafe; /* light blue */
    top: -10%;
    right: -10%;
}

.glow-circle-2 {
    width: 600px;
    height: 600px;
    background: #e0e7ff; /* light indigo */
    bottom: -15%;
    left: -10%;
    animation-delay: -5s;
}

@keyframes float {
    0% {
        transform: translate(0, 0) scale(1);
    }
    100% {
        transform: translate(50px, 30px) scale(1.05);
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* Utility Classes */
.hide {
    display: none !important;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    gap: 10px;
    transform: translateY(20px);
    opacity: 0;
    animation: slideIn 0.3s forwards cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 350px;
    font-size: 0.9rem;
    font-weight: 500;
}

.toast.success {
    border-left: 4px solid var(--accent-success);
}

.toast.error {
    border-left: 4px solid var(--accent-danger);
}

@keyframes slideIn {
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Base Layout Structure */
.app-container {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* Mobile Header (Hidden on Desktop) */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--card-border);
    z-index: 900;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.mobile-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.menu-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    transition: var(--transition);
}

.menu-toggle:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Sidebar Styling */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(4px);
    z-index: 950;
}

.sidebar {
    width: var(--sidebar-width);
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--card-border);
    padding: 24px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 1000;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 30px;
}

.logo-icon {
    font-size: 1.5rem;
}

.brand-text {
    font-weight: 700;
    font-size: 1.25rem;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 12px;
    font-weight: 500;
    font-size: 0.95rem;
    transition: var(--transition);
    border: 1px solid transparent;
}

.nav-item:hover {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.03);
}

.nav-item.active {
    background: var(--primary-color);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(0, 122, 255, 0.2);
}

/* Sidebar Footer (Profile Info) */
.sidebar-footer {
    border-top: 1px solid var(--card-border);
    padding-top: 20px;
    margin-top: 20px;
}

.user-info {
    margin-bottom: 12px;
}

.user-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    word-break: break-all;
}

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px;
    background: rgba(255, 59, 48, 0.08);
    color: var(--accent-danger);
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-logout:hover {
    background: rgba(255, 59, 48, 0.15);
}

/* Main Content Layout */
.main-content {
    flex-grow: 1;
    padding: 40px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.main-content.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.content-header {
    margin-bottom: 30px;
}

.page-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Dashboard Tab Panel Layout */
.tab-content {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

/* Glassmorphic Cards */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.card h3 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
}

/* Connection Status Block */
.status-block {
    display: flex;
    align-items: center;
    gap: 20px;
}

.status-avatar {
    width: 54px;
    height: 54px;
    border-radius: 16px;
    background: rgba(0, 122, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
}

.status-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.status-dot.connected {
    background-color: var(--accent-success);
    box-shadow: 0 0 10px rgba(52, 199, 89, 0.4);
}

.status-dot.disconnected {
    background-color: var(--accent-danger);
    box-shadow: 0 0 10px rgba(255, 59, 48, 0.4);
}

.status-info h4 {
    font-size: 1rem;
    font-weight: 600;
}

.status-info p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Forms Grid */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group.full-width {
    grid-column: span 2;
}

label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

input[type="text"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--input-bg);
    border: 1px solid transparent;
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 500;
    outline: none;
    transition: var(--transition);
}

input[type="text"]::placeholder,
input[type="password"]::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

input[type="text"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
    background: #ffffff;
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

small {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Buttons Styling */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: var(--transition);
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary-gradient);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(0, 122, 255, 0.15);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(0, 122, 255, 0.25);
    opacity: 0.95;
}

.btn-secondary {
    background: #e2e8f0;
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: #cbd5e1;
}

.btn-block {
    width: 100%;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

/* Table Style overrides (Leads Table) */
.table-container {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid var(--card-border);
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    background: rgba(0, 0, 0, 0.02);
    padding: 16px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--card-border);
}

td {
    padding: 16px;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--card-border);
    color: var(--text-primary);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: rgba(0, 0, 0, 0.015);
}

/* Badges for status */
.badge {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge.success {
    background: rgba(52, 199, 89, 0.1);
    color: var(--accent-success);
}

.badge.danger {
    background: rgba(255, 59, 48, 0.1);
    color: var(--accent-danger);
}

.badge.warning {
    background: rgba(255, 149, 0, 0.1);
    color: var(--accent-warning);
}

/* Login Page Layout */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: var(--bg-color);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 40px 30px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.05);
}

.brand {
    text-align: center;
    margin-bottom: 30px;
}

.brand-logo {
    font-size: 2.2rem;
    display: inline-block;
    margin-bottom: 10px;
}

.brand-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.brand-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.error-message {
    background: rgba(255, 59, 48, 0.08);
    color: var(--accent-danger);
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 500;
    margin-top: 10px;
    border: 1px solid rgba(255, 59, 48, 0.15);
}

/* --- Media Queries (Mobile & Tablet Responsiveness) --- */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        padding-top: 60px; /* Space for fixed mobile header */
    }

    .mobile-header {
        display: flex;
    }

    /* Transform Sidebar into a sliding drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: calc(-1 * var(--sidebar-width));
        bottom: 0;
        height: 100vh;
        z-index: 1000;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background: #ffffff; /* solid fallback */
    }

    .sidebar.active {
        transform: translateX(var(--sidebar-width));
    }

    .sidebar-overlay.active {
        display: block;
    }

    .main-content {
        padding: 20px;
    }

    .page-title {
        font-size: 1.5rem;
    }

    /* Forms single column */
    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-group.full-width {
        grid-column: span 1;
    }

    .status-block {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .form-actions {
        flex-direction: column;
    }
    
    .form-actions .btn {
        width: 100%;
    }
}
