:root {
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.6);
    --border-glass: rgba(255, 255, 255, 0.08);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --success: #22c55e;
    --sidebar-w: 260px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    background-image:
        radial-gradient(at 0% 0%, hsla(253, 16%, 7%, 1) 0, transparent 50%),
        radial-gradient(at 100% 100%, hsla(225, 39%, 20%, 1) 0, transparent 50%);
    color: var(--text-main);
    min-height: 100vh;
}

/* Utilities */
.hidden {
    display: none !important;
}

.glass-panel {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
}

.full-width {
    width: 100%;
}

.text-center {
    text-align: center;
}

.text-sm {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.flex-grow {
    flex: 1;
}

/* Login Screen */
.full-screen-flex {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    text-align: center;
}

.login-header {
    margin-bottom: 30px;
}

.login-icon {
    font-size: 48px;
    color: var(--primary);
    margin-bottom: 10px;
}

.input-wrapper {
    position: relative;
    margin-bottom: 20px;
}

.input-wrapper i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.input-wrapper input {
    width: 100%;
    padding: 12px 12px 12px 45px;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--border-glass);
    border-radius: 10px;
    color: white;
    font-family: inherit;
    transition: 0.3s;
}

.input-wrapper input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Dashboard Layout */
.dashboard-grid {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    margin: 20px;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 40px;
    padding-left: 10px;
    color: white;
}

.brand-icon {
    font-size: 24px;
    color: var(--primary);
}

.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: 0.2s;
    text-align: left;
}

.nav-item i {
    font-size: 20px;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.nav-item.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}

.sidebar-footer {
    padding-top: 20px;
    border-top: 1px solid var(--border-glass);
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.3);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 12px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
}

.status-badge.connected .dot {
    background: #22c55e;
    box-shadow: 0 0 8px #22c55e;
}

.status-badge.connected {
    border: 1px solid rgba(34, 197, 94, 0.2);
}

#logout-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: transparent;
    border: 1px solid var(--border-glass);
    color: var(--text-muted);
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.2s;
}

#logout-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 20px 20px 20px 0;
    overflow-y: auto;
}

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.view-header h2 {
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 5px;
}

.subtitle {
    color: var(--text-muted);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
}

.icon-box {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.green {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
}

.blue {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.purple {
    background: rgba(168, 85, 247, 0.1);
    color: #a855f7;
}

.stat-info h3 {
    font-size: 1.5rem;
    margin-top: 5px;
}

.stat-info .label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Dashboard Tables & Widgets */
.dashboard-row {
    display: flex;
    gap: 20px;
}

.card-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-glass);
}

.sidebar-widget {
    min-width: 300px;
}

.modern-table {
    width: 100%;
    border-collapse: collapse;
}

.modern-table th {
    text-align: left;
    padding: 16px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modern-table td {
    padding: 16px;
    border-top: 1px solid var(--border-glass);
    vertical-align: middle;
}

.action-btn {
    margin-right: 10px;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: 0.2s;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: 0.2s;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border-glass);
    background: var(--bg-card);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: 0.2s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

textarea,
input {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--border-glass);
    color: white;
    border-radius: 8px;
    padding: 10px;
    width: 100%;
    font-family: inherit;
}

.alert-box.info {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: #93c5fd;
    padding: 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999;
}

.modal-card {
    width: 90%;
    max-width: 500px;
    padding: 30px;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.close-modal {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
}

/* QR */
.qr-wrapper {
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.qr-box {
    width: 200px;
    height: 200px;
    background: white;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-box img {
    max-width: 100%;
}

.placeholder-icon {
    font-size: 64px;
    color: #cbd5e1;
}

/* Tabs */
.tabs-header {
    display: flex;
    border-bottom: 1px solid var(--border-glass);
}

.tab-btn {
    padding: 15px 24px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: 0.2s;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    padding: 30px;
}

/* Flow Editor */
/* Flow Editor Enhanced */
.flow-controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.flow-card {
    margin-bottom: 12px;
    padding: 0;
    border-left: 4px solid var(--primary);
    transition: all 0.2s ease;
    overflow: hidden;
}

.flow-card.type-menu {
    border-left-color: #a855f7;
}

.flow-card.type-system {
    border-left-color: #f59e0b;
}

.flow-card.type-message {
    border-left-color: #3b82f6;
}

.flow-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
}

.flow-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.flow-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.flow-id-badge {
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-family: monospace;
    color: var(--text-muted);
    border: 1px solid var(--border-glass);
}

.flow-summary {
    color: var(--text-muted);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

.flow-targets {
    display: flex;
    gap: 5px;
}

.target-pill {
    font-size: 0.7rem;
    background: rgba(168, 85, 247, 0.2);
    color: #d8b4fe;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(168, 85, 247, 0.3);
}

.flow-body {
    padding: 20px;
    border-top: 1px solid var(--border-glass);
    display: block;
    animation: slideDown 0.2s ease-out;
}

.flow-card.collapsed .flow-body {
    display: none;
}

.step-type-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.type-menu .step-type-icon {
    color: #a855f7;
    background: rgba(168, 85, 247, 0.1);
}

.type-system .step-type-icon {
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.1);
}

.type-message .step-type-icon {
    color: #3b82f6;
    background: rgba(59, 130, 246, 0.1);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.add-slot {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 8px;
    margin: 4px 0 12px 0;
    border: 1px dashed var(--border-glass);
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
    opacity: 0.6;
}

.add-slot:hover {
    opacity: 1;
    border-color: var(--primary);
    color: var(--primary);
}

/* TOAST NOTIFICATION */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    min-width: 250px;
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.show {
    transform: translateX(0);
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid #ef4444;
}

.toast i {
    font-size: 1.2rem;
}

.toast.success i {
    color: var(--success);
}

.toast.error i {
    color: #ef4444;
}

/* Session Cards (Compact) */
.session-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 20px 10px;
    position: relative;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    text-align: center;
    height: 100%;
}

.session-card:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.session-avatar {
    position: relative;
    margin-bottom: 5px;
}

.session-avatar img {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--border-glass);
    padding: 3px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.session-status-dot {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: 16px;
    height: 16px;
    background: #22c55e;
    border: 3px solid #1a1b26;
    border-radius: 50%;
}

.session-info {
    width: 100%;
    overflow: hidden;
}

.session-phone {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.session-step {
    display: inline-block;
    font-size: 0.7rem;
    background: rgba(168, 85, 247, 0.15);
    color: #d8b4fe;
    padding: 2px 8px;
    border-radius: 12px;
    border: 1px solid rgba(168, 85, 247, 0.2);
    margin-bottom: 5px;
}

.session-data-preview {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    opacity: 0.7;
}

.session-actions {
    position: absolute;
    top: 10px;
    right: 10px;
}

.btn-kill-session {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    cursor: pointer;
    transition: 0.2s;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-kill-session:hover {
    background: #ef4444;
    color: white;
    transform: scale(1.1);
}

/* Added Buttons */
.btn-dashed {
    background: transparent;
    border: 1px dashed var(--border-glass);
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    font-weight: 500;
}

.btn-dashed:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(255, 255, 255, 0.05);
}

.btn-delete:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444 !important;
}

.btn-edit:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.btn-license:hover {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
}

/* Fix misalignment in sidebar footer */
#connection-status-badge {
    margin-bottom: 0 !important;
}

/* Specific license status colors */
.status-badge.green {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.2)
}

.status-badge.red {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2)
}

/* --- MOBILE RESPONSIVE --- */

/* Base Styles for Mobile Elements */
.mobile-header {
    display: none;
    align-items: center;
    padding: 0 0 15px 0;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-glass);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.sidebar-overlay.show {
    opacity: 1;
    pointer-events: all;
}

@media (max-width: 768px) {

    /* Show Header */
    .mobile-header {
        display: flex;
    }

    /* Layout Stack */
    .dashboard-grid {
        display: block;
        /* Break flex row */
    }

    /* Sidebar Drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 85%;
        max-width: 300px;
        height: 100vh;
        margin: 0;
        z-index: 1000;
        background: #0f172a;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
        padding-top: 20px;
    }

    .sidebar.open {
        left: 0;
    }

    /* Main Content */
    .main-content {
        padding: 15px;
        width: 100%;
        margin-left: 0;
    }

    /* Grids */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .dashboard-row {
        flex-direction: column;
    }

    /* Tables */
    .sidebar-widget {
        width: 100%;
        overflow-x: auto;
    }

    body {
        overflow-x: hidden;
    }

    /* Modal */
    .modal-card {
        width: 95%;
        padding: 20px;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* View Header */
    .view-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    /* FIXES */
    .mobile-only {
        display: block !important;
    }

    .modern-table {
        table-layout: fixed;
        width: 100%;
    }

    .modern-table td,
    .modern-table th {
        /* Allow wrap */
        white-space: normal;
        word-wrap: break-word;
        padding: 8px 2px;
        font-size: 0.75rem;
        text-align: center;
    }

    /* Wrapper behaves normally */
    .sidebar-widget,
    .tab-content {
        display: block;
        width: 100%;
        overflow-x: hidden;
    }

    /* HIDE ID COLUMN on Mobile to save space */
    .modern-table th:nth-child(1),
    .modern-table td:nth-child(1) {
        display: none;
    }

    /* Product Name: Align Left */
    .modern-table td:nth-child(2) {
        text-align: left;
        width: 40%;
    }

    /* Phone: Break all to prevent overflow */
    .modern-table td:nth-child(3) {
        width: 35%;
        word-break: break-all;
    }

    /* Date: Smallest */
    .modern-table td:nth-child(4) {
        width: 25%;
        font-size: 0.7rem;
    }

    /* Settings Tabs Fix */
    .tabs-header {
        overflow-x: auto;
        white-space: nowrap;
        width: 100%;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 5px;
    }

    .tab-btn {
        flex: 0 0 auto;
    }
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Chat Specifics */
.chat-contact-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.chat-container ::-webkit-scrollbar-track {
    background: transparent;
}

/* --- CHAT STYLES --- */
.msg-row {
    display: flex;
    margin-bottom: 12px;
    width: 100%;
}

.msg-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 12px;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.msg-me {
    justify-content: flex-end;
}

.msg-me .msg-bubble {
    background: #0ea5e9;
    color: white;
    border-top-right-radius: 0;
    text-align: left;
    /* Garante que texto multiline alinhe a esquerda */
}

.msg-them {
    justify-content: flex-start;
}

.msg-them .msg-bubble {
    background: #334155;
    color: #e2e8f0;
    border-top-left-radius: 0;
}

.msg-meta {
    font-size: 0.70rem;
    margin-top: 4px;
    opacity: 0.7;
    text-align: right;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

.msg-type-badge {
    font-size: 0.65rem;
    padding: 2px 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    margin-right: 4px;
}

.emoji-picker {
    position: absolute;
    bottom: 50px;
    left: 0;
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    width: 320px;
    height: 250px;
    display: none;
    flex-direction: column;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 9999;
}

.emoji-picker.open {
    display: flex;
}

.emoji-grid {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
}

.emoji-btn {
    cursor: pointer;
    font-size: 1.25rem;
    text-align: center;
    transition: transform 0.1s;
}

.emoji-btn:hover {
    transform: scale(1.2);
}