
:root {
    --primary:        #4f46e5;
    --primary-light:  #ede9fe;
    --primary-hover:  #4338ca;

    --success:        #10b981;
    --success-light:  #d1fae5;
    --warning:        #f59e0b;
    --warning-light:  #fef3c7;
    --danger:         #ef4444;
    --danger-light:   #fee2e2;
    --info:           #3b82f6;
    --info-light:     #dbeafe;
    --purple:         #8b5cf6;
    --purple-light:   #ede9fe;

    --sidebar-width:  260px;
    --topbar-height:  64px;

    --bg-body:        #f1f5f9;
    --bg-card:        #ffffff;
    --border:         #e2e8f0;
    --shadow-sm:      0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:      0 4px 12px rgba(0,0,0,.08);

    --text-primary:   #1e293b;
    --text-secondary: #64748b;
    --text-muted:     #94a3b8;

    --radius-sm:      6px;
    --radius-md:      10px;
    --radius-lg:      14px;

    --transition:     0.18s ease;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-body);
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }


.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0; left: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
}

.sidebar-brand {
    height: var(--topbar-height);
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-logo {
    width: 36px; height: 36px;
    background: var(--primary);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-brand-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--text-primary);
    line-height: 1.2;
}

.sidebar-brand-sub {
    font-size: 11px;
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px 8px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 8px 12px 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    cursor: pointer;
}

.nav-link i { font-size: 16px; width: 18px; text-align: center; flex-shrink: 0; }

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

.nav-link.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.nav-link-logout { color: var(--text-secondary); }
.nav-link-logout:hover { background: var(--danger-light); color: var(--danger); }

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px;
}

.sidebar-user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role { font-size: 11px; color: var(--text-muted); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.35);
    z-index: 199;
    backdrop-filter: blur(1px);
}
.sidebar-overlay.show { display: block; }

.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-body);
}


.topbar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-left { display: flex; align-items: center; gap: 14px; }

.topbar-toggle {
    width: 36px; height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: all var(--transition);
}
.topbar-toggle:hover { background: var(--bg-body); color: var(--text-primary); }

.topbar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.topbar-right { display: flex; align-items: center; gap: 12px; }

.topbar-user {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}

.topbar-user-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}

.topbar-user-name { font-size: 13px; font-weight: 500; color: var(--text-primary); }


.page-content { flex: 1; padding: 24px; }

.app-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}
.footer-divider { color: var(--border); }


.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: transparent;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.card-body { padding: 20px; }


.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition), transform var(--transition);
    height: 100%;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.stat-icon {
    width: 52px; height: 52px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.bg-primary-soft { background: var(--primary-light); }
.bg-success-soft  { background: var(--success-light); }
.bg-warning-soft  { background: var(--warning-light); }
.bg-danger-soft   { background: var(--danger-light); }
.bg-info-soft     { background: var(--info-light); }
.bg-purple-soft   { background: var(--purple-light); }

.text-primary { color: var(--primary) !important; }
.text-success  { color: var(--success) !important; }
.text-warning  { color: var(--warning) !important; }
.text-danger   { color: var(--danger) !important; }
.text-info     { color: var(--info) !important; }
.text-purple   { color: var(--purple) !important; }

.stat-value { font-size: 26px; font-weight: 700; color: var(--text-primary); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 5px; }


.table { margin: 0; font-size: 13px; }
.table th {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    border-top: none;
    padding: 10px 16px;
    background: #f8fafc;
}
.table td { padding: 12px 16px; vertical-align: middle; border-color: var(--border); }
.table-hover tbody tr:hover td { background: #fafbff; }


.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.status-pending   { background: var(--warning-light); color: #92400e; }
.status-running   { background: var(--info-light);    color: #1e40af; }
.status-completed { background: var(--success-light); color: #065f46; }
.status-failed    { background: var(--danger-light);  color: #991b1b; }

.status-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 1.4s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .4; }
}


.empty-state {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-muted);
}
.empty-state i { font-size: 40px; display: block; margin-bottom: 12px; opacity: .4; }
.empty-state p { margin-bottom: 16px; font-size: 14px; }


.btn {
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    padding: 7px 16px;
    transition: all var(--transition);
}

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

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


.form-control, .form-select {
    border-color: var(--border);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    padding: 8px 12px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}
.form-label { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 5px; }
.input-group-text { background: #f8fafc; border-color: var(--border); color: var(--text-muted); font-size: 14px; }

.btn-password-toggle {
    cursor: pointer;
    border-left: 0 !important;
    background: #f8fafc !important;
    border-color: var(--border) !important;
    color: var(--text-muted) !important;
}
.btn-password-toggle:hover { color: var(--text-primary) !important; }

.login-body {
    background: linear-gradient(135deg, #f0f4ff 0%, #f8fafc 60%, #f0fdf4 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 24px;
}

.login-wrapper {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.login-card {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px 32px;
    box-shadow: var(--shadow-md);
}

.login-header { text-align: center; margin-bottom: 28px; }

.login-logo {
    width: 56px; height: 56px;
    background: var(--primary);
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 26px;
    margin: 0 auto 16px;
}

.login-title { font-size: 20px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.login-subtitle { font-size: 13px; color: var(--text-secondary); margin: 0; }

.btn-login { padding: 10px; font-size: 14px; font-weight: 600; }

.profile-avatar {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 28px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}

.badge-admin {
    background: var(--primary-light);
    color: var(--primary);
    font-size: 11px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 20px;
    display: inline-block;
}

.badge-user {
    background: var(--success-light);
    color: var(--success);
    font-size: 11px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 20px;
    display: inline-block;
}

.login-footer {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}


#global-loader {
    position: fixed;
    inset: 0;
    background: rgba(248,250,252,.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
    pointer-events: none;
}

#global-loader.active {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

.loader-ring {
    width: 44px; height: 44px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }


#toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 320px;
}

.gms-toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    animation: toastIn .25s ease forwards;
}

.gms-toast.hiding {
    animation: toastOut .2s ease forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(20px); }
}

.gms-toast-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.gms-toast-body { flex: 1; min-width: 0; }
.gms-toast-title { font-weight: 600; font-size: 13px; margin-bottom: 2px; color: var(--text-primary); }
.gms-toast-message { font-size: 12.5px; color: var(--text-secondary); }

.gms-toast-close {
    background: none; border: none;
    color: var(--text-muted); cursor: pointer;
    padding: 0; font-size: 14px; line-height: 1;
    flex-shrink: 0; margin-top: 1px;
    transition: color var(--transition);
}
.gms-toast-close:hover { color: var(--text-primary); }

.gms-toast.toast-success { border-left: 3px solid var(--success); }
.gms-toast.toast-danger  { border-left: 3px solid var(--danger); }
.gms-toast.toast-warning { border-left: 3px solid var(--warning); }
.gms-toast.toast-info    { border-left: 3px solid var(--info); }

.gms-toast.toast-success .gms-toast-icon { color: var(--success); }
.gms-toast.toast-danger  .gms-toast-icon { color: var(--danger); }
.gms-toast.toast-warning .gms-toast-icon { color: var(--warning); }
.gms-toast.toast-info    .gms-toast-icon { color: var(--info); }


.wa-status-icon {
    width: 72px; height: 72px;
    border-radius: 50%;
    font-size: 32px;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition);
}

.wa-connected    { background: var(--success-light); color: var(--success); }
.wa-disconnected { background: #f1f5f9; color: var(--text-muted); }

.qr-wrapper {
    width: 220px; height: 220px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    background: #fff;
}

.qr-wrapper img { width: 100%; height: 100%; object-fit: contain; }

.wa-session-info {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 0;
}

.wa-session-avatar {
    width: 52px; height: 52px;
    border-radius: 50%;
    background: var(--success-light);
    color: var(--success);
    font-size: 24px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.wa-session-name     { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.wa-session-phone    { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.wa-session-platform { font-size: 11px; color: var(--text-muted); margin-top: 2px; text-transform: capitalize; }


.table-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 11px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}


.rating-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 12px;
    font-weight: 600;
    color: #92400e;
    background: var(--warning-light);
    padding: 2px 8px;
    border-radius: 20px;
}
.rating-badge i { font-size: 10px; color: var(--warning); }

.btn-icon {
    width: 30px; height: 30px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-muted);
}

.btn-edit:hover  { background: var(--info-light);   color: var(--info); }
.btn-delete:hover{ background: var(--danger-light);  color: var(--danger); }

.role-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.role-admin { background: var(--primary-light); color: var(--primary); }
.role-user  { background: var(--success-light); color: var(--success); }


.delete-icon-wrap {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--danger-light);
    color: var(--danger);
    font-size: 24px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto;
}


.modal-content {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.modal-header {
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
}

.modal-title { font-size: 15px; font-weight: 600; }

.modal-footer {
    border-top: 1px solid var(--border);
    padding: 12px 20px;
}

.btn-light {
    background: var(--bg-body);
    border-color: var(--border);
    color: var(--text-secondary);
}

.btn-light:hover {
    background: var(--border);
    border-color: var(--border);
    color: var(--text-primary);
}


@media (max-width: 767.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
    .main-wrapper { margin-left: 0; }
    .topbar-toggle { display: flex; }
    .page-content { padding: 16px; }
    .login-card { padding: 28px 20px; }
    #toast-container { top: 12px; right: 12px; left: 12px; width: auto; }
}
