/* ============================================================
 * AHB CRM — Design System
 * UX-first light theme, dark mode toggle, smooth animations
 * ============================================================ */

/* ─── CSS Variables (Light Mode Default) ─────── */
:root {
    /* Brand Colors */
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: rgba(99, 102, 241, 0.1);
    --secondary: #10b981;
    --secondary-hover: #059669;
    --accent: #f59e0b;
    --danger: #ef4444;
    --danger-hover: #dc2626;

    /* Light Mode Palette */
    --bg-primary: #f8f9fb;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f3f9;
    --bg-card: #ffffff;
    --bg-glass: rgba(0, 0, 0, 0.02);
    --bg-input: #f4f5f7;
    --bg-hover: rgba(99, 102, 241, 0.04);

    /* Text */
    --text-primary: #1a1a2e;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    /* Borders */
    --border-color: #e2e8f0;
    --border-focus: rgba(99, 102, 241, 0.5);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);

    /* Layout */
    --sidebar-width: 260px;
    --header-height: 60px;
    --chat-sidebar-width: 360px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Font */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ─── Reset & Base ───────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary-hover);
}

img {
    max-width: 100%;
    height: auto;
}

/* ─── Typography ─────────────────────────────── */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    line-height: 1.3;
}

h1 {
    font-size: 2rem;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.5rem;
    letter-spacing: -0.01em;
}

h3 {
    font-size: 1.25rem;
}

.text-muted {
    color: var(--text-muted);
}

.text-secondary {
    color: var(--text-secondary);
}

.text-primary-color {
    color: var(--primary);
}

.text-success {
    color: var(--secondary);
}

.text-danger {
    color: var(--danger);
}

.text-center {
    text-align: center;
}

/* ─── Card ───────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

/* ─── Buttons ────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #4f46e5);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-hover), #6366f1);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-glass);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-focus);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: var(--danger-hover);
    transform: translateY(-1px);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 0.8rem 1.8rem;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ─── Form Controls ──────────────────────────── */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 0.65rem 0.9rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-control::placeholder {
    color: var(--text-muted);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%2394a3b8' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1.2rem;
    padding-right: 2.5rem;
}

.form-error {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* ─── Badge ──────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
    line-height: 1;
}

.badge-primary {
    background: var(--primary-light);
    color: var(--primary-hover);
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--secondary);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent);
}

.badge-count {
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--danger);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
}

/* ─── Layout: Auth Pages ─────────────────────── */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(135deg, #f0f2ff 0%, #e8f4f8 50%, #f8f9fb 100%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 2.5rem;
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo h1 {
    font-size: 1.8rem;
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.auth-logo h1 svg {
    flex-shrink: 0;
}

.auth-logo p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ─── Layout: Dashboard ─────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition-slow);
}

.sidebar-header {
    padding: 1.2rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-brand {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
}

.sidebar-nav {
    flex: 1;
    padding: 0.5rem;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1rem;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all var(--transition-fast);
    cursor: pointer;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary-hover);
    font-weight: 500;
}

.nav-item .nav-icon {
    font-size: 1.1rem;
    width: 1.5rem;
    text-align: center;
}

/* ─── Collapsible Nav Groups ─────────────────── */
.nav-group {
    margin-bottom: 0.25rem;
}

.nav-group+.nav-group {
    border-top: 1px solid var(--border-color);
    padding-top: 0.25rem;
    margin-top: 0.25rem;
}

.nav-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 1rem;
    cursor: pointer;
    user-select: none;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.nav-group-header:hover {
    background: var(--bg-hover);
}

.nav-group-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.nav-group-chevron {
    font-size: 0.65rem;
    color: var(--text-muted);
    transition: transform var(--transition-normal);
}

.nav-group.collapsed .nav-group-chevron {
    transform: rotate(-90deg);
}

.nav-group-items {
    overflow: hidden;
    max-height: 500px;
    transition: max-height 0.3s ease, opacity 0.25s ease;
    opacity: 1;
}

.nav-group.collapsed .nav-group-items {
    max-height: 0;
    opacity: 0;
}

/* WhatsApp brand icon color in settings */
.settings-nav-item-icon .fa-whatsapp {
    color: #25D366;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    min-height: 100vh;
}

.main-header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(10px);
}

.page-content {
    padding: 1.5rem;
}

/* ─── Page Guide Banner ──────────────────────── */
.page-guide-banner {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.06) 0%, rgba(16, 185, 129, 0.04) 100%);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
    animation: fadeInDown 0.4s ease;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Stats Grid ─────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    padding: 1.25rem;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.stat-card .stat-change {
    font-size: 0.8rem;
    margin-top: 0.5rem;
}

.stat-card .stat-change.positive {
    color: var(--secondary);
}

.stat-card .stat-change.negative {
    color: var(--danger);
}

/* ─── Table ──────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg-glass);
}

tr:hover td {
    background: var(--bg-hover);
}

/* ─── Avatar ─────────────────────────────────── */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: white;
    flex-shrink: 0;
}

.avatar-lg {
    width: 48px;
    height: 48px;
    font-size: 1.1rem;
}

.avatar-sm {
    width: 28px;
    height: 28px;
    font-size: 0.7rem;
}

/* ─── Modal ──────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal {
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.9) translateY(20px);
    transition: transform var(--transition-slow);
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    transition: color var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-primary);
}

/* ─── Toast / Notification ───────────────────── */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    font-size: 0.85rem;
    animation: slideIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 280px;
}

.toast-success {
    background: rgba(16, 185, 129, 0.2);
    border-color: var(--secondary);
}

.toast-error {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--danger);
}

.toast-info {
    background: rgba(99, 102, 241, 0.2);
    border-color: var(--primary);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ─── Loading Spinner ────────────────────────── */
.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: inherit;
}

/* ─── Empty State ────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

/* ─── Responsive ─────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .auth-card {
        padding: 1.5rem;
    }

    .page-content {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ─── Utility ────────────────────────────────── */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-end {
    justify-content: flex-end;
}

.gap-1 {
    gap: 0.5rem;
}

.gap-2 {
    gap: 1rem;
}

.gap-3 {
    gap: 1.5rem;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.hidden {
    display: none !important;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Theme Toggle ───────────────────────────── */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    border: none;
    background: var(--bg-glass);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-family: inherit;
    transition: all var(--transition-fast);
    width: 100%;
}

.theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.theme-toggle i {
    font-size: 1rem;
    width: 1.25rem;
    text-align: center;
}

/* ─── Language Switcher (sidebar) ────────────── */
.lang-switcher {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.lang-switcher:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.lang-switcher i {
    font-size: 1rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

.lang-switcher select {
    flex: 1;
    background: none;
    border: none;
    color: inherit;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    padding: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%2394a3b8' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0 center;
    background-size: 1.1rem;
    padding-right: 1.2rem;
}

.lang-switcher select option {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* ─── Language Switcher (inline / login) ─────── */
.lang-switcher-inline {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

.lang-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.lang-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-focus);
    color: var(--text-primary);
}

.lang-btn.active {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary-hover);
    font-weight: 500;
}

/* ─── Skeleton Loading ───────────────────────── */
.skeleton {
    background: linear-gradient(90deg,
            var(--bg-tertiary) 25%,
            rgba(99, 102, 241, 0.06) 50%,
            var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.skeleton-text.short {
    width: 60%;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
}

.skeleton-card {
    height: 120px;
    border-radius: var(--radius-lg);
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

/* ─── Micro-Animations ───────────────────────── */
.animate-in {
    animation: slideUp 0.4s ease forwards;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stagger-1 {
    animation-delay: 0.05s;
}

.stagger-2 {
    animation-delay: 0.1s;
}

.stagger-3 {
    animation-delay: 0.15s;
}

.stagger-4 {
    animation-delay: 0.2s;
}

/* ─── Dark Mode ──────────────────────────────── */
[data-theme="dark"] {
    --bg-primary: #0f0f23;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --bg-card: rgba(26, 26, 46, 0.8);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --bg-input: rgba(255, 255, 255, 0.08);
    --bg-hover: rgba(255, 255, 255, 0.1);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0f172a;
    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);
}

[data-theme="dark"] .card {
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

[data-theme="dark"] .auth-wrapper {
    background: radial-gradient(ellipse at top, var(--bg-tertiary), var(--bg-primary));
}

[data-theme="dark"] .loading-overlay {
    background: rgba(15, 15, 35, 0.8);
}

[data-theme="dark"] .modal-overlay {
    background: rgba(0, 0, 0, 0.7);
}

/* ─── Toast Notifications (Enhanced) ─────────── */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 380px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    animation: toastIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    backdrop-filter: blur(12px);
}

.toast span {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.toast-success {
    border-left: 4px solid var(--secondary, #10b981);
}

.toast-error {
    border-left: 4px solid var(--danger, #ef4444);
}

.toast-warning {
    border-left: 4px solid var(--accent, #f59e0b);
}

.toast-info {
    border-left: 4px solid var(--primary, #6366f1);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(40px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* ─── Page Transitions ───────────────────────── */
.page-content {
    animation: pageIn 0.3s ease;
}

@keyframes pageIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Stat Card Enhancements ─────────────────── */
.stat-card {
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    cursor: default;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    transition: color 0.2s;
}

/* Count-up animation helper */
.count-up {
    display: inline-block;
    animation: countPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes countPop {
    from {
        transform: scale(0.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* ─── Smart Badge Enhancements ───────────────── */
.badge-count {
    animation: badgePulse 0.3s ease;
}

@keyframes badgePulse {
    from {
        transform: scale(0);
    }

    50% {
        transform: scale(1.2);
    }

    to {
        transform: scale(1);
    }
}

/* ─── Card Enter Animation ───────────────────── */
.card {
    animation: cardIn 0.3s ease;
}

@keyframes cardIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Smooth Nav Transitions ─────────────────── */
.nav-item {
    transition: background 0.2s, color 0.2s, transform 0.15s;
}

.nav-item:hover {
    transform: translateX(4px);
}

.nav-item.active {
    transform: translateX(4px);
}

/* ─── Premium Input Focus ────────────────────── */
.form-control:focus {
    box-shadow: 0 0 0 3px var(--border-focus);
    transform: translateY(-1px);
    transition: box-shadow 0.2s, transform 0.2s;
}

/* ─── Scroll Bar Styling ─────────────────────── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================================
 * Phase 5: Mobile & Responsive Design
 * ============================================================ */

/* ─── Mobile Bottom Navigation Bar ───────────── */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    z-index: 8000;
    padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
}

.mobile-bottom-nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    border-radius: 10px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.65rem;
    transition: color 0.2s, background 0.2s;
    min-width: 48px;
    min-height: 48px;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-item i {
    font-size: 1.15rem;
    margin-bottom: 1px;
}

.mobile-nav-item.active {
    color: var(--primary);
    background: var(--primary-light);
}

.mobile-nav-item:active {
    transform: scale(0.92);
}

.mobile-nav-item .mobile-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    background: var(--danger);
    border-radius: 50%;
    border: 2px solid var(--bg-card);
}

/* ─── Tablet Breakpoint (≤1024px) ────────────── */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 220px;
        --chat-sidebar-width: 280px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ─── Mobile Breakpoint (≤768px) ─────────────── */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }

    html {
        font-size: 14px;
    }

    /* Sidebar becomes overlay */
    .sidebar {
        position: fixed;
        left: calc(-1 * var(--sidebar-width));
        top: 0;
        bottom: 0;
        z-index: 8500;
        transition: left 0.3s ease;
        box-shadow: none;
    }

    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    /* Sidebar backdrop */
    .sidebar.open::after {
        content: '';
        position: fixed;
        top: 0;
        left: var(--sidebar-width);
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: -1;
    }

    /* Main content takes full width */
    .main-content {
        margin-left: 0 !important;
        padding-bottom: 72px;
    }

    /* Show hamburger */
    #sidebar-toggle {
        display: flex !important;
    }

    /* Mobile bottom nav visible */
    .mobile-bottom-nav {
        display: block;
    }

    /* Stats grid compact */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    .stat-card {
        padding: 14px !important;
    }

    .stat-value {
        font-size: 1.5rem !important;
    }

    /* Touch targets */
    .btn {
        min-height: 44px;
        padding: 10px 16px;
    }

    .btn-sm {
        min-height: 36px;
        padding: 6px 12px;
    }

    .form-control {
        min-height: 44px;
        font-size: 16px;
    }

    /* Page content padding */
    .page-content {
        padding: 12px !important;
    }

    /* Card compact */
    .card {
        border-radius: var(--radius-md) !important;
    }

    /* Welcome checklist compact */
    .welcome-checklist-items {
        grid-template-columns: 1fr !important;
    }

    /* Header compact */
    .main-header h2 {
        font-size: 0.95rem !important;
    }

    /* Table responsive */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Toast mobile position */
    .toast-container {
        left: 12px;
        right: 12px;
        top: 12px;
        max-width: none;
    }

    /* Auth pages responsive */
    .auth-card {
        width: 100% !important;
        max-width: 100vw !important;
        border-radius: var(--radius-md) !important;
        margin: 12px !important;
    }
}

/* ─── Small Mobile (≤480px) ──────────────────── */
@media (max-width: 480px) {
    html {
        font-size: 13.5px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 6px !important;
    }

    .stat-card {
        padding: 10px !important;
    }

    .stat-value {
        font-size: 1.3rem !important;
    }

    .stat-label {
        font-size: 0.7rem !important;
    }

    /* Onboarding wizard compact */
    .onboarding-wizard {
        border-radius: 12px !important;
    }

    .onboarding-body {
        padding: 16px !important;
    }

    .onboarding-icon {
        width: 56px;
        height: 56px;
        font-size: 1.4rem;
    }

    .onboarding-body h2 {
        font-size: 1.15rem !important;
    }

    /* Command palette compact */
    .command-palette {
        margin: 12px;
        border-radius: 12px !important;
    }
}

/* ─── Messenger Mobile Layout ────────────────── */
@media (max-width: 768px) {
    .messenger-layout {
        flex-direction: column !important;
    }

    .chat-sidebar {
        width: 100% !important;
        max-width: 100% !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border-color);
    }

    /* When a conversation is selected, hide sidebar show chat */
    .messenger-layout.chat-active .chat-sidebar {
        display: none;
    }

    .messenger-layout.chat-active .chat-area {
        display: flex !important;
        flex-direction: column;
    }

    /* Back button visible on mobile chat */
    .messenger-layout.chat-active #back-btn {
        display: inline-flex !important;
    }

    .chat-area {
        width: 100% !important;
        height: calc(100vh - var(--header-height) - 72px) !important;
    }

    /* Compose area sticky bottom */
    .compose-area {
        position: sticky;
        bottom: 0;
    }

    .compose-input {
        font-size: 16px !important;
    }
}

/* ─── Print Styles ───────────────────────────── */
@media print {

    .sidebar,
    .mobile-bottom-nav,
    .main-header,
    .toast-container,
    .compose-area {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}

/* ─── Reduced Motion ─────────────────────────── */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ─── Landscape Mobile ───────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
    .mobile-bottom-nav {
        padding: 4px 0;
    }

    .mobile-nav-item {
        padding: 4px 10px;
        min-height: 40px;
    }

    .mobile-nav-item i {
        font-size: 1rem;
    }

    .mobile-nav-item span {
        display: none;
    }
}
