/* Estilos globales para la interfaz de Nexus */
:root {
    --sidebar-bg: #ffffff;
    --sidebar-link-color: #4b5563;
    --sidebar-link-hover-bg: #f3f4f6;
    --sidebar-link-active-color: #111827;
    --accent-color: #2563eb;
    --accent-2: #0ea5e9;
    --accent-3: #10b981;
    --topbar-bg: #ffffff;
    --content-bg: #f5f7fb;
    --text-color: #111827;
    --muted-color: #6b7280;
    --border-color: #e5e7eb;
    --card-bg: #ffffff;
    --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
    --radius: 14px;
    --transition: all 0.18s ease;
}

body {
    font-family: 'Montserrat', 'Poppins', sans-serif;
    background:
        radial-gradient(circle at 25% 20%, rgba(37, 99, 235, 0.06), transparent 30%),
        radial-gradient(circle at 75% 0%, rgba(14, 165, 233, 0.05), transparent 32%),
        linear-gradient(180deg, #f8fafc 0%, #f1f5f9 60%, #eef2f7 100%);
    color: var(--text-color);
    min-height: 100vh;
}

body::before {
    content: none;
}

/* Botón flotante y panel rápido de chat */
.chat-fab {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1100;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--accent-color), var(--accent-2));
    color: #fff !important;
    border-radius: 999px;
    box-shadow: 0 10px 25px rgba(37, 99, 235, 0.28);
    text-decoration: none;
    font-weight: 600;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.chat-fab.has-unread {
    background: #dc2626;
    box-shadow: 0 10px 25px rgba(220, 38, 38, 0.35);
}

.chat-fab:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 28px rgba(37, 99, 235, 0.4);
}

.chat-fab i {
    font-size: 1.05rem;
}

.chat-fab .chat-unread-badge {
    display: none;
    min-width: 22px;
    padding: 2px 6px;
    border-radius: 999px;
    background: #fff;
    color: #dc2626;
    font-weight: 700;
    font-size: 0.8rem;
    line-height: 1;
}

.chat-fab.has-unread .chat-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.chat-panel {
    position: fixed;
    right: 22px;
    bottom: 80px;
    width: 420px;
    max-width: calc(100vw - 40px);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.18);
    z-index: 1101;
    display: none;
    overflow: hidden;
}

.chat-panel-header {
    padding: 10px 12px;
    background: linear-gradient(135deg, var(--accent-color), var(--accent-2));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-panel-body {
    padding: 12px;
}

.chat-list {
    max-height: 170px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.chat-messages {
    max-height: 240px;
    overflow-y: auto;
    background: #f8fafc;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.chat-tabs {
    overflow-x: auto;
    white-space: nowrap;
}

.chat-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-right: 6px;
    background: #eef2ff;
    font-size: 0.85rem;
    cursor: pointer;
}

.chat-tab.active {
    background: #c7d2fe;
    border-color: #a5b4fc;
}

.chat-tab .close {
    font-size: 0.9rem;
    color: #555;
}

.chat-tab .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #e11d48;
    display: inline-block;
}

.wrapper {
    display: flex;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    transition: width 0.2s ease-out, background-color 0.2s;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    border-right: 1px solid var(--border-color);
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.06);
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.18), rgba(59, 130, 246, 0.12));
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.sidebar-header a {
    color: var(--text-color) !important;
}

.sidebar-logo {
    height: 75px;
    width: auto;
    transition: opacity 0.2s ease-out;
}

.sidebar-brand-name {
    font-size: 1.25rem;
    font-weight: 600;
    margin-left: 0.75rem;
    opacity: 1;
    transition: opacity 0.2s ease-out;
    white-space: nowrap;
}

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

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: var(--sidebar-link-color);
    text-decoration: none;
    transition: var(--transition);
    font-weight: 500;
    white-space: nowrap;
}

.sidebar-link i {
    width: 20px;
    text-align: center;
    margin-right: 0.75rem;
    font-size: 1rem;
}

.sidebar-link:hover {
    background-color: var(--sidebar-link-hover-bg);
    color: var(--sidebar-link-active-color);
    transform: translateX(2px);
}

.sidebar-link.active {
    color: var(--sidebar-link-active-color);
    background: linear-gradient(90deg, var(--accent-color) 4px, rgba(249, 115, 22, 0.08) 4px);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

/* Sidebar colapsada */
body.sidebar-collapsed .sidebar {
    width: 80px;
}

body.sidebar-collapsed .sidebar-header {
    padding: 1.25rem;
    justify-content: center;
}

body.sidebar-collapsed .sidebar-brand-name {
    display: none;
}

body.sidebar-collapsed .sidebar-link span {
    display: none;
}

body.sidebar-collapsed .sidebar-link i {
    margin-right: 0;
}

/* Contenido principal */
.main-content {
    margin-left: 260px;
    width: calc(100% - 260px);
    transition: margin-left 0.2s ease-out, width 0.2s ease-out;
    padding: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), transparent 55%);
    min-height: 100vh;
}

body.sidebar-collapsed .main-content {
    margin-left: 80px;
    width: calc(100% - 80px);
}

/* Topbar */
.topbar {
    backdrop-filter: blur(10px);
    background-color: var(--topbar-bg);
    border-bottom: 1px solid var(--border-color);
    height: 72px;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 999;
    color: var(--text-color);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

#sidebar-toggle {
    font-size: 1.15rem;
    cursor: pointer;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.7);
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
}

#sidebar-toggle:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.12);
}

.page-title {
    font-family: 'Montserrat', 'Poppins', sans-serif;
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 1.5rem;
}

.card {
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    background: var(--card-bg);
    backdrop-filter: blur(4px);
    border-radius: var(--radius);
    transition: var(--transition);
    animation: floatIn 0.35s ease;
}

.card:hover {
    transform: translateY(-3px);
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
}

.card,
.card .card-title,
.card .card-header,
.card .card-body {
    color: var(--text-color);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-color), var(--accent-2));
    border: none;
    padding: 0.75rem 1.2rem;
    font-weight: 600;
    font-size: 1.02rem;
    transition: var(--transition);
    box-shadow: 0 12px 30px rgba(37, 99, 235, 0.22);
    color: #fff;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 36px rgba(37, 99, 235, 0.32);
}

.btn-outline-secondary,
.btn-secondary {
    border-color: rgba(255, 255, 255, 0.22);
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.04);
    transition: var(--transition);
}

.btn-outline-secondary:hover,
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-color);
    transform: translateY(-1px);
}

.card-header {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(14, 165, 233, 0.06));
    border-bottom: 1px solid var(--border-color);
    color: var(--text-color);
}

.card,
.card .card-title,
.card .card-header,
.card .card-body {
    color: var(--text-color);
}

.text-muted {
    color: var(--muted-color) !important;
}

.table {
    color: var(--text-color);
}

.table thead th {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(14, 165, 233, 0.05));
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1;
}

.table-striped > tbody > tr:nth-of-type(odd) {
    --bs-table-accent-bg: rgba(255, 255, 255, 0.03);
    color: var(--text-color);
}

.table-hover tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.06);
}

.form-control,
.form-select {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    color: var(--text-color);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--accent-3);
    box-shadow: 0 0 0 0.2rem rgba(14, 165, 233, 0.2);
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-color);
}

a {
    color: var(--accent-3);
}

a:hover {
    color: var(--accent-color);
}

/* Utilidades logísticas */
.sortable-list {
    min-height: 150px;
    background-color: #f8f9fa;
    border-radius: 0.5rem;
}

.sortable-ghost {
    opacity: 0.4;
    background-color: #d1e7fd;
}

.pedido-card {
    cursor: grab;
    transition: background-color 0.2s;
}

.pedido-card:hover {
    background-color: #e9ecef;
}

.badge-pill {
    border-radius: 999px;
}

.card-metric {
    border-left: 4px solid var(--accent-color);
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.06), rgba(59, 130, 246, 0.05));
}

.chart-wrap {
    min-height: 280px;
}

.map-box {
    height: 400px;
}

.clickable-row {
    cursor: pointer;
}

.clickable-row:hover {
    background-color: #f1f1f1;
}

.items-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.item-pill {
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.item-pill.ok {
    background-color: #e8f6ed;
    color: #1f7a3d;
}

.item-pill.bad {
    background-color: #fde8e8;
    color: #b10f0f;
}

.table.no-hover-transform.table-hover tbody tr:hover {
    transform: none !important;
    transition: none !important;
}

.accent-title {
    border-left: 4px solid var(--accent-color);
    padding-left: 10px;
}

.observaciones-field {
    height: 100px;
    resize: vertical;
}

.logistica-map {
    height: 800px;
    width: 100%;
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
}

/* Página full de mapa (fuera del layout principal) */
body.mapa-full-page {
    margin: 0;
    padding: 0;
    height: 100%;
    background: linear-gradient(180deg, #f7f9fc, #eef2f7);
    color: var(--text-color);
    font-family: 'Montserrat', 'Poppins', sans-serif;
}

body.mapa-full-page #map {
    height: 65vh;
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

body.mapa-full-page .mapa-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: #ffffff;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid var(--border-color);
}

body.mapa-full-page .mapa-header h1 {
    margin: 0;
    font-size: 20px;
    letter-spacing: 0.5px;
}

body.mapa-full-page .mapa-panel {
    padding: 16px 20px;
}

body.mapa-full-page .mapa-btn {
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    background: #ffffff;
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.15s ease;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
}

body.mapa-full-page .mapa-btn:hover {
    background: var(--accent-color);
    color: #fff;
}

body.mapa-full-page .mapa-btn.secondary {
    border-color: var(--border-color);
    color: var(--text-color);
    background: #f8fafc;
}

body.mapa-full-page .mapa-btn.secondary:hover {
    background: #e2e8f0;
}

body.mapa-full-page .mapa-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    margin: 10px 0 6px;
}

body.mapa-full-page .mapa-toolbar .left,
body.mapa-full-page .mapa-toolbar .right {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

body.mapa-full-page .mapa-input {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: #ffffff;
    color: var(--text-color);
    min-width: 220px;
}

body.mapa-full-page .mapa-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--muted-color);
    font-size: 13px;
}

body.mapa-full-page .mapa-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

body.mapa-full-page .mapa-stat-card {
    background: #ffffff;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

body.mapa-full-page .mapa-stat-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
    color: var(--muted-color);
}

body.mapa-full-page .mapa-stat-value {
    font-size: 20px;
    font-weight: 700;
}

body.mapa-full-page .mapa-list {
    margin-top: 14px;
    max-height: 28vh;
    overflow-y: auto;
    padding-right: 6px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 8px;
}

body.mapa-full-page .mapa-card {
    background: #ffffff;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

body.mapa-full-page .mapa-card h3 {
    margin: 0 0 4px 0;
    font-size: 15px;
}

body.mapa-full-page .mapa-muted {
    color: var(--muted-color);
    font-size: 12px;
    margin: 0;
}

body.mapa-full-page .mapa-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

body.mapa-full-page .mapa-badge.green { background: #ecfdf3; color: #0f5132; }
body.mapa-full-page .mapa-badge.gray { background: #f1f5f9; color: #1f2937; }
body.mapa-full-page .mapa-badge.orange { background: #fff7ed; color: #9a3412; }
body.mapa-full-page .mapa-badge.red { background: #fef2f2; color: #7f1d1d; }

body.mapa-full-page .dom-marker { display: flex; align-items: center; justify-content: center; }
body.mapa-full-page .dom-dot {
    width: 18px;
    height: 18px;
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.15);
}

body.mapa-full-page .mapa-small { font-size: 12px; color: var(--muted-color); }
body.mapa-full-page .avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border-color); background: #f8fafc; }
body.mapa-full-page .popup-avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border-color); display: block; margin-bottom: 6px; }

/* Página standalone de mapa con sidebar */
body.mapa-standalone-page {
    font-family: 'Montserrat', 'Poppins', sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

body.mapa-standalone-page .header-bar {
    background-color: #f8f9fa;
    padding: 10px 20px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

body.mapa-standalone-page .header-bar img {
    height: 40px;
    margin-right: 15px;
}

body.mapa-standalone-page .header-bar h1 {
    margin: 0;
    font-size: 1.5rem;
    color: #333;
}

body.mapa-standalone-page .map-content {
    display: flex;
    flex-grow: 1;
    background: radial-gradient(circle at 20% 20%, rgba(37, 99, 235, 0.05), transparent 25%), #f5f7fb;
}

body.mapa-standalone-page #sidebar {
    width: 300px;
    background-color: #f8f9fa;
    border-right: 1px solid #e9ecef;
    overflow-y: auto;
    padding: 10px;
    flex-shrink: 0;
}

body.mapa-standalone-page #map {
    flex-grow: 1;
}

body.mapa-standalone-page .domiciliario-item {
    padding: 10px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: var(--transition);
}

body.mapa-standalone-page .domiciliario-item:hover {
    background-color: #e9ecef;
    transform: translateX(2px);
}

body.mapa-standalone-page .domiciliario-item.online {
    border-left: 5px solid green;
}

body.mapa-standalone-page .domiciliario-item.offline {
    border-left: 5px solid red;
}

body.mapa-standalone-page .domiciliario-name {
    font-weight: bold;
}

body.mapa-standalone-page .domiciliario-status {
    font-size: 0.8em;
    color: #666;
}

/* Página de login */
.login-page {
    margin: 0;
    padding: 0;
    background:
        radial-gradient(circle at 20% 20%, rgba(37, 99, 235, 0.08), transparent 26%),
        radial-gradient(circle at 80% 0%, rgba(14, 165, 233, 0.08), transparent 28%),
        linear-gradient(135deg, #f5f7fb, #eef2f7);
    font-family: 'Montserrat', 'Poppins', sans-serif;
}

.login-page .login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    backdrop-filter: blur(4px);
    background-color: rgba(255, 255, 255, 0.35);
}

.login-page .login-card {
    width: 100%;
    max-width: 900px;
    display: flex;
    flex-direction: row;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.04);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 24px 50px rgba(15, 23, 42, 0.12);
    backdrop-filter: blur(12px);
}

.login-page .logo-side {
    flex: 1;
    background: linear-gradient(180deg, rgba(37, 99, 235, 0.14), rgba(14, 165, 233, 0.16));
    padding: 40px 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.login-page .logo-side img {
    max-width: 160px;
    margin-bottom: 20px;
}

.login-page .system-title {
    font-size: 1.3rem;
    color: #555;
    font-weight: 500;
}

.login-page .form-side {
    flex: 1;
    background-color: #f8f9fa;
    padding: 40px 30px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.login-page .form-section {
    flex: 1;
}

.login-page .form-label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.login-page .form-control {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #f8fafc;
}

.login-page .input-group-text {
    background-color: rgba(255, 255, 255, 0.08);
    font-size: 1.1rem;
    color: #f8fafc;
}

.login-page .eye-toggle {
    cursor: pointer;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    padding: 0 12px;
    color: #e5e7eb;
    border-radius: 0 8px 8px 0;
}

.login-page .btn-primary {
    background: linear-gradient(135deg, #f97316, #fb923c);
    border: none;
    padding: 0.75rem 1.2rem;
    font-weight: 600;
    font-size: 1.05rem;
    transition: var(--transition);
    box-shadow: 0 8px 18px rgba(249, 115, 22, 0.28);
}

.login-page .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 26px rgba(249, 115, 22, 0.35);
}

.login-page .logo-bottom {
    text-align: center;
    margin-top: 30px;
}

.login-page .logo-bottom img {
    max-width: 220px;
    border-radius: 0;
    padding: 0;
    background-color: transparent;
    box-shadow: none;
}

.login-page .footer-text {
    font-size: 0.85rem;
    color: var(--muted-color);
    margin-top: 10px;
}

.login-page .alert-error {
    background-color: rgba(220, 53, 69, 0.9);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 15px;
    margin-bottom: 20px;
    font-weight: 500;
}

@media (max-width: 768px) {
    .login-page .login-card {
        flex-direction: column;
    }

    .login-page .logo-side,
    .login-page .form-side {
        padding: 30px 20px;
    }

    .login-page .logo-bottom img {
        max-width: 180px;
    }
}
