/* ========================================
   MODERN WhatsApp Gateway - Design System
   ======================================== */

:root {
    /* Primary Gradient */
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-light: linear-gradient(135deg, #8b9cfd 0%, #9370db 100%);

    /* Colors */
    --purple-600: #667eea;
    --purple-700: #764ba2;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    /* Semantic Colors */
    --success: #22c55e;
    --error: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   GLOBAL STYLES
   ======================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--gray-800);
    background: var(--gray-50);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   LAYOUT
   ======================================== */

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
    background: var(--gray-50);
}

/* ========================================
   SIDEBAR
   ======================================== */

.sidebar {
    width: 280px;
    background: #5046e5;
    /* Solid Indigo/Purple color */
    color: white;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-2xl);
    position: relative;
    z-index: 100;
}

.brand {
    padding: var(--space-xl) var(--space-lg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand h2 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(to right, #ffffff, #e0e7ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.menu {
    flex: 1;
    padding: var(--space-lg) 0;
    overflow-y: auto;
}

.menu::-webkit-scrollbar {
    width: 6px;
}

.menu::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-full);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    margin: var(--space-xs) var(--space-md);
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
    cursor: pointer;
    font-weight: 500;
    position: relative;
    overflow: hidden;
}

.menu-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.05);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.menu-item:hover::before {
    opacity: 1;
}

.menu-item:hover {
    color: white;
    transform: translateX(4px);
}

.menu-item.active {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-weight: 600;
}

.menu-item.active::before {
    opacity: 1;
}

.menu-item .icon {
    font-size: 1.25rem;
    width: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.device-list {
    max-height: 300px;
    overflow-y: auto;
}

.device-item {
    font-size: 0.875rem;
    padding: var(--space-sm) var(--space-lg);
}

.connection-status {
    padding: var(--space-lg);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.875rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--gray-400);
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.status-dot.connected {
    background: var(--success);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* ========================================
   MAIN CONTENT
   ======================================== */

.main-content {
    flex: 1;
    padding: var(--space-2xl);
    overflow-y: auto;
    background: var(--gray-50);
    position: relative;
    scroll-behavior: smooth;
}

.view {
    display: none;
    animation: fadeIn var(--transition-base);
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   HEADERS
   ======================================== */

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-2xl);
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.02em;
}

/* ========================================
   CARDS
   ======================================== */

.card {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--gray-200);
    transition: all var(--transition-base);
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.stat-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    transition: all var(--transition-base);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--gray-500);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-xs);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1;
}

/* ========================================
   BUTTONS
   ======================================== */

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: all var(--transition-base);
    font-weight: 600;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    padding: var(--space-md) var(--space-xl);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    font-size: 0.9375rem;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: white;
    color: var(--gray-700);
    border: 2px solid var(--gray-200);
    padding: var(--space-md) var(--space-xl);
    border-radius: var(--radius-md);
}

.btn-secondary:hover {
    background: var(--gray-50);
    border-color: var(--purple-600);
    color: var(--purple-600);
}

/* ========================================
   FORMS
   ======================================== */

.form-group {
    margin-bottom: var(--space-lg);
}

label {
    display: block;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: var(--space-sm);
    font-size: 0.875rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
textarea,
select {
    width: 100%;
    padding: var(--space-md);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.9375rem;
    transition: all var(--transition-base);
    background: white;
    color: var(--gray-800);
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--purple-600);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236B7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
}

/* ========================================
   TABLES
   ======================================== */

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    /* Removed sticky from here */
}

th {
    padding: var(--space-md);
    text-align: left;
    font-weight: 600;
    color: var(--gray-700);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}


td {
    padding: var(--space-md);
    border-bottom: 1px solid var(--gray-200);
}

tbody tr {
    transition: background-color var(--transition-fast);
}

tbody tr:hover {
    background: var(--gray-50);
}

/* Members Table Specific */
#members-table-body {
    display: table-row-group;
    width: 100%;
}

#members-table-body tr {
    display: table-row;
    background: white;
    min-height: auto;
    visibility: visible;
    opacity: 1;
}

#members-table-body tr td {
    display: table-cell;
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
    visibility: visible;
    opacity: 1;
}

#members-table-body td {
    display: table-cell;
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

/* ========================================
   MODALS
   ======================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(3px);
    z-index: 1000;
    display: none;
    justify-content: center;
    align-items: center;
    animation: fadeInOverlay var(--transition-base);
}

.modal-overlay.open {
    display: flex;
}

.modal-card {
    width: 420px;
    max-width: calc(100% - 40px);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    box-shadow: 0 20px 40px rgba(2, 6, 23, 0.12);
    border: 1px solid rgba(16, 24, 40, 0.04);
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

/* Modal animation */
.modal-overlay.open {
    display: flex;
}

.modal-card {
    transform: translateY(-12px) scale(0.98);
    opacity: 0;
    transition: transform 220ms var(--transition-base), opacity 220ms var(--transition-base);
}

.modal-overlay.open .modal-card {
    .modal-card {
        background: #fff;
        border-radius: 8px;
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
        width: 480px;
        max-width: calc(100% - 32px);
        padding: 0;
        transform: translateY(-8px) scale(0.98);
        transition: transform 200ms cubic-bezier(.2, .9, .3, 1), opacity 200ms ease;
        opacity: 0;
    }

    .modal-overlay.open .modal-card {
        transform: translateY(0) scale(1);
        opacity: 1;
    }

    transform: translateY(0) scale(1);
    opacity: 1;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.125rem;
    color: var(--gray-800);
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--gray-500);
}

.modal-body {
    padding-top: 0.25rem;
    padding-bottom: 0.5rem;
}

.modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

.btn-secondary {
    padding: 0.5rem 0.9rem;
    border-radius: 8px;
}

/* Improve input appearance inside modal */
.modal-card input[type="text"] {
    padding: 0.7rem;
    border-radius: 8px;
}

@keyframes fadeInOverlay {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.grid {
    display: grid;
    gap: var(--space-lg);
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-sm {
    gap: var(--space-sm);
}

.gap-md {
    gap: var(--space-md);
}

.gap-lg {
    gap: var(--space-lg);
}

.mt-lg {
    margin-top: var(--space-lg);
}

.mb-lg {
    margin-bottom: var(--space-lg);
}

.text-center {
    text-align: center;
}

/* ========================================
   QR CODE
======================================== */

#qr-container {
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
}

#qr-image {
    max-width: 280px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.placeholder {
    color: var(--gray-400);
    font-size: 1.125rem;
    text-align: center;
}

/* ========================================
   LOGS
   ======================================== */

#logs-container {
    max-height: 500px;
    overflow-y: auto;
}

.log-entry {
    padding: var(--space-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    border-left: 4px solid var(--gray-300);
    background: var(--gray-50);
    transition: all var(--transition-fast);
}

.log-entry:hover {
    background: white;
    box-shadow: var(--shadow-sm);
}

.log-entry.sent {
    border-left-color: var(--info);
}

.log-entry.received {
    border-left-color: var(--success);
}

/* ========================================
   MOBILE HEADER
   ======================================== */

.mobile-header {
    display: none;
    height: 60px;
    background: white;
    padding: 0 1.5rem;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 30px;
    height: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1001;
}

.menu-toggle span {
    width: 30px;
    height: 3px;
    background: #5046e5;
    border-radius: 10px;
    transition: all 0.3s linear;
    position: relative;
    transform-origin: 1px;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    .app-container {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px;
        transition: transform var(--transition-base);
        z-index: 1001;
    }

    .sidebar.show {
        transform: translateX(280px);
    }

    .main-content {
        padding: var(--space-lg);
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }

    h1 {
        font-size: 1.5rem;
    }

    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.show {
        display: block;
    }
}

/* Code Block Styles */
.code-block-wrapper {
    position: relative;
    margin-bottom: var(--space-md);
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
    backdrop-filter: blur(4px);
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.copy-btn:active {
    transform: translateY(0);
}

.copy-btn.copied {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

/* ========================================
   TOAST NOTIFICATIONS
   ======================================== */

#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: white;
    color: var(--gray-800);
    padding: 12px 20px;
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 450px;
    border-left: 4px solid var(--gray-300);
    pointer-events: auto;
    animation: toast-slide-in 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    transition: all 0.2s ease;
}

.toast.removing {
    transform: translateX(120%);
    opacity: 0;
}

.toast-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.toast-content {
    flex-grow: 1;
}

.toast-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.toast-message {
    font-size: 0.85rem;
    color: var(--gray-500);
}

.toast.success {
    border-left-color: #22c55e;
}

.toast.error {
    border-left-color: #ef4444;
}

.toast.info {
    border-left-color: #3b82f6;
}

.toast.warning {
    border-left-color: #f59e0b;
}

@keyframes toast-slide-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@media (max-width: 768px) {
    #toast-container {
        top: auto;
        bottom: 20px;
        right: 20px;
        left: 20px;
    }

    .toast {
        min-width: 0;
        width: 100%;
    }
}