:root {
    --bg-light: #f8fafc;
    --bg-white: #ffffff;
    --text-main: #334155;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --sidebar-bg: #1e293b;
    --sidebar-text: #f1f5f9;
    --sidebar-hover: #334155;
    --font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-light);
    color: var(--text-main);
    line-height: 1.5;
}

.layout {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 250px;
    min-width: 250px;
    height: 100vh;
    position: sticky;
    top: 0;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 10;
}

.brand {
    padding: 20px;
    font-size: 1.5rem;
    font-weight: bold;
    border-bottom: 1px solid var(--sidebar-hover);
    text-align: center;
}

.menu {
    flex: 1;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.menu-group {
    display: flex;
    flex-direction: column;
}

.menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background 0.2s, padding-left 0.2s;
    border-left: 4px solid transparent;
}

.menu-item-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-item svg {
    width: 20px;
    height: 20px;
}

.chevron {
    transition: transform 0.3s ease;
    width: 16px !important;
    height: 16px !important;
}

.menu-group.open .chevron {
    transform: rotate(180deg);
}

.menu-item:hover {
    background-color: var(--sidebar-hover);
}

.submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background-color: #0f172a;
}

.submenu-item {
    display: block;
    padding: 10px 20px 10px 52px;
    color: #cbd5e1;
    text-decoration: none;
    transition: all 0.2s;
    border-left: 4px solid transparent;
    font-size: 0.9rem;
}

.submenu-item:hover, .submenu-item.active {
    background-color: var(--sidebar-hover);
    color: var(--bg-white);
    border-left-color: var(--primary);
    padding-left: 48px;
}

/* Main Content */
.content {
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-width: 0;
}

.page {
    display: none;
    animation: fadeIn 0.3s ease;
    width: 95%;
    max-width: 1400px;
    margin: 20px auto;
    padding-bottom: 40px;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.page-header h1 {
    font-size: 1.8rem;
    font-weight: 600;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

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

.btn-success { background-color: var(--success); color: white; }
.btn-success:hover { background-color: var(--success-hover); }

.btn-secondary { background-color: #cbd5e1; color: var(--text-main); }
.btn-secondary:hover { background-color: #94a3b8; }

.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

/* Tables */
.table-container {
    background: var(--bg-white);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}

.table {
    width: 100% !important;
    border-collapse: collapse;
}

.table th, .table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background-color: #f1f5f9;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.8rem;
}

.table tbody tr:hover {
    background-color: #f8fafc;
}

/* Table Row Colors */
.row-danger {
    background-color: #fee2e2 !important;
}
.row-danger:hover {
    background-color: #fecaca !important;
}
.row-warning {
    background-color: #ffedd5 !important;
}
.row-warning:hover {
    background-color: #fed7aa !important;
}
.row-success {
    background-color: #ecfdf5 !important; /* bg-emerald-50 */
}
.row-success:hover {
    background-color: #d1fae5 !important; /* bg-emerald-100 */
}

.input-sm {
    padding: 5px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    width: 80px;
}

/* Cards (Caja) */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.card {
    background: var(--bg-white);
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border-top: 4px solid var(--border-color);
}

.card h3 {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.card .amount {
    font-size: 2rem;
    font-weight: bold;
    color: var(--text-main);
}

.card-success { border-top-color: var(--success); }
.card-danger { border-top-color: var(--danger); }
.card-info { border-top-color: var(--primary); }

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
}

.modal.show { display: flex; }

/* Modal stacked on top of another modal (e.g. mapa-pin sobre modal-cliente) */
.modal-top {
    z-index: 9999;
}

.modal-content {
    background-color: var(--bg-white);
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    animation: fadeIn 0.3s;
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.modal-body { padding: 20px; }
.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: var(--sidebar-bg);
    color: white;
    padding: 12px 24px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 99999;
}
.toast.show { opacity: 1; }

/* Leaflet map inside modal */
#modal-pin-map .leaflet-container {
    border-radius: 0;
}
#modal-pin-map {
    position: relative;
    z-index: 0;
}

/* Sidebar Footer & Logout */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--sidebar-hover);
    background-color: rgba(15, 23, 42, 0.6);
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-user-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: #cbd5e1;
}

.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #1d4ed8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-user-details {
    overflow: hidden;
    line-height: 1.2;
}

.sidebar-user-name {
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.72rem;
    color: #94a3b8;
    text-transform: uppercase;
}

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background-color: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.25);
    padding: 8px 12px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
    transition: all 0.2s;
    cursor: pointer;
}

.btn-logout:hover {
    background-color: var(--danger);
    color: white;
    border-color: var(--danger);
}

