/**
 * WA-Connect Custom Styles
 */

/* ======================
   CSS Variables
   ====================== */
:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --sidebar-bg: #1a1d21;
    --sidebar-text: #b8c1cc;
    --sidebar-text-active: #ffffff;
    --sidebar-hover-bg: #2d3238;
    --sidebar-active-bg: #25d366;
    --wa-green: #25d366;
    --wa-dark: #128c7e;
}

/* ======================
   Base Styles
   ====================== */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f4f6f9;
    min-height: 100vh;
}

/* ======================
   Sidebar Styles
   ====================== */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    transition: width 0.3s ease, transform 0.3s ease;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1000;
}

[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
}

/* Wrapper needs margin for desktop sidebar */
#wrapper {
    margin-left: var(--sidebar-width);
    transition: margin 0.3s ease;
}

[dir="rtl"] #wrapper {
    margin-left: 0;
    margin-right: var(--sidebar-width);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .sidebar-header h5,
.sidebar.collapsed .sidebar-nav .nav-link span,
.sidebar.collapsed .sidebar-footer {
    display: none;
}

.sidebar-header {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h5 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.sidebar-nav .nav-link {
    color: #d1d5db;
    padding: 0.875rem 1.25rem;
    display: flex;
    align-items: center;
    transition: background-color 0.2s ease, color 0.2s ease;
    border-left: 4px solid transparent;
    font-size: 0.95rem;
    font-weight: 500;
    margin: 0.125rem 0;
    text-decoration: none;
    cursor: pointer;
}

/* RTL Support for sidebar nav */
[dir="rtl"] .sidebar-nav .nav-link {
    border-left: none;
    border-right: 4px solid transparent;
}

.sidebar-nav .nav-link:hover {
    color: var(--sidebar-text-active);
    background-color: var(--sidebar-hover-bg);
}

.sidebar-nav .nav-link.active {
    color: var(--sidebar-text-active);
    background: linear-gradient(90deg, rgba(37, 211, 102, 0.15) 0%, transparent 100%);
    border-left-color: var(--wa-green);
}

/* RTL Support for active nav link */
[dir="rtl"] .sidebar-nav .nav-link.active {
    border-left-color: transparent;
    border-right-color: var(--wa-green);
    background: linear-gradient(270deg, rgba(37, 211, 102, 0.15) 0%, transparent 100%);
}

.sidebar-nav .nav-link i {
    font-size: 1.25rem;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
}

.sidebar-footer small {
    font-size: 0.75rem;
    opacity: 0.7;
}

.sidebar-footer span {
    font-weight: 500;
}

/* ======================
   Page Content
   ====================== */
#page-content-wrapper {
    min-width: 0;
    background-color: #f4f6f9;
    position: relative;
    z-index: 1;
}

/* ======================
   Top Navbar
   ====================== */
.navbar {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

#sidebarToggle {
    border: none;
    padding: 0.5rem;
    color: #495057;
}

#sidebarToggle:hover {
    color: var(--wa-green);
}

/* ======================
   Cards
   ====================== */
.card {
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    border-radius: 0.75rem;
}

.card-header {
    background-color: #ffffff;
    border-bottom: 1px solid #e9ecef;
    padding: 1rem 1.25rem;
    border-radius: 0.75rem 0.75rem 0 0 !important;
}

.card-body {
    padding: 1.25rem;
}

/* ======================
   Tables
   ====================== */
.table {
    margin-bottom: 0;
}

.table th {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6c757d;
    border-top: none;
    padding: 0.875rem 1rem;
}

.table td {
    vertical-align: middle;
    padding: 0.875rem 1rem;
}

.table-hover tbody tr:hover {
    background-color: rgba(37, 211, 102, 0.05);
}

/* ======================
   Status Badges
   ====================== */
.badge {
    font-weight: 500;
    padding: 0.4em 0.75em;
    border-radius: 0.375rem;
}

/* ======================
   Buttons
   ====================== */
.btn {
    border-radius: 0.5rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    transition: all 0.2s ease;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

.btn-primary {
    background: var(--wa-green);
    border-color: var(--wa-green);
}

.btn-primary:hover {
    background: var(--wa-dark);
    border-color: var(--wa-dark);
}

.btn-success {
    background: var(--wa-green);
    border-color: var(--wa-green);
}

.btn-success:hover {
    background: var(--wa-dark);
    border-color: var(--wa-dark);
}

/* ======================
   Forms
   ====================== */
.form-control,
.form-select {
    border-radius: 0.5rem;
    border-color: #dee2e6;
    padding: 0.625rem 0.875rem;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--wa-green);
    box-shadow: 0 0 0 0.2rem rgba(37, 211, 102, 0.2);
}

.form-label {
    font-weight: 500;
    color: #495057;
    margin-bottom: 0.5rem;
}

/* ======================
   Alerts
   ====================== */
.alert {
    border: none;
    border-radius: 0.75rem;
}

/* ======================
   WhatsApp Colors
   ====================== */
.bg-whatsapp {
    background-color: var(--wa-green) !important;
}

.text-whatsapp {
    color: var(--wa-green) !important;
}

.btn-whatsapp {
    background-color: var(--wa-green);
    border-color: var(--wa-green);
    color: #ffffff;
}

.btn-whatsapp:hover {
    background-color: var(--wa-dark);
    border-color: var(--wa-dark);
    color: #ffffff;
}

/* ======================
   Stats Cards
   ====================== */
.card.bg-primary,
.card.bg-success,
.card.bg-info,
.card.bg-secondary {
    border: none;
    border-radius: 0.75rem;
}

.card.bg-primary .card-body,
.card.bg-success .card-body,
.card.bg-info .card-body,
.card.bg-secondary .card-body {
    padding: 1rem;
}

/* ======================
   QR Code Styles
   ====================== */
.qr-container {
    padding: 2rem;
    background: #ffffff;
    border-radius: 1rem;
    display: inline-block;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.qr-container img {
    max-width: 256px;
    height: auto;
}

/* ======================
   Message Preview
   ====================== */
.message-bubble {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    margin-bottom: 0.5rem;
}

.message-bubble.outgoing {
    background-color: #dcf8c6;
    margin-left: auto;
    border-bottom-right-radius: 0.25rem;
}

.message-bubble.incoming {
    background-color: #ffffff;
    border-bottom-left-radius: 0.25rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* ======================
   Loading States
   ====================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* ======================
   Chart Container
   ====================== */
.chart-container {
    position: relative;
    width: 100%;
}

/* ======================
   Responsive - Mobile Sidebar
   ====================== */

/* Sidebar backdrop overlay for mobile */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1050;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

/* Hide backdrop on desktop */
@media (min-width: 992px) {
    .sidebar-backdrop {
        display: none !important;
    }
}

@media (max-width: 991.98px) {
    /* Remove wrapper margin on mobile */
    #wrapper {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Hide sidebar off-screen by default (LTR) */
    .sidebar {
        width: 260px !important;
        z-index: 1060 !important;
        left: 0;
        right: auto;
        transform: translateX(-100%);
        box-shadow: none;
    }

    /* RTL: Hide sidebar to the right */
    html[dir="rtl"] .sidebar,
    [dir="rtl"] .sidebar {
        left: auto !important;
        right: 0 !important;
        transform: translateX(100%) !important;
    }

    /* Show sidebar when toggle is clicked (LTR) */
    .sidebar.show {
        transform: translateX(0) !important;
        box-shadow: 4px 0 25px rgba(0, 0, 0, 0.5);
    }

    /* RTL: Show sidebar from right */
    html[dir="rtl"] .sidebar.show,
    [dir="rtl"] .sidebar.show {
        left: auto !important;
        right: 0 !important;
        transform: translateX(0) !important;
        box-shadow: -4px 0 25px rgba(0, 0, 0, 0.5);
    }

    /* Sidebar nav links on mobile */
    .sidebar .nav-link {
        padding: 1rem 1.25rem;
        font-size: 1rem;
        color: #e9ecef;
        -webkit-tap-highlight-color: rgba(37, 211, 102, 0.3);
        touch-action: manipulation;
    }

    .sidebar .nav-link:active {
        background-color: rgba(37, 211, 102, 0.2) !important;
    }

    /* Prevent body scroll when sidebar is open */
    body.sidebar-open {
        overflow: hidden;
    }

    /* Make toggle button more visible on mobile */
    #sidebarToggle {
        padding: 0.5rem;
    }

    #sidebarToggle i {
        font-size: 1.5rem;
        color: #212529;
    }
}


/* ======================
   Utilities
   ====================== */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cursor-pointer {
    cursor: pointer;
}

.min-h-100 {
    min-height: 100%;
}

/* ======================
   Mobile Improvements
   ====================== */
@media (max-width: 767.98px) {
    /* Smaller padding on mobile */
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .table th,
    .table td {
        font-size: 0.85rem;
        padding: 0.625rem 0.5rem;
    }

    .table td.text-truncate {
        max-width: 100px !important;
    }

    /* Stack cards properly on mobile */
    .card {
        margin-bottom: 0.75rem;
    }

    /* Better button sizing on mobile */
    .btn-group .btn-sm {
        padding: 0.35rem 0.5rem;
        font-size: 0.8rem;
    }

    /* Dashboard stats cards */
    .card.bg-primary .card-body,
    .card.bg-success .card-body,
    .card.bg-info .card-body,
    .card.bg-secondary .card-body {
        padding: 0.875rem;
    }

    .fs-3 {
        font-size: 1.5rem !important;
    }
}

/* ======================
   Language Switcher
   ====================== */
.lang-switcher-dashboard {
    display: flex;
    gap: 4px;
}

.lang-switcher-dashboard a {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
    color: #6c757d;
    border: 1px solid #dee2e6;
    transition: all 0.2s ease;
}

.lang-switcher-dashboard a.active {
    background: var(--wa-green);
    color: white;
    border-color: var(--wa-green);
}

.lang-switcher-dashboard a:hover:not(.active) {
    background: #f8f9fa;
    border-color: #ced4da;
}
